Make QSignalTransition take a pointer-to-const QObject

The obvious idea is that a connect() happens behind the scenes.
As QObject::connect takes a pointer-to-const, QSignalTransition should
do that as well.

TODO: the API becomes asymmetric in that it takes
a "const QObject *" but returns a "QObject *". Reasoning is needed.

Change-Id: I18d0436e7036eee851fd36d5b8ccda4a4757938f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
Giuseppe D'Angelo 2012-09-13 19:23:10 +01:00 committed by The Qt Project
parent f052ee467d
commit 8b032fe423
6 changed files with 9 additions and 9 deletions

View File

@ -148,7 +148,7 @@ QSignalTransition::QSignalTransition(QState *sourceState)
Constructs a new signal transition associated with the given \a signal of Constructs a new signal transition associated with the given \a signal of
the given \a sender, and with the given \a sourceState. the given \a sender, and with the given \a sourceState.
*/ */
QSignalTransition::QSignalTransition(QObject *sender, const char *signal, QSignalTransition::QSignalTransition(const QObject *sender, const char *signal,
QState *sourceState) QState *sourceState)
: QAbstractTransition(*new QSignalTransitionPrivate, sourceState) : QAbstractTransition(*new QSignalTransitionPrivate, sourceState)
{ {
@ -171,13 +171,13 @@ QSignalTransition::~QSignalTransition()
QObject *QSignalTransition::senderObject() const QObject *QSignalTransition::senderObject() const
{ {
Q_D(const QSignalTransition); Q_D(const QSignalTransition);
return d->sender; return const_cast<QObject *>(d->sender);
} }
/*! /*!
Sets the \a sender object associated with this signal transition. Sets the \a sender object associated with this signal transition.
*/ */
void QSignalTransition::setSenderObject(QObject *sender) void QSignalTransition::setSenderObject(const QObject *sender)
{ {
Q_D(QSignalTransition); Q_D(QSignalTransition);
if (sender == d->sender) if (sender == d->sender)

View File

@ -59,12 +59,12 @@ class Q_CORE_EXPORT QSignalTransition : public QAbstractTransition
Q_PROPERTY(QByteArray signal READ signal WRITE setSignal) Q_PROPERTY(QByteArray signal READ signal WRITE setSignal)
public: public:
QSignalTransition(QState *sourceState = 0); QSignalTransition(QState *sourceState = 0);
QSignalTransition(QObject *sender, const char *signal, QSignalTransition(const QObject *sender, const char *signal,
QState *sourceState = 0); QState *sourceState = 0);
~QSignalTransition(); ~QSignalTransition();
QObject *senderObject() const; QObject *senderObject() const;
void setSenderObject(QObject *sender); void setSenderObject(const QObject *sender);
QByteArray signal() const; QByteArray signal() const;
void setSignal(const QByteArray &signal); void setSignal(const QByteArray &signal);

View File

@ -71,7 +71,7 @@ public:
virtual void callOnTransition(QEvent *e); virtual void callOnTransition(QEvent *e);
QObject *sender; const QObject *sender;
QByteArray signal; QByteArray signal;
int signalIndex; int signalIndex;
int originalSignalIndex; int originalSignalIndex;

View File

@ -348,7 +348,7 @@ void QState::addTransition(QAbstractTransition *transition)
object, and returns the new QSignalTransition object. The transition has object, and returns the new QSignalTransition object. The transition has
this state as the source, and the given \a target as the target state. this state as the source, and the given \a target as the target state.
*/ */
QSignalTransition *QState::addTransition(QObject *sender, const char *signal, QSignalTransition *QState::addTransition(const QObject *sender, const char *signal,
QAbstractState *target) QAbstractState *target)
{ {
if (!sender) { if (!sender) {

View File

@ -83,7 +83,7 @@ public:
void setErrorState(QAbstractState *state); void setErrorState(QAbstractState *state);
void addTransition(QAbstractTransition *transition); void addTransition(QAbstractTransition *transition);
QSignalTransition *addTransition(QObject *sender, const char *signal, QAbstractState *target); QSignalTransition *addTransition(const QObject *sender, const char *signal, QAbstractState *target);
QAbstractTransition *addTransition(QAbstractState *target); QAbstractTransition *addTransition(QAbstractState *target);
void removeTransition(QAbstractTransition *transition); void removeTransition(QAbstractTransition *transition);
QList<QAbstractTransition*> transitions() const; QList<QAbstractTransition*> transitions() const;

View File

@ -1739,7 +1739,7 @@ void QStateMachinePrivate::registerSignalTransition(QSignalTransition *transitio
Q_Q(QStateMachine); Q_Q(QStateMachine);
if (QSignalTransitionPrivate::get(transition)->signalIndex != -1) if (QSignalTransitionPrivate::get(transition)->signalIndex != -1)
return; // already registered return; // already registered
QObject *sender = QSignalTransitionPrivate::get(transition)->sender; const QObject *sender = QSignalTransitionPrivate::get(transition)->sender;
if (!sender) if (!sender)
return; return;
QByteArray signal = QSignalTransitionPrivate::get(transition)->signal; QByteArray signal = QSignalTransitionPrivate::get(transition)->signal;