mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-03 10:34:14 +02:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user