Results 1 to 14 of 14

Thread: QwtPlotOverlay

  1. #1
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default QwtPlotOverlay

    Hi.

    Can U expain what is QwtPlotOverlay and how it using for example with QwtPlotMarker.... There is no clear how to do this from ItemEditor example...

    So I have plot, I have 1 QwtPlotMarker that is VLine , and for example 3 QwtPlotMarker that is Labels with text, and I have 3 QwtPlotCurve for each QwtPlotMarker...

    So I want that on plot will show 3 QwtPlotCurve and QwtPlotMarkers will show with help on QwtPlotOverllay ( this I need to do because I need that when I move my QwtPlotMarker that is VLine ( posititin of this VLine = pos.x() getting from mouse coordinates).

    As I understand for this task there is good to use QwtPlotOverllay, but how I need to use this in my task?

    In example is function:
    Qt Code:
    1. bool Editor::moved( const QPoint& pos ) {
    2. ....
    3. d_editedItem->setShape( d_editedItem->shape().translated( p2 - p1 ) );
    4. }
    To copy to clipboard, switch view to plain text mode 
    So as I think in generall all that i need to do is to use instead QwtPlotShapeItem* d_editedItem; - smth like QwtPlotMarjer ..., and in function that i show above do smth like d_editedItem->setValue(....) ?

  2. #2
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    Hi.

    I try to do like in ItemEditor, but there is no work... Can U see this code...


    I understood what was wrong... In code that I post I need to do replot myself, than all is ok. But there as I think bad because there is need to do replot and when i will have a lot graphics that is hard to repaint it will be working slowly. Am I right? Or QwtPlotOverlay will do it more faster? Can U explain how it work? I thought that we draw an item on QwtPlot Overlay'e and it turns out that we draw again on the plot. Am I right?

    And how be when I have 4 QwtPlotMarker and when I move mouse I need to move all 4 QwtPlotMarker? maskHint what will return?
    Attached Files Attached Files
    Last edited by carhun; 3rd September 2012 at 13:06.

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

    Default Re: QwtPlotOverlay

    The basic idea of using an overlay is, that all moving parts are displayed in a widget on top of the canvas ( the overlay ) and the screen can always been restored from the cached content of the plot - without an expensive replot.

    The editor from the example detects clicks on a plot item, then detaches the clicked item from the plot showing it as overlay widget. When the mouse is released the overlay gets destroyed and the item gets re-attached with modified coordinates.

    QwtPlotOverlay does some specific stuff for you - but of course you need to implement YourOverlay::drawOverlay yourself. The implementation of how to translate mouse clicks into selections is a different story. But the basic steps can be seen in the example.

    Uwe

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

    carhun (4th September 2012)

  5. #4
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    In ItemEditor it helps because move of some shape item we did on a widget...

    But in my variant is bad to do in same way, because I need to move my QwtPlotMarker with correspond mouse pos when I enter widget and when I leave widget I need to delete overlay and attached QwtPlotMarker to plot... so it turns out that it redraws only when I go out for the widget...

    If I understand it does not suit me to use QwtPlotMarker/QwtPlotOverlay in my task?

    And why it dont show any change while I dont leave widget... ?

    Qt Code:
    1. bool Editor::eventFilter(QObject *object, QEvent *event) {
    2. QwtPlot *plot = qobject_cast<QwtPlot *>(parent());
    3. if (plot && object == plot->canvas()) {
    4. switch(event->type()) {
    5. case QEvent::Enter:
    6. if (!m_overlay) {
    7. detach();
    8.  
    9. m_overlay = new Overlay(plot->canvas(), this);
    10.  
    11. m_overlay->updateOverlay();
    12. m_overlay->show();
    13. }
    14. break;
    15.  
    16. case QEvent::Leave:
    17. if (m_overlay) {
    18. attach();
    19.  
    20. delete m_overlay;
    21. m_overlay = 0;
    22. }
    23. break;
    24.  
    25. case QEvent::MouseMove:
    26. if (m_overlay) {
    27. const QMouseEvent* mouseEvent =
    28. static_cast< QMouseEvent* >( event );
    29.  
    30. const bool accepted = moved(mouseEvent->pos());
    31. if ( accepted )
    32. m_overlay->updateOverlay();
    33. }
    34. break;
    35.  
    36. default:
    37. break;
    38. }
    39.  
    40. return false;
    41. }
    42.  
    43. return QObject::eventFilter( object, event );
    44. }
    45.  
    46. bool Editor::detach()
    47. {
    48. m_markers = findPlotMarkers();
    49.  
    50. if (!m_markers.empty()) {
    51. setItemVisible(false);
    52.  
    53. return true;
    54. }
    55.  
    56. return false; // don't accept the position
    57. }
    58.  
    59. bool Editor::attach()
    60. {
    61. if (!m_markers.empty())
    62. {
    63. setItemVisible(true);
    64.  
    65. return true;
    66. }
    67.  
    68. return false;
    69. }
    70.  
    71. bool Editor::moved(const QPoint &pos) {
    72. if (!plot())
    73. return false;
    74.  
    75. QwtPlotMarker *marker;
    76.  
    77. for (int i = 0; i < m_markers.size(); i++) {
    78. marker = (QwtPlotMarker *)m_markers.at(i);
    79.  
    80. const QwtScaleMap xMap = plot()->canvasMap(marker->xAxis());
    81. const QwtScaleMap yMap = plot()->canvasMap(marker->yAxis());
    82. const QPointF point = QwtScaleMap::invTransform(xMap, yMap, pos);
    83. const QPointF p1 = QPointF(point.x() + 25*i, point.y() + 25*i);
    84.  
    85. marker->setValue(p1);
    86. }
    87.  
    88. return true;
    89. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by carhun; 4th September 2012 at 09:22.

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

    Default Re: QwtPlotOverlay

    Hard to understand what your requirements are, but maybe all you want to do is using QwtPlotPicker ( configured to show a line and a text ) with a QwtPickerTrackerMachine.
    QwtPickerTrackerMachine de/activates the picker ( hide/show the internal picker overlays ) for leave/enter events.

    You can modify the bode example ( assign a different machine to the picker ) to see how it works.

    If this is not what you need better try to explain what the general requirement of your application is - before asking about details of your implementation.

    HTH,
    Uwe

  7. #6
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    About requirement:

    I have plots, on plots there is some amount of curves.
    I want to do next: when mouse enter plot i draw VLine (which is responsible for value X), than I for each curve calculate value of Y for current X and this value Y I need to show in position (X, Y)... And If I move mouse recalculate all...

    About QwtPlotPicker. I tried to do in this way, but I didnt find way to do for other plots QwtPlotPicker always visible ( QwtPlotPicker is visible as I understand when mouse cursor is on plot) and I didnt find way to change text of QwtPlotMarker and background of text ( I need to do background of text as color of curve).

    So I need to use as I undestand QwtPlotMarkers. But there is hard to do always replot to show QwtPlotMarkers, so I need to use something like QwtPlotOverlay....

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

    Default Re: QwtPlotOverlay

    Quote Originally Posted by carhun View Post
    I have plots, on plots there is some amount of curves.
    I want to do next: when mouse enter plot i draw VLine (which is responsible for value X), than I for each curve calculate value of Y for current X and this value Y I need to show in position (X, Y)... And If I move mouse recalculate all...
    Then QwtPlotPicker is exactly what you are looking for.

    All you need to do is to use the machine above and configure a vertical line as rubberband and enable the tracker text to AlwaysOn. Then overload QwtPlotPicker::trackerTextF where you calculate the corresponding y value for the curve ( or several curves ):

    Qt Code:
    1. class YourPicker: public QwtPlotPicker
    2. {
    3. virtual QwtText trackerTextF( const QPointF &pos ) const
    4. {
    5. return QwtPlotPicker::trackerTextF( x, findCurvePos( pos.x() );
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    How to implement findCurvePos in an effective way depends on the characteristics of your samples. F.e when your samples are ordered in x direction you could use some binary search algorithm ( if this is what you need I can post code lying on my disk ).

    Uwe

  9. #8
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    Quote Originally Posted by Uwe View Post
    Then QwtPlotPicker is exactly what you are looking for.

    All you need to do is to use the machine above and configure a vertical line as rubberband and enable the tracker text to AlwaysOn. Then overload QwtPlotPicker::trackerTextF where you calculate the corresponding y value for the curve ( or several curves ):

    Qt Code:
    1. class YourPicker: public QwtPlotPicker
    2. {
    3. virtual QwtText trackerTextF( const QPointF &pos ) const
    4. {
    5. return QwtPlotPicker::trackerTextF( x, findCurvePos( pos.x() );
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    How to implement findCurvePos in an effective way depends on the characteristics of your samples. F.e when your samples are ordered in x direction you could use some binary search algorithm ( if this is what you need I can post code lying on my disk ).

    Uwe
    1. How for QwtPlotPicker I can draw more than one Text? I need for each curve text with value Y
    2. Can I control QwtPlotPicker? What I mean? I have 2 plots. than I want when I move QwtPlotPicker at plot 1 I need to move automatically move QwtPlotPicker at plot 2?
    3. How can I set position of VLine of Picker?
    4. As I can see I cant control text of QwtPlotPicker?... I dont see how I can do f.e. red backgroud and white letter for text of QwtPlotPicker...

    If I can do this, than this way suits me and I will thanks if U post code how to implement findCurvePos...

    And can U tell me why dont work QwtPlotMarker with QwtPlotOverlay like I show code above?

    Mb to do this task will be better to draw VLine by painter on QwtPlotOverlay and using QwtText for show value of Y for each curve? If it is more prefer way, can I draw QwtText not into rectangle? f.e. into circle or another shape that I want?

    F.e.:
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QWidget>
    5. #include <QDebug>
    6.  
    7.  
    8. class Widget;
    9. class QwtPlot;
    10. class Picker;
    11.  
    12. class Widget : public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit Widget(QWidget *parent = 0);
    18. ~Widget();
    19.  
    20. private:
    21. QVBoxLayout *m_layout;
    22.  
    23. QwtPlot *m_plot1;
    24. QwtPlot *m_plot2;
    25.  
    26. Picker *m_picker1; // for m_plot1
    27. Picker *m_picker2; // for m_plot2
    28. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "widget.h"
    2.  
    3. #include <QWidget>
    4. #include <QVBoxLayout>
    5.  
    6. #include "plot.h"
    7.  
    8. #include "picker.h"
    9.  
    10. Widget::Widget(QWidget *parent) :
    11. QWidget(parent)
    12. {
    13. m_layout = new QVBoxLayout(this);
    14. m_layout->setMargin(0);
    15.  
    16. m_plot1 = new QwtPlot(this);
    17. m_plot2 = new QwtPlot(this);
    18.  
    19. m_layout->addWidget(m_plot1);
    20. m_layout->addWidget(m_plot2);
    21.  
    22. m_picker1 = new Picker(m_plot1->canvas());
    23. m_picker2 = new Picker(m_plot2->canvas());
    24.  
    25. connect(m_picker1, SIGNAL(moved(QPoint)),
    26. m_picker2, SLOT(slot_move(QPoint)));
    27.  
    28. connect(m_picker2, SIGNAL(moved(QPoint)),
    29. m_picker1, SLOT(slot_move(QPoint)));
    30.  
    31. setLayout(m_layout);
    32. }
    33.  
    34. Widget::~Widget()
    35. {
    36. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef PICKER_H
    2. #define PICKER_H
    3.  
    4. #include <qwt/qwt_plot_picker.h>
    5.  
    6. class Picker : public QwtPlotPicker
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit Picker(QWidget *parent = 0);
    11.  
    12. signals:
    13.  
    14. public slots:
    15. void slot_move(const QPoint &pos);
    16. };
    17.  
    18. #endif // PICKER_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "picker.h"
    2.  
    3. #include <qwt/qwt_picker_machine.h>
    4.  
    5. Picker::Picker(QWidget *parent) :
    6. QwtPlotPicker(parent)
    7. {
    8. setRubberBandPen(QColor(Qt::magenta));
    9. setRubberBand(QwtPicker::VLineRubberBand);
    10. setTrackerPen(QColor(Qt::darkRed));
    11. setTrackerMode(QwtPicker::AlwaysOn);
    12. setTrackerFont(QFont("Helvetica"));
    13.  
    14. setStateMachine(new QwtPickerTrackerMachine);
    15. }
    16.  
    17. void Picker::slot_move(const QPoint &pos)
    18. {
    19. move(pos);
    20. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by carhun; 4th September 2012 at 14:32.

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

    Default Re: QwtPlotOverlay

    1. How for QwtPlotPicker I can draw more than one Text? I need for each curve text with value Y
    You need a text displaying one x and many y values - but not more than one text and it's up to you how to implement the trackerTextF() hook. Note that QwtText can do rich text ( even if it is not fast ), what means that you can even return tables or whatever.
    2. Can I control QwtPlotPicker? What I mean? I have 2 plots. than I want when I move QwtPlotPicker at plot 1 I need to move automatically move QwtPlotPicker at plot 2?
    I remember that I once posted an implementation for a cursor ( a moving vertical line ) implemented as picker, where the position is modified by application code. Check the archive.
    3. How can I set position of VLine of Picker?
    Answer is the same as for 2.
    4. As I can see I cant control text of QwtPlotPicker?... I dont see how I can do f.e. red backgroud and white letter for text of QwtPlotPicker...
    See QwtText::setBackgroundBrush(), QwtText::setBackgroundPen(), QwtText::setColor() - f.e used in spectrogram example.
    When using rich text ( even it is no fast ) each letter might have a different font and color ( see Qt docs ).

    QwtText != QString !!


    Uwe

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

    carhun (4th September 2012)

  12. #10
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    I would like to clarify about text of QwtPlotPicker... It must be only ONE text, i.e. I can't display for QwtPlotPicker with help of reimplement of trackerTextF() something like: at (pos.x(), pox.y()) - text will be pos.y(), at (pos.x(), pos.y1()) - text will be pos.y1() ? For this I need use separately class QwtText? Am I rigth?

    About moving line as picker Ill try to find in examples, thanks.

    Mb I understand U wrong, but in what archive I need to find about implementation picker as moving vertical line by cursor? I tried to find in examples, there is only bode example use QwtPlotPicker, but not in way that i need...
    Last edited by carhun; 4th September 2012 at 15:46.

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

    Default Re: QwtPlotOverlay

    I can't display for QwtPlotPicker with help of reimplement of trackerTextF() something like: at (pos.x(), pox.y()) - text will be pos.y(), at (pos.x(), pos.y1()) - text will be pos.y1() ?
    QwtText is a QString with additional attributes - how it is built and what information you want to display is completely up to you. You could return the name of your grandma if you want to.
    Mb I understand U wrong, but in what archive I need to find about implementation picker as moving vertical line by cursor?
    The archive of this forum or the Qwt mailing list - I can't remember, but I had posted a full implementation somewhere in the last year.

    Uwe

  14. #12
    Join Date
    Jun 2012
    Posts
    33
    Thanks
    6

    Default Re: QwtPlotOverlay

    Quote Originally Posted by Uwe View Post
    QwtText is a QString with additional attributes - how it is built and what information you want to display is completely up to you. You could return the name of your grandma if you want to.
    I dont undestand for what I need to return the name of grandma... Can U explain more detail?
    I want (red color) to get Untitled.png

    The archive of this forum or the Qwt mailing list - I can't remember, but I had posted a full implementation somewhere in the last year.
    I coudn't find too. All that I found was to do with help of QwtPlotMarker(http://sourceforge.net/mailarchive/m...sg_id=19655286) or with help of QwtPlotTrackerMachine (this is not exactly what I need - http://sourceforge.net/mailarchive/m...sg_id=24922429)

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

    Default Re: QwtPlotOverlay

    As you are not the first one who is asking for a "curve tracker" and I have the code on my disk I will add it as example to SVN trunk.

    Uwe

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

    carhun (6th September 2012)

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

    Default Re: QwtPlotOverlay

    O.k. now you find a new example "playground/curvetracker" in SVN trunk. It is not exactly your use case as it draws one tracker label ( with the positions of all curves ) aligned to the first curve. If you want to have different labels for each curve simply use several curve picker, where only one of them has the vertical line enabled ( of course you need to modify the picker a bit then ).

    The tracker shows a multicolored text, where the color is taken from the corresponding curve pen. Take this as an example how to use rich text.

    The tracker uses a new method qwtUpperSampleIndex, that performs a binary search on the curve points. If you want to use Qwt 6.0 you can simply copy the template into your application code. Beside this the CurveTracker should be compatible with Qwt 6.0.

    Please check if the way how the template is declared in qwt_series_data.h is compatible with Windows compilers ( when you are on this system ).

    HTH,
    Uwe

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

    carhun (10th September 2012)

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.