Skip to content

Commit

Permalink
STYLE: Use Qt pimpls directly instead of CTK pimpls
Browse files Browse the repository at this point in the history
Qt pimpls have the big advantage of supporting pimple derivation.
The recommended way of using them is shown below:
Header file:

class MyClassPrivate;
class MyClass
{
public:
  ...
  virtual ~MyClass();
  ...
protected:
  QScopedPointer<MyClassPrivate> d_ptr;
private:
  Q_DECLARE_PRIVATE(MyClass);
  Q_DISABLE_COPY(MyClass);
};

Implementation file (Private has no access to public:
class MyClassPrivate
{
public:
...
};
...
MyClass::MyClass():d_ptr(new MyClassPrivate)
{
}

Implementation file (Private has access to public):
class MyClassPrivate
{
  Q_DECLARE_PUBLIC(MyClass);
protected:
  MyClass* const q_ptr;
public:
  MyClassPrivate(MyClass&);
...
};
MyClassPrivate::MyClassPrivate(MyClass& o)
  :q_ptr(&o)
{
}
...
MyClass::MyClass():d_ptr(new MyClassPrivate(*this))
{
}
  • Loading branch information
finetjul committed Sep 15, 2010
1 parent a55a9df commit bab1874
Show file tree
Hide file tree
Showing 134 changed files with 2,032 additions and 1,564 deletions.
1 change: 0 additions & 1 deletion Libs/Core/Testing/Cpp/ctkBranchingWorkflowStep.h
Expand Up @@ -33,7 +33,6 @@ class ctkBranchingWorkflowStep : public ctkWorkflowStep

typedef ctkWorkflowStep Superclass;
explicit ctkBranchingWorkflowStep(ctkWorkflow* newWorkflow, const QString& newId) : Superclass(newWorkflow, newId){};
virtual ~ctkBranchingWorkflowStep(){}

void setBranchId(const QString& newId)
{
Expand Down
13 changes: 9 additions & 4 deletions Libs/Core/Testing/Cpp/ctkExampleDerivedWorkflowStep.cpp
Expand Up @@ -22,7 +22,7 @@
#include "ctkExampleDerivedWorkflowStep.h"

//-----------------------------------------------------------------------------
class ctkExampleDerivedWorkflowStepPrivate : public ctkPrivate<ctkExampleDerivedWorkflowStep>
class ctkExampleDerivedWorkflowStepPrivate
{
public:
ctkExampleDerivedWorkflowStepPrivate();
Expand All @@ -49,8 +49,13 @@ ctkExampleDerivedWorkflowStepPrivate::ctkExampleDerivedWorkflowStepPrivate()
//-----------------------------------------------------------------------------
ctkExampleDerivedWorkflowStep::ctkExampleDerivedWorkflowStep(ctkWorkflow* newWorkflow, const QString& newId) :
Superclass(newWorkflow, newId)
, d_ptr(new ctkExampleDerivedWorkflowStepPrivate)
{
}

//-----------------------------------------------------------------------------
ctkExampleDerivedWorkflowStep::~ctkExampleDerivedWorkflowStep()
{
CTK_INIT_PRIVATE(ctkExampleDerivedWorkflowStep);
}

//-----------------------------------------------------------------------------
Expand All @@ -69,7 +74,7 @@ void ctkExampleDerivedWorkflowStep::onEntry(
Q_UNUSED(transitionType);

// Simply implements our counter of the number of times we have run this function
CTK_D(ctkExampleDerivedWorkflowStep);
Q_D(ctkExampleDerivedWorkflowStep);
d->numberOfTimesRanOnEntry++;

// signals that we are finished
Expand All @@ -86,7 +91,7 @@ void ctkExampleDerivedWorkflowStep::onExit(

// simply implements our counter of the number of times we have run
// this function
CTK_D(ctkExampleDerivedWorkflowStep);
Q_D(ctkExampleDerivedWorkflowStep);
d->numberOfTimesRanOnExit++;

// signals that we are finished
Expand Down
8 changes: 6 additions & 2 deletions Libs/Core/Testing/Cpp/ctkExampleDerivedWorkflowStep.h
Expand Up @@ -40,7 +40,7 @@ class ctkExampleDerivedWorkflowStep : public ctkWorkflowStep

typedef ctkWorkflowStep Superclass;
explicit ctkExampleDerivedWorkflowStep(ctkWorkflow* newWorkflow, const QString& newId);
virtual ~ctkExampleDerivedWorkflowStep(){}
virtual ~ctkExampleDerivedWorkflowStep();

/// Get the values for the counters of the number of times we have
/// run the onEntry() and onExit() functions
Expand All @@ -57,8 +57,12 @@ class ctkExampleDerivedWorkflowStep : public ctkWorkflowStep
virtual void onExit(const ctkWorkflowStep* goingTo,
const ctkWorkflowInterstepTransition::InterstepTransitionType transitionType);

protected:
QScopedPointer<ctkExampleDerivedWorkflowStepPrivate> d_ptr;

private:
CTK_DECLARE_PRIVATE(ctkExampleDerivedWorkflowStep);
Q_DECLARE_PRIVATE(ctkExampleDerivedWorkflowStep);
Q_DISABLE_COPY(ctkExampleDerivedWorkflowStep);

};

Expand Down
Expand Up @@ -28,7 +28,7 @@
#include <iostream>

//-----------------------------------------------------------------------------
class ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate : public ctkPrivate<ctkExampleWorkflowStepUsingSignalsAndSlots>
class ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate
{
public:
ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate();
Expand All @@ -54,8 +54,13 @@ ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate::ctkExampleWorkflowStepUsingSi

//-----------------------------------------------------------------------------
ctkExampleWorkflowStepUsingSignalsAndSlots::ctkExampleWorkflowStepUsingSignalsAndSlots(QObject* _parent) : Superclass(_parent)
, d_ptr(new ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate)
{
}

//-----------------------------------------------------------------------------
ctkExampleWorkflowStepUsingSignalsAndSlots::~ctkExampleWorkflowStepUsingSignalsAndSlots()
{
CTK_INIT_PRIVATE(ctkExampleWorkflowStepUsingSignalsAndSlots);
}

//-----------------------------------------------------------------------------
Expand All @@ -80,7 +85,7 @@ void ctkExampleWorkflowStepUsingSignalsAndSlots::onEntry(const ctkWorkflowStep*

// simply implements our counter of the number of times we have run
// this function
CTK_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
Q_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
d->numberOfTimesRanOnEntry++;

// signals that we are finished
Expand All @@ -95,7 +100,7 @@ void ctkExampleWorkflowStepUsingSignalsAndSlots::onExit(const ctkWorkflowStep* g

// simply implements our counter of the number of times we have run
// this function
CTK_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
Q_D(ctkExampleWorkflowStepUsingSignalsAndSlots);
d->numberOfTimesRanOnExit++;

// signals that we are finished
Expand Down
Expand Up @@ -75,7 +75,7 @@ class ctkExampleWorkflowStepUsingSignalsAndSlots : public QObject
public:
typedef QObject Superclass;
explicit ctkExampleWorkflowStepUsingSignalsAndSlots(QObject* parent = 0);
virtual ~ctkExampleWorkflowStepUsingSignalsAndSlots(){}
virtual ~ctkExampleWorkflowStepUsingSignalsAndSlots();

/// Get the values for the counters of the number of times we have
/// run the onEntry() and onExit() functions
Expand Down Expand Up @@ -105,8 +105,12 @@ protected slots:
void onEntryComplete()const;
void onExitComplete()const;

protected:
QScopedPointer<ctkExampleWorkflowStepUsingSignalsAndSlotsPrivate> d_ptr;

private:
CTK_DECLARE_PRIVATE(ctkExampleWorkflowStepUsingSignalsAndSlots);
Q_DECLARE_PRIVATE(ctkExampleWorkflowStepUsingSignalsAndSlots);
Q_DISABLE_COPY(ctkExampleWorkflowStepUsingSignalsAndSlots);

};

Expand Down
16 changes: 8 additions & 8 deletions Libs/Core/Testing/Cpp/ctkWorkflowTest1.cpp
Expand Up @@ -90,7 +90,7 @@ int transitionTest(ctkWorkflow* workflow, int defaultTime, QApplication& app, ct
}

//-----------------------------------------------------------------------------
int testStartWorkflow(ctkWorkflow* workflow, int defaultTime, QApplication& app, int shouldRun, ctkExampleDerivedWorkflowStep* expectedStep=0, ctkExampleDerivedWorkflowStep* step1=0, int step1Entry=0, int step1Exit=0, ctkExampleDerivedWorkflowStep* step2=0, int step2Entry=0, int step2Exit=0, ctkExampleDerivedWorkflowStep* step3=0, int step3Entry=0, int step3Exit=0, ctkExampleDerivedWorkflowStep* step4=0, int step4Entry=0, int step4Exit=0)
int testStartWorkflow(ctkWorkflow* workflow, int defaultTime, QApplication& app, bool shouldRun, ctkExampleDerivedWorkflowStep* expectedStep=0, ctkExampleDerivedWorkflowStep* step1=0, int step1Entry=0, int step1Exit=0, ctkExampleDerivedWorkflowStep* step2=0, int step2Entry=0, int step2Exit=0, ctkExampleDerivedWorkflowStep* step3=0, int step3Entry=0, int step3Exit=0, ctkExampleDerivedWorkflowStep* step4=0, int step4Entry=0, int step4Exit=0)
{
workflow->start();
QTimer::singleShot(defaultTime, &app, SLOT(quit()));
Expand Down Expand Up @@ -150,7 +150,7 @@ int ctkWorkflowTest1(int argc, char * argv [] )
// workflow with no steps
// try erroneously starting with no steps

if (!testStartWorkflow(workflow, defaultTime, app, 0))
if (!testStartWorkflow(workflow, defaultTime, app, false))
{
std::cerr << "empty workflow is running after start()";
return EXIT_FAILURE;
Expand All @@ -164,7 +164,7 @@ int ctkWorkflowTest1(int argc, char * argv [] )
}

// try erroneously starting with no initial step
if (!testStartWorkflow(workflow, defaultTime, app, 0))
if (!testStartWorkflow(workflow, defaultTime, app, false))
{
std::cerr << "workflow is running after start() with no initial step";
return EXIT_FAILURE;
Expand All @@ -177,7 +177,7 @@ int ctkWorkflowTest1(int argc, char * argv [] )
workflow->setInitialStep(step1);

// try starting with one step
if (!testStartWorkflow(workflow, defaultTime, app, 1, step1, step1, 1, 0, step2, 0, 0))
if (!testStartWorkflow(workflow, defaultTime, app, true, step1, step1, 1, 0, step2, 0, 0))
{
std::cerr << "workflow is not running after start() with a single step";
return EXIT_FAILURE;
Expand Down Expand Up @@ -218,7 +218,7 @@ int ctkWorkflowTest1(int argc, char * argv [] )
}

// start the workflow
if (!testStartWorkflow(workflow, defaultTime, app, 1, step1, step1, 2, 1, step2, 0, 0))
if (!testStartWorkflow(workflow, defaultTime, app, true, step1, step1, 2, 1, step2, 0, 0))
{
std::cerr << "workflow is not running after start() with two steps";
return EXIT_FAILURE;
Expand Down Expand Up @@ -319,7 +319,7 @@ int ctkWorkflowTest1(int argc, char * argv [] )

// now that we've stopped and restarted the state machine, we should
// be back in the initial step (step 1)
if (!testStartWorkflow(workflow, defaultTime, app, 1, step1, step1, 4, 3, step2, 1, 1, step3, 0, 0))
if (!testStartWorkflow(workflow, defaultTime, app, true, step1, step1, 4, 3, step2, 1, 1, step3, 0, 0))
{
std::cerr << "workflow is not running after start() with three steps";
return EXIT_FAILURE;
Expand Down Expand Up @@ -367,7 +367,7 @@ int ctkWorkflowTest1(int argc, char * argv [] )
// workflow with a finish step (step 3)

// restart the workflow
if (!testStartWorkflow(workflow, defaultTime, app, 1, step1, step1, 5, 4, step2, 3, 3, step3, 1, 1))
if (!testStartWorkflow(workflow, defaultTime, app, true, step1, step1, 5, 4, step2, 3, 3, step3, 1, 1))
{
std::cerr << "workflow with finish step is not running after start()";
return EXIT_FAILURE;
Expand Down Expand Up @@ -404,7 +404,7 @@ int ctkWorkflowTest1(int argc, char * argv [] )
workflow->addTransition(step3, step4);

// restart the workflow
if (!testStartWorkflow(workflow, defaultTime, app, 1, step1, step1, 8, 7, step2, 5, 5, step3, 3, 3, step4, 0, 0))
if (!testStartWorkflow(workflow, defaultTime, app, true, step1, step1, 8, 7, step2, 5, 5, step3, 3, 3, step4, 0, 0))
{
std::cerr << "workflow with two finish steps is not running after start()";
return EXIT_FAILURE;
Expand Down
4 changes: 2 additions & 2 deletions Libs/Core/Testing/Cpp/ctkWorkflowTest2.cpp
Expand Up @@ -91,7 +91,7 @@ int transitionTest(ctkWorkflow* workflow, int defaultTime, QApplication& app, ct
}

//-----------------------------------------------------------------------------
int testStartWorkflow(ctkWorkflow* workflow, int defaultTime, QApplication& app, int shouldRun, ctkWorkflowStep* expectedStep=0, ctkExampleWorkflowStepUsingSignalsAndSlots* step1=0, int step1Entry=0, int step1Exit=0, ctkExampleWorkflowStepUsingSignalsAndSlots* step2=0, int step2Entry=0, int step2Exit=0, ctkExampleWorkflowStepUsingSignalsAndSlots* step3=0, int step3Entry=0, int step3Exit=0, ctkExampleWorkflowStepUsingSignalsAndSlots* step4=0, int step4Entry=0, int step4Exit=0)
int testStartWorkflow(ctkWorkflow* workflow, int defaultTime, QApplication& app, bool shouldRun, ctkWorkflowStep* expectedStep=0, ctkExampleWorkflowStepUsingSignalsAndSlots* step1=0, int step1Entry=0, int step1Exit=0, ctkExampleWorkflowStepUsingSignalsAndSlots* step2=0, int step2Entry=0, int step2Exit=0, ctkExampleWorkflowStepUsingSignalsAndSlots* step3=0, int step3Entry=0, int step3Exit=0, ctkExampleWorkflowStepUsingSignalsAndSlots* step4=0, int step4Entry=0, int step4Exit=0)
{
workflow->start();
QTimer::singleShot(defaultTime, &app, SLOT(quit()));
Expand Down Expand Up @@ -216,7 +216,7 @@ int ctkWorkflowTest2(int argc, char * argv [] )
}

// start the workflow
if (!testStartWorkflow(workflow, defaultTime, app, 1, step1, qObject1, 1, 0, qObject2, 0, 0, qObject3, 0, 0, qObject4, 0, 0))
if (!testStartWorkflow(workflow, defaultTime, app, 1, step1, qObject1, true, 0, qObject2, 0, 0, qObject3, 0, 0, qObject4, 0, 0))
{
std::cerr << "error starting workflow";
return EXIT_FAILURE;
Expand Down
1 change: 0 additions & 1 deletion Libs/Core/ctkAbstractFactory.h
Expand Up @@ -42,7 +42,6 @@ class ctkAbstractFactoryItem
{
public:
explicit ctkAbstractFactoryItem();
virtual ~ctkAbstractFactoryItem(){}

virtual QString loadErrorString()const;
virtual bool load() = 0;
Expand Down
2 changes: 1 addition & 1 deletion Libs/Core/ctkAbstractLibraryFactory.h
Expand Up @@ -39,7 +39,7 @@ class ctkFactoryLibraryItem : public ctkAbstractFactoryItem<BaseClassType>

public:
explicit ctkFactoryLibraryItem(const QString& path);
virtual ~ctkFactoryLibraryItem(){}

virtual bool load();
QString path()const;
virtual QString loadErrorString()const;
Expand Down

0 comments on commit bab1874

Please sign in to comment.