Kross

actioncollectionmodel.h
1 /***************************************************************************
2  * actioncollectionmodel.h
3  * This file is part of the KDE project
4  * copyright (C) 2006-2007 by Sebastian Sauer ([email protected])
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  ***************************************************************************/
19 
20 #ifndef KROSS_MODEL_H
21 #define KROSS_MODEL_H
22 
23 #include <kross/ui/krossui_export.h>
24 
25 #include <QModelIndex>
26 #include <QSortFilterProxyModel>
27 
28 namespace Kross
29 {
30 
31 // Forward declarations.
32 class Action;
33 class ActionCollection;
34 class ActionCollectionModelItem;
35 
47 class KROSSUI_EXPORT ActionCollectionModel : public QAbstractItemModel
48 {
49  Q_OBJECT
50 public:
51  enum Mode {
52  None = 0,
53  Icons = 1,
54  ToolTips = 2,
55  UserCheckable = 4
56  //Editable = 8
57  };
58 
59  explicit ActionCollectionModel(QObject *parent, ActionCollection *collection = nullptr, Mode mode = Mode(Icons | ToolTips));
60  virtual ~ActionCollectionModel();
61 
62  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
63  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
64  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
65  QModelIndex parent(const QModelIndex &index) const override;
66  Qt::ItemFlags flags(const QModelIndex &index) const override;
67  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
68  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
69 
70  bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
71  bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
72  bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
73  bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
74 
75  //Qt::DropActions supportedDragActions() const;
76  QStringList mimeTypes() const override;
77  QMimeData *mimeData(const QModelIndexList &indexes) const override;
78  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
79 
80  Qt::DropActions supportedDropActions() const override;
81 
82  QModelIndex indexForCollection(ActionCollection *collection) const;
83  QModelIndex indexForAction(Action *action) const;
85  ActionCollection *rootCollection() const;
86 
91  static Action *action(const QModelIndex &index);
92 
97  static ActionCollection *collection(const QModelIndex &index);
98 
99 protected:
101  int rowNumber(ActionCollection *collection) const;
102 
103 private Q_SLOTS:
104  void slotUpdated();
105 
106  void slotDataChanged(ActionCollection *);
107  void slotDataChanged(Action *);
108 
109  void slotCollectionToBeInserted(ActionCollection *child, ActionCollection *parent);
110  void slotCollectionInserted(ActionCollection *child, ActionCollection *parent);
111  void slotCollectionToBeRemoved(ActionCollection *child, ActionCollection *parent);
112  void slotCollectionRemoved(ActionCollection *child, ActionCollection *parent);
113 
114  void slotActionToBeInserted(Action *child, ActionCollection *parent);
115  void slotActionInserted(Action *child, ActionCollection *parent);
116  void slotActionToBeRemoved(Action *child, ActionCollection *parent);
117  void slotActionRemoved(Action *child, ActionCollection *parent);
118 private:
120  class Private;
122  Private *const d;
123 };
124 
130 {
131 public:
132  explicit ActionCollectionProxyModel(QObject *parent, ActionCollectionModel *model = nullptr);
133  virtual ~ActionCollectionProxyModel();
134 
135 private:
137  void setSourceModel(QAbstractItemModel *sourceModel) override;
139  bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
140 };
141 
142 }
143 
144 #endif
145 
The ActionCollectionModel class implements a QAbstractItemModel to provide a model for views of a Act...
Definition: action.cpp:36
The ActionCollectionProxyModel class implements a QSortFilterProxyModel for a ActionCollectionModel i...
DisplayRole
The Action class is an abstract container to deal with scripts like a single standalone script file...
Definition: action.h:95
The ActionCollection class manages collections of Action instances.
DropAction
typedef ItemFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 10 2020 22:57:12 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.