##// END OF EJS Templates
Improved zoom features on SocExplorer Plot.
jeandet -
r74:7e54838aea98 default
parent child
Show More
This diff has been collapsed as it changes many lines, (506 lines changed) Show them Hide them
@@ -3,199 +3,222
3
3
4
4
5 SocExplorerPlot::SocExplorerPlot(QWidget *parent) :
5 SocExplorerPlot::SocExplorerPlot(QWidget *parent) :
6 QWidget(parent)
6 QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this))
7 {
7 {
8 this->m_plot = new QCustomPlot(this);
8 this->m_plot = new QCustomPlot(this);
9 this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes |
9 this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes |
10 QCP::iSelectLegend | QCP::iSelectPlottables);
10 QCP::iSelectLegend | QCP::iSelectPlottables);
11 this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
11 this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
12 this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
12 this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
13 this->m_mainlayout = new QGridLayout(this);
13 this->m_mainlayout = new QGridLayout(this);
14 this->setLayout(this->m_mainlayout);
14 this->setLayout(this->m_mainlayout);
15 this->m_mainlayout->addWidget(this->m_plot);
15 this->m_mainlayout->addWidget(this->m_plot);
16 this->setMinimumSize(400,300);
16 this->setMinimumSize(400,300);
17 this->setFocusPolicy(Qt::WheelFocus);
17 this->setFocusPolicy(Qt::WheelFocus);
18 this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
18 this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
19 this->ctrl_hold = false;
19 this->ctrl_hold = false;
20 this->shift_hold = false;
20 this->shift_hold = false;
21 this->mouse_hold = false;
21 this->mouse_hold = false;
22 this->m_plot->setNoAntialiasingOnDrag(true);
22 this->m_plot->setNoAntialiasingOnDrag(true);
23 this->show();
23 this->show();
24 }
24
25
26 SocExplorerPlot::~SocExplorerPlot()
27 {
28 delete mRubberBand;
25 }
29 }
26
30
27 void SocExplorerPlot::show()
31 void SocExplorerPlot::show()
28 {
32 {
29 QWidget::show();
33 QWidget::show();
34 }
35
36 void SocExplorerPlot::replot()
37 {
38 this->m_plot->replot();
30 }
39 }
31
40
32 void SocExplorerPlot::setTitle(QString title)
41 void SocExplorerPlot::setTitle(QString title)
33 {
42 {
34 Q_UNUSED(title)
43 Q_UNUSED(title)
35 //this->m_plot->setTitle(title);
44 //this->m_plot->setTitle(title);
36 /*!
45 /*!
37 @todo Function borcken fixe this!
46 @todo Function borcken fixe this!
38 */
47 */
39 this->repaint();
48 this->repaint();
40 }
49 }
41
50
42 void SocExplorerPlot::setXaxisLabel(QString label)
51 void SocExplorerPlot::setXaxisLabel(QString label)
43 {
52 {
44 this->m_plot->xAxis->setLabel(label);
53 this->m_plot->xAxis->setLabel(label);
45 this->repaint();
54 this->repaint();
46 }
55 }
47
56
48 void SocExplorerPlot::setYaxisLabel(QString label)
57 void SocExplorerPlot::setYaxisLabel(QString label)
49 {
58 {
50 this->m_plot->yAxis->setLabel(label);
59 this->m_plot->yAxis->setLabel(label);
51 this->repaint();
60 this->repaint();
52 }
61 }
53
62
54 void SocExplorerPlot::setXaxisRange(double lower, double upper)
63 void SocExplorerPlot::setXaxisRange(double lower, double upper)
55 {
64 {
56 this->m_plot->xAxis->setRange(lower,upper);
65 this->m_plot->xAxis->setRange(lower,upper);
57 }
66 }
58
67
59 void SocExplorerPlot::setYaxisRange(double lower, double upper)
68 void SocExplorerPlot::setYaxisRange(double lower, double upper)
60 {
69 {
61 this->m_plot->yAxis->setRange(lower,upper);
70 this->m_plot->yAxis->setRange(lower,upper);
62 }
71 }
63
72
64
73
65 void SocExplorerPlot::rescaleAxis()
74 void SocExplorerPlot::rescaleAxis()
66 {
75 {
67 this->m_plot->rescaleAxes();
76 this->m_plot->rescaleAxes();
68 this->m_plot->replot();
77 this->m_plot->replot();
69 }
78 }
70
79
71 void SocExplorerPlot::setLegendFont(QFont font)
80 void SocExplorerPlot::setLegendFont(QFont font)
72 {
81 {
73 this->m_plot->legend->setFont(font);
82 this->m_plot->legend->setFont(font);
74 this->repaint();
83 this->repaint();
75 }
84 }
76
85
77 void SocExplorerPlot::setLegendSelectedFont(QFont font)
86 void SocExplorerPlot::setLegendSelectedFont(QFont font)
78 {
87 {
79 this->m_plot->legend->setSelectedFont(font);
88 this->m_plot->legend->setSelectedFont(font);
80 this->repaint();
89 this->repaint();
81 }
90 }
82
91
83 void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable)
92 void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable)
84 {
93 {
85 this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable);
94 this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable);
86 }
95 }
87
96
88 int SocExplorerPlot::addGraph()
97 int SocExplorerPlot::addGraph()
89 {
98 {
90 this->m_plot->addGraph();
99 this->m_plot->addGraph();
91 return this->m_plot->graphCount() -1;
100 return this->m_plot->graphCount() -1;
101 }
102
103 bool SocExplorerPlot::removeGraph(int graphIndex)
104 {
105 return this->m_plot->removeGraph(graphIndex);
106 }
107
108 void SocExplorerPlot::removeAllGraphs()
109 {
110 int graphCount=this->m_plot->graphCount();
111 for(int i=0;i<graphCount;i++)
112 {
113 this->m_plot->removeGraph(0);
114 }
92 }
115 }
93
116
94
117
95 void SocExplorerPlot::setGraphName(int graphIndex,QString name)
118 void SocExplorerPlot::setGraphName(int graphIndex,QString name)
96 {
119 {
97 if(graphIndex<this->m_plot->graphCount())
120 if(graphIndex<this->m_plot->graphCount())
98 {
121 {
99 this->m_plot->graph(graphIndex)->setName(name);
122 this->m_plot->graph(graphIndex)->setName(name);
100 }
123 }
101 }
124 }
102
125
103
126
104 void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
127 void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
105 {
128 {
106 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
129 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
107 {
130 {
108 QVector<double> _x(x.count()), _y(y.count());
131 QVector<double> _x(x.count()), _y(y.count());
109 for(int i=0;i<x.count();i++)
132 for(int i=0;i<x.count();i++)
110 {
133 {
111 /*_x[i] = x.at(i).value<double>();
134 /*_x[i] = x.at(i).value<double>();
112 _y[i] = y.at(i).value<double>();*/
135 _y[i] = y.at(i).value<double>();*/
113 _x[i] = x.at(i).toDouble();
136 _x[i] = x.at(i).toDouble();
114 _y[i] = y.at(i).toDouble();
137 _y[i] = y.at(i).toDouble();
115 }
138 }
116 this->m_plot->graph(graphIndex)->setData(_x,_y);
139 this->m_plot->graph(graphIndex)->setData(_x,_y);
117 }
140 }
118 this->m_plot->replot();
141 this->m_plot->replot();
119 }
142 }
120
143
121 void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
144 void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
122 {
145 {
123 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
146 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
124 {
147 {
125 QVector<double> _x(x.count()), _y(y.count());
148 QVector<double> _x(x.count()), _y(y.count());
126 for(int i=0;i<x.count();i++)
149 for(int i=0;i<x.count();i++)
127 {
150 {
128 /*_x[i] = x.at(i).value<double>();
151 /*_x[i] = x.at(i).value<double>();
129 _y[i] = y.at(i).value<double>();*/
152 _y[i] = y.at(i).value<double>();*/
130 _x[i] = x.at(i).toDouble();
153 _x[i] = x.at(i).toDouble();
131 _y[i] = y.at(i).toDouble();
154 _y[i] = y.at(i).toDouble();
132 }
155 }
133 this->m_plot->graph(graphIndex)->addData(_x,_y);
156 this->m_plot->graph(graphIndex)->addData(_x,_y);
134 }
157 }
135 this->m_plot->replot();
158 this->m_plot->replot();
136 }
159 }
137
160
138 void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y)
161 void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y)
139 {
162 {
140 if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double))
163 if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double))
141 {
164 {
142 this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble());
165 this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble());
143 }
166 }
144 this->m_plot->replot();
167 this->m_plot->replot();
145 }
168 }
146
169
147 void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen)
170 void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen)
148 {
171 {
149 if(graphIndex<this->m_plot->graphCount())
172 if(graphIndex<this->m_plot->graphCount())
150 {
173 {
151 this->m_plot->graph(graphIndex)->setPen(pen);
174 this->m_plot->graph(graphIndex)->setPen(pen);
152 }
175 }
153 }
176 }
154
177
155 QPen SocExplorerPlot::getGraphPen(int graphIndex)
178 QPen SocExplorerPlot::getGraphPen(int graphIndex)
156 {
179 {
157 if(graphIndex<this->m_plot->graphCount())
180 if(graphIndex<this->m_plot->graphCount())
158 {
181 {
159 return this->m_plot->graph(graphIndex)->pen();
182 return this->m_plot->graph(graphIndex)->pen();
160 }
183 }
161 return this->m_plot->graph()->pen();
184 return this->m_plot->graph()->pen();
162 }
185 }
163
186
164
187
165
188
166 void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle)
189 void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle)
167 {
190 {
168 if(graphIndex<this->m_plot->graphCount())
191 if(graphIndex<this->m_plot->graphCount())
169 {
192 {
170 if(!lineStyle.compare("none"))
193 if(!lineStyle.compare("none"))
171 {
194 {
172 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone);
195 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone);
173 return;
196 return;
174 }
197 }
175 if(!lineStyle.compare("line"))
198 if(!lineStyle.compare("line"))
176 {
199 {
177 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine);
200 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine);
178 return;
201 return;
179 }
202 }
180 if(!lineStyle.compare("stepleft"))
203 if(!lineStyle.compare("stepleft"))
181 {
204 {
182 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft);
205 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft);
183 return;
206 return;
184 }
207 }
185 if(!lineStyle.compare("stepright"))
208 if(!lineStyle.compare("stepright"))
186 {
209 {
187 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight);
210 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight);
188 return;
211 return;
189 }
212 }
190 if(!lineStyle.compare("stepcenter"))
213 if(!lineStyle.compare("stepcenter"))
191 {
214 {
192 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter);
215 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter);
193 return;
216 return;
194 }
217 }
195 if(!lineStyle.compare("impulse"))
218 if(!lineStyle.compare("impulse"))
196 {
219 {
197 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse);
220 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse);
198 return;
221 return;
199 }
222 }
200
223
201
224
@@ -204,166 +227,213 void SocExplorerPlot::setGraphLineStyle(
204
227
205 void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle)
228 void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle)
206 {
229 {
207 if(graphIndex<this->m_plot->graphCount())
230 if(graphIndex<this->m_plot->graphCount())
208 {
231 {
209 if(!scatterStyle.compare("none"))
232 if(!scatterStyle.compare("none"))
210 {
233 {
211 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone);
234 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone);
212 return;
235 return;
213 }
236 }
214 if(!scatterStyle.compare("dot"))
237 if(!scatterStyle.compare("dot"))
215 {
238 {
216 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot);
239 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot);
217 return;
240 return;
218 }
241 }
219 if(!scatterStyle.compare("cross"))
242 if(!scatterStyle.compare("cross"))
220 {
243 {
221 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross);
244 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross);
222 return;
245 return;
223 }
246 }
224 if(!scatterStyle.compare("plus"))
247 if(!scatterStyle.compare("plus"))
225 {
248 {
226 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus);
249 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus);
227 return;
250 return;
228 }
251 }
229 if(!scatterStyle.compare("circle"))
252 if(!scatterStyle.compare("circle"))
230 {
253 {
231 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle);
254 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle);
232 return;
255 return;
233 }
256 }
234 if(!scatterStyle.compare("disc"))
257 if(!scatterStyle.compare("disc"))
235 {
258 {
236 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc);
259 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc);
237 return;
260 return;
238 }
261 }
239 if(!scatterStyle.compare("square"))
262 if(!scatterStyle.compare("square"))
240 {
263 {
241 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare);
264 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare);
242 return;
265 return;
243 }
266 }
244 if(!scatterStyle.compare("diamond"))
267 if(!scatterStyle.compare("diamond"))
245 {
268 {
246 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond);
269 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond);
247 return;
270 return;
248 }
271 }
249 if(!scatterStyle.compare("star"))
272 if(!scatterStyle.compare("star"))
250 {
273 {
251 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar);
274 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar);
252 return;
275 return;
253 }
276 }
254 if(!scatterStyle.compare("triangle"))
277 if(!scatterStyle.compare("triangle"))
255 {
278 {
256 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle);
279 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle);
257 return;
280 return;
258 }
281 }
259 if(!scatterStyle.compare("invertedtriangle"))
282 if(!scatterStyle.compare("invertedtriangle"))
260 {
283 {
261 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted);
284 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted);
262 return;
285 return;
263 }
286 }
264 if(!scatterStyle.compare("crosssquare"))
287 if(!scatterStyle.compare("crosssquare"))
265 {
288 {
266 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare);
289 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare);
267 return;
290 return;
268 }
291 }
269 if(!scatterStyle.compare("plussquare"))
292 if(!scatterStyle.compare("plussquare"))
270 {
293 {
271 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare);
294 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare);
272 return;
295 return;
273 }
296 }
274 if(!scatterStyle.compare("crosscircle"))
297 if(!scatterStyle.compare("crosscircle"))
275 {
298 {
276 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle);
299 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle);
277 return;
300 return;
278 }
301 }
279 if(!scatterStyle.compare("pluscircle"))
302 if(!scatterStyle.compare("pluscircle"))
280 {
303 {
281 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle);
304 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle);
282 return;
305 return;
283 }
306 }
284 if(!scatterStyle.compare("peace"))
307 if(!scatterStyle.compare("peace"))
285 {
308 {
286 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace);
309 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace);
287 return;
310 return;
288 }
311 }
289
312
290 }
313 }
291 }
314 }
292
315
316 void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type)
317 {
318 this->m_plot->xAxis->setTickLabelType(type);
319 }
320
321 void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format)
322 {
323 this->m_plot->xAxis->setDateTimeFormat(format);
324 }
325
293
326
294
327
295
328
296
329
297 void SocExplorerPlot::keyPressEvent(QKeyEvent * event)
330 void SocExplorerPlot::keyPressEvent(QKeyEvent * event)
298 {
331 {
299 switch(event->key())
332 switch(event->key())
300 {
333 {
301 case Qt::Key_Control:
334 case Qt::Key_Control:
302 this->ctrl_hold = true;
335 this->ctrl_hold = true;
303 break;
336 setCursor(Qt::CrossCursor);
337 break;
304 case Qt::Key_Shift:
338 case Qt::Key_Shift:
305 this->shift_hold = true;
339 this->shift_hold = true;
306 break;
340 break;
307 case Qt::Key_M:
341 case Qt::Key_M:
308 this->rescaleAxis();
342 this->rescaleAxis();
309 break;
343 break;
344 case Qt::Key_Left:
345 if(!ctrl_hold)
346 {
347 move(-0.1,Qt::Horizontal);
348 }
349 else
350 {
351 zoom(2,this->width()/2,Qt::Horizontal);
352 }
353 break;
354 case Qt::Key_Right:
355 if(!ctrl_hold)
356 {
357 move(0.1,Qt::Horizontal);
358 }
359 else
360 {
361 zoom(0.5,this->width()/2,Qt::Horizontal);
362 }
363 break;
364 case Qt::Key_Up:
365 if(!ctrl_hold)
366 {
367 move(0.1,Qt::Vertical);
368 }
369 else
370 {
371 zoom(0.5,this->height()/2,Qt::Vertical);
372 }
373 break;
374 case Qt::Key_Down:
375 if(!ctrl_hold)
376 {
377 move(-0.1,Qt::Vertical);
378 }
379 else
380 {
381 zoom(2,this->height()/2,Qt::Vertical);
382 }
383 break;
310 default:
384 default:
311 QWidget::keyPressEvent(event);
385 QWidget::keyPressEvent(event);
312 break;
386 break;
313 }
387 }
314 }
388 }
315
389
316 void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event)
390 void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event)
317 {
391 {
318 switch(event->key())
392 switch(event->key())
319 {
393 {
320 case Qt::Key_Control:
394 case Qt::Key_Control:
321 event->accept();
395 event->accept();
322 this->ctrl_hold = false;
396 this->ctrl_hold = false;
323 break;
397 break;
324 case Qt::Key_Shift:
398 case Qt::Key_Shift:
325 event->accept();
399 event->accept();
326 this->shift_hold = false;
400 this->shift_hold = false;
327 break;
401 break;
328 default:
402 default:
329 QWidget::keyReleaseEvent(event);
403 QWidget::keyReleaseEvent(event);
330 break;
404 break;
331 }
405 }
406 setCursor(Qt::ArrowCursor);
332 }
407 }
333
408
334 void SocExplorerPlot::wheelEvent(QWheelEvent * event)
409 void SocExplorerPlot::wheelEvent(QWheelEvent * event)
335 {
410 {
336 double factor;
411 double factor;
337 double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
412 double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
338 if(ctrl_hold)
413 if(ctrl_hold)
339 {
340 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
341 {
342 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
343 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(Qt::Vertical);
344 axis->scaleRange(factor, axis->pixelToCoord(event->pos().y()));
345 }
346 this->m_plot->replot();
347 QWidget::wheelEvent(event);
348 return;
349 }
350 if(shift_hold)
351 {
414 {
352 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
415 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
353 {
416 {
354 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
417 setCursor(Qt::SizeVerCursor);
355 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(Qt::Horizontal);
418 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
356 axis->scaleRange(factor, axis->pixelToCoord(event->pos().x()));
419 zoom(factor,event->pos().y(),Qt::Vertical);
357 }
420 }
358 this->m_plot->replot();
421 QWidget::wheelEvent(event);
359 QWidget::wheelEvent(event);
422 return;
360 return;
361 }
423 }
362 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
424 if(shift_hold)
363 double rg = (Haxis->range().upper - Haxis->range().lower)*(wheelSteps/10);
425 {
364 Haxis->setRange(Haxis->range().lower+(rg), Haxis->range().upper+(rg));
426 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
365 this->m_plot->replot();
427 {
366 QWidget::wheelEvent(event);
428 setCursor(Qt::SizeHorCursor);
429 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
430 zoom(factor,event->pos().x(),Qt::Horizontal);
431 }
432 QWidget::wheelEvent(event);
433 return;
434 }
435 move(wheelSteps/10,Qt::Horizontal);
436 QWidget::wheelEvent(event);
367 }
437 }
368
438
369
439
@@ -371,38 +441,86 void SocExplorerPlot::wheelEvent(QWheelE
371
441
372 void SocExplorerPlot::mousePressEvent(QMouseEvent *event)
442 void SocExplorerPlot::mousePressEvent(QMouseEvent *event)
373 {
443 {
374 if(event->button()==Qt::LeftButton)
444 if(event->button()==Qt::LeftButton)
375 {
445 {
376 mDragStart = event->pos();
446 if(ctrl_hold)
377 this->mouse_hold = true;
447 {
378 DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
448 setCursor(Qt::CrossCursor);
379 DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range();
449 mOrigin = event->pos();
450 mRubberBand->setGeometry(QRect(mOrigin, QSize()));
451 mRubberBand->show();
452 }
453 else
454 {
455 setCursor(Qt::ClosedHandCursor);
456 mDragStart = event->pos();
457 this->mouse_hold = true;
458 DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
459 DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range();
460 }
380 }
461 }
381 QWidget::mousePressEvent(event);
462 QWidget::mousePressEvent(event);
382 }
463 }
383
464
384 void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event)
465 void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event)
385 {
466 {
386 if(event->button()==Qt::LeftButton)
467 if(event->button()==Qt::LeftButton)
468 {
469 this->mouse_hold = false;
470 }
471 if (mRubberBand->isVisible())
387 {
472 {
388 this->mouse_hold = false;
473 const QRect & zoomRect = mRubberBand->geometry();
474 int xp1, yp1, xp2, yp2;
475 zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2);
476 double x1 = this->m_plot->xAxis->pixelToCoord(xp1);
477 double x2 = this->m_plot->xAxis->pixelToCoord(xp2);
478 double y1 = this->m_plot->yAxis->pixelToCoord(yp1);
479 double y2 = this->m_plot->yAxis->pixelToCoord(yp2);
480
481 this->m_plot->xAxis->setRange(x1, x2);
482 this->m_plot->yAxis->setRange(y1, y2);
483
484 mRubberBand->hide();
485 this->m_plot->replot();
389 }
486 }
390 QWidget::mouseReleaseEvent(event);
487 setCursor(Qt::ArrowCursor);
488 QWidget::mouseReleaseEvent(event);
489 }
490
491 void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation)
492 {
493 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation);
494 axis->scaleRange(factor, axis->pixelToCoord(center));
495 this->m_plot->replot();
391 }
496 }
392
497
498 void SocExplorerPlot::move(double factor, Qt::Orientation orientation)
499 {
500 QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation);
501 double rg = (axis->range().upper - axis->range().lower)*(factor);
502 axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg));
503 this->m_plot->replot();
504 }
505
506
393 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
507 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
394 {
508 {
395 if(mouse_hold)
509 if(mouse_hold)
396 {
510 {
397 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
511 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
398 QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
512 QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
399 double diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x());
513 double diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x());
400 Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff);
514 Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff);
401 diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y());
515 diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y());
402 Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff);
516 Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff);
403 this->m_plot->replot();
517 this->m_plot->replot();
404 }
518 }
405 QWidget::mouseMoveEvent(event);
519 if (mRubberBand->isVisible())
520 {
521 mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized());
522 }
523 QWidget::mouseMoveEvent(event);
406 }
524 }
407
525
408
526
@@ -4,53 +4,67
4 #include <QWidget>
4 #include <QWidget>
5 #include <QGridLayout>
5 #include <QGridLayout>
6 #include <qcustomplot.h>
6 #include <qcustomplot.h>
7 #include <QRubberBand>
8 #include <QPoint>
7
9
8 class SocExplorerPlot : public QWidget
10 class SocExplorerPlot : public QWidget
9 {
11 {
10 Q_OBJECT
12 Q_OBJECT
11 public:
13 public:
12 explicit SocExplorerPlot(QWidget *parent = 0);
14 explicit SocExplorerPlot(QWidget *parent = 0);
13 void setTitle(QString title);
15 ~SocExplorerPlot();
14 void setXaxisLabel(QString label);
16 void setTitle(QString title);
15 void setXaxisRange(double lower, double upper);
17 void setXaxisLabel(QString label);
16 void setYaxisLabel(QString label);
18 void setXaxisRange(double lower, double upper);
17 void setYaxisRange(double lower, double upper);
19 void setYaxisLabel(QString label);
18 void rescaleAxis();
20 void setYaxisRange(double lower, double upper);
19 void setLegendFont(QFont font);
21 void rescaleAxis();
20 void setLegendSelectedFont(QFont font);
22 void setLegendFont(QFont font);
21 void setAdaptativeSampling(int graphIndex,bool enable);
23 void setLegendSelectedFont(QFont font);
22 int addGraph();
24 void setAdaptativeSampling(int graphIndex,bool enable);
23 void setGraphName(int graphIndex,QString name);
25 int addGraph();
24 void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
26 bool removeGraph(int graphIndex);
25 void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
27 void removeAllGraphs();
26 void addGraphData(int graphIndex, QVariant x, QVariant y);
28 void setGraphName(int graphIndex,QString name);
27 void setGraphPen(int graphIndex,QPen pen);
29 void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
28 QPen getGraphPen(int graphIndex);
30 void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true);
29 void setGraphLineStyle(int graphIndex,QString lineStyle);
31 void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
30 void setGraphScatterStyle(int graphIndex,QString scatterStyle);
32 void addGraphData(int graphIndex, QVariant x, QVariant y);
31 void show();
33 void setGraphPen(int graphIndex,QPen pen);
34 QPen getGraphPen(int graphIndex);
35 void setGraphLineStyle(int graphIndex,QString lineStyle);
36 void setGraphScatterStyle(int graphIndex,QString scatterStyle);
37 void setXaxisTickLabelType(QCPAxis::LabelType type);
38 void setXaxisDateTimeFormat(const QString &format);
39 void show();
40 void replot();
32
41
33 signals:
42 signals:
34
43
35 public slots:
44 public slots:
36
45
37 protected:
46 protected:
38 void keyPressEvent(QKeyEvent *);
47 void keyPressEvent(QKeyEvent *);
39 void keyReleaseEvent(QKeyEvent *);
48 void keyReleaseEvent(QKeyEvent *);
40 void wheelEvent(QWheelEvent *);
49 void wheelEvent(QWheelEvent *);
41 void mousePressEvent(QMouseEvent *);
50 void mousePressEvent(QMouseEvent *);
42 void mouseMoveEvent(QMouseEvent *);
51 void mouseMoveEvent(QMouseEvent *);
43 void mouseReleaseEvent(QMouseEvent *);
52 void mouseReleaseEvent(QMouseEvent *);
44
53
45 private:
54 private:
46 QCustomPlot* m_plot;
55 void zoom(double factor, int center, Qt::Orientation orientation);
47 QGridLayout* m_mainlayout;
56 void move(double factor, Qt::Orientation orientation);
48 bool ctrl_hold;
57 QCustomPlot* m_plot;
49 bool shift_hold;
58 QGridLayout* m_mainlayout;
50 bool mouse_hold;
59 bool ctrl_hold;
51 QCPRange DragStartHorzRange;
60 bool shift_hold;
52 QCPRange DragStartVertRange;
61 bool mouse_hold;
53 QPoint mDragStart;
62 QCPRange DragStartHorzRange;
63 QCPRange DragStartVertRange;
64 QPoint mDragStart;
65 bool mZoomMode;
66 QRubberBand * mRubberBand;
67 QPoint mOrigin;
54 };
68 };
55
69
56 #endif // SOCEXPLORERPLOT_H
70 #endif // SOCEXPLORERPLOT_H
General Comments 0
You need to be logged in to leave comments. Login now