Hey community,


I have the following problem. I am constructing a simple 2D-Plot. At the begining I construct a QwtPlot etc. . In an other thread I compute a Vector from a function or whatever. Then this Thread is calling the "preview::createCurve()" methode to draw the curve to the constructed plot. Normally the plot ist automatically rescaled (if i do not set the axisscales manually) to the plotted curve. Since I want to provide zooming in my plots, I have to tell the ZoomingClass the initial ScaleCoordinates of the plotted curve (so the coordinates to which the zoomer goes back when you press the right mouse button). => how can I do that?

Another question is: What if I plot another curve in the same Plot. Will he rescale the plot canvas automatically, when I have rescaled the ZoomingClasScale before ?

here the code and sorry for my crappy english:

Qt Code:
  1. #include "curve.h"
  2.  
  3. class Zoomer: public QwtPlotZoomer
  4. {
  5. public:
  6. Zoomer(QwtPlotCanvas *canvas):
  7. QwtPlotZoomer(canvas)
  8. {
  9. setRubberBandPen(QPen(Qt::darkGreen, 1.5, Qt::SolidLine));
  10. }
  11.  
  12. virtual QwtText trackerTextF(const QPointF &pos) const
  13. {
  14. QColor bg(Qt::white);
  15. QwtText text = QwtPlotZoomer::trackerTextF(pos);
  16. text.setBackgroundBrush( QBrush( bg ));
  17. return text;
  18. }
  19.  
  20. virtual void rescale()
  21. {
  22. QwtPlotZoomer::rescale();
  23. }
  24. };
  25.  
  26. curve::curve(QWidget *parent, const QString &title) : QWidget()
  27. {
  28. QFont font("Arial" , 12);
  29. plot = new QwtPlot;
  30. plotGrid = new QwtPlotGrid;
  31. plotGridLayout = new QGridLayout;
  32. plotZoom = new Zoomer(plot->canvas());
  33.  
  34. //plotTitle
  35. plotTitle.setFont(font);
  36. plotTitle.setText(title);
  37. //plotGrid
  38. plotGrid->enableXMin(true);
  39. plotGrid->enableYMin(true);
  40. plotGrid->setMajPen(QPen(Qt::black,1,Qt::SolidLine));
  41. plotGrid->setMinPen(QPen(Qt::darkGray,0,Qt::DotLine));
  42. plotGrid->attach(plot);
  43. //Plot
  44. plot->setTitle(plotTitle);
  45. plot->setMaximumSize(800,800);
  46. plot->setMinimumSize(400,400);
  47. plot->setCanvasLineWidth(2);
  48. plot->setCanvasBackground(QBrush(QColor(240,240,240), Qt::SolidPattern));
  49. plot->setAxisFont(0, font);
  50. plot->setAxisFont(2, font);
  51. plot->axisWidget(0)->setMargin(0);
  52. plot->axisWidget(2)->setMargin(0);
  53. plot->plotLayout()->setAlignCanvasToScales(true);
  54.  
  55. plotGridLayout->addWidget(plot);
  56. this->setLayout(plotGridLayout);
  57. }
  58.  
  59. //plotCurve
  60. void curve::createCurve(const QVector<QPointF> &vector, const QString &title)
  61. {
  62. plotCurve = new QwtPlotCurve(title);
  63. //Std Color = blue
  64. plotCurve->setPen(QPen(Qt::blue, 1.5));
  65. plotCurve->setSymbol(new QwtSymbol(QwtSymbol::XCross, Qt::NoBrush, QPen(Qt::black), QSize(3, 3)));
  66.  
  67. //Std_style = lines, antialiased
  68. plotCurve->setCurveAttribute(QwtPlotCurve::Fitted);
  69. plotCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
  70.  
  71. //Points = vector
  72. plotCurve->setSamples(vector);
  73. //Std_Plot = plot
  74. plotCurve->attach(plot);
  75.  
  76. }
To copy to clipboard, switch view to plain text mode