File indexing completed on 2025-01-19 03:53:36

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-10-27
0007  * Description : Model to an ItemHistoryGraph
0008  *
0009  * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_ITEM_HISTORY_GRAPH_MODEL_H
0016 #define DIGIKAM_ITEM_HISTORY_GRAPH_MODEL_H
0017 
0018 // Qt includes
0019 
0020 #include <QAbstractItemModel>
0021 
0022 // Local includes
0023 
0024 #include "dragdropimplementations.h"
0025 #include "itemhistorygraph.h"
0026 #include "digikam_export.h"
0027 
0028 namespace Digikam
0029 {
0030 
0031 class ItemHistoryGraph;
0032 class ItemInfo;
0033 class ItemListModel;
0034 class FilterAction;
0035 
0036 class DIGIKAM_DATABASE_EXPORT ItemHistoryGraphModel : public QAbstractItemModel,
0037                                                       public DragDropModelImplementation
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042 
0043     enum Mode
0044     {
0045         ImagesListMode,
0046         ImagesTreeMode,
0047         CombinedTreeMode
0048     };
0049 
0050     enum ExtraRoles
0051     {
0052         IsImageItemRole        = Qt::UserRole + 1000,
0053         IsFilterActionItemRole = Qt::UserRole + 1001,
0054         IsHeaderItemRole       = Qt::UserRole + 1002,
0055         IsCategoryItemRole     = Qt::UserRole + 1003,
0056         IsSeparatorItemRole    = Qt::UserRole + 1004,
0057 
0058         IsSubjectImageRole     = Qt::UserRole + 1010,
0059 
0060         FilterActionRole       = Qt::UserRole + 1020
0061     };
0062 
0063 public:
0064 
0065     explicit ItemHistoryGraphModel(QWidget* const parent);
0066     ~ItemHistoryGraphModel()                                                                        override;
0067 
0068     void setMode(Mode mode);
0069     Mode mode()                                                                               const;
0070 
0071     /**
0072      * Set the history subject and the history graph.
0073      * Per default, the subject's history graph is read.
0074      */
0075     void setHistory(const ItemInfo& subject,
0076                     const ItemHistoryGraph& graph = ItemHistoryGraph());
0077 
0078     ItemInfo subject()                                                                        const;
0079 
0080     bool isImage(const QModelIndex& index)                                                    const;
0081     bool hasImage(const ItemInfo& info);
0082     ItemInfo imageInfo(const QModelIndex& index)                                              const;
0083 
0084     /// Note: There may be multiple indexes for an info. The index found first is returned.
0085     QModelIndex indexForInfo(const ItemInfo& info)                                            const;
0086 
0087     bool isFilterAction(const QModelIndex& index)                                             const;
0088     FilterAction filterAction(const QModelIndex& index)                                       const;
0089 
0090     ///@{
0091     /// QAbstractItemModel implementation
0092     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0093     int rowCount(const QModelIndex& parent = QModelIndex())                                   const override;
0094     int columnCount(const QModelIndex& parent = QModelIndex())                                const override;
0095     Qt::ItemFlags flags(const QModelIndex& index)                                             const override;
0096     bool hasChildren(const QModelIndex& parent = QModelIndex())                               const override;
0097     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex())         const override;
0098     QModelIndex parent(const QModelIndex& index)                                              const override;
0099     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole)                       const override;
0100     bool setData(const QModelIndex& index, const QVariant& value, int role)                         override;
0101     ///@}
0102 
0103     DECLARE_MODEL_DRAG_DROP_METHODS
0104 
0105     /**
0106      * Returns an internal image model used for entries representing images.
0107      * Note: Set a thumbnail thread on this model if you need thumbnails.
0108      */
0109     ItemListModel* imageModel()                                                               const;
0110 
0111     /**
0112      * If the given index is represented by the internal image model,
0113      * return the image model's index.
0114      * Otherwise an invalid index is returned.
0115      */
0116     QModelIndex imageModelIndex(const QModelIndex& index)                                     const;
0117 
0118 private:
0119 
0120     // Disable
0121     ItemHistoryGraphModel(const ItemHistoryGraphModel&)            = delete;
0122     ItemHistoryGraphModel& operator=(const ItemHistoryGraphModel&) = delete;
0123 
0124     class Private;
0125     Private* const d;
0126 };
0127 
0128 } // namespace Digikam
0129 
0130 #endif // DIGIKAM_ITEM_HISTORY_GRAPH_MODEL_H