View Full Version : need design suggestion

19th January 2008, 01:58
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:

class Plotter: public QwtPlot
Plotter( QObject parent = 0 );
bool addCurve( QString curveId, QwtData *data );
bool removeCurve( QString curveId );
const QwtPlotCurve* curve( QString curveId );
const QwtData* data( QString curveId );
QMultiHash<QString, QwtPlotCurve*, QwtData* > curveHash;

bool Plotter::addCurve( QString curveId, QwtData *data ) {
if( !curveHash.contains( curveId ) ) return false;
QwtPlotCurve * curve = new QwtPlotCurve;
curveHash.insert( curveId, curve, data );
return true;

bool Plotter::removeCurve( QString curveId ) {
if( !curveHash.contains( curveId ) ) return false;
curveHash.value( curveId ).curve->detach(this);
delete curveHash.value( curveId ).curve;
delete curveHash.value( curveId ).data;
curveHash.remove( curveId );
return true;
I like this code, but maybe there's a better design.