Results 1 to 3 of 3

Thread: qwt spectral plot stay zoomed after a replot()

  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default qwt spectral plot stay zoomed after a replot()

    My QwtPlot does not stay zoomed in or panned.

    I have a spatial water model using QwtPlot to look at GIS type output while it is running. There are two spectralplots attached to it, one is semi transparent on top of another. Apologies for the long code!
    The following is done once in a setup function
    Qt Code:
    1. drawMap = new QwtPlotSpectrogram();
    2. drawMap->setRenderThreadCount( 0 );
    3. drawMap->attach( MPlot );
    4.  
    5. baseMap = new QwtPlotSpectrogram();
    6. baseMap->setRenderThreadCount( 0 );
    7. baseMap->attach( MPlot );
    8.  
    9. RD = new QwtMatrixRasterData();
    10. RDb = new QwtMatrixRasterData();
    11.  
    12. rightAxis = new QwtScaleWidget();
    13. /... etc/
    14.  
    15. mapRescaler = new QwtPlotRescaler( MPlot->canvas() );
    16. /... etc/
    17.  
    18. magnifier = new QwtPlotMagnifier( MPlot->canvas() );
    19. magnifier->setAxisEnabled( MPlot->yRight, false );
    20.  
    21. panner = new QwtPlotPanner( MPlot->canvas() );
    22. panner->setAxisEnabled( MPlot->yRight, false );
    To copy to clipboard, switch view to plain text mode 

    then every model cycle I update the data in RD, I have a vector "mapdata" and replace the data in it and link it to the plot:
    RD->setValueMatrix( mapData,nrCols );

    Next I calculate the new maximum value and update the output and legend:. Because the user can select between 4 possible output maps, each with there own legend and colour scheme, these are updated also each timestep
    Qt Code:
    1. if (op.drawMapType == 1)
    2. {
    3. MinV = 0.01;
    4. MPlot->setTitle("Runoff (l/s)");
    5. drawMap->setColorMap(new colorMapWaterLog());
    6. maxAxis1 = qMax(maxAxis1, MaxV);
    7. RD->setInterval( Qt::ZAxis, QwtInterval( 0, qMax(MinV, maxAxis1)));
    8. }
    9. else
    10. if (op.drawMapType == 2)
    11. { ... }
    12. else
    13. if (op.drawMapType == 3)
    14. { ... }
    15. else
    16. if (op.drawMapType == 4)
    17. { ... }
    18.  
    19. drawMap->setData(RD);
    20. // link raster data to drawMap
    21.  
    22. // add legend right of axis
    23. if (op.drawMapType == 1)
    24. {
    25. // log scale for runoff
    26. rightAxis->setColorMap( drawMap->data()->interval( Qt::ZAxis ), new colorMapWaterLog());
    27. if (maxAxis1 < 100)
    28. MPlot->setAxisScale( MPlot->yRight, MinV, qMax(1.0,maxAxis1));
    29. else
    30. MPlot->setAxisScale( MPlot->yRight, MinV, qMax(10.0,maxAxis1));
    31. MPlot->setAxisScaleEngine( MPlot->yRight, new QwtLog10ScaleEngine() );
    32. }
    33. else
    34. if (op.drawMapType == 2)
    35. { ... }
    36. else
    37. if (op.drawMapType == 3)
    38. { ... }
    39. else
    40. if (op.drawMapType == 4)
    41. { ... }
    42.  
    43. MPlot->enableAxis( MPlot->yRight );
    44.  
    45. MPlot->plotLayout()->setAlignCanvasToScales( true );
    46.  
    47. MPlot->setAxisScale( MPlot->xBottom, 0.0, nrCols, nrCols/20);
    48. MPlot->setAxisMaxMinor( MPlot->xBottom, 0 );
    49. MPlot->setAxisScale( MPlot->yLeft, 0.0, nrRows, nrRows/20);
    50. MPlot->setAxisMaxMinor( MPlot->yLeft, 0 );
    51. mapRescaler->rescale();
    52.  
    53. MPlot->replot(); //<=======
    To copy to clipboard, switch view to plain text mode 
    Evry cycle the plot resets to the original zoom level showing the whole plot, and does not stay zoomed in.
    Obviously I am doing something wrong!

    Thanks
    Victor Jetten

    P.S. Uwe: just a thought, have you considered microfinancing this thing, using kickstarter or something?
    Last edited by qt_gotcha; 23rd January 2013 at 11:13.

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

    Default Re: qwt spectral plot stay zoomed after a replot()

    Qt Code:
    1. MPlot->setAxisScale( MPlot->xBottom, 0.0, nrCols, nrCols/20);
    2. MPlot->setAxisScale( MPlot->yLeft, 0.0, nrRows, nrRows/20);
    3. MPlot->replot(); //<=======
    To copy to clipboard, switch view to plain text mode 

    For your understanding: each scale has a current setting ( min/max + tick positions ) only and you are setting it explicitly with the lines above. Note that there is only 1 method changing the scale: QwtPlot::setAxisScaleDiv() - everything else ends up there.

    "Zooming" also is nothing else than setting a new range, but QwtPlotZoomer maps user interactions to setAxisScale() calls + maintains a history of the previous scale ranges.

    Your code has 2 effects:

    1) you explicitly assign a new range
    2) the zoom history is not aware of this new range and it won't appear in its history

    How zooming works is unfortunately one of the issues Qwt users are confused most ( I had planned to come up with something more intuitive for Qwt 6.1, but was running out of time ). So I'm afraid you have to understand how the classes manipulating the scales play together - what is the first document I will write when Qwt 6,1 final is done.

    have you considered microfinancing this thing, using kickstarter or something?
    From time to time I receive donations ( details can be found at http://qwt.sf.net ), I'm using for buying stuff I need for Qwt development - like a Windows or VMWare license.

    Uwe

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

    qt_gotcha (24th January 2013)

  4. #3
    Join Date
    Jul 2009
    Posts
    92
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default Re: qwt spectral plot stay zoomed after a replot()

    thanks, it works, very helpful

Similar Threads

  1. Replies: 11
    Last Post: 29th May 2012, 15:00
  2. Replies: 3
    Last Post: 14th February 2012, 12:37
  3. Replies: 1
    Last Post: 11th March 2011, 10:00
  4. Replies: 0
    Last Post: 30th May 2009, 05:43
  5. QGraphicsPixmapItem cuts off when zoomed
    By abbapatris in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2008, 15:05

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
  •  
Qt is a trademark of The Qt Company.