This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
87 lines (74 loc) · 1.9 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dao.h"
#include "threaddao.h"
#include "sleeperthread.h"
#include "QProgressIndicator.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
pi(new QProgressIndicator(this)),
td(*pi)
{
ui->setupUi(this);
QVBoxLayout* vbl = new QVBoxLayout(ui->pushButton);
vbl->addWidget(pi, 0, Qt::AlignCenter);
td.start();
}
MainWindow::~MainWindow()
{
td.stopThread();
delete ui;
}
void MainWindow::on_btnSendQuery_clicked()
{
// usage of database access
QString query("SELECT * FROM table1");
// prepare lambda "how to freeze" and "how to unfreeze"
// specialized on GUI interaction
func freeze = [this] (void)
{
qDebug() << " # in lambda \"freeze GUI\"";
setGuiEnabled(false);
};
func unfreeze = [this] (void)
{
qDebug() << " # in lambda \"unfreeze GUI\"";
setGuiEnabled(true);
};
DAO concreteDao;
concreteDao.applyQuery(query, freeze, unfreeze);
}
void MainWindow::setGuiEnabled(bool enabled)
{
ui->btnSendQuery->setEnabled(enabled);
if (enabled)
{
ui->lblStatus->setText("Idle");
} else {
ui->lblStatus->setText("Working too long");
}
}
void MainWindow::on_pushButton_clicked()
{
qDebug() << "\t in on_pushButton_clicked";
int intValue = 0;
td.callSync(
// lambda goes here
[this, &intValue] (void)
{
qDebug() << "\t in lambda";
QString temp;
for (int i=1; i<300; ++i)
{
temp.append(QString::number(i*i / (i+1), 'f', 1));
SleeperThread::msSleep(10);
}
intValue = 42;
qDebug() << "\t lambda ends" << temp;
},
*ui->pushButton);
qDebug() << "After calling lambda: " << intValue;
ui->pushButton->setText(QString::number(intValue));
}