KDStateMachineEditor  1.1.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-2016 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 QT_BEGIN_NAMESPACE
38 class QAbstractState;
39 class QState;
40 class QStateMachine;
41 QT_END_NAMESPACE
42 
43 namespace KDSME {
44 
45 class StateModel;
46 class State;
47 
48 class KDSME_CORE_EXPORT TransitionModel : public QSortFilterProxyModel
49 {
50  Q_OBJECT
51 
52 public:
53  explicit TransitionModel(QObject* parent = nullptr);
54  ~TransitionModel();
55 
56  void setSourceModel(QAbstractItemModel* sourceModel) override;
57 
58  bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
59 
60 private:
61  struct Private;
62  QScopedPointer<Private> d;
63 };
64 
65 class KDSME_CORE_EXPORT TransitionListModel : public QAbstractListModel
66 {
67  Q_OBJECT
68  Q_PROPERTY(KDSME::State* state READ state WRITE setState)
69 
70 public:
71  enum Role {
72  ObjectRole = Qt::UserRole + 1,
73  };
74 
75  enum Column {
76  NameColumn,
77  SourceStateColumn,
78  TargetStateColumn,
79  _LastColumn
80  };
81 
82  explicit TransitionListModel(QObject* parent = nullptr);
84 
85  State* state() const;
86  void setState(State* list);
87 
88  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
89  int columnCount(const QModelIndex& parent) const override;
90  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
91  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
92  QHash< int, QByteArray > roleNames() const override;
93 
94 private:
95  struct Private;
96  QScopedPointer<Private> d;
97 };
98 
99 class KDSME_CORE_EXPORT StateModel : public ObjectTreeModel
100 {
101  Q_OBJECT
102  Q_PROPERTY(KDSME::State* state READ state WRITE setState)
103 
104 public:
105  enum Role {
106  ElementRole = ObjectTreeModel::UserRole + 1,
108  };
109 
110  explicit StateModel(QObject* parent = nullptr);
111  ~StateModel();
112 
113  State* state() const;
114  void setState(State* state);
115 
116  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
117  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
118  Qt::ItemFlags flags(const QModelIndex& index) const override;
119 
120 private:
121  struct Private;
122  QScopedPointer<Private> d;
123 };
124 
125 }
126 
127 Q_DECLARE_METATYPE(KDSME::TransitionModel*)
128 Q_DECLARE_METATYPE(KDSME::StateModel*)
129 
130 #endif
Definition: elementmodel.h:65
Definition: elementmodel.h:99
Definition: elementmodel.h:48
Role
Definition: elementmodel.h:105
return quint64
Definition: elementmodel.h:107
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