00001 /* 00002 Copyright © 2010 yan Verdavaine 00003 00004 This file is part of QExtend. 00005 00006 QExtend is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 any later version. 00010 00011 QExtend is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with QExtend. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include "actionscheduler.hpp" 00021 #include "connector.hpp" 00022 00023 #include "signalcheckpoint.hpp" 00024 #include <QStateMachine> 00025 00026 00027 00028 namespace QExtend 00029 { 00030 struct propertyParam 00031 { 00032 ExtendPtr<const QObject , WEAK> object; 00033 const char * property; 00034 QString name; 00035 00036 }; 00037 00038 struct ActionSchedulerPrivate : public QObject 00039 { 00040 Q_OBJECT 00041 public : 00042 QStateMachine stateMachine; 00043 SignalCheckPoint listener; 00044 QList<propertyParam> otherparams; 00045 ActionScheduler * actionSheduler; 00046 00047 ActionSchedulerPrivate (ActionScheduler * actionSheduler) 00048 :QObject(actionSheduler),actionSheduler(actionSheduler) 00049 { 00050 00051 QState * sBegin = new QState(&stateMachine); 00052 QState * sRuning = new QState(&stateMachine); 00053 QState * sWait = new QState(&stateMachine); 00054 00055 sBegin -> addTransition ( &listener , SIGNAL(parameters(const QVariantMap &)) , sRuning ); 00056 sRuning -> addTransition ( &listener , SIGNAL(parameters(const QVariantMap &)) , sWait ); 00057 sWait -> addTransition ( this , SIGNAL(actionFinished()) , sRuning ); 00058 sRuning -> addTransition ( this , SIGNAL(actionFinished()) , sBegin ); 00059 00060 EMITTER(sRuning , entered () ) >> RECEIVER ( this , launchAction()); 00061 stateMachine.setInitialState(sBegin); 00062 stateMachine.start(); 00063 } 00064 00065 public Q_SLOTS : 00066 void emitActionFinished () 00067 { 00068 Q_EMIT actionFinished(); 00069 } 00070 void launchAction () 00071 { 00072 00073 QVariantMap map = listener.getParameters(); 00074 Q_FOREACH(const propertyParam & pp,otherparams) 00075 { 00076 map[pp.name] = pp.object->property(pp.property); 00077 } 00078 00079 Q_EMIT actionSheduler->launchAction( map ); 00080 } 00081 00082 Q_SIGNALS: 00083 void actionFinished(); 00084 00085 }; 00086 00087 00088 00089 00090 ActionScheduler::ActionScheduler(QObject * parent) 00091 :QObject(parent),m_internal(this) 00092 { 00093 } 00094 00095 00096 void ActionScheduler::addListenEmitter(const Emitter &emitter,const QStringList & list) 00097 { 00098 m_internal->listener.addEmitter(emitter , list ); 00099 } 00100 void ActionScheduler::addListenEmitterProperty(const Emitter &emitter,const char * p, const QString & s) 00101 { 00102 m_internal->listener.addEmitterProperty(emitter , p , s ); 00103 } 00104 void ActionScheduler::addListenProperty(const QObject * obj,const char * p, const QString & s ) 00105 { 00106 propertyParam tmp; 00107 tmp.object = obj; 00108 tmp.name = s; 00109 tmp.property = p; 00110 00111 m_internal->otherparams << tmp; 00112 } 00113 00114 void ActionScheduler::actionFinished() 00115 { 00116 m_internal->emitActionFinished(); 00117 } 00118 00119 00120 00121 00122 } 00123 #include "actionscheduler.moc"
Les sources présentées sur cette page sont libres de droits et vous pouvez les utiliser à votre convenance. Par contre, la page de présentation constitue une œuvre intellectuelle protégée par les droits d'auteur. Copyright © 2010 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site ni de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon vous encourez selon la loi jusqu'à trois ans de prison et jusqu'à 300 000 € de dommages et intérêts.