Settings: only write the prefix rows that were edited

Review findings on the prefix editor:

- OK without touching anything changed the file: every row was written
  back, so an explicit <prefix/>, which reads as an empty field and
  cancels the inheritance, was dropped and that folder started
  inheriting its parent's prefix again. A row is now written only when
  it was edited or no longer holds what the file has, and the two kinds
  of empty field look different: hasPrefix() tells an explicit
  <prefix/> from a missing one, which is what the field hint shows.
- load() copied a broken file aside before the user had chosen
  anything, so every "Corriger le fichier" left a .bak behind while the
  message said nothing had been modified. The copy is now made by
  save(), right before the file is replaced: repairing or cancelling
  leaves nothing behind, and a copy that cannot be made stops the write
  rather than destroying the only copy.
- The button followed the combo box only for "Parcourir...": put back
  on "Par defaut" it fell back to the previously saved path instead of
  the default one. The directory of the entry being displayed is now
  used, "Par defaut" being dataDir()/elements/.
This commit is contained in:
Kellermorph
2026-09-30 11:01:31 +02:00
parent 03bffa96c7
commit 1d339a8b27
4 changed files with 104 additions and 36 deletions
+5 -2
View File
@@ -61,6 +61,7 @@ class QetLabelsFile
bool load(const QString &collection_dir);
QString prefix(const QStringList &relative_path) const;
bool hasPrefix(const QStringList &relative_path) const;
QStringList orphanPaths(const QList<QStringList> &folders) const;
void ensureStructure(const QList<QStringList> &folders);
void setPrefix(const QStringList &relative_path, const QString &prefix);
@@ -70,8 +71,10 @@ class QetLabelsFile
QString filePath() const {return m_file_path;}
QString backupPath() const {return m_backup_path;}
QString errorString() const {return m_error;}
///true when the existing file was found unusable and had to
///be backed up before an empty document was used instead
///true when the existing file was found unusable and an
///empty document is used instead. Its copy is only made by
///save(), right before the file is replaced, so repairing
///the file instead of rebuilding it leaves no copy behind
bool isBroken() const {return m_broken;}
///what exactly is wrong with that file (line and column of
///the syntax error for instance), so the caller can tell the