KDStateMachineEditor  1.0.0
A framework for creating Qt State Machine metacode using a graphical user interface
elementmodel.h
1 /*
2  elementmodel.h
3 
4  This file is part of the KDAB State Machine Editor Library.
5 
6  Copyright (C) 2014-2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com.
7  All rights reserved.
8  Author: Kevin Funk <kevin.funk@kdab.com>
9 
10  Licensees holding valid commercial KDAB State Machine Editor Library
11  licenses may use this file in accordance with the KDAB State Machine Editor
12  Library License Agreement provided with the Software.
13 
14  This file may be distributed and/or modified under the terms of the
15  GNU Lesser General Public License version 2.1 as published by the
16  Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
17 
18  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 
21  Contact info@kdab.com if any conditions of this licensing are not
22  clear to you.
23 */
24 
25 #ifndef KDSME_MODEL_ELEMENTMODEL_H
26 #define KDSME_MODEL_ELEMENTMODEL_H
27 
28 #include "element.h"
29 #include "objecttreemodel.h"
30 #include "kdsme_core_export.h"
31 
32 #include <QAbstractItemModel>
33 #include <QObject>
34 #include <QPointer>
35 #include <QSortFilterProxyModel>
36 
37 class QAbstractState;
38 class QState;
39 class QStateMachine;
40 
41 namespace KDSME {
42 
43 class StateModel;
44 class State;
45 
46 class KDSME_CORE_EXPORT TransitionModel : public QSortFilterProxyModel
47 {
48  Q_OBJECT
49 
50 public:
51  explicit TransitionModel(QObject* parent = nullptr);
52  virtual ~TransitionModel();
53 
54  virtual void setSourceModel(QAbstractItemModel* sourceModel) override;
55 
56  virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
57 
58 private:
59  struct Private;
60  QScopedPointer<Private> d;
61 };
62 
63 class KDSME_CORE_EXPORT TransitionListModel : public QAbstractListModel
64 {
65  Q_OBJECT
66  Q_PROPERTY(KDSME::State* state READ state WRITE setState)
67 
68 public:
69  enum Role {
70  ObjectRole = Qt::UserRole + 1,
71  };
72 
73  enum Column {
74  NameColumn,
75  SourceStateColumn,
76  TargetStateColumn,
77  _LastColumn
78  };
79 
80  explicit TransitionListModel(QObject* parent = nullptr);
81  virtual ~TransitionListModel();
82 
83  State* state() const;
84  void setState(State* list);
85 
86  virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
87  virtual int columnCount(const QModelIndex& parent) const override;
88  virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
89  virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
90  virtual QHash< int, QByteArray > roleNames() const override;
91 
92 private:
93  struct Private;
94  QScopedPointer<Private> d;
95 };
96 
97 class KDSME_CORE_EXPORT StateModel : public ObjectTreeModel
98 {
99  Q_OBJECT
100  Q_PROPERTY(KDSME::State* state READ state WRITE setState)
101 
102 public:
103  enum Role {
104  ElementRole = ObjectTreeModel::UserRole + 1
105  };
106 
107  explicit StateModel(QObject* parent = nullptr);
108  virtual ~StateModel();
109 
110  State* state() const;
111  void setState(State* state);
112 
113  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
114  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
115  Qt::ItemFlags flags(const QModelIndex& index) const override;
116 
117 private:
118  struct Private;
119  QScopedPointer<Private> d;
120 };
121 
122 }
123 
124 Q_DECLARE_METATYPE(KDSME::TransitionModel*)
125 Q_DECLARE_METATYPE(KDSME::StateModel*)
126 
127 #endif
Definition: elementmodel.h:63
Definition: elementmodel.h:97
Definition: elementmodel.h:46
Definition: objecttreemodel.h:36
Definition: state.h:35
Definition: abstractexporter.h:33

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
https://github.com/KDAB/KDStateMachineEditor