-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathResponseWidget.cpp
More file actions
172 lines (134 loc) · 4.19 KB
/
ResponseWidget.cpp
File metadata and controls
172 lines (134 loc) · 4.19 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
#include "ResponseWidget.h"
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <MainWindow.h>
#include <QSpinBox>
#include <qcustomplot.h>
ResponseWidget::ResponseWidget(MainWindow *mainWindow,
int mainItem,
QString &label,
QString &xLabel,
QString &yLabel,
QWidget *parent)
: QWidget(parent), theItem(0), mainWindowItem(mainItem), main(mainWindow)
{
// create a main layout
QVBoxLayout *mainLayout = new QVBoxLayout();
//
// spin box
//
dataSET = false;
theSpinBox = new QSpinBox();
theSpinBox->setMinimum(1);
theSpinBox->setMaximum(99);
theSpinBox->setMinimumWidth(100);
QHBoxLayout *theSpinLayout = new QHBoxLayout();
QLabel *spinLabel = new QLabel(label);
theSpinLayout->addWidget(spinLabel);
theSpinLayout->addWidget(theSpinBox);
theSpinLayout->addStretch();
connect(theSpinBox,SIGNAL(valueChanged(int)), this, SLOT(itemEditChanged(int)));
mainLayout->addLayout(theSpinLayout);
//
// graphic window
//
thePlot=new QCustomPlot();
thePlot->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
QRect rec = QApplication::desktop()->screenGeometry();
int height = 0.2*rec.height();
int width = 0.5*rec.width();
thePlot->setMinimumWidth(width);
thePlot->setMinimumHeight(height);
mainLayout->addWidget(thePlot);
thePlot->xAxis->setLabel(xLabel);
thePlot->yAxis->setLabel(yLabel);
this->setLayout(mainLayout);
}
ResponseWidget::~ResponseWidget()
{
}
int
ResponseWidget::getItem() {
return theItem;
}
void
ResponseWidget::setItem(int newItem) {
theItem = newItem;
theSpinBox->setValue(newItem);
}
void
ResponseWidget::itemEditChanged(int theItem) {
if (dataSET == true)
main->setResponse(theItem, mainWindowItem);
}
void
ResponseWidget::setData(QVector<double> &data, QVector<double> &time, int numSteps, double dt, int index = -1) {
dataSET = false;
if (index != -1) {
theSpinBox->setSingleStep(1);
theSpinBox->setValue(index);
}
dataSET = true;
if (time.size() != data.size()) {
qDebug() << "ResponseWidget - setData vectors of differing sizes";
return;
}
if (time.size() != numSteps) {
qDebug() << "ResponseWidget - setData vector and step size do not agree";
return;
}
thePlot->clearGraphs();
graph = thePlot->addGraph();
thePlot->graph(0)->setData(time, data);
double minValue = 0;
double maxValue = 0;
for (int i=0; i<numSteps; i++) {
double value = data.at(i);
if (value < minValue)
minValue = value;
if (value > maxValue)
maxValue = value;
}
thePlot->xAxis->setRange(0, numSteps*dt);
thePlot->yAxis->setRange(minValue, maxValue);
//thePlot->axisRect()->setAutoMargins(QCP::msNone);
thePlot->axisRect()->setMargins(QMargins(0,0,0,0));
thePlot->replot();
}
void
ResponseWidget::setData(QVector<double> &data, QVector<double> &x, int numSteps, int index) {
dataSET = false;
if (index != -1) {
theSpinBox->setRange(1, main->getNumFloors());
theSpinBox->setValue(index);
}
dataSET = true;
thePlot->clearGraphs();
thePlot->clearPlottables();
curve = new QCPCurve(thePlot->xAxis, thePlot->yAxis);
curve->setData(x,data);
//thePlot->graph(0)->setData(x, data, true);
double minValue = 0;
double maxValue = 0;
double xMinValue = 0;
double xMaxValue = 0;
for (int i=0; i<numSteps; i++) {
double value = data.at(i);
double xValue = x.at(i);
if (value < minValue)
minValue = value;
if (value > maxValue)
maxValue = value;
if (xValue < xMinValue)
xMinValue = xValue;
if (xValue > xMaxValue)
xMaxValue = xValue;
}
thePlot->yAxis->setRange(minValue, maxValue);
thePlot->xAxis->setRange(xMinValue, xMaxValue);
//thePlot->axisRect()->setAutoMargins(QCP::msNone);
// thePlot->axisRect()->setMargins(QMargins(0,0,0,0));
thePlot->replot();
}