I whant a plot that will show a nuber of curves with the ability to add/remove curves.
The first idea i got was to use a QHash to store information about attached curves. So this is an overview:
Qt Code:
  1. class Plotter: public QwtPlot
  2. {
  3. public:
  4. Plotter( QObject parent = 0 );
  5. ~Plotter();
  6. bool addCurve( QString curveId, QwtData *data );
  7. bool removeCurve( QString curveId );
  8. const QwtPlotCurve* curve( QString curveId );
  9. const QwtData* data( QString curveId );
  10. private:
  11. QMultiHash<QString, QwtPlotCurve*, QwtData* > curveHash;
  12. };
  13.  
  14. bool Plotter::addCurve( QString curveId, QwtData *data ) {
  15. if( !curveHash.contains( curveId ) ) return false;
  16. QwtPlotCurve * curve = new QwtPlotCurve;
  17. curve->setData(*data);
  18. curve->attach(this);
  19. curveHash.insert( curveId, curve, data );
  20. return true;
  21. }
  22.  
  23. bool Plotter::removeCurve( QString curveId ) {
  24. if( !curveHash.contains( curveId ) ) return false;
  25. curveHash.value( curveId ).curve->detach(this);
  26. delete curveHash.value( curveId ).curve;
  27. delete curveHash.value( curveId ).data;
  28. curveHash.remove( curveId );
  29. return true;
  30. }
To copy to clipboard, switch view to plain text mode 
I like this code, but maybe there's a better design.