mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-19 12:34:15 +02:00
Terminal block manager: show the folios being read, stay responsive
Linux build and tests / Build and test (Qt 6, Debug) (push) Failing after 1m41s
Linux build and tests / Build and test (Qt 6, Debug) (push) Failing after 1m41s
Opening the terminal block manager builds the folios not built yet (lazy folios). This is done in one go without running the event loop, so the window system said the opening message was "not responding". - QETProject::setFolioBuildObserver(): a function called after each folio built by buildFolios(), with the number of folios built and to build. - The manager uses it to show "Reading folio n of N..." with a real progress bar, and runs the event loop (without the user input) between two folios, so the window system keeps getting answers. - The autosave skips its turn while folios are being built, since the event loop can now run then. - The opening message only has a title bar: nothing to minimize, maximize or close.
This commit is contained in:
+33
-1
@@ -407,6 +407,11 @@ void QETProject::init()
|
||||
m_autosave_timer.setInterval(ms);
|
||||
connect(&m_autosave_timer, &QTimer::timeout, this, [this]()
|
||||
{
|
||||
//Not while folios are being built (the event loop can run
|
||||
//then, see setFolioBuildObserver()) : the next time
|
||||
if (this->m_state == ProjectParsingRunning) {
|
||||
return;
|
||||
}
|
||||
if(!this->m_file_path.isEmpty())
|
||||
{
|
||||
//No one is there to ask: a file changed behind this
|
||||
@@ -762,6 +767,18 @@ void QETProject::loadFolios() const
|
||||
buildFolios(m_diagrams_list);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::setFolioBuildObserver
|
||||
@p observer is called after each folio built by buildFolios(), with the
|
||||
number of folios built so far and the number to build : a long build
|
||||
can show its progress, and keep the window system answered by running
|
||||
the event loop (without the user input) in @p observer. The autosave
|
||||
waits meanwhile. An empty function removes the observer.
|
||||
*/
|
||||
void QETProject::setFolioBuildObserver(std::function<void (int, int)> observer) {
|
||||
m_folio_build_observer = std::move(observer);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::buildFolios
|
||||
Build those of @p folios still waiting, as opening builds them: all
|
||||
@@ -785,8 +802,23 @@ void QETProject::buildFolios(const QList<Diagram *> &folios) const
|
||||
const bool signals_were_blocked = self->m_data_base.signalsBlocked();
|
||||
self->m_data_base.blockSignals(true);
|
||||
QList<Diagram *> built;
|
||||
int waiting_ = 0;
|
||||
if (m_folio_build_observer) {
|
||||
for (Diagram *d : folios)
|
||||
if (!d->isLoaded()) ++waiting_;
|
||||
}
|
||||
for (Diagram *d : folios)
|
||||
if (d->buildDeferred()) built << d;
|
||||
{
|
||||
if (d->buildDeferred())
|
||||
{
|
||||
built << d;
|
||||
//Someone shows the progress (a long build, opening the
|
||||
//terminal block manager...)
|
||||
if (m_folio_build_observer) {
|
||||
m_folio_build_observer(built.size(), waiting_);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Diagram *d : std::as_const(built))
|
||||
self->folioLoaded(d);
|
||||
self->m_data_base.blockSignals(signals_were_blocked);
|
||||
|
||||
Reference in New Issue
Block a user