Results 1 to 4 of 4

Thread: Sharing zoom with multiple plots

  1. #1
    Join Date
    Jan 2014
    Posts
    36
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Sharing zoom with multiple plots

    I've got multiple plots that are aligned vertically, displaying data samples that share a common time scale. I've implemented a zoom feature using the mousewheel to zoom in/out based on current cursor position and that works great on the individual plot. What I'd like to do is sync all the plots together so that when a zoom happens on one plot, the others all zoom the same way, ensuring the plots all stay in sync.

    Any thoughts on the best way to do that? Right now I maintain an internal zoom stack, so I could emit a signal that propagates that zoom stack out to the others. I'm not sure if that's the cleanest way to do it though?

  2. #2
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Sharing zoom with multiple plots

    I experimented with two plots...

    I subclassed QwtPlotZoomer (see below)

    Qt Code:
    1. class Zoomer : public QwtPlotZoomer
    2. {
    3. public:
    4. Zoomer( QwtPlot* otherPlot, QWidget*w):QwtPlotZoomer(w), _otherPlot(otherPlot)
    5. {
    6.  
    7. }
    8. virtual void zoom( const QRectF & rc)
    9. {
    10. QwtPlotZoomer::zoom(rc);
    11. QwtInterval intv = plot()->axisInterval (QwtPlot::xBottom);
    12. _otherPlot->setAxisScale(QwtPlot::xBottom, intv.minValue(), intv.maxValue());
    13. intv = plot()->axisInterval (QwtPlot::yLeft);
    14. _otherPlot->setAxisScale(QwtPlot::yLeft, intv.minValue(), intv.maxValue());
    15. _otherPlot->replot();
    16. }
    17. private:
    18. QwtPlot* _otherPlot; //This could be list of plots
    19. };
    To copy to clipboard, switch view to plain text mode 

    Now the custom zoomer is aware of _otherPlot whose scale is adjusted should any zooming occur.

    Clients of custom plot do...

    QwtPlot * plot = new QwtPlot(this);
    QwtPlot * plot1 = new QwtPlot(this);

    ...
    ...

    Zoomer* z = new Zoomer(plot1, plot->canvas());
    Zoomer* z1 = new Zoomer(plot, plot1->canvas());

    I did not check this thoroughly.


    Added after 1 48 minutes:


    Clients of custom plot do...
    Error...
    This should read Clients of Zoomer do ...
    Last edited by Cah; 9th February 2014 at 01:19.

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

    Default Re: Sharing zoom with multiple plots

    Maybe a more general approach would be to connect to the QwtScaleWidget::scaleDivChanged() signal.

    Uwe

  4. #4
    Join Date
    Dec 2013
    Location
    Toronto, Canada
    Posts
    62
    Thanked 16 Times in 15 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Sharing zoom with multiple plots

    Maybe a more general approach would be to connect to the QwtScaleWidget::scaleDivChanged() signal.
    Absolutely...

    Qt Code:
    1. class Plot: public QwtPlot
    2. {
    3. Q_OBJECT
    4. public:
    5. Plot( QWidget * parent= NULL):QwtPlot(parent)
    6. {
    7.  
    8. }
    9. private slots:
    10. void scaleDivChangedSlot ()
    11. {
    12. QwtPlot* plt = static_cast<QwtPlot*>((sender())->parent());
    13. QwtInterval intv = plt->axisInterval (QwtPlot::xBottom);
    14. this->setAxisScale(QwtPlot::xBottom, intv.minValue(), intv.maxValue());
    15. intv = plt->axisInterval (QwtPlot::yLeft);
    16. this->setAxisScale(QwtPlot::yLeft, intv.minValue(), intv.maxValue());
    17. this->replot();
    18. }
    19. };
    To copy to clipboard, switch view to plain text mode 


    Plot* plot = new Plot;
    Plot* plot1 = new Plot;

    QObject::connect(((QObject*)plot->axisWidget(QwtPlot::xBottom)) , SIGNAL(scaleDivChanged () ), plot1, SLOT(scaleDivChangedSlot () ));
    QObject::connect(((QObject*)plot1->axisWidget(QwtPlot::xBottom)) , SIGNAL(scaleDivChanged () ), plot, SLOT(scaleDivChangedSlot () ));


    With this arrangement QwtPlotZoomer, QwtPlotMagnifier and QwtPlotPanner can operate and keep things in sync.

Similar Threads

  1. Multiple Plots in One Window
    By cookie0427 in forum Qwt
    Replies: 3
    Last Post: 4th June 2010, 16:14
  2. Multiple Plots in one Window
    By cookie0427 in forum Newbie
    Replies: 0
    Last Post: 2nd June 2010, 20:21
  3. Reg multiple plots in Qwt
    By Tavit in forum Qwt
    Replies: 4
    Last Post: 23rd June 2008, 14:43
  4. Lining up multiple plots
    By joel in forum Qwt
    Replies: 2
    Last Post: 20th June 2008, 01:25
  5. Replies: 4
    Last Post: 25th October 2007, 13:23

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.