Skip to content
Snippets Groups Projects
Commit 77f31348 authored by Silas Dohm's avatar Silas Dohm
Browse files

removed sleep, delay no longer blocks event loop

parent 8d5394b7
Branches
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSpacerItem>
#include <QTimer>
Window::Window(QWidget *parent)
: QWidget{parent}
......@@ -85,7 +86,7 @@ void Window::solveButtonClicked()
while (1)
{
repaint(); // draw cells again
QThread::msleep(m_delay);
delay(m_delay);
if (backtracking)
{
hist.back()->cell->un();
......@@ -97,7 +98,7 @@ void Window::solveButtonClicked()
backtracking = false;
int choiceNr = rand() % hist.back()->index.size(); // choose a random number;
repaint(); // draw cells again
QThread::msleep(m_delay);
delay(m_delay);
hist.back()->cell->collapse(hist.back()->index[choiceNr]); // collapse cell with chosen number;
std::vector<int>::iterator it;
it = hist.back()->index.begin() + choiceNr;
......@@ -145,7 +146,14 @@ void Window::solveButtonClicked()
}
// qInfo("%d---:)");
}
inline void Window::delay(int millisecondsWait)
{
QEventLoop loop;
QTimer t;
t.connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit);
t.start(millisecondsWait);
loop.exec();
}
void Window::clearButtonClicked()
{
for (auto &x : m_cell)
......
......@@ -35,6 +35,7 @@ private:
}
}
};
inline void delay(int millisecondsWait);
signals:
void counterReached();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment