Commit 3f9a331e authored by Michael Reeves's avatar Michael Reeves

Avoid unessarcy EventLoop nesting.

EventLoops are a very expensive use of stack memmory. Additionally
deep nesting as was done in ProgressDialog can cause all sorts fun
problems. Only one loop is needed for the dialog itself to emulate exec.
To reenter it use EventLoop::ProcessEvents not a new event loop. Cancel now works without crashing.
parent 4a8cbc61
......@@ -13,11 +13,13 @@
#include "common.h"
#include <QApplication>
#include <QEventLoop>
#include <QLabel>
#include <QPointer>
#include <QProgressBar>
#include <QPushButton>
#include <QStatusBar>
#include <QTimer>
#include <QThread>
#include <QVBoxLayout>
......@@ -274,11 +276,16 @@ void ProgressDialog::enterEventLoop(KJob* pJob, const QString& jobInfo)
show();
// instead of using exec() the eventloop is entered and exited often without hiding/showing the window.
QPointer<QEventLoop> pEventLoop = QPointer<QEventLoop>(new QEventLoop(this));
m_eventLoopStack.push_back(pEventLoop);
pEventLoop->exec(); // this function only returns after ProgressDialog::exitEventLoop() is called.
pEventLoop.clear();
m_eventLoopStack.pop_back();
if(m_eventLoop == nullptr)
{
m_eventLoop = QPointer<QEventLoop>(new QEventLoop(this));
m_eventLoop->exec(); // this function only returns after ProgressDialog::exitEventLoop() is called.
m_eventLoop.clear();
}
else
{
m_eventLoop->processEvents(QEventLoop::WaitForMoreEvents);
}
}
void ProgressDialog::exitEventLoop()
......@@ -287,8 +294,8 @@ void ProgressDialog::exitEventLoop()
killTimer(m_progressDelayTimer);
m_progressDelayTimer = 0;
m_pJob = nullptr;
if(!m_eventLoopStack.empty())
m_eventLoopStack.back()->exit();
if( m_eventLoop != nullptr)
m_eventLoop->exit();
}
void ProgressDialog::recalc(bool bUpdate)
......@@ -339,7 +346,6 @@ void ProgressDialog::recalc(bool bUpdate)
}
}
#include <QTimer>
void ProgressDialog::show()
{
if(m_progressDelayTimer)
......@@ -438,6 +444,8 @@ void ProgressDialog::cancel(e_CancelReason eCancelReason)
{
m_bWasCancelled = true;
m_eCancelReason = eCancelReason;
if(m_eventLoop != nullptr)
m_eventLoop->exit(1);
}
}
......
......@@ -14,6 +14,7 @@
#define PROGRESS_H
#include <QDialog>
#include <QPointer>
#include <QTime>
#include <QList>
......@@ -84,7 +85,7 @@ private:
int m_progressDelayTimer;
int m_delayedHideTimer;
int m_delayedHideStatusBarWidgetTimer;
QList<QEventLoop*> m_eventLoopStack;
QPointer<QEventLoop> m_eventLoop;
QProgressBar* m_pProgressBar;
QProgressBar* m_pSubProgressBar;
......@@ -96,7 +97,7 @@ private:
QTime m_t2;
bool m_bWasCancelled;
e_CancelReason m_eCancelReason;
KJob* m_pJob;
KJob* m_pJob = nullptr;
QString m_currentJobInfo; // Needed if the job doesn't stop after a reasonable time.
bool m_bStayHidden;
QThread* m_pGuiThread;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment