Results 1 to 4 of 4

Thread: Accessing member variables of QwtPlotCurve from within the

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Posts
    55
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Accessing member variables of QwtPlotCurve from within the

    Accessing member variables (minXValue, minYValue...) of QwtPlotCurve from within the parent class
    Qwt 6.0.1, Qt 4.8.4

    Hello everyone!

    I have realized my own plot class derived from QwtPlot.
    I have defined a method setMarkerOnMax() which needs as parameters among others a pointer to the data and the data size. But those are already known by the plot object, so I find it boring to have to reinter that information.
    Within the method attachCurve() I can successfuly access those variables, but I did´nt succeed in accessing them from within the parent class. I took a look to Qwt_plot_item and Qwt_plot_dict but have no idea how to proceed.

    I have attached some code snippets.

    Any idea?

    Thanks for reading.

    Alain

    Qt Code:
    1. // Usage
    2. Plot2D* pLogSpectrum = new Plot2D( "Spectrum", "frequency", "magnitude [dB]", Qt::darkBlue, app );
    3. pLogSpectrum->attachCurve( pXData, pLogMag, HALF_LENGTH, "noisy sine", Qt::cyan );
    4. pLogSpectrum->setMarkerOnMax( pXData, pLogMag, HALF_LENGTH, -3 );
    To copy to clipboard, switch view to plain text mode 

    I would prefer:
    Qt Code:
    1. pLogSpectrum->setMarkerOnMax( -3 );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // Declaration
    2. class Plot2D: public QwtPlot
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. Plot2D( QString plotTitle = "Data Plot",
    8. QString xLabel = "x-axis",
    9. QString yLabel = "y-axis",
    10. QColor backgoundColor = Qt::darkGray,
    11. QWidget *parent = NULL );
    12.  
    13. void attachCurve( double* xData,
    14. double *yData,
    15. int dataCount,
    16. QString curveLabel = "",
    17. QColor lineColor = Qt::yellow );
    18.  
    19. void setMarkerOnMax( SLData_t* xData,
    20. SLData_t* yData,
    21. SLArrayIndex_t dataCount,
    22. int precision = 4, // positive value for '%.*g', negative value for '%.*f'
    23. Qt::Alignment alignment = Qt::AlignHCenter | Qt::AlignTop );
    24.  
    25. void setMarker( double X,
    26. double Y,
    27. int precision = 4, // positive value for '%.*g', negative value for '%.*f'
    28. Qt::Alignment alignment = Qt::AlignHCenter | Qt::AlignTop );
    29.  
    30. ...
    31.  
    32. public Q_SLOTS:
    33. void autoRescale( QRectF );
    34. void printDocument();
    35. void exportDocument();
    36.  
    37. protected:
    38. virtual void resizeEvent( QResizeEvent * );
    39.  
    40. private:
    41. int mWindowHeight, mWindowWidth;
    42. int mWindowXPosition, mWindowYPosition;
    43. QwtPlotGrid* grid;
    44. QwtLegend* legend;
    45. QwtPlotZoomer* zoomer;
    46. QPushButton* btnPrint;
    47. QPushButton* btnExport;
    48. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // implementation
    2. Plot2D::Plot2D( QString plotTitle,
    3. QString xLabel,
    4. QString yLabel,
    5. QColor backgroundColor,
    6. QWidget *parent ):
    7. QwtPlot( parent )
    8. {
    9. // plot object
    10. setWindowTitle ( QString( "SigLibGraph - Plot2D" ));
    11. setTitle( plotTitle );
    12. setCanvasBackground( backgroundColor);
    13.  
    14. // window size and position
    15. setMinimumSize( QSize( 240, 170 ));
    16. mWindowWidth = 550; mWindowHeight = 365;
    17. mWindowXPosition = 200; mWindowYPosition = 200;
    18. setGeometry( mWindowXPosition, mWindowYPosition, mWindowWidth, mWindowHeight );
    19.  
    20. // axis
    21. setAxisTitle( QwtPlot::xBottom, xLabel );
    22. setAxisTitle( QwtPlot::yLeft, yLabel );
    23.  
    24. // grid
    25. grid = new QwtPlotGrid;
    26. grid->enableXMin( true );
    27. grid->setMajPen( QPen( Qt::white, 0, Qt::DotLine ));
    28. grid->setMinPen( QPen( Qt::gray, 0 , Qt::DotLine ));
    29. grid->attach( this );
    30.  
    31. // legend
    32. legend = new QwtLegend;
    33. insertLegend( legend, QwtPlot::RightLegend );
    34.  
    35. //zoomer
    36. ...
    37.  
    38. // print functionality
    39. btnPrint = new QPushButton( "&Print", this );
    40. ...
    41.  
    42. // export functionality
    43. btnExport = new QPushButton( "&Export", this );
    44. ...
    45.  
    46. show();
    47. }
    48.  
    49. void Plot2D::attachCurve( SLData_t* xData,
    50. SLData_t* yData,
    51. int dataCount,
    52. QString curveLabel,
    53. QColor lineColor )
    54. {
    55. QwtPlotCurve* curve = new QwtPlotCurve;
    56.  
    57. curve->setSamples( xData, yData, dataCount );
    58. // following works well
    59. //qDebug() << "xMin=" << curve->minXValue() << " | xMax=" << curve->maxXValue()
    60. // << " | yMin=" << curve->minYValue() << " | yMax=" << curve->maxYValue()
    61. // << " | data count=" << curve->dataSize();
    62.  
    63. QPen curvePen;
    64. curvePen.setColor( lineColor );
    65. curve->setPen( curvePen );
    66.  
    67. curve->setRenderHint( QwtPlotItem::RenderAntialiased );
    68.  
    69. curve->setTitle( curveLabel );
    70.  
    71. if ( curveLabel.isEmpty() )
    72. curve->setItemAttribute( QwtPlotItem::Legend, false );
    73. else
    74. curve->setLegendAttribute( QwtPlotCurve::LegendShowLine );
    75.  
    76. curve->attach( this );
    77. }
    78.  
    79. void Plot2D::setMarkerOnMax( SLData_t* xData,
    80. SLData_t* yData,
    81. SLArrayIndex_t dataCount,
    82. int precision, // positive value for '%.*g', negative value for '%.*f'
    83. Qt::Alignment alignment )
    84. {
    85. SLArrayIndex_t index = SDA_MaxPos( xData, dataCount ); // get the index of max value
    86. setMarker( xData[index], yData[index], precision, alignment ); // set marker position
    87. }
    88.  
    89. void Plot2D::setMarker( double X,
    90. double Y,
    91. int precision,
    92. Qt::Alignment alignment )
    93. {
    94. QwtPlotMarker* marker = new QwtPlotMarker();
    95. marker->setValue( X, Y );
    96. marker->setSymbol( new QwtSymbol( QwtSymbol::Cross,
    97. QColor( Qt::white ),
    98. QColor( Qt::white ),
    99. QSize( 10, 10 )));
    100. QString label;
    101. if (precision < 0)
    102. label.sprintf( "(%.*f | %.*f)", -precision, X, -precision, Y );
    103. else
    104. label.sprintf( "(%.*g | %.*g)", precision, X, precision, Y );
    105. QwtText text( label );
    106. text.setColor( QColor( Qt::white ));
    107. text.setFont( QFont("Helvetica", 8, QFont::Bold ));
    108.  
    109. marker->setLabel( text );
    110. marker->setLabelAlignment( alignment );
    111. marker->attach( this );
    112. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by alainstgt; 29th October 2013 at 13:32. Reason: updated contents

Similar Threads

  1. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 14:53
  2. QDevelop debuggng - viewing class member variables
    By dbrmik in forum Qt-based Software
    Replies: 0
    Last Post: 7th January 2009, 10:40
  3. Replies: 22
    Last Post: 8th October 2008, 13:54
  4. Replies: 5
    Last Post: 18th December 2007, 11:39
  5. Accessing Environment Variables
    By mhoover in forum Qt Programming
    Replies: 6
    Last Post: 21st September 2006, 15:05

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