StateTreeController.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <QAbstractItemModel>
27#include <QSortFilterProxyModel>
28#include <QTreeView>
29
33
38
42#include "model/StateTreeNode.h"
43
44
45class QProcess;
46
47namespace armarx
48{
49
51 using StatechartProfilesPtr = std::shared_ptr<StatechartProfiles>;
52
53
55 using StateTreeControllerPtr = std::shared_ptr<StateTreeController>;
56
57 class StateTreeController : public QAbstractItemModel
58 {
59 Q_OBJECT
60
61 public:
63 VariantInfoPtr variantInfo,
64 QList<QVariant> headerInfo,
65 QTreeView* treeView,
66 QLineEdit* filterLineEdit,
67 const ArmarXPackageToolInterfacePtr& packageTool,
68 const StatechartProfilesPtr& statechartProfiles,
69 StatechartProfilePtr currentProfile,
70 QObject* parent = 0);
71 ~StateTreeController() override;
72
73 QVariant data(const QModelIndex& index, int role) const override;
74 Qt::ItemFlags flags(const QModelIndex& index) const override;
75 QVariant headerData(int section,
76 Qt::Orientation orientation,
77 int role = Qt::DisplayRole) const override;
78 QModelIndex
79 index(int row, int column, const QModelIndex& parentIndex = QModelIndex()) const override;
80 QModelIndex parent(const QModelIndex& index) const override;
81 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
82 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
83 StatechartGroupPtr loadAndAddGroup(QString groupDefinitionFile);
84 StatechartGroupPtr loadGroup(QString groupDefinitionFile);
85 StatechartGroupPtr addNewGroup(const QString& groupName,
86 const QString& groupPath,
87 const QString& description,
88 const QString& packageName,
89 const QList<QString> proxies,
90 bool generateContext,
91 const QMap<QString, QString>& statechartGroupConfigurations);
92
93 void loadAllStates();
94
100 bool nodeIsGroup(StateTreeNodePtr node);
102 bool selectedNodeIsState();
104 bool selectedNodeIsGroup();
107 StateTreeNodePtr createNewState(QString name,
109 bool createDynamicRemoteState = false);
111 //StateTreeNodePtr get
112 void tryDeleteState();
113 void removeState(StateTreeNodePtr stateNode);
114 void tryDeleteFolder();
115 void removeFolder(StateTreeNodePtr folderNode);
116 void tryDeleteGroup();
117
119
120 void saveAll();
121
122 StateTreeNodePtr getNode(QModelIndex index) const;
123
125
126 signals:
128
129 public slots:
130 void onContextMenu(const QPoint& point);
133 void onNewFolder();
134 void onDeleteNode();
135 void onMakeStatePublic(bool enable);
136 void onFindStateUsages();
137 void onRenameState();
138 void onOpenCMakeProject();
139 void onShowFullPath();
140 void onOpenStateCPP();
141 void onOpenGroup(QString groupFile = "");
142 void onExecuteGroup();
143 void onStatechartFinished(int exitCode);
144 //void onGenerateStateBaseClass();
145 //void onGenerateRsoBaseClass();
147 void onRenameGroup();
148 void onCloneGroup();
149 void onGroupProperties();
150 void collapseAll();
151 void selectNode(StateTreeNodePtr node);
152
153 void executeGroup(StatechartGroupPtr group, QString startState = "");
154
156
157 void executeGroupWithDependencies(StatechartGroupPtr group, QString startState);
158
160
161 public:
163
164 private slots:
165 void processOutputReady();
166 void processErrorsReady();
167 void stateAddedOrRemoved();
168 void expandFilterResults(const QString& filterString);
169
170 private:
171 QModelIndex getIndex(StateTreeNodePtr node);
172 QString buildStateUsageString(QList<statechartmodel::StateInstancePtr> instances);
173
174 StateTreeNodePtr rootNode;
175 QList<QVariant> headerInfo;
176 QTreeView* treeView;
177 StateTreeModelPtr stateTreeModel;
178 InfixFilterModel* proxyModel;
179 GroupClonerPtr groupCloner;
180 GroupRenamerPtr groupRenamer;
181 StatechartGroupPtr activeGroup;
182 QMenu* contextMenuGroup;
183 QMenu* contextMenuFolder;
184 QMenu* contextMenuState;
185 QAction* actionNewStateDefinition;
186 QAction* actionNewDynamicRemoteStateDefinition;
187 QAction* actionNewFolder;
188 QAction* actionDeleteNode;
189 QAction* actionMakeStatePublic;
190 QAction* actionFindStateUsages;
191 QAction* actionRenameState;
192 QAction* actionOpenCMakeProject;
193 QAction* actionShowFullPath;
194 QAction* actionOpenStateCPP;
195 QAction* actionExecuteGroup;
196 //QAction *actionGenerateStateBaseClass;
197 //QAction *actionGenerateRsoBaseClass;
198 QAction* actionGenerateStateCPP;
199 QAction* actionCloneGroup;
200 QAction* actionRenameGroup;
201 QAction* actionGroupProperties;
203
205 EditorFileOpener opener;
206 QMap<QString, QProcess*> processes;
207 VariantInfoPtr variantInfo;
208 StatechartProfilesPtr profiles;
209 StatechartProfilePtr currentProfile;
210 Ice::CommunicatorPtr communicator;
211
212 struct StateMimeData : AbstractStateMimeData
213 {
214 StateMimeData(statechartmodel::StatePtr state, StateTreeModelPtr stateTreeModel);
215 bool isInSameGroup(statechartmodel::StatePtr state) const override;
216 bool isPublic() const override;
217
218 private:
219 StateTreeModelPtr stateTreeModel;
220 };
221
222 // QAbstractItemModel interface
223 bool retrieveNewStateName(QString& newStateName,
224 StateTreeNodePtr& node,
225 bool& createCPPFiles,
226 bool askForCPPFiles);
227 /*!
228 * \brief Buffers the icons so that they are not loaded each time again
229 * \param path Path to icon, can be resource.
230 * \return Freshly loaded or buffered icon.
231 */
232 QIcon getIcon(const QString& path) const;
233 mutable QMap<QString, QIcon> icons;
234
235 public:
236 QStringList mimeTypes() const override;
237 QMimeData* mimeData(const QModelIndexList& indexes) const override;
238 };
239} // namespace armarx
uint8_t index
The AbstractStateMimeData class is used to transport state data from the treeview to the stateview an...
statechartmodel::StatePtr state
The EditorFileOpener class.
This proxy model reimplements the filterAcceptsRow function with a new behavior: All elements that fi...
QStringList mimeTypes() const override
void stopGroupExecutionWithDependencies(StatechartGroupPtr group)
void onOpenGroup(QString groupFile="")
StateTreeNodePtr getClosestParentFolderOrGroupNode(StateTreeNodePtr node)
StateTreeNodePtr getNodeByState(statechartmodel::StatePtr state)
StatechartGroupPtr addNewGroup(const QString &groupName, const QString &groupPath, const QString &description, const QString &packageName, const QList< QString > proxies, bool generateContext, const QMap< QString, QString > &statechartGroupConfigurations)
void stopGroupExecution(StatechartGroupPtr group)
StateTreeNodePtr createNewState(QString name, StateTreeNodePtr parent, bool createDynamicRemoteState=false)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void removeFolder(StateTreeNodePtr folderNode)
Qt::ItemFlags flags(const QModelIndex &index) const override
bool nodeIsFolderOrGroup(StateTreeNodePtr node)
void executeGroup(StatechartGroupPtr group, QString startState="")
void removeNodeFromTree(StateTreeNodePtr node)
StateTreeNodePtr tryCreateNewState(QString name)
StateTreeNodePtr createNewFolder(QString name, StateTreeNodePtr parent)
StatechartGroupPtr loadGroup(QString groupDefinitionFile)
void executeGroupWithDependencies(StatechartGroupPtr group, QString startState)
StateTreeController(Ice::CommunicatorPtr ic, VariantInfoPtr variantInfo, QList< QVariant > headerInfo, QTreeView *treeView, QLineEdit *filterLineEdit, const ArmarXPackageToolInterfacePtr &packageTool, const StatechartProfilesPtr &statechartProfiles, StatechartProfilePtr currentProfile, QObject *parent=0)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void selectNode(StateTreeNodePtr node)
StateTreeNodePtr getNode(QModelIndex index) const
QModelIndex parent(const QModelIndex &index) const override
void onContextMenu(const QPoint &point)
void selectNodeByState(statechartmodel::StatePtr state)
void openStateCPP(StateTreeNodePtr node)
bool nodeIsFolder(StateTreeNodePtr node)
QModelIndex index(int row, int column, const QModelIndex &parentIndex=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
StatechartGroupPtr loadAndAddGroup(QString groupDefinitionFile)
bool nodeIsState(StateTreeNodePtr node)
QMimeData * mimeData(const QModelIndexList &indexes) const override
bool nodeIsGroup(StateTreeNodePtr node)
void removeState(StateTreeNodePtr stateNode)
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
Definition IceManager.h:49
std::shared_ptr< Application > ApplicationPtr
std::shared_ptr< State > StatePtr
Definition State.h:48
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< StatechartProfiles > StatechartProfilesPtr
std::shared_ptr< StatechartGroup > StatechartGroupPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition VariantInfo.h:39
std::shared_ptr< StateTreeModel > StateTreeModelPtr
std::shared_ptr< class StatechartProfile > StatechartProfilePtr
std::shared_ptr< GroupCloner > GroupClonerPtr
Definition GroupCloner.h:46
std::shared_ptr< StateTreeNode > StateTreeNodePtr
std::shared_ptr< GroupRenamer > GroupRenamerPtr
std::shared_ptr< StateTreeController > StateTreeControllerPtr
std::shared_ptr< ArmarXPackageToolInterface > ArmarXPackageToolInterfacePtr