Results 1 to 10 of 10

Thread: QwtPlotIntervalCurve's constant width.

  1. #1
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QwtPlotIntervalCurve's constant width.

    Here is situation. I have a class inherited from QwtPlot. I use QwtPlotIntervalCurve to plot squares of certain height regardless of scaling (i.e. width between top and bottom side of square set by QwtPlotInterval must be always constant if I zoom in or zoom out). But it looks like if I use something like QWidget::mapToGlobal() or QWidget::mapFromGlobal of QwtPlotCanvas (this->canvas()->mapFromGlobal()) all conversions are done inside of QwtPlotCanvas automatically, and size of square is wrong. Am I right about it? In that case is it possible in Qwt to play with local and global coordinates for solving that situation, and if answer is "yes", how can it be done?

    P.S. Am I right that every coordinate that we specify to plot elements are firstly exist in global coordinate space and QwtPlot converts it to local coordinate space itself?

    Here is code I used:

    Qt Code:
    1. ...
    2.  
    3. const qreal c_dYCoord = findMiddleYCoordByInterval(m_vYCoords[c_uCurveNum]);
    4. const qreal c_dSquareheight = qMax(static_cast<qreal>(msc_iTextHeight), msc_iLineNonEmptyWidth * c_dPercents / msc_uMaxPercents);
    5. const QPointF c_top = this->canvas()->mapFromGlobal(QPoint(0, c_dYCoord + c_dSquareheight));
    6. const QPointF c_bottom = this->canvas()->mapFromGlobal(QPoint(0, c_dYCoord - c_dSquareheight));
    7.  
    8. const qreal c_dRealHeight = c_top.y() - c_bottom.y();
    9.  
    10. const QwtInterval c_intervalToAttach(c_dYCoord - c_dRealHeight, c_dYCoord + c_dRealHeight);
    11.  
    12. ...
    13.  
    14. currentCurve.push_back(QwtIntervalSample(dCurTime_sec, c_intervalToAttach)); //currentCurve is actually vector of QwtIntervalSample
    15.  
    16. currPlotElement->setSamples(currentCurve); //currPlotElement is QwtPlotIntervalCurve* sample.
    17.  
    18. ...
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Toniy.
    Last edited by Toniy; 17th August 2015 at 11:13.

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

    Default Re: QwtPlotIntervalCurve's constant width.

    Quote Originally Posted by Toniy View Post
    I use QwtPlotIntervalCurve to plot squares of certain height regardless of scaling (i.e. width between top and bottom side of square set by QwtPlotInterval must be always constant if I zoom in or zoom out).
    Then QwtPlotIntervalCurve is obviously not the right plot item - it is for plotting series of x vs. y1->y2 samples.

    But before recommending any solution I need to know the answer to my standard questions:


    • how does your data look like ?
    • how do you want to have it displayed ?


    Am I right that every coordinate that we specify to plot elements are firstly exist in global coordinate space and QwtPlot converts it to local coordinate space itself?
    No, there are also geometries, that are in paint device coordinates.

    Uwe

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

    Toniy (17th August 2015)

  4. #3
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotIntervalCurve's constant width.

    Thanks for quick response.

    Picture is attached to post.

    P.S.: "Zooming in", maybe, not very accurate term. My fault. Actually I change scale of Y axis.

    Zoomed_squares.jpg

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

    Default Re: QwtPlotIntervalCurve's constant width.

    Before recommending any solution I need to know the answer to my standard questions ...

    Uwe

  6. #5
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotIntervalCurve's constant width.

    Data is represented as a vector of values which are follow each other after some interval. For each temporal discrete I must plot square with value typed inside if value != 0 (I use QwtPlotMarker for it) or plot nothing if value equals zero (actually I do it with making QwtPlotIntervalCurve's pen's color equal to canvas' color). Every square that represents value of the same vector must be placed at the same Y coordinate. But if I change Y axis' scale, actual size of square must be same (like at the picture I attached in my previous post)

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

    Default Re: QwtPlotIntervalCurve's constant width.

    Quote Originally Posted by Toniy View Post
    For each temporal discrete I must plot square with value typed inside if value != 0. Every square that represents value of the same vector must be placed at the same Y coordinate.
    Assuming that the center of each square in plot coordinates is related to the data ( right ? ) - what about the size of the square. Is it something related to plot or widget coordinates ?

    Uwe

  8. #7
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotIntervalCurve's constant width.

    Yes, there is value typed in centre of square.
    Size must not be smaller than text inside the square (all markers have the same font size which is not mutable). Actually later it will be necessary to change square size but according to text size, not to axis' scale.
    I just need to understand how can I get real square's height to compare it with text's size.

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

    Default Re: QwtPlotIntervalCurve's constant width.

    Well then the size of the square depends on some QFontMetrics and is of course in widget coordinates.

    This is something you can do with symbols - in you case ( as you need to draw a value inside ) it would be a symbol made of a QPixmap or QwtGraphic ( what would give nicer results in a PDF document ). All geometries of a symbol are in widget coordinates, what means, that a square remains a square ( but don't you have this already using QwtPlotMarker ? ).

    Another option would be to derive from QwtPlotItem and do the squares for each vector in YourItem::draw(). Implementing such an item wouldn't be hard - simply translating the center into widget coordinates, then doing a QPainter::fillRect() followed by a QPainter::drawText().

    Uwe

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

    Toniy (17th August 2015)

  11. #9
    Join Date
    Jul 2015
    Posts
    22
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QwtPlotIntervalCurve's constant width.

    Thanks! I almost get it. One more question: are coordinates on canvas widget and coordinates that shown at QwtScaleDraw not the same (coordinates that shown at QwtScaleDraw are converted coordinates of canvas widget)? I mean if, for example, our Y axis has 100 as min value and 200 for max value and X axis has the same limits, then is point [0;0] of canvas widget (top-left corner) the same as point [200, 100] of our graph (or it is more complicated)?

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

    Default Re: QwtPlotIntervalCurve's constant width.

    The widget coordinates are usually bounded by plot->canvas()->contentsRect() ( = QWidget::rect() without margins ). Then it depends on your configuration how the scales are aligned to the canvas - f.e. there might be extra margins to have some space for the tick labels ( see QwtPlotLayout ). The necessary space depends on some factors f.e if a horizontal scale can be extended below a vertical scale etc.

    So the answer is yes - usually it is more complicated. Better use QwtPlot::canvasMap() to translate between plot ( = what is spanned by the scales ) and paint device coordinates ( = widget ).

    Uwe

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

    Toniy (18th August 2015)

Similar Threads

  1. Replies: 1
    Last Post: 10th August 2015, 23:38
  2. Problem with QwtPlotIntervalCurve
    By SandyEmerald in forum Qwt
    Replies: 2
    Last Post: 11th October 2013, 16:16
  3. yLeft axis constant width
    By baray98 in forum Qwt
    Replies: 4
    Last Post: 4th January 2013, 16:40
  4. Auto-adjusting height of a constant width window
    By akiross in forum Qt Programming
    Replies: 0
    Last Post: 7th July 2010, 01:46
  5. Replies: 1
    Last Post: 28th January 2009, 14:47

Tags for this Thread

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.