Results 1 to 8 of 8

Thread: Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

  1. #1
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

    I updated the Qwt version from 5.2.3 to 6.1.6 and the Plot Grid and Plot Background are not visible anymore in the plot.

    I have classes that reimplements the draw method:
    Qt Code:
    1. class PlotGrid : public QwtPlotGrid
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. class PlotBackground : public QwtPlotShapeItem
    To copy to clipboard, switch view to plain text mode 
    .

    The implementation is working with Qwt 5.2.3 and Qt 4.8.2 and updated the Qwt to 6.1.6 and Qt 5.15.2 and the plot grid and plot background are not shown anymore in the plot panel.

    I already added the libraries needed qwtd.dll, qwt.dll, Qt5Core.dll, Qt5Cored.dll, Qt5Gui.dll, Qt5Guid.dll, Qt5Widgets.dll and Qt5Widgetsd.dll.

    I added a break point in the draw method and it does not trigger the break points in VS2019. Testing my old Qt and Qwt version in VS2008 will trigger the break point in the draw method.

    The only difference in the code is that I inherit the PlotGrid class to QwtPlotGrid instead of QwtPlotItem


    Regards,
    olredi
    Last edited by olredi; 6th April 2021 at 08:25.

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

    Default Re: Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

    Quote Originally Posted by olredi View Post
    I added a break point in the draw method and it does not trigger the break points in VS2019.
    Then you already know the problem.

    Uwe

  3. #3
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

    Yes but why it is not working with the version 6.1.6? I suspect that it has something to do with the QwtItemPlot since the previous implementation of PlotBackground is:
    Qt Code:
    1. class PlotBackground : public QwtPlotItem
    To copy to clipboard, switch view to plain text mode 
    and I changed it to
    Qt Code:
    1. class PlotBackground : public QwtPlotShapeItem
    To copy to clipboard, switch view to plain text mode 
    .
    The PlotGrid also inherits to QwtPlotItem and grids and background are displayed but when I inherit to class
    Qt Code:
    1. class PlotGrid : public QwtPlotGrid
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. class PlotBackground : public QwtPlotShapeItem
    To copy to clipboard, switch view to plain text mode 
    , the grids and background are not displayed anymore.

    Is there a flag or attributes that I need to set in order for the draw() method triggered? I think I implemented the attach method correctly.

    Qt Code:
    1. m_plot = new Plot(plotStyle, this);
    2. m_plot->move(PLOT_HORIZONTAL_BORDER, PLOT_TOP_BORDER);
    3.  
    4. m_plotBackground = new PlotBackground;
    5. m_plotBackground->attach(m_plot);
    6.  
    7. m_plotGrid = new PlotGrid;
    8. m_plotGrid->attach(m_plot);
    To copy to clipboard, switch view to plain text mode 

    and somewhere in the code will call the
    Qt Code:
    1. m_plot->replot();
    To copy to clipboard, switch view to plain text mode 

    Thanks for the reply

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,278
    Thanked 872 Times in 820 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

    Without knowing your code I can't say anything useful.

  5. #5
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

    Quote Originally Posted by Uwe View Post
    Without knowing your code I can't say anything useful.
    The code is long and complex but I try to minimize it regarding background, grids and plot only. Here are the simplified source codes:

    Starting with the class that initialize the Plot Panel
    Qt Code:
    1. //includes here
    2. //namespace here
    3.  
    4. MethodResultScreen::MethodResultScreen(PMT::ItfResultMngmt::IResultReader::SPtr resultReader, QWidget *parent) :
    5. BasicScreen(parent),
    6. m_journalModel(0),
    7. m_journalView(0),
    8. m_plotPanel(0),
    9. m_journalTab(0),
    10. m_chartTab(0),
    11. m_filterControl(0),
    12. m_backButton(0),
    13. m_printButton(0),
    14. m_deleteButton(0),
    15. m_exportButton(0),
    16. m_advancedFilterSettingsScreen(0),
    17. m_filterSelection(DEFAULT_FILTER),
    18. m_isNavigationFromAdvanceFilter(false)
    19. {
    20. Q_ASSERT(resultReader);
    21.  
    22. //intialize journal view here
    23.  
    24. // create chart view
    25.  
    26. m_plotPanel = new PMT::GuiBase::PlotPanel(DISCRETE_PLOT, REDUCED_RULER, this);
    27. m_plotPanel->enableLimitText(true);
    28.  
    29. m_plotDataAdapter.setModel(m_chartModel);
    30.  
    31. PlotCurve *curve = new PlotCurve(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE));
    32. curve->setAxes(X_AXIS, Y_AXIS);
    33. curve->attach(m_plotPanel->plot());
    34. //Upcast needed. The QwtSeriesStore<QPointF>::setData needs the parameter of QwtSeriesData<QPointF> *param
    35. //PlotDataAdapter inherits from QwtSeriesData
    36. QwtSeriesData<QPointF> *parentData = &m_plotDataAdapter;
    37. curve->setData(parentData);
    38.  
    39. // intialize tabs and buttons here
    40.  
    41. connect(m_plotPanel, SIGNAL(controlValueSelected(int, bool)), SLOT(onControlValueSelected(int)));
    42. }
    43.  
    44. MethodResultScreen::~MethodResultScreen()
    45. {
    46. }
    47.  
    48. void MethodResultScreen::showEvent(QShowEvent *showEvent)
    49. {
    50. updateView();
    51. BasicScreen::showEvent(showEvent);
    52. }
    53.  
    54. void MethodResultScreen::updateView(void)
    55. {
    56. Q_ASSERT(m_journalModel);
    57. Q_ASSERT(m_filterControl);
    58.  
    59. //some implementations here regarding filter
    60. m_journalModel->reload();
    61.  
    62. configurePlot();
    63. }
    64.  
    65. void MethodResultScreen::configurePlot(void)
    66. {
    67. Q_ASSERT(m_plotPanel);
    68.  
    69. qDebug("Start configuring plot"); // 140515
    70. static QTime time;
    71. time.restart();
    72.  
    73. PlotControlLimitSet controlLimitSet = PlotControlLimitSet();
    74.  
    75. if( m_journalModel->chartRows().size() > 0 )
    76. {
    77. QModelIndex valueIndex = m_chartModel->index( m_journalModel->chartRows().at(0), 0 );
    78.  
    79. if( valueIndex.isValid() && m_journalModel->isMethodVersionCurrent( valueIndex ) )
    80. {
    81. controlLimitSet = m_controlLimitSet;
    82. }
    83. }
    84.  
    85. // calculate y-axis scale
    86.  
    87. ChartScaleCalculator chartScaleCalculator;
    88. chartScaleCalculator.calculate(&m_plotDataAdapter, &controlLimitSet);
    89.  
    90. //TODO:add minimal border gap on maximum.
    91. double minimum = chartScaleCalculator.minimum();
    92. double maximum = chartScaleCalculator.maximum();
    93.  
    94.  
    95. m_plotPanel->setControlLimitSet(controlLimitSet);
    96. m_plotPanel->plot()->setAxisScale(Y_AXIS, minimum, maximum);
    97.  
    98. int sampleCount = m_plotDataAdapter.size();
    99.  
    100. // calculate x-axis scale
    101.  
    102. QwtScaleDiv scaleDiv = DiscreteScaleDivFactory::create(sampleCount);
    103. m_plotPanel->plot()->setAxisScaleDiv(X_AXIS, scaleDiv);
    104.  
    105. // add control values
    106.  
    107. //initialize controlValues here
    108. m_plotPanel->setControlValues(controlValues, true);
    109. if (controlValues.size() > 0)
    110. {
    111. m_plotPanel->selectControlValue(controlValues.last());
    112. }
    113.  
    114. // set unit label
    115.  
    116. m_plotPanel->setAxisLabel(Y_AXIS, m_resultUnit);
    117.  
    118. // trigger axis update
    119.  
    120. m_plotPanel->plot()->updateAxes();
    121. qDebug("Finished configuring plot in: %d ms", time.elapsed()); // 140515
    122.  
    123. }
    To copy to clipboard, switch view to plain text mode 
    And simplified PlotPanel class
    Qt Code:
    1. //some includes here
    2. //namespace
    3.  
    4. const qreal PlotPanel::TEXT_OPACITY = 0.4;
    5.  
    6. PlotPanel::PlotPanel(PlotStyle plotStyle, RulerType rulerType, QWidget *parent) :
    7. QWidget(parent),
    8. m_plot(0),
    9. m_plotBackground(0),
    10. m_plotGrid(0),
    11. m_plotRulerPanel(0),
    12. m_leftButton(0),
    13. m_rightButton(0),
    14. m_showLeftLabel(true),
    15. m_showRightLabel(false),
    16. m_showBottomLabel(true),
    17. m_predResultUncertainty(0.0)
    18. {
    19. setFixedSize(StyleInfo::PLOT_PANEL_WIDTH, StyleInfo::PLOT_PANEL_HEIGHT);
    20.  
    21. m_plot = new Plot(plotStyle, this);
    22. m_plot->move(PLOT_HORIZONTAL_BORDER, PLOT_TOP_BORDER);
    23.  
    24. m_plotBackground = new PlotBackground;
    25. m_plotBackground->attach(m_plot);
    26.  
    27. m_plotGrid = new PlotGrid;
    28. m_plotGrid->attach(m_plot);
    29. }
    30.  
    31. PlotPanel::~PlotPanel()
    32. {
    33. }
    34.  
    35. void PlotPanel::setControlLimitSet(const PlotControlLimitSet &controlLimitSet)
    36. {
    37. Q_ASSERT(m_plotGrid);
    38. m_plotGrid->setControlLimitSet(controlLimitSet);
    39. }
    40.  
    41. void PlotPanel::enableLimitText(bool enable)
    42. {
    43. Q_ASSERT(m_plotGrid);
    44. m_plotGrid->enableLimitText(enable);
    45. }
    46.  
    47. void PlotPanel::setControlValues(const QList< ControlValue > &controlValues, bool chartModel)
    48. {
    49. m_plot->replot();
    50.  
    51. //some implementations here regarding control values and plot markers
    52.  
    53. m_plot->replot();
    54. }
    55.  
    56. void PlotPanel::showAxis(Axis axis, bool show)
    57. {
    58. Q_ASSERT(m_plot);
    59. m_plot->showAxis((QwtPlot::Axis)axis, show);
    60.  
    61. switch (axis)
    62. {
    63. case QwtPlot::yLeft :
    64. {
    65. m_showLeftLabel = show;
    66. break;
    67. }
    68. case QwtPlot::yRight :
    69. {
    70. m_showRightLabel = show;
    71. break;
    72. }
    73. case QwtPlot::xBottom :
    74. {
    75. m_showBottomLabel = show;
    76. break;
    77. }
    78. default:
    79. {
    80. break;
    81. }
    82. }
    83. update();
    84. }
    85.  
    86. void PlotPanel::paintEvent(QPaintEvent *)
    87. {
    88. Q_ASSERT(m_plot);
    89.  
    90. QPainter painter(this);
    91.  
    92. painter.setFont(StyleInfo::font(StyleInfo::FONT_SIZE_SMALL));
    93. painter.fillRect(rect(), Qt::white);
    94. painter.setOpacity(TEXT_OPACITY);
    95.  
    96. if (m_showLeftLabel)
    97. {
    98. drawLeftLabel(&painter);
    99. }
    100. if (m_showRightLabel)
    101. {
    102. drawRightLabel(&painter);
    103. }
    104. if (m_showBottomLabel)
    105. {
    106. drawBottomLabel(&painter);
    107. }
    108. }
    To copy to clipboard, switch view to plain text mode 
    PlotBackground implementation is as is
    Qt Code:
    1. //includes here
    2. //namespace here
    3.  
    4. void PlotBackground::draw(QPainter *painter, const QwtScaleMap &,
    5. const QwtScaleMap &, const QRect &rect) const
    6. {
    7. Q_ASSERT(painter);
    8. if( !m_backgroundText.isEmpty() )
    9. {
    10. painter->viewport();
    11.  
    12. painter->setOpacity(StyleInfo::opacity(StyleInfo::FONT_INTENSITY_MIDDLE));
    13. painter->setPen(QPen(StyleInfo::fontBaseColor(StyleInfo::FONT_COLOR_POSITIVE_GREY_ON_LIGHT)));
    14. painter->setFont(StyleInfo::font(StyleInfo::FONT_SIZE_STANDARD));
    15.  
    16. painter->drawText(rect, Qt::AlignCenter, m_backgroundText);
    17. }
    18. else
    19. {
    20. QPixmap background;
    21. PixmapDatabase::find(PixmapDatabase::PIXMAP_PLOT_BACKGROUND, &background);
    22. painter->drawPixmap(rect, background);
    23. }
    24. }
    25.  
    26.  
    27. void PlotBackground::setBackgroundText(const QString &text)
    28. {
    29. m_backgroundText = text;
    30. }
    31.  
    32. } // namespace GuiBase
    33. } // namespace PMT
    To copy to clipboard, switch view to plain text mode 
    And lastly the PlotGrid class
    Qt Code:
    1. PlotGrid::PlotGrid() :
    2. m_enableLimitText(false)
    3. {
    4. }
    5.  
    6. void PlotGrid::draw(QPainter *painter, const QwtScaleMap &xMap,
    7. const QwtScaleMap &yMap, const QRect &rect) const
    8. {
    9. Q_ASSERT(painter);
    10.  
    11. painter->save();
    12.  
    13. painter->setOpacity(0.2);
    14.  
    15. painter->setPen(QPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_THREE)));
    16. drawLines(painter, rect, Qt::Vertical, xMap,
    17. m_xScaleDiv.ticks(QwtScaleDiv::MajorTick));
    18.  
    19. painter->setPen(QPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE)));
    20. drawLines(painter, rect, Qt::Horizontal, yMap,
    21. m_yScaleDiv.ticks(QwtScaleDiv::MajorTick));
    22.  
    23. painter->setOpacity(1.0);
    24.  
    25. // paint scale backbones
    26.  
    27. painter->setPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_ONE));
    28. painter->drawLine(rect.left(), rect.top(), rect.left(), rect.bottom());
    29.  
    30. painter->setPen(StyleInfo::skinColor(StyleInfo::SKIN_COLOR_PLOT_THREE));
    31. painter->drawLine(rect.left(), rect.bottom(), rect.right(), rect.bottom());
    32.  
    33. painter->restore();
    34. }
    35.  
    36. void PlotGrid::updateScaleDiv(const QwtScaleDiv &xScaleDiv, const QwtScaleDiv &yScaleDiv)
    37. {
    38. m_xScaleDiv = xScaleDiv;
    39. m_yScaleDiv = yScaleDiv;
    40. }
    41.  
    42. void PlotGrid::update(void)
    43. {
    44. // todo: is there a better way to force an update??
    45. QwtPlot *qwtPlot = plot();
    46. if (qwtPlot)
    47. {
    48. QwtPlotCanvas *plotCanvas = (QwtPlotCanvas*)qwtPlot->canvas();
    49. if (plotCanvas)
    50. {
    51. plotCanvas->invalidateBackingStore();
    52. plotCanvas->update();
    53. }
    54. }
    55. }
    To copy to clipboard, switch view to plain text mode 
    The previous implementation in PlotGrid::update() is plotCanvas->invalidatePaintCache() and it is replaced now by plotCanvas->invalidateBackingStore().
    Attached is the Plot view (top is using qwt 5.2.3 and bottom where grid, background and markers are missing with 6.1.6)

    Thanks and sorry if this is still not enough
    Attached Images Attached Images

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

    Default Re: Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

    Your draw methods are not overriding - they have a QRect while QwtPlotItem::draw has a QRectF in the signature.
    Using the C++11 override keyword would have told you.

    HTH,
    Uwe

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

    olredi (9th April 2021)

  8. #7
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

    Thanks a lot. That solves my problem.

    Using the C++11 override keyword would have told you.
    Did not see anything regarding override.

    Thanks,
    olredi

  9. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,019
    Thanks
    280
    Thanked 817 Times in 806 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qwt Plot Grid and Plot Background problem when updating qwt 5.2.3 to 6.1.6

    Did not see anything regarding override.
    "override" is a new keyword starting in C++11. You place it at the end of the declaration of a virtual class method that you are overriding. If you make a mistake in the declaration (QRect instead of QRectF for example) the compiler will issue an error because the signature is wrong.

    Qt Code:
    1. void draw(QPainter *painter, const QwtScaleMap &, const QwtScaleMap &, const QRect &rect) const override;
    To copy to clipboard, switch view to plain text mode 
    would cause a compile error with Qwt 6.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  10. The following user says thank you to d_stranz for this useful post:

    olredi (9th April 2021)

Similar Threads

  1. Plot above/below grid
    By link19 in forum Qwt
    Replies: 1
    Last Post: 3rd September 2019, 16:31
  2. How to force plot grid to follow top axis?
    By Sintegrial in forum Qwt
    Replies: 5
    Last Post: 13th November 2015, 10:13
  3. Replies: 13
    Last Post: 20th September 2011, 09:50
  4. sync plot grid w/ external scale widget
    By Kevin Ching in forum Qwt
    Replies: 6
    Last Post: 30th September 2010, 17:12
  5. Qwt plot + grid huge pdf file
    By giusepped in forum Qwt
    Replies: 3
    Last Post: 17th December 2008, 13:53

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.