Results 1 to 6 of 6

Thread: rotating a custom made symbol for QwtPlotCurve

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default rotating a custom made symbol for QwtPlotCurve

    hi
    i have created a customized symbol by subclassing the QwtSymbol class and reimplementing the function,

    Qt Code:
    1. class feather : public QwtSymbol
    2. {
    3. public:
    4. void draw(QPainter *painter, const QRect &r) const
    5. {
    6. //shape of symbol( |___ )
    7. QwtPainter::drawLine(painter, r.bottomLeft(), r.topLeft());
    8. QwtPainter::drawLine(painter, r.bottomLeft(), r.bottomRight());
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    i want to rotate the symbols at some angle. but,i can not use the painter argument for doing this because its co-ordinates are not the co-ordinates of r(argument QRect).

    how can i do this.

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

    Default Re: rotating a custom made symbol for QwtPlotCurve

    i have created a customized symbol by subclassing the QwtSymbol class and reimplementing the function, ...
    Note, that you can't customize the symbol of a marker/curve by subclassing, because it gets copied as QwtSymbol. Instead you have to subclass QwtPlotCurve and reimplement QwtPlotCurve::drawSymbols(). In Qwt 5.1-SVN ( svn co https://qwt.svn.sourceforge.net/svnroot/qwt/branches/qwt-5.1 ) you can subclass if you reimplement a QwtSymbol::copy() method.
    i want to rotate the symbols at some angle. but,i can not use the painter argument for doing this because its co-ordinates are not the co-ordinates of r(argument QRect).
    The QRect is the rectangle ( position + size), where you have to paint your symbol. I'm not sure , what you mean by painter coordinates - maybe its translation ?

    It depends on your type of symbol, if QPainter::rotate is the best way to paint it. If you want to use it you might have to set QPainter::translate to the position of your rotation.

    HTH,
    Uwe

  3. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: rotating a custom made symbol for QwtPlotCurve

    hi
    i have subclassed the QwtPlotCurve like this .

    Qt Code:
    1. #include <QtGui>
    2. #include "qwt_plot.h"
    3. #include "qwt_plot_curve.h"
    4. #include "qwt_valuelist.h"
    5. #include "qwt_scale_div.h"
    6. #include "qwt_symbol.h"
    7. #include "qwt_painter.h"
    8. class feather : public QwtSymbol
    9. {
    10. public:
    11.  
    12. void draw(QPainter *painter, const QRect &r) const
    13. {
    14. //painter->translate(r.topLeft());
    15.  
    16. //shape |_|__
    17. QwtPainter::drawLine(painter, r.bottomLeft(), r.topLeft());
    18. QwtPainter::drawLine(painter, r.bottomLeft(), r.bottomRight());
    19. QwtPainter::drawLine(painter, r.right()-r.width()/2, r.bottom(),
    20. r.right()-r.width()/2, r.top());
    21. }
    22. };
    23.  
    24. class curve_data : public QwtPlotCurve
    25. {
    26. public:
    27. void drawSymbols(QPainter *painter, const QwtSymbol &symbol,
    28. const QwtScaleMap &xMap, const QwtScaleMap &yMap, int from, int to) const
    29. {
    30. QRect rect;
    31. rect.setSize(QwtPainter::metricsMap().screenToLayout(symbol.size()));
    32.  
    33. for (int i = from; i <= to; i++)
    34. {
    35. const int xi = xMap.transform(x(i));
    36. const int yi = yMap.transform(y(i));
    37. rect.moveCenter(QPoint(xi, yi));
    38. painter->setPen(QPen(Qt::blue));
    39.  
    40. feather f;
    41. f.draw(painter, rect);
    42. }
    43. }
    44. };
    45.  
    46. int main(int argc, char *argv[])
    47. {
    48. QApplication a(argc, argv);
    49. QwtPlot *qwt =new QwtPlot;
    50. qwt->setCanvasBackground(QColor(Qt::white));
    51.  
    52. //set scale for x-axis
    53. qwt->setAxisScale(QwtPlot::xBottom, 13, 0);
    54. qwt->setAxisMaxMajor(QwtPlot::xBottom, 24);
    55. qwt->setAxisMaxMinor(QwtPlot::xBottom, 0);
    56.  
    57. //set scale for y-axis
    58. qwt->setAxisScale(QwtPlot::yLeft, 0, 31);
    59.  
    60. //create data for curve
    61. int MAX=12*30;
    62. double x[MAX], y[MAX];
    63. int k=1;
    64. int l=1;
    65.  
    66. for (int i=0; i<MAX; i++)
    67. {
    68. x[i]=k;
    69. y[i]=l;
    70. k++;
    71. if (k>12)
    72. {
    73. k=1;
    74. l++;
    75. }
    76. }
    77.  
    78. //create symbol for curve
    79. feather sym;
    80. sym.setStyle(QwtSymbol::Cross);
    81. sym.setSize(30, 10);
    82.  
    83. //create curve , set symbol and data to curve
    84. curve_data *cur=new curve_data;
    85. cur->setStyle(QwtPlotCurve::NoCurve);
    86. cur->setSymbol(sym);
    87. cur->setData(x, y, MAX);
    88. cur->attach(qwt);
    89.  
    90. qwt->resize(800, 600);
    91. qwt->show();
    92.  
    93. return a.exec();
    94. }
    To copy to clipboard, switch view to plain text mode 

    i get the symbols , but i need to rotate individual symbols at different angles.
    Last edited by babu198649; 17th March 2008 at 12:33.

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

    Default Re: rotating a custom made symbol for QwtPlotCurve

    i get the symbols , but i need to rotate individual symbols at different angles.
    You know the position and the size of your symbol and you have control over the painting code.
    What is missing ( maybe, that you don't know how to paint something rotated at all ) ?

    Uwe

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

    babu198649 (18th March 2008)

  6. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: rotating a custom made symbol for QwtPlotCurve

    i have messed with the co-oridnates and now i have corrected it .
    thank u.

    also i have noticed that the subclassed function of QwtSymbol (draw ) is called twice ,
    i have 360 symbols but the draw function is called 720 times.which i have found through global variable.

    why is it called twice.
    Last edited by babu198649; 18th March 2008 at 09:36.

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

    Default Re: rotating a custom made symbol for QwtPlotCurve

    why is it called twice.
    It is called, whenever the content of your plot canvas has to be recreated ( QwtPlot::replot ). Use your debugger set a breakpoint in QwtPlotCurve::drawSymbols() and look at the stack, where you are.

    Uwe

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12
  2. Link Errors
    By magikalpnoi in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 22:04

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.