digiKam
setupcollectionview.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 : 2008-11-15
7  * Description : collections setup tab model/view
8  *
9  * Copyright (C) 2008-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2005-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_SETUP_COLLECTION_VIEW_H
26 #define DIGIKAM_SETUP_COLLECTION_VIEW_H
27 
28 // Qt includes
29 
30 #include <QAbstractItemModel>
31 #include <QAbstractItemDelegate>
32 #include <QList>
33 #include <QTreeView>
34 #include <QStyledItemDelegate>
35 #include <QPushButton>
36 #include <QToolButton>
37 
38 // Local includes
39 
40 #include "collectionlocation.h"
41 #include "dwitemdelegate.h"
42 #include "digikam_export.h"
43 
44 namespace Digikam
45 {
46 
47 class DIGIKAM_GUI_EXPORT SetupCollectionModel : public QAbstractItemModel
48 {
49  Q_OBJECT
50 
51 public:
52 
61  {
63  IsCategoryRole = Qt::UserRole,
64 
66  CategoryButtonDisplayRole = Qt::UserRole + 1,
67  CategoryButtonMapId = Qt::UserRole + 2,
68 
70  IsUpdateRole = Qt::UserRole + 3,
71 
73  UpdateDecorationRole = Qt::UserRole + 4,
74  UpdateMapId = Qt::UserRole + 5,
75 
77  IsDeleteRole = Qt::UserRole + 6,
78 
80  DeleteDecorationRole = Qt::UserRole + 7,
81  DeleteMapId = Qt::UserRole + 8
82  };
83 
84  enum Columns
85  {
86  ColumnStatus = 0,
87  ColumnName = 1,
88  ColumnPath = 2,
89  ColumnUpdateButton = 3,
90  ColumnDeleteButton = 4,
91  NumberOfColumns
92  };
93 
94  enum Category
95  {
96  CategoryLocal = 0,
97  CategoryRemovable = 1,
98  CategoryRemote = 2,
99  NumberOfCategories
100  };
101 
102 public:
103 
104  explicit SetupCollectionModel(QObject* const parent = nullptr);
105  ~SetupCollectionModel() override;
106 
108  void loadCollections();
109 
111  void setParentWidgetForDialogs(QWidget* const widget);
112 
114  void apply();
115 
116  QModelIndex indexForCategory(Category category) const;
117  QList<QModelIndex> categoryIndexes() const;
118 
120  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
121  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
122  int rowCount(const QModelIndex& parent = QModelIndex()) const override;
123  int columnCount(const QModelIndex& parent = QModelIndex()) const override;
124  Qt::ItemFlags flags(const QModelIndex& index) const override;
125  bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
126  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
127  QModelIndex parent(const QModelIndex& index) const override;
128 
129 /*
130  virtual Qt::DropActions supportedDropActions() const;
131  virtual QStringList mimeTypes() const;
132  virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
133  virtual QMimeData * mimeData(const QModelIndexList& indexes) const;
134 */
135 
136 Q_SIGNALS:
137 
140 
141 public Q_SLOTS:
142 
148  void slotCategoryButtonPressed(int mappedId);
149 
155  void slotUpdatePressed(int mappedId);
156  void slotDeletePressed(int mappedId);
157 
158 protected Q_SLOTS:
159 
160  void addCollection(int category);
161  void updateCollection(int internalId);
162  void deleteCollection(int internalId);
163 
164 protected:
165 
166  QModelIndex indexForId(int id, int column) const;
167 
168  bool askForNewCollectionPath(int category, QString* const newPath, QString* const newLabel);
169  bool askForNewCollectionCategory(int* const category);
170 
171  int categoryButtonMapId(const QModelIndex& index) const;
172  int buttonMapId(const QModelIndex& index) const;
173 
174  static Category typeToCategory(CollectionLocation::Type type);
175 
176 protected:
177 
178  class Item
179  {
180  public:
181 
182  Item();
183  explicit Item(const CollectionLocation& location);
184  Item(const QString& path, const QString& label, SetupCollectionModel::Category category);
185 
186  public:
187 
189  QString label;
190  QString path;
191  int parentId;
192  bool updated;
193  bool deleted;
194  };
195 
196 protected:
197 
200 };
201 
202 // -----------------------------------------------------------------------
203 
204 class SetupCollectionTreeView : public QTreeView
205 {
206  Q_OBJECT
207 
208 public:
209 
210  explicit SetupCollectionTreeView(QWidget* const parent = nullptr);
211 
212  void setModel(SetupCollectionModel* model);
213 
214 protected Q_SLOTS:
215 
216  void modelLoadedCollections();
217 
218 private:
219 
220  void setModel(QAbstractItemModel* model) override
221  {
222  setModel(static_cast<SetupCollectionModel*>(model));
223  }
224 };
225 
226 // -----------------------------------------------------------------------
227 
229 {
230  Q_OBJECT
231 
232 public:
233 
234  explicit SetupCollectionDelegate(QAbstractItemView* const view,
235  QObject* const parent = nullptr);
236  ~SetupCollectionDelegate() override;
237 
238  QWidget* createEditor(QWidget* parent,
239  const QStyleOptionViewItem& option,
240  const QModelIndex& index) const override;
241 
242  bool editorEvent(QEvent* event,
243  QAbstractItemModel* model,
244  const QStyleOptionViewItem& option,
245  const QModelIndex& index) override;
246 
247  void paint(QPainter* painter,
248  const QStyleOptionViewItem& option,
249  const QModelIndex& index) const override;
250 
251  void setEditorData(QWidget* editor,
252  const QModelIndex& index) const override;
253 
254  void setModelData(QWidget* editor,
255  QAbstractItemModel* model,
256  const QModelIndex& index) const override;
257 
258  QSize sizeHint(const QStyleOptionViewItem& option,
259  const QModelIndex& index) const override;
260 
261  void updateEditorGeometry(QWidget* editor,
262  const QStyleOptionViewItem& option,
263  const QModelIndex& index) const override;
264 
265  QList<QWidget*> createItemWidgets(const QModelIndex& index) const override;
266  void updateItemWidgets(const QList<QWidget*>& widgets,
267  const QStyleOptionViewItem& option,
268  const QPersistentModelIndex& index) const override;
269 
270 Q_SIGNALS:
271 
272  void categoryButtonPressed(int mappedId) const; // clazy:exclude=const-signal-or-slot
273  void updatePressed(int mappedId) const; // clazy:exclude=const-signal-or-slot
274  void deletePressed(int mappedId) const; // clazy:exclude=const-signal-or-slot
275 
276 protected:
277 
278  QStyledItemDelegate* m_styledDelegate;
279 
280  QPushButton* m_samplePushButton;
281  QToolButton* m_sampleUpdateButton;
282  QToolButton* m_sampleDeleteButton;
284 };
285 
286 } // namespace Digikam
287 
288 #endif // DIGIKAM_SETUP_COLLECTION_VIEW_H
Definition: collectionlocation.h:41
Type
Definition: collectionlocation.h:80
Definition: dwitemdelegate.h:60
Definition: setupcollectionview.h:229
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: setupcollectionview.cpp:260
QList< QWidget * > createItemWidgets(const QModelIndex &index) const override
Definition: setupcollectionview.cpp:99
void updatePressed(int mappedId) const
void categoryButtonPressed(int mappedId) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Definition: setupcollectionview.cpp:270
int m_categoryMaxStyledWidth
Definition: setupcollectionview.h:283
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Definition: setupcollectionview.cpp:254
void updateItemWidgets(const QList< QWidget * > &widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const override
Definition: setupcollectionview.cpp:191
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: setupcollectionview.cpp:275
QStyledItemDelegate * m_styledDelegate
Definition: setupcollectionview.h:278
void deletePressed(int mappedId) const
QPushButton * m_samplePushButton
Definition: setupcollectionview.h:280
~SetupCollectionDelegate() override
Definition: setupcollectionview.cpp:95
QToolButton * m_sampleUpdateButton
Definition: setupcollectionview.h:281
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Definition: setupcollectionview.cpp:265
QToolButton * m_sampleDeleteButton
Definition: setupcollectionview.h:282
SetupCollectionDelegate(QAbstractItemView *const view, QObject *const parent=nullptr)
Definition: setupcollectionview.cpp:65
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: setupcollectionview.cpp:130
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Definition: setupcollectionview.cpp:249
Definition: setupcollectionview.h:179
QString path
Definition: setupcollectionview.h:190
QString label
Definition: setupcollectionview.h:189
CollectionLocation location
Definition: setupcollectionview.h:188
bool updated
Definition: setupcollectionview.h:192
int parentId
Definition: setupcollectionview.h:191
bool deleted
Definition: setupcollectionview.h:193
Definition: setupcollectionview.h:48
Category
Definition: setupcollectionview.h:95
SetupCollectionDataRole
Definition: setupcollectionview.h:61
void collectionsLoaded()
Emitted when all collections were loaded and the model reset in loadCollections.
QList< Item > m_collections
Definition: setupcollectionview.h:198
Columns
Definition: setupcollectionview.h:85
QWidget * m_dialogParentWidget
Definition: setupcollectionview.h:199
Definition: setupcollectionview.h:205
void modelLoadedCollections()
Definition: setupcollectionview.cpp:324
SetupCollectionTreeView(QWidget *const parent=nullptr)
Definition: setupcollectionview.cpp:282
void setModel(SetupCollectionModel *model)
Definition: setupcollectionview.cpp:294
qulonglong value
Definition: itemviewutilities.cpp:592
@ Orientation
Definition: coredbfields.h:86
Category
Definition: coredbconstants.h:95
std::vector< T > location(const std::vector< T > &shape, unsigned long idx)
Definition: shapepredictor.h:109
Definition: datefolderview.cpp:43