Details
-
Suggestion
-
Resolution: Invalid
-
Not Evaluated
-
4.5.0
-
None
Description
It is not necessary to invoke an action in a state for a state to have sense.
Imagine for example using a state machine to implement the design pattern "State pattern".
So the abstract method onEntry() does not always make sense (like in QHistoryState, StartState, etc where it is not implemented). It could be better to have a pure virtual destructor to ensure the class is abstract.
Here is a patch to change this (onEntry() and onExit() are also made inline in this patch):
diff --git a/src/corelib/statemachine/qabstractstate.cpp b/src/corelib/statemachine/qabstractstate.cpp
index 49bdc41..1d1a85e 100644
— a/src/corelib/statemachine/qabstractstate.cpp
+++ b/src/corelib/statemachine/qabstractstate.cpp
@@ -290,19 +290,17 @@ void QAbstractState::addTransition(QAbstractState *target)
}
/*!
- This function is called when the state is exited. Reimplement this function
- to perform custom processing when the state is exited. The default
+ This function is called when the state is exited. Reimplement this function
+ to perform custom processing when the state is exited. The default
implementation does nothing.
*/
-void QAbstractState::onExit()
- { -}
/*!
\fn QAbstractState::onEntry()
This function is called when the state is entered. Reimplement this function
- to perform custom processing when the state is entered.
+ to perform custom processing when the state is entered. The default
+ implementation does nothing.
*/
QT_END_NAMESPACE
diff --git a/src/corelib/statemachine/qabstractstate.h b/src/corelib/statemachine/qabstractstate.h
index b761c74..38fc7a0 100644
— a/src/corelib/statemachine/qabstractstate.h
+++ b/src/corelib/statemachine/qabstractstate.h
@@ -33,7 +33,7 @@ public:
Parallel
};
- ~QAbstractState();
+ ~QAbstractState() = 0;
QAbstractState *parentState() const;
@@ -49,8 +49,8 @@ protected:
QAbstractState(QAbstractState *parent);
QAbstractState(Type type, QAbstractState *parent);
- virtual void onEntry() = 0;
- virtual void onExit();
+ inline virtual void onEntry() {};
+ inline virtual void onExit() {};
protected:
QAbstractState(QAbstractStatePrivate &dd, QAbstractState *parent);