File indexing completed on 2025-01-19 03:56:06

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-03-22
0007  * Description : Qt Model for Albums
0008  *
0009  * SPDX-FileCopyrightText: 2008-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_ALBUM_MODEL_H
0016 #define DIGIKAM_ALBUM_MODEL_H
0017 
0018 // Qt includes
0019 
0020 #include <QDateTime>
0021 
0022 // Local includes
0023 
0024 #include "abstractalbummodel.h"
0025 #include "digikam_export.h"
0026 
0027 namespace Digikam
0028 {
0029 
0030 class DIGIKAM_GUI_EXPORT AlbumModel : public AbstractCheckableAlbumModel
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035 
0036     /**
0037      * Create a model containing all physical albums
0038      */
0039     explicit AlbumModel(RootAlbumBehavior rootBehavior = IncludeRootAlbum, QObject* const parent = nullptr);
0040     ~AlbumModel() override;
0041 
0042     PAlbum* albumForIndex(const QModelIndex& index) const;
0043 
0044 private Q_SLOTS:
0045 
0046     void slotUpdateTrashCounters();
0047 
0048 protected:
0049 
0050     QVariant albumData(Album* a, int role)          const override;
0051     QVariant decorationRoleData(Album* a)           const override;
0052     Album*   albumForId(int id)                     const override;
0053 };
0054 
0055 // ------------------------------------------------------------------
0056 
0057 class DIGIKAM_GUI_EXPORT TagModel : public AbstractCheckableAlbumModel
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062 
0063     /**
0064      * Create a model containing all tags
0065      */
0066     explicit TagModel(RootAlbumBehavior rootBehavior = IncludeRootAlbum, QObject* const parent = nullptr);
0067 
0068     TAlbum*      albumForIndex(const QModelIndex& index) const;
0069     void         setColumnHeader(const QString& header);
0070     void         activateFaceTagModel();
0071 
0072 protected:
0073 
0074     QVariant     albumData(Album* a, int role)           const override;
0075     QVariant     decorationRoleData(Album* a)            const override;
0076     Album*       albumForId(int id)                      const override;
0077     QVariant     fontRoleData(Album* a)                  const override;
0078     bool         setData(const QModelIndex& index,
0079                          const QVariant& value,
0080                          int role = Qt::EditRole)              override;
0081 
0082 private:
0083 
0084     QHash<int, int> m_unconfirmedFaceCount;
0085 };
0086 
0087 // ------------------------------------------------------------------
0088 
0089 class DIGIKAM_GUI_EXPORT SearchModel : public AbstractCheckableAlbumModel
0090 {
0091     Q_OBJECT
0092 
0093 public:
0094 
0095     /**
0096      * Create a model containing searches
0097      */
0098     explicit SearchModel(QObject* const parent = nullptr);
0099 
0100     SAlbum* albumForIndex(const QModelIndex& index) const;
0101 
0102     /**
0103      * Set a hash of internal names (key) that shall be replaced by a user-visible string (value).
0104      * This affects Qt::DisplayRole and AlbumTitleRole.
0105      */
0106     void setReplaceNames(const QHash<QString, QString>& replaceNames);
0107     void addReplaceName(const QString& technicalName, const QString& userVisibleName);
0108 
0109     /**
0110      * Set pixmaps for the DecorationRole
0111      */
0112     void setPixmapForNormalSearches(const QPixmap& pix);
0113     void setDefaultPixmap(const QPixmap& pix);
0114     void setPixmapForTimelineSearches(const QPixmap& pix);
0115     void setPixmapForHaarSearches(const QPixmap& pix);
0116     void setPixmapForMapSearches(const QPixmap& pix);
0117     void setPixmapForDuplicatesSearches(const QPixmap& pix);
0118 
0119 protected:
0120 
0121     QVariant albumData(Album* a, int role)          const override;
0122     Album*   albumForId(int id)                     const override;
0123 
0124 private Q_SLOTS:
0125 
0126     void albumSettingsChanged();
0127 
0128 protected:
0129 
0130     QHash<int, QPixmap>     m_pixmaps;
0131     QHash<QString, QString> m_replaceNames;
0132 };
0133 
0134 // ------------------------------------------------------------------
0135 
0136 /**
0137  * A model for date based albums.
0138  */
0139 class DIGIKAM_GUI_EXPORT DateAlbumModel : public AbstractCountingAlbumModel
0140 {
0141     Q_OBJECT
0142 
0143 public:
0144 
0145     /**
0146      * Constructor.
0147      *
0148      * @param parent the parent for Qt's parent child mechanism
0149      */
0150     explicit DateAlbumModel(QObject* const parent = nullptr);
0151 
0152     DAlbum* albumForIndex(const QModelIndex& index)     const;
0153 
0154     /**
0155      * Finds an album index based on a date. The given date is therefore
0156      * normalized to year-month-form. The day is ignored. This means the
0157      * returned index always points to a month DAlbum.
0158      *
0159      * @param date the date to search for (year and month)
0160      * @return model index corresponding to the album with the given date or an
0161      *         empty index if not found
0162      */
0163     QModelIndex monthIndexForDate(const QDate& date)    const;
0164 
0165     /**
0166      * Set pixmaps for the DecorationRole
0167      */
0168     void setPixmaps(const QPixmap& forYearAlbums,
0169                     const QPixmap& forMonthAlbums);
0170 
0171 public Q_SLOTS:
0172 
0173     void setYearMonthMap(const QMap<YearMonth, int>& yearMonthMap);
0174 
0175 protected:
0176 
0177     QString  albumName(Album* a)                        const override;
0178     QVariant decorationRoleData(Album* a)               const override;
0179     QVariant sortRoleData(Album* a)                     const override;
0180     Album*   albumForId(int id)                         const override;
0181 
0182 protected:
0183 
0184     QPixmap m_yearPixmap;
0185     QPixmap m_monthPixmap;
0186 };
0187 
0188 } // namespace Digikam
0189 
0190 #endif // DIGIKAM_ALBUM_MODEL_H