Skip to content

Commit

Permalink
BUG: Ensure virtual functions can be called from derived ctkVTK view …
Browse files Browse the repository at this point in the history
…pimpl

Add protected constructor to ctkVTKRenderView and ctkVTKSliceView for
associating a derived pimpl.

This is required to have the complete virtual function chain executed
when virtual function are called in the pimpl init() function.
  • Loading branch information
jcfr committed Oct 29, 2023
1 parent 98c5ac9 commit bc7d4e5
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Libs/Visualization/VTK/Widgets/ctkVTKAbstractView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ ctkVTKAbstractViewPrivate::ctkVTKAbstractViewPrivate(ctkVTKAbstractView& object)
this->PauseRenderCount = 0;
}

// --------------------------------------------------------------------------
ctkVTKAbstractViewPrivate::~ctkVTKAbstractViewPrivate() = default;

// --------------------------------------------------------------------------
void ctkVTKAbstractViewPrivate::init()
{
Expand Down
1 change: 1 addition & 0 deletions Libs/Visualization/VTK/Widgets/ctkVTKAbstractView_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ctkVTKAbstractViewPrivate : public QObject

public:
ctkVTKAbstractViewPrivate(ctkVTKAbstractView& object);
virtual ~ctkVTKAbstractViewPrivate();

/// Convenient setup methods
virtual void init();
Expand Down
28 changes: 23 additions & 5 deletions Libs/Visualization/VTK/Widgets/ctkVTKRenderView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ ctkVTKRenderViewPrivate::ctkVTKRenderViewPrivate(ctkVTKRenderView& object)
this->Orientation->SetOrientationMarker(this->Axes);
}

// --------------------------------------------------------------------------
ctkVTKRenderViewPrivate::~ctkVTKRenderViewPrivate() = default;

// --------------------------------------------------------------------------
void ctkVTKRenderViewPrivate::init()
{
this->ctkVTKAbstractViewPrivate::init();

// The interactor in RenderWindow exists after the renderwindow is set to
// the QVTKWidet
this->Orientation->SetInteractor(this->RenderWindow->GetInteractor());
this->Orientation->SetEnabled(1);
this->Orientation->InteractiveOff();
}

// --------------------------------------------------------------------------
void ctkVTKRenderViewPrivate::setupCornerAnnotation()
{
Expand Down Expand Up @@ -204,18 +219,21 @@ ctkVTKRenderView::ctkVTKRenderView(QWidget* parentWidget)
{
Q_D(ctkVTKRenderView);
d->init();
}

// The interactor in RenderWindow exists after the renderwindow is set to
// the QVTKWidet
d->Orientation->SetInteractor(d->RenderWindow->GetInteractor());
d->Orientation->SetEnabled(1);
d->Orientation->InteractiveOff();
// --------------------------------------------------------------------------
ctkVTKRenderView::ctkVTKRenderView(ctkVTKRenderViewPrivate* pimpl, QWidget* parentWidget)
: Superclass(pimpl, parentWidget)
{
// derived classes must call init manually. Calling init() here may results in
// actions on a derived public class not yet finished to be created
}

//----------------------------------------------------------------------------
ctkVTKRenderView::~ctkVTKRenderView()
{
}

//----------------------------------------------------------------------------
void ctkVTKRenderView::setInteractor(vtkRenderWindowInteractor* newInteractor)
{
Expand Down
3 changes: 3 additions & 0 deletions Libs/Visualization/VTK/Widgets/ctkVTKRenderView.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public Q_SLOTS:
/// Return zoom factor
double zoomFactor()const;

protected:
ctkVTKRenderView(ctkVTKRenderViewPrivate* pimpl, QWidget* parent);

private:
Q_DECLARE_PRIVATE(ctkVTKRenderView);
Q_DISABLE_COPY(ctkVTKRenderView);
Expand Down
4 changes: 3 additions & 1 deletion Libs/Visualization/VTK/Widgets/ctkVTKRenderView_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ class vtkRenderWindowInteractor;

//-----------------------------------------------------------------------------
/// \ingroup Visualization_VTK_Widgets
class ctkVTKRenderViewPrivate : public ctkVTKAbstractViewPrivate
class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKRenderViewPrivate : public ctkVTKAbstractViewPrivate
{
Q_OBJECT
Q_DECLARE_PUBLIC(ctkVTKRenderView);

public:
ctkVTKRenderViewPrivate(ctkVTKRenderView& object);
virtual ~ctkVTKRenderViewPrivate();

/// Convenient setup methods
void init() override;
void setupCornerAnnotation() override;
void setupRendering() override;

Expand Down
21 changes: 20 additions & 1 deletion Libs/Visualization/VTK/Widgets/ctkVTKSliceView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ ctkVTKSliceViewPrivate::ctkVTKSliceViewPrivate(ctkVTKSliceView& object)
this->OverlayRenderer = vtkSmartPointer<vtkRenderer>::New();
}

// --------------------------------------------------------------------------
ctkVTKSliceViewPrivate::~ctkVTKSliceViewPrivate() = default;

// --------------------------------------------------------------------------
void ctkVTKSliceViewPrivate::init()
{
Q_Q(ctkVTKSliceView);
this->ctkVTKAbstractViewPrivate::init();

q->VTKWidget()->installEventFilter(q);
}

// --------------------------------------------------------------------------
void ctkVTKSliceViewPrivate::setupCornerAnnotation()
{
Expand Down Expand Up @@ -100,7 +112,14 @@ ctkVTKSliceView::ctkVTKSliceView(QWidget* parentWidget)
{
Q_D(ctkVTKSliceView);
d->init();
this->VTKWidget()->installEventFilter(this);
}

// --------------------------------------------------------------------------
ctkVTKSliceView::ctkVTKSliceView(ctkVTKSliceViewPrivate* pimpl, QWidget* parentWidget)
: Superclass(pimpl, parentWidget)
{
// derived classes must call init manually. Calling init() here may results in
// actions on a derived public class not yet finished to be created
}

// --------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions Libs/Visualization/VTK/Widgets/ctkVTKSliceView.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public Q_SLOTS:
void resized(const QSize& size);

protected:
ctkVTKSliceView(ctkVTKSliceViewPrivate* pimpl, QWidget* parent);
bool eventFilter(QObject *object, QEvent *event) override;

private:
Expand Down
6 changes: 5 additions & 1 deletion Libs/Visualization/VTK/Widgets/ctkVTKSliceView_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ class vtkRenderWindowInteractor;

//-----------------------------------------------------------------------------
/// \ingroup Visualization_VTK_Widgets
class ctkVTKSliceViewPrivate : public ctkVTKAbstractViewPrivate
class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKSliceViewPrivate : public ctkVTKAbstractViewPrivate
{
Q_OBJECT
Q_DECLARE_PUBLIC(ctkVTKSliceView);

public:
ctkVTKSliceViewPrivate(ctkVTKSliceView&);
virtual ~ctkVTKSliceViewPrivate();

/// Convenient setup methods
void init() override;
void setupCornerAnnotation() override;
void setupRendering() override;

Expand Down

0 comments on commit bc7d4e5

Please sign in to comment.