-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubplottab.cpp
More file actions
179 lines (150 loc) · 5.82 KB
/
Copy pathsubplottab.cpp
File metadata and controls
179 lines (150 loc) · 5.82 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "subplottab.h"
#include "ui_subplottab.h"
SubplotTab::SubplotTab(QWidget *parent, int id, QCustomPlot* plotParent) :
QWidget(parent),
ui(new Ui::SubplotTab)
{
ui->setupUi(this);
mainWidget = parent;
_id = id;
plot = plotParent;
axesRect = new QCPAxisRect(plot);
plot->plotLayout()->addElement(id-1, 0, axesRect);
plot->replot();
ui->checkBox_scrollX->setChecked(true);
ui->checkBox_resizeY->setChecked(true);
connect(plot, SIGNAL(selectionChangedByUser()), this, SLOT(selectionChanged()));
connect(plot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress()));
connect(plot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel()));
addLine();
enableDisableXWindow(ui->checkBox_scrollX->isChecked());
enableDisableYWindow(ui->checkBox_scrollY->isChecked());
ui->horizontalSlider_xWindow->setValue(500);
ui->horizontalSlider_yWindow->setValue(500);
}
SubplotTab::~SubplotTab()
{
delete ui;
}
int SubplotTab::id() {
return _id;
}
void SubplotTab::addLine() {
int nLines = countLines();
LineForm* newLine = new LineForm(this, mainWidget, nLines+1, plot, axesRect);
connect(ui->horizontalSlider_xWindow, SIGNAL(valueChanged(int)), newLine, SLOT(xWindowChanged(int)));
connect(ui->horizontalSlider_yWindow, SIGNAL(valueChanged(int)), newLine, SLOT(yWindowChanged(int)));
newLine->setObjectName("LineForm_" + QString::number(nLines + 1));
newLine->findChildren<QGroupBox*>().first()->setTitle("Line " + QString::number(nLines + 1));
ui->verticalLayout_2->insertWidget(nLines, newLine);
}
void SubplotTab::removeLine() {
QWidget* toRemove = this->findChildren<LineForm*>().last();
ui->verticalLayout_2->removeWidget(toRemove);
delete toRemove;
}
void SubplotTab::clearPlot() {
// qDebug() << "SubplotTab::clearPlot()";
QList<LineForm*> toclear_list = this->findChildren<LineForm*>();
// qDebug() << toclear_list;
QListIterator<LineForm*> toclear_it(toclear_list);
while (toclear_it.hasNext()) {
LineForm* toclear = toclear_it.next();
toclear->clearPlot();
}
}
void SubplotTab::on_spinBox_numberLines_valueChanged(int arg1)
{
int nlines = countLines();
if(nlines < arg1) {
for(int i = nlines; i < arg1; i++) {
addLine();
}
} else {
for(int i = nlines; i > arg1; i--) {
removeLine();
}
}
}
int SubplotTab::countLines() {
return ui->verticalLayout_2->count();
}
void SubplotTab::on_checkBox_scrollX_toggled(bool checked)
{
ui->checkBox_resizeX->setEnabled(!checked);
enableDisableXWindow(checked);
}
void SubplotTab::on_checkBox_resizeX_toggled(bool checked)
{
ui->checkBox_scrollX->setEnabled(!checked);
}
void SubplotTab::on_checkBox_scrollY_toggled(bool checked)
{
ui->checkBox_resizeY->setEnabled(!checked);
enableDisableYWindow(checked);
}
void SubplotTab::on_checkBox_resizeY_toggled(bool checked)
{
ui->checkBox_scrollY->setEnabled(!checked);
}
void SubplotTab::selectionChanged() {
if (axesRect->axis(QCPAxis::atBottom, 0)->selectedParts().testFlag(QCPAxis::spAxis) || axesRect->axis(QCPAxis::atBottom, 0)->selectedParts().testFlag(QCPAxis::spTickLabels)) {
axesRect->axis(QCPAxis::atBottom, 0)->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
}
if (axesRect->axis(QCPAxis::atLeft, 0)->selectedParts().testFlag(QCPAxis::spAxis) || axesRect->axis(QCPAxis::atLeft, 0)->selectedParts().testFlag(QCPAxis::spTickLabels)) {
axesRect->axis(QCPAxis::atLeft, 0)->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
}
}
void SubplotTab::mousePress() {
if (axesRect->axis(QCPAxis::atBottom, 0)->selectedParts().testFlag(QCPAxis::spAxis) && !axesRect->axis(QCPAxis::atLeft, 0)->selectedParts().testFlag(QCPAxis::spAxis)) {
axesRect->setRangeDrag(Qt::Horizontal);
} else if (axesRect->axis(QCPAxis::atLeft, 0)->selectedParts().testFlag(QCPAxis::spAxis) && !axesRect->axis(QCPAxis::atBottom, 0)->selectedParts().testFlag(QCPAxis::spAxis)) {
axesRect->setRangeDrag(Qt::Vertical);
} else {
axesRect->setRangeDrag(Qt::Horizontal|Qt::Vertical);
}
}
void SubplotTab::mouseWheel() {
if (axesRect->axis(QCPAxis::atBottom, 0)->selectedParts().testFlag(QCPAxis::spAxis) && !axesRect->axis(QCPAxis::atLeft, 0)->selectedParts().testFlag(QCPAxis::spAxis)) {
axesRect->setRangeZoom(Qt::Horizontal);
} else if (axesRect->axis(QCPAxis::atLeft, 0)->selectedParts().testFlag(QCPAxis::spAxis) && !axesRect->axis(QCPAxis::atBottom, 0)->selectedParts().testFlag(QCPAxis::spAxis)) {
axesRect->setRangeZoom(Qt::Vertical);
} else {
axesRect->setRangeZoom(Qt::Horizontal|Qt::Vertical);
}
}
void SubplotTab::enableDisableXWindow(bool state){
for(int i = 0; i<ui->horizontalLayout_xWindow->count(); i++) {
QWidget* w = ui->horizontalLayout_xWindow->itemAt(i)->widget();
if(w) {
w->setEnabled(state);
}
}
}
void SubplotTab::enableDisableYWindow(bool state){
for(int i = 0; i<ui->horizontalLayout_yWindow->count(); i++) {
QWidget* w = ui->horizontalLayout_yWindow->itemAt(i)->widget();
if(w) {
w->setEnabled(state);
}
}
}
void SubplotTab::on_horizontalSlider_xWindow_valueChanged(int value)
{
ui->label_xWindow->setText(QString::number(value/100.0, 'f', 2) + "s");
}
void SubplotTab::on_horizontalSlider_yWindow_valueChanged(int value)
{
ui->label_yWindow->setText(QString::number(value/100.0, 'f', 2) + "s");
}
void SubplotTab::link_x_windows_check_changed(bool b) {
for(int i = 0; i<ui->horizontalLayout_xWindow->count(); i++) {
QWidget* w = ui->horizontalLayout_xWindow->itemAt(i)->widget();
if(w) {
w->setEnabled(!b);
}
}
}
void SubplotTab::link_x_windows_value_changed(int v) {
ui->horizontalSlider_xWindow->setValue(v);
}