mfranke
mfranke

Reputation: 3

Change base class of existing derivated class

At the moment I'm writing an application which shows level measurement data into some graphs. Always I have date/time on x-axis and data on th y-axis. I use Qwt for this and modified QwtPlotPicker class to show proper time labels. I did this by derivation and redefining a member function:

class myQwtPlotPicker : public QwtPlotPicker {
Q_OBJECT

public:
  explicit myQwtPlotPicker( QWidget* canvas, bool DateScale = false );
  explicit myQwtPlotPicker( int xAxis, int yAxis, QWidget* canvas, bool DateScale = false );
  explicit myQwtPlotPicker( int xAxis, int yAxis, RubberBand rubberBand, DisplayMode trackerMode, QWidget* canvas, bool DateScale = false );
  virtual ~myQwtPlotPicker() {};

protected:
  virtual QwtText trackerTextF( const QPointF &position ) const {
    ... redefinition of the label text ...
  }

};

As you can see I also added a new parameter DateScale which turns date labels on or off. This works perfectly, but there is a class QwtPlotZommer which is derivated from QwtPlotPicker:

class QWT_EXPORT QwtPlotZoomer: public QwtPlotPicker { };

Now, the problem is, how do I get the class QwtPlotZommer to derive from myQwtPlotPicker and not from QwtPlotPicker? Or course I could edit the Qwt sources, but there has to be a proper way of doing this.

I hope there is a proper way to do this. I would be glad, if someone could help me with this.

Upvotes: 0

Views: 241

Answers (4)

Uwe
Uwe

Reputation: 725

You have to overload QwtPlotZoomer reimplementing trackerTextF(). If you also have a use case of a standalone QwtPlotPicker - not being a QwtPlotZoomer - you have to do it twice:

class YourPicker: public QwtPlotPicker ... class YourZoomer: public QwtPlotZoomer ...

As your implementation is a one-liner I don't see a problem in writing it twice, but if you want to avoid that, you have to put the code to some other class, that is called in both overloaded methods.

Upvotes: 0

goldstar
goldstar

Reputation: 337

Try multiple inheritance:

class myQwtPlotZoomer : public QwtPlotZoomer, public QwtPlotPicker { };

Upvotes: 2

Hulk
Hulk

Reputation: 6573

I guess that you should reconsider your design - you cannot and should not change the inheritance hierarchy of some library class.

Did you look at some examples to see how the classes you mentioned are intended to be used? Perhaps you should ask a new question to find out how to solve the problem you are actually facing (i.e. how to create a zoomable plot in qwt if I understand you correctly)

Upvotes: 1

Paul Evans
Paul Evans

Reputation: 27567

There's no way to change class hierarchy at runtime in C++.

Upvotes: 1

Related Questions