-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChartsWidget.cpp
101 lines (80 loc) · 2.85 KB
/
ChartsWidget.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "ChartsWidget.h"
#include "ui_ChartsWidget.h"
ChartsWidget::ChartsWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ChartsWidget)
{
ui->setupUi(this);
}
ChartsWidget::~ChartsWidget()
{
delete this->ui;
}
QVBoxLayout *ChartsWidget::getChartVBoxLayout()
{
return this->ui->chartVBoxLayout;
}
int ChartsWidget::getGraphCount()
{
return this->graphcount;
}
void ChartsWidget::stopAllRepainters(bool quitInProgress)
{
this->quitInProgress = quitInProgress;
QVBoxLayout *vboxlayout = this->ui->chartVBoxLayout;
int c = this->graphcount;
int cr = (c == 1) ? 1 : static_cast<int>(ceil(c/2));
for (int i = 0; i < cr; i++) {
QSplitter *w = static_cast<QSplitter *>(vboxlayout->itemAt(i%2)->widget());
if (w->count() > 0) {
ChartWrapper *wr1 = static_cast<ChartWrapper *>(w->widget(0));
emit stoppedFromParent(wr1->getRepainter());
if (w->count() > 1) {
ChartWrapper *wr2 = static_cast<ChartWrapper *>(w->widget(1));
emit stoppedFromParent(wr2->getRepainter());
}
}
}
}
void ChartsWidget::chartRepainterStopped(ChartRepainter *repainter)
{
QSplitter *splitter = static_cast<QSplitter *>(repainter->getParent()->parent());
ChartWrapper *w = static_cast<ChartWrapper *>(repainter->getParent());
this->ui->chartVBoxLayout->removeWidget(w);
delete w;
this->graphcount--;
if (splitter->count() == 0)
delete splitter;
if (this->quitInProgress && this->graphcount == 0)
emit quitReady();
}
void ChartsWidget::addGraph(GPU *gpu, int xAxisTicks, int yAxisTicks, unsigned long refreshMS,
QString caption, QString monitorValue)
{
QVBoxLayout *vboxlayout = this->ui->chartVBoxLayout;
int c = this->graphcount;
int x = c % 2;
int y = c / 2;
QSplitter *splitter = nullptr;
if (x == 0) {
splitter = new QSplitter(this);
vboxlayout->addWidget(splitter);
vboxlayout->setStretchFactor(splitter, 1);
} else {
splitter = static_cast<QSplitter *>(vboxlayout->itemAt(y)->widget());
}
splitter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
ChartWrapper *dia = new ChartWrapper(this, gpu, xAxisTicks, yAxisTicks, refreshMS, caption,
monitorValue);
splitter->addWidget(dia);
connect(dia, SIGNAL(chartRepainterStopped(ChartRepainter*)), this,
SLOT(chartRepainterStopped(ChartRepainter*)));
splitter->addWidget(dia);
this->graphcount++;
int layoutheight = (static_cast<QWidget *>(this->parent()))->geometry().height();
for (int i = 0; i < c; i++) {
if (i % 2 == 0)
vboxlayout->itemAt(i%2)->widget()->setFixedHeight(layoutheight/graphcount);
}
QThreadPool::globalInstance()->start(dia->getRepainter());
}