Results 1 to 5 of 5

Thread: How to write a derived class of QwtSymbol?

  1. #1
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default How to write a derived class of QwtSymbol?

    Hi all,

    I meet a problem with QwtSymbol, I want to design some symbols so I have to write a derived class of QwtSymbol,
    but It seems like that I need to access the PrivateData of parent class, and the Enumerated type Style of parent class doesn't include the style I designed, how could I write this derived class?

    Please excuse me for my poor English, I am not good at it, but I am trying to improve it.

    Momo
    Last edited by momo; 11th February 2014 at 07:36. Reason: spelling corrections

  2. #2
    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: How to write a derived class of QwtSymbol?

    You can use symbols types >= QwtSymbol::UserStyle + overloading QwtSymbol::renderSymbols(). But I would expect that the implementation you are looking for is to use one of the symbol types >= QwtSymbol::Path.

    Uwe

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

    momo (12th February 2014)

  4. #3
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write a derived class of QwtSymbol?

    Hi Uwe,
    Thank you for your reply. My team use Qwt 6.0.2 to develop so I can not use QwtSymbol::Path.
    In my derived class CSymbol I wrote an enum Style that added a TestSymbol after UserStyle, now I meet two questions:
    1. How to write CSymbol's Constructors? QwtSymbol's constructors need QwtSymbol::Style in theirs first parameter, but I have to use CSymbol::Style.
    2. In QwtSymbol::renderSymbols() (It called drawSymbols() in Qwt6.0.2) it accessed d_data which is private in parent class, and one of the d_data's memeber is QwtSymbol::Style, but I have to use CSymbol::Style. Should I write a new d_data?

    Here is Symbol.h's code:
    Qt Code:
    1. #ifndef SYMBOL_H_
    2. #define SYMBOL_H_
    3.  
    4. #include <qwt/qwt_symbol.h>
    5.  
    6. class CSymbol : public QwtSymbol
    7. {
    8. public:
    9. enum Style
    10. {
    11. //! No Style. The symbol cannot be drawn.
    12. NoSymbol = -1,
    13.  
    14. //! Ellipse or circle
    15. Ellipse,
    16.  
    17. //! Rectangle
    18. Rect,
    19.  
    20. //! Diamond
    21. Diamond,
    22.  
    23. //! Triangle pointing upwards
    24. Triangle,
    25.  
    26. //! Triangle pointing downwards
    27. DTriangle,
    28.  
    29. //! Triangle pointing upwards
    30. UTriangle,
    31.  
    32. //! Triangle pointing left
    33. LTriangle,
    34.  
    35. //! Triangle pointing right
    36. RTriangle,
    37.  
    38. //! Cross (+)
    39. Cross,
    40.  
    41. //! Diagonal cross (X)
    42. XCross,
    43.  
    44. //! Horizontal line
    45. HLine,
    46.  
    47. //! Vertical line
    48. VLine,
    49.  
    50. //! X combined with +
    51. Star1,
    52.  
    53. //! Six-pointed star
    54. Star2,
    55.  
    56. //! Hexagon
    57. Hexagon,
    58.  
    59. /*!
    60.   Styles >= QwtSymbol::UserSymbol are reserved for derived
    61.   classes of QwtSymbol that overload drawSymbols() with
    62.   additional application specific symbol types.
    63.   */
    64. UserStyle = 1000,
    65.  
    66. TestSymbol
    67. };
    68.  
    69. public:
    70. // How to write this Constructors?
    71. CSymbol( Style style = NoSymbol ) : QwtSymbol(style) {};
    72. CSymbol( Style style, const QBrush &brush, const QPen &pen, const QSize &size )
    73. : QwtSymbol(style, brush, pen, size) {};
    74. CSymbol( const CSymbol &symbol ) : QwtSymbol(symbol) {};
    75. virtual ~CSymbol() {~QwtSymbol(); };
    76.  
    77. protected:
    78. virtual void drawSymbols( QPainter *,
    79. const QPointF *, int numPoints ) const;
    80. }; // SYMBOL_H_
    81. #endif
    To copy to clipboard, switch view to plain text mode 

    Here is CSymbol::drawSymbols()'s code:
    Qt Code:
    1. void CSymbol::drawSymbols( QPainter *painter,
    2. const QPointF *points, int numPoints ) const
    3. {
    4. if ( numPoints <= 0 )
    5. return;
    6.  
    7. painter->save();
    8.  
    9. // here is accessing QwtSymbol::d_data
    10. switch ( d_data->style )
    11. {
    12. case CSymbol::Ellipse:
    13. {
    14. qwtDrawEllipseSymbols( painter, points, numPoints, *this );
    15. break;
    16. }
    17. case CSymbol::Rect:
    18. {
    19. qwtDrawRectSymbols( painter, points, numPoints, *this );
    20. break;
    21. }
    22. case CSymbol::Diamond:
    23. {
    24. qwtDrawDiamondSymbols( painter, points, numPoints, *this );
    25. break;
    26. }
    27. case CSymbol::Cross:
    28. {
    29. qwtDrawLineSymbols( painter, Qt::Horizontal | Qt::Vertical,
    30. points, numPoints, *this );
    31. break;
    32. }
    33. case CSymbol::XCross:
    34. {
    35. qwtDrawXCrossSymbols( painter, points, numPoints, *this );
    36. break;
    37. }
    38. case CSymbol::Triangle:
    39. case CSymbol::UTriangle:
    40. {
    41. qwtDrawTriangleSymbols( painter, QwtTriangle::Up,
    42. points, numPoints, *this );
    43. break;
    44. }
    45. case CSymbol::DTriangle:
    46. {
    47. qwtDrawTriangleSymbols( painter, QwtTriangle::Down,
    48. points, numPoints, *this );
    49. break;
    50. }
    51. case CSymbol::RTriangle:
    52. {
    53. qwtDrawTriangleSymbols( painter, QwtTriangle::Right,
    54. points, numPoints, *this );
    55. break;
    56. }
    57. case CSymbol::LTriangle:
    58. {
    59. qwtDrawTriangleSymbols( painter, QwtTriangle::Left,
    60. points, numPoints, *this );
    61. break;
    62. }
    63. case CSymbol::HLine:
    64. {
    65. qwtDrawLineSymbols( painter, Qt::Horizontal,
    66. points, numPoints, *this );
    67. break;
    68. }
    69. case CSymbol::VLine:
    70. {
    71. qwtDrawLineSymbols( painter, Qt::Vertical,
    72. points, numPoints, *this );
    73. break;
    74. }
    75. case CSymbol::Star1:
    76. {
    77. qwtDrawStar1Symbols( painter, points, numPoints, *this );
    78. break;
    79. }
    80. case CSymbol::Star2:
    81. {
    82. qwtDrawStar2Symbols( painter, points, numPoints, *this );
    83. break;
    84. }
    85. case CSymbol::Hexagon:
    86. {
    87. qwtDrawHexagonSymbols( painter, points, numPoints, *this );
    88. break;
    89. }
    90. case CSymbol::TestSymbol:
    91. {
    92. qwtDrawTestSymbols( painter, points, numPoints, *this );
    93. break;
    94. }
    95. default:;
    96. }
    97. painter->restore();
    98. }
    To copy to clipboard, switch view to plain text mode 

    Momo
    Last edited by momo; 12th February 2014 at 01:52. Reason: spelling corrections

  5. #4
    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: How to write a derived class of QwtSymbol?

    Simply start with your enum ( no need to copy the QwtSymbol symbol types ) from QwtSymbol::UserStyle and use c++ casts. In the end an enum is just a number and it is completely safe to cast between them.

    Uwe

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

    momo (13th February 2014)

  7. #5
    Join Date
    Feb 2014
    Posts
    28
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to write a derived class of QwtSymbol?

    Problem solved. Thank you Uwe!

    Momo

Similar Threads

  1. QwtPlot derived class
    By Marco Trapanese in forum Qwt
    Replies: 15
    Last Post: 4th December 2012, 10:05
  2. Replies: 3
    Last Post: 6th April 2012, 16:44
  3. Use QWidget derived class in Dialog
    By qtneuling in forum Qt Tools
    Replies: 2
    Last Post: 17th May 2008, 23:29
  4. rtti() of derived class
    By quickNitin in forum Newbie
    Replies: 4
    Last Post: 8th October 2006, 14:20
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

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.