digiKam
abstractalbumtreeview.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 : 2009-03-25
7  * Description : Tree View for album models
8  *
9  * Copyright (C) 2009-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com>
11  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_H
27 #define DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_H
28 
29 // Qt includes
30 
31 #include <QTreeView>
32 
33 // Local includes
34 
35 #include "albummanager.h"
36 #include "albummodel.h"
37 #include "albumfiltermodel.h"
38 #include "albumpointer.h"
39 #include "statesavingobject.h"
40 
41 namespace Digikam
42 {
43 
44 class ContextMenuHelper;
45 class TagModificationHelper;
46 
47 // NOTE: This structure name can be in conflict with QAbstractItemView::State. FIXME later.
48 struct State;
49 
61 class AbstractAlbumTreeView : public QTreeView,
62  public StateSavingObject
63 {
64  Q_OBJECT
65 
66 public:
67 
68  enum Flag
69  {
75 
80 
86 
92 
98 
100  };
101  Q_DECLARE_FLAGS(Flags, Flag)
102 
103 public:
104 
110  AbstractAlbumTreeView(QWidget* const parent, Flags flags);
111  ~AbstractAlbumTreeView() override;
112 
115 
119  void setExpandOnSingleClick(const bool doThat);
120 
124  void setExpandNewCurrentItem(const bool doThat);
125 
132  void setSelectAlbumOnClick(const bool selectOnClick);
133 
141  void setEnableContextMenu(const bool enable);
142 
151  void setSelectOnContextMenu(const bool select);
152 
158  void setContextMenuIcon(const QPixmap& pixmap);
159  void setContextMenuTitle(const QString& title);
160 
166  QModelIndex indexVisuallyAt(const QPoint& p);
167 
177  bool expandMatches(const QModelIndex& index);
178 
180 
194  void doLoadState() override;
195  void doSaveState() override;
196 
198 
204  void setAlbumManagerCurrentAlbum(const bool setCurrentAlbum);
205 
213  {
214  public:
215 
216  ContextMenuElement() = default;
217  virtual ~ContextMenuElement() = default;
218 
227  virtual void addActions(AbstractAlbumTreeView* view,
228  ContextMenuHelper& cmh,
229  Album* album) = 0;
230 
231  private:
232 
233  Q_DISABLE_COPY(ContextMenuElement)
234  };
235 
236  void addContextMenuElement(ContextMenuElement* const element);
237  void removeContextMenuElement(ContextMenuElement* const element);
239 
240  template<class A>
242 
246  bool viewportEvent(QEvent* event) override;
247 
252 
253 public Q_SLOTS:
254 
255  void setSearchTextSettings(const SearchTextSettings& settings);
256 
264  void setCurrentAlbums(const QList<Album*>& albums, bool selectInAlbumManager = true);
265 
269  void adaptColumnsToContent();
270 
274  void scrollToSelectedAlbum();
275 
281  void expandEverything(const QModelIndex& index);
282 
286  void slotExpandNode();
287 
291  void slotCollapseNode();
292 
296  void slotCollapseAllNodes();
297 
298 Q_SIGNALS:
299 
303  void currentAlbumChanged(Album* currentAlbum);
304 
308  void selectedAlbumsChanged(const QList<Album*>& selectedAlbums);
309 
310 protected Q_SLOTS:
311 
315  virtual void slotRootAlbumAvailable();
316 
317  void slotSearchTextSettingsChanged(bool wasSearching, bool searching);
318  void slotSearchTextSettingsAboutToChange(bool searched, bool willSearch);
319  void slotCurrentChanged();
320  void slotSelectionChanged();
321 
322  void albumSettingsChanged();
323 
324 protected:
325 
327 
328  // Context menu handling
329 
340  virtual bool showContextMenuAt(QContextMenuEvent* event, Album* albumForEvent);
341 
348  virtual QPixmap contextMenuIcon() const;
349 
355  virtual QString contextMenuTitle() const;
356 
364  virtual void addCustomContextMenuActions(ContextMenuHelper& cmh, Album* album);
365 
375  virtual void handleCustomContextMenuAction(QAction* action,
376  const AlbumPointer<Album>& album);
377 
379 
381 
383 
384  void mousePressEvent(QMouseEvent* e) override;
385 
386  void rowsInserted(const QModelIndex& index, int start, int end) override;
387  void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) override;
388  void startDrag(Qt::DropActions supportedActions) override;
389  void dragEnterEvent(QDragEnterEvent* e) override;
390  void dragMoveEvent(QDragMoveEvent* e) override;
391  void dragLeaveEvent(QDragLeaveEvent* e) override;
392  void dropEvent(QDropEvent* e) override;
393 
394  virtual void middleButtonPressed(Album* a);
395  virtual QPixmap pixmapForDrag(const QStyleOptionViewItem& option, QList<QModelIndex> indexes);
396 
397  void setAlbumFilterModel(AlbumFilterModel* const filterModel);
398  void setAlbumModel(AbstractSpecificAlbumModel* const model);
399 
401 
402 protected:
403 
407 
411  Flags m_flags;
412 
413 private:
414 
415  void saveStateRecursive(const QModelIndex& index,
416  QList<int>& selection, QList<int>& expansion);
417 
426  void restoreStateForHierarchy(const QModelIndex& index,
427  const QMap<int, Digikam::State>& stateStore);
428 
432  void restoreState(const QModelIndex& index,
433  const QMap<int, Digikam::State>& stateStore);
434 
440  void contextMenuEvent(QContextMenuEvent* event) override;
441 
442 private Q_SLOTS:
443 
451  void adaptColumnsOnDataChange(const QModelIndex& topLeft, const QModelIndex& bottomRight);
452 
461  void adaptColumnsOnRowChange(const QModelIndex& parent, int start, int end);
462 
466  void adaptColumnsOnLayoutChange();
467 
472  void currentAlbumChangedForBackupSelection(Album* currentAlbum);
473 
477  void slotScrollBarValueChanged(int value);
478  void slotScrollBarActionTriggered(int action);
479 
480 private:
481 
482  class Private;
483  Private* d;
484 };
485 
486 } // namespace Digikam
487 
488 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::AbstractAlbumTreeView::Flags)
489 
490 #endif // DIGIKAM_ABSTRACT_ALBUM_TREE_VIEW_H
Definition: abstractalbumtreeview.h:213
virtual void addActions(AbstractAlbumTreeView *view, ContextMenuHelper &cmh, Album *album)=0
Definition: abstractalbumtreeview_p.h:157
Definition: abstractalbumtreeview.h:63
QList< ContextMenuElement * > contextMenuElements() const
Definition: abstractalbumtreeview.cpp:1085
virtual QString contextMenuTitle() const
Definition: abstractalbumtreeview.cpp:1070
void setAlbumFilterModel(AlbumFilterModel *const filterModel)
Definition: abstractalbumtreeview.cpp:116
void scrollToSelectedAlbum()
Definition: abstractalbumtreeview.cpp:850
void slotCurrentChanged()
Definition: abstractalbumtreeview.cpp:426
virtual QPixmap pixmapForDrag(const QStyleOptionViewItem &option, QList< QModelIndex > indexes)
Definition: abstractalbumtreeview.cpp:547
void mousePressEvent(QMouseEvent *e) override
Other helper methods.
Definition: abstractalbumtreeview.cpp:466
bool viewportEvent(QEvent *event) override
Definition: abstractalbumtreeview.cpp:625
void adaptColumnsToContent()
Definition: abstractalbumtreeview.cpp:845
void startDrag(Qt::DropActions supportedActions) override
Definition: abstractalbumtreeview.cpp:515
virtual void addCustomContextMenuActions(ContextMenuHelper &cmh, Album *album)
Definition: abstractalbumtreeview.cpp:1147
void setCurrentAlbums(const QList< Album * > &albums, bool selectInAlbumManager=true)
Definition: abstractalbumtreeview.cpp:402
AbstractSpecificAlbumModel * albumModel() const
Definition: abstractalbumtreeview.cpp:189
void expandEverything(const QModelIndex &index)
Definition: abstractalbumtreeview.cpp:861
AbstractAlbumTreeView(QWidget *const parent, Flags flags)
Definition: abstractalbumtreeview.cpp:33
void setContextMenuTitle(const QString &title)
Definition: abstractalbumtreeview.cpp:1060
void doSaveState() override
Definition: abstractalbumtreeview.cpp:973
virtual QPixmap contextMenuIcon() const
Definition: abstractalbumtreeview.cpp:1065
void dropEvent(QDropEvent *e) override
Definition: abstractalbumtreeview.cpp:605
virtual void slotRootAlbumAvailable()
Definition: abstractalbumtreeview.cpp:317
void albumSettingsChanged()
Definition: abstractalbumtreeview.cpp:1159
QList< A * > currentAlbums()
Definition: abstractalbumtreeview.cpp:230
void setSelectAlbumOnClick(const bool selectOnClick)
Definition: abstractalbumtreeview.cpp:209
bool m_checkOnMiddleClick
Definition: abstractalbumtreeview.h:409
void setSearchTextSettings(const SearchTextSettings &settings)
Definition: abstractalbumtreeview.cpp:392
void setExpandOnSingleClick(const bool doThat)
Definition: abstractalbumtreeview.cpp:199
AlbumModelDragDropHandler * m_dragDropHandler
Definition: abstractalbumtreeview.h:406
void slotCollapseNode()
slotCollapseNode - collapse recursively selected nodes
Definition: abstractalbumtreeview.cpp:882
void currentAlbumChanged(Album *currentAlbum)
Flag
Definition: abstractalbumtreeview.h:69
@ CreateDefaultDelegate
Definition: abstractalbumtreeview.h:85
@ AlwaysShowInclusiveCounts
Definition: abstractalbumtreeview.h:97
@ CreateDefaultFilterModel
Definition: abstractalbumtreeview.h:79
@ DefaultFlags
Definition: abstractalbumtreeview.h:99
@ ShowCountAccordingToSettings
Definition: abstractalbumtreeview.h:91
@ CreateDefaultModel
Definition: abstractalbumtreeview.h:74
void slotSearchTextSettingsChanged(bool wasSearching, bool searching)
Definition: abstractalbumtreeview.cpp:278
bool m_restoreCheckState
Definition: abstractalbumtreeview.h:410
AbstractSpecificAlbumModel * m_albumModel
Definition: abstractalbumtreeview.h:404
void slotSelectionChanged()
Definition: abstractalbumtreeview.cpp:453
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override
Definition: abstractalbumtreeview.cpp:824
~AbstractAlbumTreeView() override
Definition: abstractalbumtreeview.cpp:77
virtual bool showContextMenuAt(QContextMenuEvent *event, Album *albumForEvent)
Definition: abstractalbumtreeview.cpp:1048
void doLoadState() override
Definition: abstractalbumtreeview.cpp:635
void dragEnterEvent(QDragEnterEvent *e) override
Definition: abstractalbumtreeview.cpp:559
void dragMoveEvent(QDragMoveEvent *e) override
Definition: abstractalbumtreeview.cpp:574
AlbumFilterModel * albumFilterModel() const
Definition: abstractalbumtreeview.cpp:194
int m_lastScrollBarValue
Definition: abstractalbumtreeview.h:408
AlbumFilterModel * m_albumFilterModel
Definition: abstractalbumtreeview.h:405
virtual void middleButtonPressed(Album *a)
Definition: abstractalbumtreeview.cpp:510
void selectedAlbumsChanged(const QList< Album * > &selectedAlbums)
void setExpandNewCurrentItem(const bool doThat)
Definition: abstractalbumtreeview.cpp:204
void removeContextMenuElement(ContextMenuElement *const element)
Definition: abstractalbumtreeview.cpp:1080
void setAlbumModel(AbstractSpecificAlbumModel *const model)
Definition: abstractalbumtreeview.cpp:82
void slotSearchTextSettingsAboutToChange(bool searched, bool willSearch)
Definition: abstractalbumtreeview.cpp:248
void setAlbumManagerCurrentAlbum(const bool setCurrentAlbum)
Definition: abstractalbumtreeview.cpp:397
Flags m_flags
Definition: abstractalbumtreeview.h:411
void dragLeaveEvent(QDragLeaveEvent *e) override
Definition: abstractalbumtreeview.cpp:600
void slotExpandNode()
slotExpandNode - expands recursively selected nodes
Definition: abstractalbumtreeview.cpp:871
QModelIndex indexVisuallyAt(const QPoint &p)
Definition: abstractalbumtreeview.cpp:214
void setSelectOnContextMenu(const bool select)
Definition: abstractalbumtreeview.cpp:1142
void setContextMenuIcon(const QPixmap &pixmap)
Definition: abstractalbumtreeview.cpp:1055
void setEnableContextMenu(const bool enable)
Definition: abstractalbumtreeview.cpp:1043
void slotCollapseAllNodes()
slotCollapseAllNodes - collapse all nodes without root node
Definition: abstractalbumtreeview.cpp:916
void addContextMenuElement(ContextMenuElement *const element)
Definition: abstractalbumtreeview.cpp:1075
virtual void handleCustomContextMenuAction(QAction *action, const AlbumPointer< Album > &album)
Definition: abstractalbumtreeview.cpp:1153
QList< Album * > selectedItems()
selectedItems() -
Definition: abstractalbumtreeview.cpp:630
bool expandMatches(const QModelIndex &index)
Definition: abstractalbumtreeview.cpp:322
void rowsInserted(const QModelIndex &index, int start, int end) override
Definition: abstractalbumtreeview.cpp:801
Definition: abstractalbummodel.h:237
Definition: albumfiltermodel.h:45
Definition: albummodeldragdrophandler.h:39
Definition: albumpointer.h:48
Abstract base class for all album types.
Definition: album.h:67
A helper class to add actions and special menus to the context menu.
Definition: contextmenuhelper.h:80
Definition: searchtextbar.h:43
Definition: statesavingobject.h:76
Definition: piwigotalker.h:48
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43