digiKam
categorizeditemmodel.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2010-12-02
7  * Description : Generic, standard item based model for DCategorizedView
8  *
9  * Copyright (C) 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_CATEGORIZED_ITEM_MODEL_H
25 #define DIGIKAM_CATEGORIZED_ITEM_MODEL_H
26 
27 // Qt includes
28 
29 #include <QStandardItemModel>
30 
31 // Local includes
32 
33 #include "digikam_export.h"
35 
36 class QAction;
37 
38 namespace Digikam
39 {
40 
41 class DIGIKAM_EXPORT CategorizedItemModel : public QStandardItemModel
42 {
43  Q_OBJECT
44 
45 public:
46 
48  {
50  ItemOrderRole = Qt::UserRole + 1
51  };
52 
53 public:
54 
55  explicit CategorizedItemModel(QObject* const parent = nullptr);
56 
57  QStandardItem* addItem(const QString& text, const QVariant& category, const QVariant& categorySorting = QVariant());
58  QStandardItem* addItem(const QString& text, const QIcon& decoration, const QVariant& category,
59  const QVariant& categorySorting = QVariant());
60 
61  virtual DCategorizedSortFilterProxyModel* createFilterModel();
62 };
63 
64 // -----------------------------------------------------------------------------------------------------------------------
65 
66 class DIGIKAM_EXPORT ActionItemModel : public CategorizedItemModel
67 {
68  Q_OBJECT
69 
70 public:
71 
73  {
74  ItemActionRole = Qt::UserRole + 10
75  };
76 
78  {
80  ToplevelMenuCategory = 1 << 0,
81 
83  ParentMenuCategory = 1 << 1,
84 
86  SortCategoriesAlphabetically = 1 << 10,
87 
89  SortCategoriesByInsertionOrder = 1 << 11
90  };
91  Q_DECLARE_FLAGS(MenuCategoryMode, MenuCategoryFlag)
92 
93 public:
94 
101  explicit ActionItemModel(QObject* const parent = nullptr);
102 
103  QStandardItem* addAction(QAction* action, const QString& category, const QVariant& categorySorting = QVariant());
104 
105  void setMode(MenuCategoryMode mode);
106  MenuCategoryMode mode() const;
107 
108  void addActions(QWidget* widget);
109  void addActions(QWidget* widget, const QList<QAction*>& actionWhiteList);
110 
111  DCategorizedSortFilterProxyModel* createFilterModel() override;
112 
117  QStandardItem* itemForAction(QAction* action) const;
118  QModelIndex indexForAction(QAction* action) const;
119 
124  static QAction* actionForIndex(const QModelIndex& index);
125 
126 public Q_SLOTS:
127 
133  void hover(const QModelIndex& index);
134  void toggle(const QModelIndex& index);
135  void trigger(const QModelIndex& index);
136 
137 protected Q_SLOTS:
138 
139  void slotActionChanged();
140 
141 protected:
142 
143  void setPropertiesFromAction(QStandardItem* item, QAction* action);
144 
145 protected:
146 
147  MenuCategoryMode m_mode;
149 };
150 
151 } // namespace Digikam
152 
153 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::ActionItemModel::MenuCategoryMode)
154 
155 #endif // DIGIKAM_CATEGORIZED_ITEM_MODEL_H
Definition: categorizeditemmodel.h:67
DCategorizedSortFilterProxyModel * m_filterModel
Definition: categorizeditemmodel.h:148
MenuCategoryFlag
Definition: categorizeditemmodel.h:78
MenuCategoryMode m_mode
Definition: categorizeditemmodel.h:147
Definition: categorizeditemmodel.h:42
ExtraRoles
Definition: categorizeditemmodel.h:48
Definition: dcategorizedsortfilterproxymodel.h:53
Definition: datefolderview.cpp:43