Changeset 204 for Evidence/Edd
- Timestamp:
- 05/03/10 17:37:03 (15 years ago)
- Location:
- Evidence/Edd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Edd/Edd.cc
r174 r204 9 9 a DIM status service 10 10 11 February2010, Oliver Grimm11 April 2010, Oliver Grimm 12 12 13 13 ============================================================ */ … … 195 195 setAttribute(Qt::WA_DeleteOnClose); 196 196 setAutoReplot(false); 197 setCanvasBackground(QColor(Qt::yellow)); 198 setAxisScaleDraw(QwtPlot::xBottom, new TimeScale()); 197 setCanvasBackground(EddPlotBackgroundColor); 198 setAxisScaleDraw(QwtPlot::xBottom, new EddTimeScale); 199 setMargin(15); 200 201 // Update additional information (e.g. time range) on widget when axis change 202 connect(axisWidget(QwtPlot::xBottom), SIGNAL(scaleDivChanged()), SLOT(update())); 203 204 Picker = new QwtPicker(QwtPicker::CornerToCorner|QwtPicker::RectSelection, QwtPicker::RectRubberBand, QwtPicker::AlwaysOff, this); 205 connect(Picker, SIGNAL(selected(const QwtPolygon &)), SLOT(MouseSelection(const QwtPolygon &))); 199 206 200 207 Zoomer = new QwtPlotZoomer(QwtPlot::xBottom,QwtPlot::yLeft,canvas()); 201 208 connect(Zoomer, SIGNAL(zoomed(const QwtDoubleRect &)), this, SLOT(HandleZoom(const QwtDoubleRect &))); 209 210 Magnifier = new QwtPlotMagnifier(canvas()); 211 Magnifier->setMouseButton(Qt::NoButton,Qt::NoButton); 212 Magnifier->setZoomInKey(Qt::Key_M, Qt::NoModifier); 213 Magnifier->setZoomOutKey(Qt::Key_M, Qt::ShiftModifier); 214 202 215 Panner = new QwtPlotPanner(canvas()); 203 216 Panner->setMouseButton(Qt::LeftButton, Qt::ShiftModifier); 217 204 218 Grid = new QwtPlotGrid; 205 219 Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine)); 206 220 Grid->attach(this); 221 207 222 Legend = new QwtLegend(); 208 223 Legend->setItemMode(QwtLegend::ClickableItem); 209 insertLegend(Legend, QwtPlot::TopLegend); 210 224 insertLegend(Legend, QwtPlot::TopLegend, 0.3); 211 225 connect(this, SIGNAL(legendClicked (QwtPlotItem *)), SLOT(LegendClicked(QwtPlotItem *))); 212 226 … … 218 232 // Context menu 219 233 Menu = new QMenu(this); 234 StripAction = Menu->addAction("Stripchart", this, SLOT(UpdatePlot())); 235 StripAction->setCheckable(true); 236 Menu->addSeparator(); 220 237 YLogAction = Menu->addAction("y scale log", this, SLOT(UpdatePlot())); 221 238 YLogAction->setCheckable(true); … … 232 249 Menu->addSeparator(); 233 250 Menu->addAction("Paste service", this, SLOT(MenuPasteService())); 251 Menu->addAction("Plot help", this, SLOT(MenuPlotHelp())); 234 252 235 253 // DIM client … … 245 263 Handler->Unsubscribe(Items[i].Name); 246 264 delete Items[i].Signal; 247 } 265 } 266 248 267 delete Grid; 249 268 delete Mutex; … … 363 382 void EddPlot::UpdatePlot() { 364 383 384 double Lower = axisScaleDiv(QwtPlot::xBottom)->lowerBound(); 385 double Upper = axisScaleDiv(QwtPlot::xBottom)->upperBound(); 386 double MaxTime = DBL_MIN; 365 387 static QwtSymbol Symbol, Sym1; 366 388 Symbol.setStyle(QwtSymbol::Ellipse); 367 389 Symbol.setSize(4); 368 390 391 // Select engine for linear or logarithmic scale 369 392 if (!YLogAction->isChecked()) { 370 393 setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine); … … 376 399 377 400 for (int ItemNo=0; ItemNo<Items.size(); ItemNo++) { 378 401 // Determine current maximum value for strip chart plotting 402 if (Items[ItemNo].Signal->boundingRect().right() > MaxTime) { 403 MaxTime = Items[ItemNo].Signal->boundingRect().right(); 404 } 405 406 // Set symbol if requested 379 407 if (StyleAction->isChecked()) Items[ItemNo].Signal->setSymbol(Symbol); 380 408 else Items[ItemNo].Signal->setSymbol(Sym1); 381 409 410 // Determine number of data points 382 411 int DataPoints = Items[ItemNo].x.size(); 383 412 if (DataPoints == 0) continue; … … 399 428 Items[ItemNo].Signal->setData(Items[ItemNo].x.data(), y, DataPoints); 400 429 Items[ItemNo].Signal->show(); 401 Zoomer->setZoomBase(Items[ItemNo].Signal->boundingRect()); 402 403 delete[] y; 404 } 430 delete[] y; 431 432 // Generate bounding box of all curves for zoomer 433 BBox = BBox.unite(Items[ItemNo].Signal->boundingRect()); 434 } 435 436 // Reset zoom base to include all data 437 Zoomer->setZoomBase(BBox); 438 439 // If plot is strip char, only move axis but keep range 440 if (StripAction->isChecked()) { 441 setCanvasBackground(EddPlotBackgroundColor.lighter(90)); 442 setAxisScale(QwtPlot::xBottom, Lower+ BBox.right() - MaxTime, Upper + BBox.right() - MaxTime); 443 } 444 else setCanvasBackground(EddPlotBackgroundColor); 445 405 446 replot(); 406 447 } 448 449 // Add text indicating time range to plot 450 void EddPlot::paintEvent(QPaintEvent *) { 451 452 QString Text; 453 QFont Font; 454 QPainter Painter(this); 455 456 Text = QDateTime::fromTime_t((int) axisScaleDiv(QwtPlot::xBottom)->lowerBound()).toString("d-MMM-yyyy hh:mm:ss") + " to " + QDateTime::fromTime_t((int) axisScaleDiv(QwtPlot::xBottom)->upperBound()).toString("d-MMM-yyyy hh:mm:ss"); 457 458 Font.setPointSize(6); 459 Painter.setFont(Font); 460 Painter.drawText(0, height(),Text); 461 } 462 463 // Rescale plot in case selection has been made outside the canvas 464 void EddPlot::MouseSelection(const QPolygon &P) { 465 466 QwtDoubleInterval xPlot, xMouse, yPlot, yMouse; 467 468 // Shift selected rectangle so that upper left corner is 0/0 on canvas 469 QRect R = P.boundingRect().translated(-plotLayout()->canvasRect().topLeft()); 470 471 // Current axis intervals 472 xPlot = axisScaleDiv(QwtPlot::xBottom)->interval(); 473 yPlot = axisScaleDiv(QwtPlot::yLeft)->interval(); 474 475 // Selected axis intervals 476 xMouse = QwtDoubleInterval(invTransform(QwtPlot::xBottom, R.left()), 477 invTransform(QwtPlot::xBottom, R.right())); 478 yMouse = QwtDoubleInterval(invTransform(QwtPlot::yLeft, R.bottom()), 479 invTransform(QwtPlot::yLeft, R.top())); 480 481 // Selection region outside all axis? 482 if (R.right() < 0 && R.top() > plotLayout()->canvasRect().height()) return; 483 484 // Rescale both axis if selected rectangle encompasses canvas completely 485 if (P.boundingRect().contains(plotLayout()->canvasRect())) { 486 yMouse.setMaxValue(yMouse.maxValue() + yPlot.width()); 487 yMouse.setMinValue(yMouse.minValue() - yPlot.width()); 488 xMouse.setMinValue(xMouse.minValue() - xPlot.width()); 489 xMouse.setMaxValue(xMouse.maxValue() + xPlot.width()); 490 491 setAxisScale(QwtPlot::xBottom, xMouse.minValue(), xMouse.maxValue()); 492 setAxisScale(QwtPlot::yLeft, yMouse.minValue(), yMouse.maxValue()); 493 } 494 495 // Rescale y axis (increase range if selected rectangle larger than axis area) 496 if (R.right() < 0) { 497 if (R.top() < plotLayout()->canvasRect().top()) { 498 yMouse.setMaxValue(yMouse.maxValue() + yPlot.width()); 499 } 500 if (R.bottom() > plotLayout()->canvasRect().bottom()) { 501 yMouse.setMinValue(yMouse.minValue() - yPlot.width()); 502 } 503 504 setAxisScale(QwtPlot::yLeft, yMouse.minValue(), yMouse.maxValue()); 505 } 506 507 // Rescale x axis (increase range if selected rectangle larger than axis area) 508 if (R.top() > plotLayout()->canvasRect().height()) { 509 if (R.left() < plotLayout()->canvasRect().left()) { 510 xMouse.setMinValue(xMouse.minValue() - xPlot.width()); 511 } 512 if (R.right() > plotLayout()->canvasRect().right()) { 513 xMouse.setMaxValue(xMouse.maxValue() + xPlot.width()); 514 } 515 setAxisScale(QwtPlot::xBottom, xMouse.minValue(), xMouse.maxValue()); 516 } 517 518 // Draw new scales 519 replot(); 520 } 521 407 522 408 523 // … … 537 652 } 538 653 654 // Help text 655 void EddPlot::MenuPlotHelp() { 656 657 QMessageBox::about(this, "Edd - Plot navigation", 658 "Zoom\tMouse wheel\n" 659 "\tKeys m and shift-m\n" 660 "\tSelecting region with left mouse button\n" 661 "\tMiddle button zooms out one level\n" 662 "\tSelecting a range on an axis\n" 663 "\tSelecting whole canvas\n\n" 664 "Pan\tShift and left mouse button\n\n" 665 "ESC cancels selection\n" 666 "Cursor keys move mouse"); 667 } 668 539 669 540 670 ////////////////////////////////////// … … 754 884 755 885 756 // 757 // Main GUI (all widgets have ultimately Central as parent) 886 //-------------------------------------------------------------------- 887 //*************************** Main GUI ******************************* 888 //-------------------------------------------------------------------- 889 // 890 // All widgets have ultimately Central as parent. 758 891 // 759 892 GUI::GUI() { … … 1002 1135 } 1003 1136 1004 1005 //---------------------------------------------------------------------1006 //************************ All functions ****************************1007 //-------------------------------------------------------------------1008 1009 1137 // Quit application when clicking close button on window 1010 1138 void GUI::closeEvent(QCloseEvent *) { -
Evidence/Edd/Edd.h
r174 r204 8 8 #include <qwt_plot_grid.h> 9 9 #include <qwt_plot_zoomer.h> 10 #include <qwt_plot_magnifier.h> 10 11 #include <qwt_plot_panner.h> 11 12 #include <qwt_scale_engine.h> … … 16 17 #include <qwt_legend_item.h> 17 18 #include <qwt_symbol.h> 19 #include <qwt_plot_marker.h> 18 20 19 21 #include <limits.h> … … 25 27 #define SVN_REVISION "$Revision$" 26 28 29 const QColor EddPlotBackgroundColor(Qt::yellow); 30 27 31 QWidget *OpenHistory(char *, int); 28 32 29 33 // Time scale for axis 30 class TimeScale: public QwtScaleDraw { 31 public: 32 TimeScale() { } 34 class EddTimeScale: public QwtScaleDraw { 35 36 public: 37 EddTimeScale() {} 38 33 39 virtual QwtText label(double v) const { 34 QDateTime t = QDateTime::fromTime_t((int) v); 35 return t.toString("dMMM'\n'hh:mm:ss"); 40 41 // Adapt text format to time span 42 QString Format; 43 if (scaleDiv().range() < 60*60) Format = "hh' h\n'mm:ss"; 44 else if (scaleDiv().range() < 24*60*60) Format = "hh:mm"; 45 else if (scaleDiv().range() < 30*24*60*60) Format = "h' h\n'd-MMM"; 46 else Format = "d-MMM'\n'yyyy"; 47 48 // Generate text 49 QwtText Text = QDateTime::fromTime_t((int) v).toString(Format); 50 QFont Font = Text.font(); 51 Font.setPointSize(7); 52 Text.setFont(Font); 53 54 return Text; 36 55 } 37 56 }; … … 89 108 QAction *NormAction; 90 109 QAction *StyleAction; 110 QAction *StripAction; 91 111 92 112 QwtPlotPanner *Panner; 93 113 QwtPlotGrid *Grid; 94 114 QwtPlotZoomer *Zoomer; 95 QwtLegend *Legend; 96 115 QwtPlotMagnifier *Magnifier; 116 QwtPicker *Picker; 117 QwtLegend *Legend; 118 QwtDoubleRect BBox; 119 97 120 void dragEnterEvent(QDragEnterEvent *); 98 121 void dropEvent(QDropEvent *); 99 122 void paintEvent(QPaintEvent *); 123 100 124 public: 101 125 EddPlot(QString = QString(), int = 0, QWidget * = NULL); … … 108 132 109 133 void HandleZoom(const QwtDoubleRect &); 110 void contextMenuEvent(QContextMenuEvent *); 134 void MouseSelection(const QwtPolygon &); 135 void contextMenuEvent(QContextMenuEvent *); 111 136 void LegendClicked(QwtPlotItem *); 112 137 void MenuZoomOut(); … … 116 141 void MenuPrint(); 117 142 void MenuPasteService(); 143 void MenuPlotHelp(); 118 144 }; 119 145
Note:
See TracChangeset
for help on using the changeset viewer.