Results 1 to 12 of 12

Thread: QwtPlotZoomer question

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QwtPlotZoomer question

    Following is the example of simple date-value curve constructed using 100 days on x axis and random y-values.

    My question is about the zoomer behavior. When I do "zoom-in" the curve displays correctly and ticks/labels also looks correct. When I do "zoom-out" back to the original view, the curve dissapears and labels are also wrong.

    I'll appreciate the review of the code below. What am I doing wrong here?


    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. MainWindow(QWidget *parent = 0);
    7. ~MainWindow();
    8.  
    9. void createDefaultCurve();
    10. QwtScaleDiv dateScaleDiv ();
    11.  
    12. private:
    13. Ui::MainWindowClass *ui;
    14.  
    15. QwtPlotCurve * _curve;
    16. QVector<double> _xData;
    17. QVector<double> _yData;
    18. };
    19.  
    20.  
    21. MainWindow::MainWindow(QWidget *parent)
    22. : QMainWindow(parent), ui(new Ui::MainWindowClass), _curve(0)
    23. {
    24. ui->setupUi(this);
    25.  
    26. ui->plot->setCanvasBackground(Qt::white);
    27.  
    28. // taken from friedberg example
    29. QwtPlotZoomer* zoomer = new QwtPlotZoomer( ui->plot->canvas() );
    30. zoomer->setRubberBandPen( QColor( Qt::black ) );
    31. zoomer->setTrackerPen( QColor( Qt::black ) );
    32. zoomer->setMousePattern( QwtEventPattern::MouseSelect2,
    33. Qt::RightButton, Qt::ControlModifier );
    34. zoomer->setMousePattern( QwtEventPattern::MouseSelect3,
    35. Qt::RightButton );
    36.  
    37. _curve = new QwtPlotCurve();
    38. _curve->attach(this->ui->plot);
    39.  
    40. createDateCurve();
    41.  
    42. ui->plot->replot();
    43. }
    44.  
    45. // one hundred dates, from today forward
    46. void MainWindow::createDateCurve()
    47. {
    48. unsigned int time ;
    49. for( int x = 0; x < 100; ++x){
    50. time = QDateTime::currentDateTime().addDays(x).toTime_t();
    51. _xData.append((double)time);
    52. _yData.append((double) (qrand()&0xFF));
    53. }
    54.  
    55. _curve->setRawSamples(&_xData[0], &_yData[0], _xData.size());
    56.  
    57. ui->plot->setAxisScaleDiv( QwtPlot::xBottom, dateScaleDiv() );
    58. ui->plot->setAxisScaleDraw(QwtPlot::xBottom, new DateScaleDraw("dd/MM/yyyy"));
    59.  
    60. ui->plot->setAxisScale(QwtPlot::xBottom, _xData.first() ,_xData.last());
    61. }
    62.  
    63.  
    64. // major ticks - days
    65. // medium ticks - 12am
    66. // minor ticks - every 2 hours
    67. QwtScaleDiv MainWindow::dateScaleDiv ()
    68. {
    69. QList<double> ticks[QwtScaleDiv::NTickTypes];
    70.  
    71. QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
    72. double val;
    73. foreach (val, _xData)
    74. majorTicks += val;
    75.  
    76. QList<double> &mediumTicks = ticks[QwtScaleDiv::MediumTick];
    77. for (int i = 0; i < _xData.count() - 1; ++i)
    78. mediumTicks += QDateTime::fromTime_t(_xData[i]).addSecs(3600 * 12).toTime_t();
    79.  
    80. QList<double> &minorTicks = ticks[QwtScaleDiv::MinorTick];
    81. for (int i = 0; i < _xData.count() - 1; ++i)
    82. for (int j = 2; j < 24; j += 2)
    83. minorTicks += QDateTime::fromTime_t(_xData[i]).addSecs(120 * j).toTime_t();
    84.  
    85. QwtScaleDiv scaleDiv( _xData.first(), _xData.last(), ticks );
    86. return scaleDiv;
    87. }
    88.  
    89.  
    90. class DateScaleDraw: public QwtScaleDraw
    91. {
    92. public:
    93. DateScaleDraw(QString fmt) : format(fmt)
    94. {
    95. setTickLength( QwtScaleDiv::MinorTick, 2 );
    96. setTickLength( QwtScaleDiv::MediumTick, 4 );
    97. setTickLength( QwtScaleDiv::MajorTick, 8 );
    98. }
    99.  
    100. virtual QwtText label(double v) const
    101. {
    102. QDate t = QDateTime::fromTime_t((int)v).date();
    103. return t.toString(format);
    104. }
    105. private:
    106. const QString format;
    107. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotZoomer question

    This has been answered 100 times in this forum - see QwtPlotZoomer::setZoomBase().

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    TorAn (1st May 2011)

  4. #3
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotZoomer question

    I have the same issue. Where should I call setZoomBase()?
    I put it into the modified plot class:

    Qt Code:
    1. Zoomer *zoomer = new Zoomer(QwtPlot::xBottom, QwtPlot::yLeft, this->canvas());
    2. zoomer->setZoomBase();
    To copy to clipboard, switch view to plain text mode 

    Didn't help...

    Thx!
    Last edited by falconium; 3rd May 2011 at 23:18.

  5. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotZoomer question

    you don't have to create a new zoomer. call setZoomBase() on the existing one...

  6. #5
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotZoomer question

    Hi, that was the only existing one, but I changed the code as follows, and still the same result which is not showing round hours, but in between on scales after zooming out:

    QwtPlotZoomer *zoomer = new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, this->canvas());
    zoomer->setZoomBase();

    Or do you mean something else on existing one?

    Basically, this is my Plot code:

    Qt Code:
    1. ChartPlot::ChartPlot(QStandardItemModel *model, QWidget *parent) : QwtPlot(parent)
    2. {
    3. setAutoReplot(false);
    4.  
    5. plotLayout()->setAlignCanvasToScales(true);
    6.  
    7. QwtLegend *legend = new QwtLegend;
    8. legend->setItemMode(QwtLegend::CheckableItem);
    9. insertLegend(legend, QwtPlot::RightLegend);
    10.  
    11. setAxisTitle(QwtPlot::xBottom, "Report time");
    12. setAxisLabelRotation(QwtPlot::xBottom, -45.0);
    13. setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
    14. setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());
    15.  
    16. QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
    17. const int fmh = QFontMetrics(scaleWidget->font()).height();
    18. scaleWidget->setMinBorderDist(0, fmh / 2);
    19.  
    20. setAxisTitle(QwtPlot::yLeft, "Quantity");
    21.  
    22. QwtPlotGrid *grid = new Grid;
    23. grid->attach(this);
    24.  
    25. Background *bg = new Background();
    26. bg->attach(this);
    27.  
    28. //QwtScaleDiv scaleDiv;
    29.  
    30. for (int row=0; row<model->rowCount(); row++)
    31. {
    32. QDateTime xDateTime = model->item(row, 0)->data(Qt::EditRole).toDateTime();
    33. xData << xDateTime.toTime_t();
    34. }
    35.  
    36. for (int column = 1; column < model->columnCount(); column++)
    37. {
    38. QVector<double> yData;
    39.  
    40. curve = new ChartCurve(model->horizontalHeaderItem(column)->text());
    41. curve->setStyle(QwtPlotCurve::Lines);
    42. QVariant decoration = model->item(0, column)->data(Qt::DecorationRole);
    43. if (decoration.type() == QVariant::Color)
    44. {
    45. curve->setColor(decoration.value<QColor>());
    46. }
    47. curve->setCurveAttribute(QwtPlotCurve::Fitted, true);
    48. curve->setCurveFitter(curveFitter);
    49. curve->setZ(curve->z() - 1);
    50. curve->attach(this);
    51.  
    52. for (int row=0; row<model->rowCount(); row++)
    53. {
    54. yData << model->item(row, column)->data(Qt::EditRole).toDouble();
    55. }
    56.  
    57. curve->setSamples(xData, yData);
    58. showCurve(curve, true);
    59. }
    60.  
    61.  
    62.  
    63. scaleEngineX->setAttribute(QwtScaleEngine::Floating, true);
    64.  
    65. setAxisScaleEngine(QwtPlot::xBottom, scaleEngineX);
    66.  
    67. setAxisScaleDiv(QwtPlot::xBottom, scaleDiv());
    68.  
    69. scaleEngineY->setAttribute(QwtScaleEngine::IncludeReference, true);
    70. scaleEngineY->setReference(0);
    71. setAxisScaleEngine(QwtPlot::yLeft, scaleEngineY);
    72.  
    73. PlotPicker *picker = new PlotPicker(QwtPlot::xBottom,
    74. QwtPlot::yLeft,
    75. QwtPlotPicker::CrossRubberBand,
    76. QwtPicker::ActiveOnly,
    77. this->canvas());
    78.  
    79. picker->setStateMachine(new QwtPickerTrackerMachine());
    80. picker->setRubberBandPen(QPen(Qt::DotLine));
    81. picker->setRubberBand(QwtPicker::CrossRubberBand);
    82.  
    83. QwtPlotZoomer *zoomer = new QwtPlotZoomer(QwtPlot::xBottom, QwtPlot::yLeft, this->canvas());
    84. zoomer->setZoomBase();
    85.  
    86. replot();
    87.  
    88. connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), SLOT(showCurve(QwtPlotItem *, bool)));
    89. }
    To copy to clipboard, switch view to plain text mode 

    This is the code for divisions:

    Qt Code:
    1. QwtScaleDiv ChartPlot::scaleDiv()
    2. {
    3. QList<double> ticks[QwtScaleDiv::NTickTypes];
    4.  
    5. QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
    6.  
    7. foreach (double value, xData)
    8. majorTicks += value;
    9.  
    10. if (xData.count()>1)
    11. {
    12. QList<double> &mediumTicks = ticks[QwtScaleDiv::MediumTick];
    13. for (int i = 0; i < xData.count() - 1; i++)
    14. for (int j = 1; j < 6; j++)
    15. mediumTicks += xData[i] + j * (xData[i+1] - xData[i]) / 5;
    16.  
    17. QList<double> &minorTicks = ticks[QwtScaleDiv::MinorTick];
    18. for (int i = 0; i < xData.count()*10 - 1; i++)
    19. for (int j = 1; j < 11; j++)
    20. minorTicks += xData[i] + j * (xData[i+1] - xData[i]) / 10;
    21. }
    22.  
    23. return QwtScaleDiv(xData.first(), xData.last(), ticks);
    24. }
    To copy to clipboard, switch view to plain text mode 

  7. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotZoomer question

    Quote Originally Posted by falconium View Post
    Where should I call setZoomBase()?
    It initializes the zoom stack with the current boundaries of the scales. So call it, when you have assigned your initial scales - or in combination with autoscaling, when the complete scene ( all plot items with all data ) has been attached.

    The constructor of the zoomer already initializes the zoom stack, so your code is completely pointless. setZoomBase is only for situations, where you want reininitialize to your zoom stack, f.e. when you have changed your scales later.

    Uwe

  8. The following user says thank you to Uwe for this useful post:

    missoni (25th April 2012)

  9. #7
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotZoomer question

    Quote Originally Posted by Uwe View Post
    It initializes the zoom stack with the current boundaries of the scales. So call it, when you have assigned your initial scales - or in combination with autoscaling, when the complete scene ( all plot items with all data ) has been attached.

    The constructor of the zoomer already initializes the zoom stack, so your code is completely pointless. setZoomBase is only for situations, where you want reininitialize to your zoom stack, f.e. when you have changed your scales later.
    OK, now I know when to call it, but still don't know how. So, what should I so instead of creating a new zoomer? I have added it to have the needed effect, but as you said, it is pointless.
    I have initialized the scale, the curves, everything, so how should I call this setZoomBase, or do I have to call it at all, because you wrote 'setZoomBase is only for situations, where you want reininitialize to your zoom stack, f.e. when you have changed your scales later'. I only define scale at initialization, it is not changed/reinitialized (unless zooming itself means that).

    So, all in all, it is still the same, after zooming out, the scale is screwed (initialized to some default). If I write QwtPlotZoomer::setZoomBase(), then it is not an instance and doesn't work... of course. Sorry for being this demanding... but I couldn't figure it out.
    Last edited by falconium; 10th May 2011 at 05:56.

  10. #8
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotZoomer question

    Bouncing up...

  11. #9
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotZoomer question

    Quote Originally Posted by falconium View Post
    If I write QwtPlotZoomer::setZoomBase(), then it is not an instance and doesn't work... of course. Sorry for being this demanding... but I couldn't figure it out.
    If you want to reinitialize a zoomer you need to store a pointer to it somewhere - f.e as member of your plot. Then you have the instance of the zoomer you need to reinitialize.

    But this is so very, very basic C++ that I'm surprised that you got any application running so far.

    Uwe

  12. #10
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotZoomer question

    I know it is time consuming to go through the code, but this is what I had done earlier, but didn't work. You can check the code above, but better to check code below, as it has a modified zoomer that causes to go only one stack back on right mouse click, doesn't go back to 0 immediately.

    Please, point it out for me where should I put it in the code....

    Qt Code:
    1. #include <qapplication.h>
    2. #include <qlayout.h>
    3. #include <qlabel.h>
    4. #include <qtime>
    5. #include <qpainter.h>
    6. #include "chartplot.h"
    7.  
    8. class PlotPicker : public QwtPlotPicker
    9. {
    10. public:
    11. PlotPicker(QwtPlot::Axis xAxis,
    12. QwtPlot::Axis yAxis,
    13. QwtPicker::RubberBand rb,
    14. QwtPicker::DisplayMode dm,
    15. QwtPlotCanvas* canvas) : QwtPlotPicker( xAxis, yAxis, rb , dm , canvas)
    16. {
    17. setStateMachine(new QwtPickerTrackerMachine());
    18. setRubberBandPen(QPen(Qt::DotLine));
    19. setRubberBand(QwtPicker::CrossRubberBand);
    20. }
    21.  
    22. private:
    23. QwtText trackerTextF(const QPointF &pos) const
    24. {
    25. QwtText text("X = " + QDateTime::fromTime_t(pos.x()).toString("yyyy.MM.dd. hh:mm:ss") + "\nY = " + QString::number(pos.y()));
    26. QColor bgColor(Qt::lightGray);
    27. bgColor.setAlpha(100);
    28. text.setBackgroundBrush(QBrush(bgColor));
    29. return text;
    30. }
    31.  
    32. };
    33.  
    34. QwtScaleDiv ChartPlot::scaleDiv()
    35. {
    36. QList<double> ticks[QwtScaleDiv::NTickTypes];
    37.  
    38. QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
    39. QList<double> &mediumTicks = ticks[QwtScaleDiv::MediumTick];
    40. QList<double> &minorTicks = ticks[QwtScaleDiv::MinorTick];
    41.  
    42. if (xData.count()<11)
    43. {
    44. foreach (double value, xData)
    45. majorTicks += value;
    46.  
    47. if (xData.count()>1)
    48. {
    49. for (int i = 0; i < xData.count() - 1; i++)
    50. for (int j = 1; j < 6; j++)
    51. mediumTicks += xData[i] + j * (xData[i+1] - xData[i]) / 5;
    52.  
    53. for (int i = 0; i < xData.count() - 1; i++)
    54. for (int j = 1; j < 11; j++)
    55. minorTicks += xData[i] + j * (xData[i+1] - xData[i]) / 10;
    56. }
    57. }
    58. else
    59. {
    60.  
    61. // Quantity-based division
    62.  
    63. // QVector<double> tempXData;
    64. // for (int i=0; i<11; i++)
    65. // {
    66. // int value = (i*(xData.count()-1)/10);
    67. // tempXData.append(xData[value]);
    68. // majorTicks += tempXData[i];
    69. // }
    70.  
    71. // Value-based division
    72. QVector<double> tempXData;
    73. for (int i=0; i<11; i++)
    74. {
    75. tempXData.append(xData[0] + i*(xData[xData.count()-1] - xData[0])/10);
    76. majorTicks += tempXData.last();
    77. }
    78. for (int i = 0; i < tempXData.count() - 1; i++)
    79. for (int j = 1; j < 6; j++)
    80. mediumTicks += tempXData[i] + j * (tempXData[i+1] - tempXData[i]) / 5;
    81. for (int i = 0; i < tempXData.count() - 1; i++)
    82. for (int j = 1; j < 11; j++)
    83. minorTicks += tempXData[i] + j * (tempXData[i+1] - tempXData[i]) / 10;
    84. }
    85.  
    86. return QwtScaleDiv(xData.first(), xData.last(), ticks);
    87. }
    88.  
    89. class Zoomer: public QwtPlotZoomer
    90. {
    91. public:
    92. Zoomer(int xAxis, int yAxis, QwtPlotCanvas *canvas) : QwtPlotZoomer(xAxis, yAxis, canvas)
    93. {
    94. setMousePattern(QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier);
    95. setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton);
    96. setZoomBase();
    97. }
    98. };
    99.  
    100. class Grid: public QwtPlotGrid
    101. {
    102. public:
    103. Grid()
    104. {
    105. enableXMin(true);
    106. setMajPen(QPen(Qt::white, 0, Qt::DotLine));
    107. setMinPen(QPen(Qt::lightGray, 0 , Qt::DotLine));
    108. }
    109.  
    110. virtual void updateScaleDiv(const QwtScaleDiv &xMap, const QwtScaleDiv &yMap)
    111. {
    112. QList<double> ticks[QwtScaleDiv::NTickTypes];
    113.  
    114. ticks[QwtScaleDiv::MajorTick] = xMap.ticks(QwtScaleDiv::MajorTick);
    115. ticks[QwtScaleDiv::MinorTick] = xMap.ticks(QwtScaleDiv::MinorTick);
    116.  
    117. QwtPlotGrid::updateScaleDiv(QwtScaleDiv(xMap.lowerBound(), xMap.upperBound(), ticks), yMap);
    118. }
    119. };
    120.  
    121. class TimeScaleDraw: public QwtScaleDraw
    122. {
    123. public:
    124. TimeScaleDraw()
    125. {
    126. setTickLength(QwtScaleDiv::MajorTick, 8);
    127. setTickLength(QwtScaleDiv::MinorTick, 2);
    128. setTickLength(QwtScaleDiv::MediumTick, 4);
    129. setLabelRotation(0);
    130. setLabelAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    131. setSpacing(15);
    132. }
    133.  
    134. virtual QwtText label(double value) const
    135. {
    136. QDateTime time;
    137. time = time.fromTime_t(value);
    138. return time.toString("yyyy.MM.dd.\nhh:mm:ss");
    139. }
    140. };
    141.  
    142. class Background: public QwtPlotItem
    143. {
    144. public:
    145. Background()
    146. {
    147. setZ(0.0);
    148. }
    149.  
    150. virtual int rtti() const
    151. {
    152. return QwtPlotItem::Rtti_PlotUserItem;
    153. }
    154.  
    155. virtual void draw(QPainter *painter,
    156. const QwtScaleMap &,
    157. const QwtScaleMap &,
    158. const QRectF &rect) const
    159. {
    160. QColor color(Qt::gray);
    161. color = color.darker(150);
    162. painter->fillRect(rect, color);
    163. }
    164. };
    165.  
    166. class ChartCurve: public QwtPlotCurve
    167. {
    168. public:
    169. ChartCurve(const QString &title) : QwtPlotCurve(title)
    170. {
    171. setRenderHint(QwtPlotItem::RenderAntialiased);
    172. }
    173.  
    174. void setColor(const QColor &color)
    175. {
    176. QColor c = color;
    177. c.setAlpha(150);
    178.  
    179. setPen(c);
    180. setBrush(c);
    181. }
    182. };
    183.  
    184. ChartPlot::ChartPlot(QStandardItemModel *model, bool isSplineUsed, QWidget *parent) : QwtPlot(parent)
    185. {
    186. this->model = model;
    187. splineUsed = isSplineUsed;
    188.  
    189. setAutoReplot(false);
    190.  
    191. plotLayout()->setAlignCanvasToScales(true);
    192.  
    193. signs = new QwtLegend;
    194. signs->setItemMode(QwtLegend::CheckableItem);
    195. insertLegend(signs, QwtPlot::RightLegend);
    196.  
    197. setAxisTitle(QwtPlot::xBottom, "Report time");
    198. setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());
    199.  
    200. scaleWidget = axisWidget(QwtPlot::xBottom);
    201. const int fmh = QFontMetrics(scaleWidget->font()).height();
    202. scaleWidget->setMinBorderDist(0, fmh / 2);
    203.  
    204. setAxisTitle(QwtPlot::yLeft, "Quantity");
    205.  
    206. grid = new Grid;
    207. grid->attach(this);
    208.  
    209. bg = new Background();
    210. bg->attach(this);
    211.  
    212. countPlot();
    213.  
    214. scaleEngineX = new QwtLinearScaleEngine;
    215. scaleEngineX->setAttribute(QwtScaleEngine::Floating, true);
    216. setAxisScaleEngine(QwtPlot::xBottom, scaleEngineX);
    217. setAxisScaleDiv(QwtPlot::xBottom, scaleDiv());
    218.  
    219. scaleEngineY = new QwtLinearScaleEngine;
    220. scaleEngineY->setAttribute(QwtScaleEngine::IncludeReference, true);
    221. scaleEngineY->setReference(0);
    222. setAxisScaleEngine(QwtPlot::yLeft, scaleEngineY);
    223.  
    224. picker = new PlotPicker(QwtPlot::xBottom,
    225. QwtPlot::yLeft,
    226. QwtPlotPicker::CrossRubberBand,
    227. QwtPicker::ActiveOnly,
    228. this->canvas());
    229. replot();
    230. zoomer = new Zoomer(QwtPlot::xBottom, QwtPlot::yLeft, this->canvas());
    231. zoomer->setZoomBase(false);
    232. connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), SLOT(showCurve(QwtPlotItem *, bool)));
    233. }
    234.  
    235. void ChartPlot::showCurve(QwtPlotItem *item, const bool &on, const bool &replt)
    236. {
    237. item->setVisible(on);
    238. QWidget *w = legend()->find(item);
    239. if (w && w->inherits("QwtLegendItem")) ((QwtLegendItem *)w)->setChecked(on);
    240. if (replt) replot();
    241. }
    242.  
    243. void ChartPlot::useSpline(bool on, bool refresh)
    244. {
    245. if (on)
    246. {
    247. for (int i=0; i<curve.count(); i++)
    248. {
    249. curveFitter = new QwtSplineCurveFitter;
    250. curve.at(i)->setCurveFitter(curveFitter);
    251. }
    252. }
    253. else
    254. {
    255. for (int i=0; i<curve.count(); i++)
    256. {
    257. curveFitter = new QwtWeedingCurveFitter;
    258. curve.at(i)->setCurveFitter(curveFitter);
    259. }
    260. }
    261. if (refresh) replot();
    262. }
    263.  
    264. void ChartPlot::countPlot()
    265. {
    266. // Store current visibility of curves if they exist, otherwise initialize visibility to true
    267. QList<bool> visible;
    268. if (curve.isEmpty())
    269. {
    270. for (int column = 1; column < model->columnCount(); column++)
    271. visible.append(true);
    272. }
    273. else
    274. {
    275. for (int column = 1; column < model->columnCount(); column++)
    276. {
    277. visible.append(curve[column - 1]->isVisible());
    278. curve[column - 1]->detach();
    279. }
    280. curve.clear();
    281. }
    282. // Read X-axis data from table
    283. for (int row=0; row<model->rowCount(); row++)
    284. {
    285. QDateTime xDateTime = model->item(row, 0)->data(Qt::EditRole).toDateTime();
    286. xData << xDateTime.toTime_t();
    287. }
    288. // Read Y-axis data from table
    289. for (int column = 1; column < model->columnCount(); column++)
    290. {
    291. QVector<double> yData;
    292.  
    293. curve.append(new ChartCurve(model->horizontalHeaderItem(column)->text()));
    294. curve.last()->setStyle(QwtPlotCurve::Lines);
    295. QVariant decoration = model->item(0, column)->data(Qt::DecorationRole);
    296. if (decoration.type() == QVariant::Color)
    297. {
    298. curve.last()->setColor(decoration.value<QColor>());
    299. }
    300. curve.last()->setCurveAttribute(QwtPlotCurve::Fitted, true);
    301. curve.last()->setZ(curve.last()->z() - 1);
    302. curve.last()->attach(this);
    303.  
    304. for (int row=0; row<model->rowCount(); row++)
    305. {
    306. yData << model->item(row, column)->data(Qt::EditRole).toDouble();
    307. }
    308. curve.last()->setSamples(xData, yData);
    309. showCurve(curve.last(), visible[column - 1], false);
    310. }
    311. useSpline(splineUsed, false);
    312. }
    To copy to clipboard, switch view to plain text mode 

    I have tried many combinations of calling setZoomBase() and adding Zoomer to plot, no success.

    Maybe it would be easier to understand if you could just show me the line where I should put it. I even checked your code, and examples (randomplot uses the same code as me), no success.

    Could the solution be inside rescale() of Zoomer class? Please, help, my application is finished, running smoothly, except this one.

  13. #11
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotZoomer question

    Here is my understanding of zoomer.
    Default scales are 1000 for both the axes. So first you need to setZoomBase() after you do setSamples(). However, when you do zoom in, the autoscales are set to off. This is done implicitly. So we also need to setAutoScale(). The place to do that is in the slot for the signal zoomed(QRectF) of zoomer. Some code to explain it..
    Qt Code:
    1. connect(d_zoomer, SIGNAL(zoomed(QRectF), this, SLOT(autoRescale(QRectF)); //d_zoomer is zoomer's pointer
    To copy to clipboard, switch view to plain text mode 
    function implementation...
    Qt Code:
    1. void myPlot::autoRescale(QRectF)
    2. {
    3. if(d_zoomer->zoomRectIndex()==0) // autorescale only if u are at base... otherwise u defined scales by zoomer right..
    4. {
    5. setAxisAutoScale(yLeft);
    6. setAxisAutoScale(xBottom);
    7. d_zoomer->setZoomBase();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    HTH
    Last edited by pkj; 17th May 2011 at 17:55. Reason: QwtPlotZoomer

  14. The following user says thank you to pkj for this useful post:

    embeddedmz (30th July 2019)

  15. #12
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotZoomer question

    Thanks, it could be the reason! I also thought that it could rather be about that zoomer drops the original scaling after zooming. I'm going to give it a try, and let you know about the result.

Similar Threads

  1. QwtPlotZoomer->setZoomBase
    By gronerth in forum Qwt
    Replies: 2
    Last Post: 24th January 2014, 16:01
  2. QwtPlotZoomer very slow
    By locke in forum Qwt
    Replies: 2
    Last Post: 7th July 2010, 16:56
  3. Sorry - more QwtPlotZoomer questions
    By cnbp173 in forum Qwt
    Replies: 4
    Last Post: 7th May 2010, 09:26
  4. QwtPlotZoomer, using two zoomers.
    By jma in forum Qwt
    Replies: 2
    Last Post: 30th September 2008, 08:29
  5. Problem with QwtPlotZoomer
    By seguprasad in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2007, 08:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.