00001 #include "constants.h"
00002
00003 #include "stateManager.h"
00004 #include "editor.h"
00005 #include "state.h"
00006 #include "stateNormal.h"
00007 #include "stateVar.h"
00008 #include "stateDialogs.h"
00009
00010 #include <QPoint>
00011 #include <QtGlobal>
00012
00013 bool StateManager::instantiated = false;
00014 StateManager* StateManager::manager = NULL;
00015
00016 StateManager::StateManager()
00017 {
00018 stateTypeList << "State" << "FinalState" << "StateVar" << "FinalStateVar";
00019 int i = 0;
00020 typeNameToInstanceMap[stateTypeList[i++]] = &StateManager::createStateNormal;
00021 typeNameToInstanceMap[stateTypeList[i++]] = &StateManager::createStateNormalFinal;
00022 typeNameToInstanceMap[stateTypeList[i++]] = &StateManager::createStateVar;
00023 typeNameToInstanceMap[stateTypeList[i++]] = &StateManager::createStateVarFinal;
00024 }
00025
00026 StateManager* StateManager::getInstance()
00027 {
00028 if(!instantiated)
00029 {
00030 manager = new StateManager();
00031 instantiated = true;
00032 return manager;
00033 }
00034 else
00035 {
00036 return manager;
00037 }
00038 }
00039
00040 const QList<QString>& StateManager::getTypeNameList() const
00041 {
00042 return stateTypeList;
00043 }
00044
00045 int StateManager::getTypeNameId(const QString &typeName) const
00046 {
00047 Q_ASSERT(stateTypeList.contains(typeName));
00048 return stateTypeList.indexOf(typeName);
00049 }
00050
00051 State* StateManager::createState(Editor *editor, const QPoint& pos, const StateDialog &sd)
00052 {
00053 Q_ASSERT(typeNameToInstanceMap.contains(stateTypeList[sd.getType()]));
00054 return (this->*(typeNameToInstanceMap[stateTypeList[sd.getType()]]))
00055 (editor, pos, sd.getLabel(), sd.getName(), sd.isDimmed());
00056 }
00057
00058 State* StateManager::createState(const QString& typeName, Editor *editor, const QPoint& pos,
00059 const QString& label, const QString& name, bool dimmed)
00060 {
00061 Q_ASSERT(typeNameToInstanceMap.contains(typeName));
00062 return (this->*(typeNameToInstanceMap[typeName]))
00063 (editor, pos, label, name, dimmed);
00064 }
00065
00066
00067
00068
00069
00070 State* StateManager::createStateNormal(Editor *editor, const QPoint& pos, const QString& label,
00071 const QString& name,bool dimmed)
00072 {
00073 return new StateNormal(pos, editor, label, name, false, dimmed);
00074 }
00075
00076 State* StateManager::createStateNormalFinal(Editor *editor, const QPoint& pos, const QString& label,
00077 const QString& name,bool dimmed)
00078 {
00079 return new StateNormal(pos, editor, label, name, true, dimmed);
00080 }
00081
00082 State* StateManager::createStateVar(Editor *editor, const QPoint& pos, const QString& label,
00083 const QString& name,bool dimmed)
00084 {
00085 return new StateVar(pos, editor, label, name, false, dimmed);
00086 }
00087
00088 State* StateManager::createStateVarFinal(Editor *editor, const QPoint& pos, const QString& label,
00089 const QString& name,bool dimmed)
00090 {
00091 return new StateVar(pos, editor, label, name, true, dimmed);
00092 }