1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2008-03-22
 * Description : Qt Model for Albums
 *
 * SPDX-FileCopyrightText: 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#ifndef DIGIKAM_ALBUM_MODEL_H
#define DIGIKAM_ALBUM_MODEL_H

// Qt includes

#include <QDateTime>

// Local includes

#include "abstractalbummodel.h"
#include "digikam_export.h"

namespace Digikam
{

class DIGIKAM_GUI_EXPORT AlbumModel : public AbstractCheckableAlbumModel
{
    Q_OBJECT

public:

    /**
     * Create a model containing all physical albums
     */
    explicit AlbumModel(RootAlbumBehavior rootBehavior = IncludeRootAlbum, QObject* const parent = nullptr);
    ~AlbumModel() override = default;

    PAlbum* albumForIndex(const QModelIndex& index) const;<--- Derived function 'AlbumModel::albumForIndex'

private Q_SLOTS:

    void slotUpdateTrashCounters();

protected:

    QVariant albumData(Album* a, int role)          const override;
    QVariant decorationRoleData(Album* a)           const override;
    Album*   albumForId(int id)                     const override;
};

// ------------------------------------------------------------------

class DIGIKAM_GUI_EXPORT TagModel : public AbstractCheckableAlbumModel
{
    Q_OBJECT

public:

    /**
     * Create a model containing all tags
     */
    explicit TagModel(RootAlbumBehavior rootBehavior = IncludeRootAlbum, QObject* const parent = nullptr);

    TAlbum*      albumForIndex(const QModelIndex& index) const;<--- Derived function 'TagModel::albumForIndex'
    void         setColumnHeader(const QString& header);<--- Derived function 'TagModel::setColumnHeader'
    void         activateFaceTagModel();

protected:

    QVariant     albumData(Album* a, int role)           const override;
    QVariant     decorationRoleData(Album* a)            const override;
    Album*       albumForId(int id)                      const override;
    QVariant     fontRoleData(Album* a)                  const override;
    bool         setData(const QModelIndex& index,
                         const QVariant& value,
                         int role = Qt::EditRole)              override;

private:

    QHash<int, int> m_unconfirmedFaceCount;
};

// ------------------------------------------------------------------

class DIGIKAM_GUI_EXPORT SearchModel : public AbstractCheckableAlbumModel
{
    Q_OBJECT

public:

    /**
     * Create a model containing searches
     */
    explicit SearchModel(QObject* const parent = nullptr);

    SAlbum* albumForIndex(const QModelIndex& index) const;<--- Derived function 'SearchModel::albumForIndex'

    /**
     * Set a hash of internal names (key) that shall be replaced by a user-visible string (value).
     * This affects Qt::DisplayRole and AlbumTitleRole.
     */
    void setReplaceNames(const QHash<QString, QString>& replaceNames);
    void addReplaceName(const QString& technicalName, const QString& userVisibleName);

    /**
     * Set pixmaps for the DecorationRole
     */
    void setPixmapForNormalSearches(const QPixmap& pix);
    void setDefaultPixmap(const QPixmap& pix);
    void setPixmapForTimelineSearches(const QPixmap& pix);
    void setPixmapForHaarSearches(const QPixmap& pix);
    void setPixmapForMapSearches(const QPixmap& pix);
    void setPixmapForDuplicatesSearches(const QPixmap& pix);

protected:

    QVariant albumData(Album* a, int role)          const override;
    Album*   albumForId(int id)                     const override;

private Q_SLOTS:

    void albumSettingsChanged();

protected:

    QHash<int, QPixmap>     m_pixmaps;
    QHash<QString, QString> m_replaceNames;
};

// ------------------------------------------------------------------

/**
 * A model for date based albums.
 */
class DIGIKAM_GUI_EXPORT DateAlbumModel : public AbstractCountingAlbumModel
{
    Q_OBJECT

public:

    /**
     * Constructor.
     *
     * @param parent the parent for Qt's parent child mechanism
     */
    explicit DateAlbumModel(QObject* const parent = nullptr);

    DAlbum* albumForIndex(const QModelIndex& index)     const;<--- Derived function 'DateAlbumModel::albumForIndex'

    /**
     * Finds an album index based on a date. The given date is therefore
     * normalized to year-month-form. The day is ignored. This means the
     * returned index always points to a month DAlbum.
     *
     * @param date the date to search for (year and month)
     * @return model index corresponding to the album with the given date or an
     *         empty index if not found
     */
    QModelIndex monthIndexForDate(const QDate& date)    const;

    /**
     * Set pixmaps for the DecorationRole
     */
    void setPixmaps(const QPixmap& forYearAlbums,
                    const QPixmap& forMonthAlbums);

public Q_SLOTS:

    void setYearMonthMap(const QMap<YearMonth, int>& yearMonthMap);

protected:

    QString  albumName(Album* a)                        const override;
    QVariant decorationRoleData(Album* a)               const override;
    QVariant sortRoleData(Album* a)                     const override;
    Album*   albumForId(int id)                         const override;

protected:

    QPixmap m_yearPixmap;
    QPixmap m_monthPixmap;
};

} // namespace Digikam

#endif // DIGIKAM_ALBUM_MODEL_H