Make the font restoration counters safe against nested project loads

DialogWaiting pumps the event loop while the folios of a project are
built, so a second openAndAddProject() can run to completion nested
inside the first one (drop on another editor window, queued open) and
the plain reset/read counters would then report the wrong numbers.

Replace them with a RAII counting window (FontRestorationScope): the
constructor keeps the enclosing counts aside, the destructor restores
them. The nesting is strictly LIFO - the nested load completes inside
the pump of the outer one - so each load reports exactly its own
numbers, and the early-return paths of openAndAddProject() restore the
outer window automatically.

Suggested by ispyisail in the review of the reporting change.
This commit is contained in:
Dieter Mayer
2026-08-01 11:13:57 +02:00
parent 0fa2591c4f
commit 3bc2e8e712
3 changed files with 49 additions and 18 deletions
+23 -3
View File
@@ -34,9 +34,29 @@ namespace QETUtils
void pixelSizedFont (QFont &font);
QString fontToString (const QFont &font);
bool fontFromString (QFont &font, const QString &description);
void resetFontRestorationCounters ();
int salvagedFontCount ();
int unreadableFontCount ();
/**
RAII counting window for the font descriptions fontFromString()
salvages or fails to read: construction opens a fresh window, the
destructor restores the enclosing one. Windows nest strictly LIFO,
which covers project loads re-entered through the event loop
(DialogWaiting pumps it while the folios are built).
*/
class FontRestorationScope
{
public:
FontRestorationScope();
~FontRestorationScope();
FontRestorationScope(const FontRestorationScope &) = delete;
FontRestorationScope &operator=(const FontRestorationScope &) = delete;
int salvaged() const;
int unreadable() const;
private:
int m_outer_salvaged;
int m_outer_unreadable;
};
bool sortBeginIntString(const QString &str_a, const QString &str_b);