KDStateMachineEditor  1.1.0
A framework for creating Qt State Machine metacode using a graphical user interface
abstractscene.h
1 /*
2  This file is part of the KDAB State Machine Editor Library.
3 
4  Copyright (C) 2014-2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com.
5  All rights reserved.
6  Author: Kevin Funk <kevin.funk@kdab.com>
7 
8  Licensees holding valid commercial KDAB State Machine Editor Library
9  licenses may use this file in accordance with the KDAB State Machine Editor
10  Library License Agreement provided with the Software.
11 
12  This file may be distributed and/or modified under the terms of the
13  GNU Lesser General Public License version 2.1 as published by the
14  Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
15 
16  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
17  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 
19  Contact info@kdab.com if any conditions of this licensing are not
20  clear to you.
21 */
22 
23 #ifndef KDSME_VIEW_ABSTRACTSCENE_H
24 #define KDSME_VIEW_ABSTRACTSCENE_H
25 
26 #include "kdsme_view_export.h"
27 
28 #include <QQuickItem>
29 #include <QPointer>
30 
31 QT_BEGIN_NAMESPACE
32 class QAbstractItemModel;
33 class QItemSelection;
34 class QItemSelectionModel;
35 class QModelIndex;
36 QT_END_NAMESPACE
37 
38 namespace KDSME {
39 
40 class AbstractScenePrivate;
41 class AbstractSceneContextMenuEventPrivate;
42 class Element;
43 
44 class KDSME_VIEW_EXPORT AbstractSceneContextMenuEvent : public QContextMenuEvent
45 {
46 public:
47  AbstractSceneContextMenuEvent(Reason reason, const QPoint & pos, const QPoint& globalPos, Qt::KeyboardModifiers modifiers = {}, Element* elementUnderCursor = nullptr);
48 
50 
51  Element* elementUnderCursor() const;
52 
53 private:
54  QScopedPointer<AbstractSceneContextMenuEventPrivate> d;
55 };
56 
57 class KDSME_VIEW_EXPORT AbstractScene : public QQuickItem
58 {
59  Q_OBJECT
60  Q_PROPERTY(QAbstractItemModel* model READ model WRITE setModel NOTIFY modelChanged)
61  Q_PROPERTY(QQuickItem* instantiator READ instantiator WRITE setInstantiator NOTIFY instantiatorChanged)
62  Q_PROPERTY(ViewState viewState READ viewState NOTIFY stateChanged FINAL)
63  Q_PROPERTY(Qt::ContextMenuPolicy ContextMenuPolicy READ contextMenuPolicy WRITE setContextMenuPolicy NOTIFY contextMenuPolicyChanged FINAL)
64 
65 public:
66  enum EditTrigger {
67  NoEditTriggers,
68  SelectedClicked
69  };
70  Q_DECLARE_FLAGS(EditTriggers, EditTrigger)
71 
72  enum ViewState {
73  NoState,
74  RefreshState,
75  };
76  Q_ENUMS(ViewState)
77 
78  explicit AbstractScene(QQuickItem* parent = nullptr);
79  virtual ~AbstractScene();
80 
81  virtual void setModel(QAbstractItemModel *model);
82  QAbstractItemModel *model() const;
83 
84  virtual void setSelectionModel(QItemSelectionModel *selectionModel);
85  QItemSelectionModel *selectionModel() const;
86 
87  QQuickItem* instantiator() const;
88  void setInstantiator(QQuickItem* instantiator);
89 
90  void setEditTriggers(EditTriggers triggers);
91  EditTriggers editTriggers() const;
92 
93  void setContextMenuPolicy(Qt::ContextMenuPolicy contextMenuPolicy);
94  Qt::ContextMenuPolicy contextMenuPolicy() const;
95 
96  QObject* itemForIndex(const QModelIndex& index) const;
97 
98  ViewState viewState() const;
99 
100  QModelIndex currentIndex() const;
101 
102 public Q_SLOTS:
103  void setCurrentIndex(const QModelIndex& index);
104 
105 protected:
106  bool event(QEvent* event) override;
107 
108 protected Q_SLOTS:
109  virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
110  virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
111 
112  virtual void rowsInserted(const QModelIndex& parent, int start, int end);
113  virtual void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
114 
119  virtual void layoutChanged();
120 
121  void setViewState(ViewState state);
122 
123 Q_SIGNALS:
124  void modelChanged(QAbstractItemModel* model);
125  void stateChanged(ViewState state);
126  void instantiatorChanged(QObject* instantiator);
127  void contextMenuPolicyChanged(Qt::ContextMenuPolicy contextMenuPolicy);
128 
135  void customContextMenuEvent(KDSME::AbstractSceneContextMenuEvent* event);
136 
137 private:
138  friend AbstractScenePrivate;
139  QScopedPointer<AbstractScenePrivate> d;
140 };
141 
142 }
143 
144 Q_DECLARE_METATYPE(KDSME::AbstractScene*)
145 Q_DECLARE_METATYPE(KDSME::AbstractScene::ViewState)
146 
147 #endif // ABSTRACTVIEW_H
Definition: abstractscene.h:57
Definition: abstractscene.h:44
Definition: element.h:43
Definition: abstractexporter.h:33

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