-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlineform.cpp
More file actions
238 lines (200 loc) · 8.14 KB
/
Copy pathlineform.cpp
File metadata and controls
238 lines (200 loc) · 8.14 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "lineform.h"
#include "ui_lineform.h"
LineForm::LineForm(QWidget *parent, QWidget *mainWidget, int id, QCustomPlot* plotParent, QCPAxisRect *axesRectParent) :
QWidget(parent),
ui(new Ui::LineForm)
{
ui->setupUi(this);
lineProperties.id = id;
defaultLineProperties();
tab = parent;
plot = plotParent;
axesRect = axesRectParent;
widget = mainWidget;
// GRAPH
// graph = new QCPGraph(axesRect->axis(QCPAxis::atBottom), axesRect->axis(QCPAxis::atLeft));
// graph->setPen(lineProperties.pen);
// plot->addPlottable(graph);
// CURVE
curve = new QCPCurve(axesRect->axis(QCPAxis::atBottom), axesRect->axis(QCPAxis::atLeft));
// curve = new QCPGraph(axesRect->axis(QCPAxis::atBottom), axesRect->axis(QCPAxis::atLeft));
curve->setPen(lineProperties.pen);
// curve->setLineStyle(QCPGraph::lsStepLeft);
plot->addPlottable(curve);
// POINT
point = new QCPGraph(axesRect->axis(QCPAxis::atBottom), axesRect->axis(QCPAxis::atLeft));
point->setPen(lineProperties.pen);
point->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 5));
plot->addPlottable(point);
// STYLING THE COLOR BUTTON
QString qss = QString("background-color: %1").arg(lineProperties.pen.color().name()) + ";border-style: outset;border-width: 2px;border-radius: 10px;border-color: white;";
ui->pushButton_color->setStyleSheet(qss);
connect(mainWidget, SIGNAL(newDataAvailable(QVector<QVector<double>>const &)), this, SLOT(processNewData(QVector<QVector<double>>const &)));
// LINESTYLE SETUP
int iconWidth = 50;
int iconHeight = 1;
ui->comboBox_style->setIconSize(QSize(iconWidth, iconHeight));
QList<QString> lineStyleNames;
lineStyleNames << "none" << "solid" << "dash" << "dot" << "dash dot" << "dash dot dot";
for (int lineStyle = Qt::NoPen; lineStyle < Qt::CustomDashLine; lineStyle++)
{
QPixmap pix(iconWidth, iconHeight);
pix.fill(Qt::white);
QBrush brush(Qt::black);
QPen pen(brush, 1, (Qt::PenStyle)lineStyle);
QPainter painter(&pix);
painter.setPen(pen);
painter.drawLine(0, iconHeight/2, iconWidth, iconHeight/2);
ui->comboBox_style->addItem(QIcon(pix), lineStyleNames.at(lineStyle));
}
ui->comboBox_style->setCurrentIndex(1);
// LINE WIDTH
iconHeight = 6;
ui->comboBox_width->setIconSize(QSize(iconWidth, iconHeight));
for (int width = 1; width < 6; width++)
{
QPixmap pix(iconWidth, iconHeight);
pix.fill(Qt::white);
QBrush brush(Qt::black);
QPen pen(brush, (double)width, Qt::SolidLine);
QPainter painter(&pix);
painter.setPen(pen);
painter.drawLine(0, iconHeight/2, iconWidth, iconHeight/2);
ui->comboBox_width->addItem(QIcon(pix),QString::number(width));
}
// LIMIT LAST
ui->checkBox_limitLen->setChecked(false);
// POINT STYLE
pointShapes << QCPScatterStyle::ssCustom;
pointShapes << QCPScatterStyle::ssCross;
pointShapes << QCPScatterStyle::ssPlus;
pointShapes << QCPScatterStyle::ssCircle;
pointShapes << QCPScatterStyle::ssDisc;
pointShapes << QCPScatterStyle::ssSquare;
pointShapes << QCPScatterStyle::ssDiamond;
pointShapes << QCPScatterStyle::ssStar;
pointShapes << QCPScatterStyle::ssTriangle;
pointShapes << QCPScatterStyle::ssTriangleInverted;
pointShapes << QCPScatterStyle::ssCrossSquare;
pointShapes << QCPScatterStyle::ssPlusSquare;
pointShapes << QCPScatterStyle::ssCrossCircle;
pointShapes << QCPScatterStyle::ssPlusCircle;
pointShapes << QCPScatterStyle::ssPeace;
for(int i=0; i<pointShapes.count(); i++) {
QCPScatterStyle ss = pointShapes.at(i);
ss.setSize(10);
QPixmap pm(14, 14);
QCPPainter qp(&pm);
qp.fillRect(0, 0, 14, 14, QBrush(Qt::white, Qt::SolidPattern));
ss.applyTo(&qp, QPen(Qt::black));
ss.drawShape(&qp, 7, 7);
QIcon icon = QIcon(pm);
ui->comboBox_pointShape->addItem(icon, "");
}
ui->comboBox_pointShape->setCurrentIndex(4);
xWindow = 5.0;
}
LineForm::~LineForm()
{
delete ui;
}
const linePropertiesT & LineForm::getLineProperties(){
return lineProperties;
}
void LineForm::defaultLineProperties(){
lineProperties.pen.setWidth(1);
lineProperties.pen.setStyle(Qt::SolidLine);
//// default color = blue
//lineProperties.pen.setColor(Qt::blue);
//// random first color
//QStringList colorNames = QColor::colorNames();
//qsrand(time(NULL));
//lineProperties.color = colorNames.at(qrand() % (colorNames.length() + 1));
//// list for standard first color cicling
QList<QColor> basicColors({Qt::blue, Qt::red, Qt::green, Qt::black, Qt::magenta});
lineProperties.pen.setColor(basicColors.at((lineProperties.id - 1) % basicColors.length()));
lineProperties.xIndex = 1;
lineProperties.yIndex = 2;
}
void LineForm::on_pushButton_color_clicked()
{
QColor color = QColorDialog::getColor(lineProperties.pen.color());
if(color.isValid()) {
lineProperties.pen.setColor(color);
QString qss = QString("background-color: %1").arg(color.name()) + ";border-style: outset;border-width: 2px;border-radius: 10px;border-color: white;";
ui->pushButton_color->setStyleSheet(qss);
// graph->setPen(lineProperties.pen);
curve->setPen(lineProperties.pen);
point->setPen(lineProperties.pen);
}
}
void LineForm::on_spinBox_xIndex_valueChanged(int arg1)
{
// graph->clearData();
curve->clearData();
lineProperties.xIndex = arg1;
}
void LineForm::on_spinBox_yIndex_valueChanged(int arg1)
{
// graph->clearData();
curve->clearData();
lineProperties.yIndex = arg1;
}
void LineForm::processNewData(const QVector<QVector<double> > &data) {
// qDebug() << "updateing line " << lineProperties.id;
unsigned int numData = data.length();
if(lineProperties.xIndex <= numData && lineProperties.yIndex <= numData) {
// graph->addData(data[lineProperties.xIndex - 1], data[lineProperties.yIndex - 1]);
//// CURVE
curve->addData(data[0], data[lineProperties.xIndex - 1], data[lineProperties.yIndex - 1]);
if(ui->checkBox_limitLen->isChecked()) {
curve->removeDataBefore(data[0].last() - ui->doubleSpinBox_limitLen->value());
}
point->setData(data[lineProperties.xIndex - 1].mid(data[0].length()-1), data[lineProperties.yIndex - 1].mid(data[0].length()-1));
} else {
ui->spinBox_xIndex->setMaximum(numData);
ui->spinBox_yIndex->setMaximum(numData);
}
//// ALIGNMENT
QList<QCheckBox*> scrollSettings = tab->findChildren<QCheckBox*>();
if( scrollSettings.at(0)->isChecked() ) {
axesRect->axis(QCPAxis::atBottom)->setRange(data[lineProperties.xIndex - 1].last() + xWindow*0.1 - xWindow , data[lineProperties.xIndex - 1].last() + xWindow*0.1);
} else if (scrollSettings.at(1)->isChecked()) {
curve->rescaleKeyAxis();
}
if( scrollSettings.at(2)->isChecked() ) {
axesRect->axis(QCPAxis::atLeft)->setRange(data[lineProperties.yIndex - 1].last() + yWindow*0.1, data[lineProperties.yIndex - 1].last() - yWindow + yWindow*0.1);
} else if (scrollSettings.at(3)->isChecked()) {
curve->rescaleValueAxis();
}
}
void LineForm::on_comboBox_style_currentIndexChanged(int index)
{
lineProperties.pen.setStyle(Qt::PenStyle(index));
curve->setPen(lineProperties.pen);
}
void LineForm::on_comboBox_width_currentIndexChanged(int index)
{
lineProperties.pen.setWidth(index+1);
curve->setPen(lineProperties.pen);
}
void LineForm::on_checkBox_limitLen_toggled(bool checked)
{
ui->doubleSpinBox_limitLen->setEnabled(checked);
ui->label_style_limitLen->setEnabled(checked);
}
void LineForm::on_comboBox_pointShape_currentIndexChanged(int index)
{
point->setScatterStyle(QCPScatterStyle(pointShapes.at(index), 5));
}
void LineForm::xWindowChanged(int value){
xWindow = value/100.0;
}
void LineForm::yWindowChanged(int value){
yWindow = value/100.0;
}
void LineForm::clearPlot() {
// qDebug() << "LineForm::clearPlot()";
curve->clearData();
point->clearData();
}