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 | /* ============================================================
*
* 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
*
* ============================================================ */
#include "albummodel_p.h"
namespace Digikam
{
DateAlbumModel::DateAlbumModel(QObject* const parent)
: AbstractCountingAlbumModel(Album::DATE,
AlbumManager::instance()->findDAlbum(0),
IgnoreRootAlbum, parent)
{
m_columnHeader = i18n("Dates");
connect(AlbumManager::instance(), SIGNAL(signalDAlbumsDirty(QMap<YearMonth,int>)),
this, SLOT(setYearMonthMap(QMap<YearMonth,int>)));
setYearMonthMap(AlbumManager::instance()->getDAlbumsCount());
setup();
}
DAlbum* DateAlbumModel::dalbumForIndex(const QModelIndex& index) const
{
return (static_cast<DAlbum*>(AbstractCountingAlbumModel::albumForIndex(index)));
}
QModelIndex DateAlbumModel::monthIndexForDate(const QDate& date) const
{
// iterate over all years
for (int yearIndex = 0 ; yearIndex < rowCount() ; ++yearIndex)
{
QModelIndex year = index(yearIndex, 0);
DAlbum* const yearAlbum = dalbumForIndex(year);<--- Variable 'yearAlbum' can be declared as pointer to const
// do not search through months if we are sure, that the year already
// does not match
if (
yearAlbum &&
(yearAlbum->range() == DAlbum::Year) &&
(yearAlbum->date().year() != date.year())
)
{
continue;
}
// search the album with the correct month
for (int monthIndex = 0 ; monthIndex < rowCount(year) ; ++monthIndex)
{
QModelIndex month = index(monthIndex, 0, year);
DAlbum* const monthAlbum = dalbumForIndex(month);<--- Variable 'monthAlbum' can be declared as pointer to const
if (
monthAlbum &&
(monthAlbum->range() == DAlbum::Month) &&
(monthAlbum->date().year() == date.year()) &&
(monthAlbum->date().month() == date.month())
)
{
return month;
}
}
}
return QModelIndex();
}
void DateAlbumModel::setPixmaps(const QPixmap& forYearAlbums, const QPixmap& forMonthAlbums)
{
m_yearPixmap = forYearAlbums;
m_monthPixmap = forMonthAlbums;
}
QString DateAlbumModel::albumName(Album* album) const
{
DAlbum* const dalbum = static_cast<DAlbum*>(album);<--- Variable 'dalbum' can be declared as pointer to const
if (dalbum->range() == DAlbum::Year)
{
return QString::number(dalbum->date().year());
}
else
{
return QLocale().standaloneMonthName(dalbum->date().month(), QLocale::LongFormat);
}
}
QVariant DateAlbumModel::decorationRoleData(Album* album) const
{
DAlbum* const dalbum = static_cast<DAlbum*>(album);<--- Variable 'dalbum' can be declared as pointer to const
if (dalbum->range() == DAlbum::Year)
{
return m_yearPixmap;
}
else
{
return m_monthPixmap;
}
}
QVariant DateAlbumModel::sortRoleData(Album* a) const
{
DAlbum* const dalbum = static_cast<DAlbum*>(a);<--- Variable 'dalbum' can be declared as pointer to const
if (dalbum)
{
return dalbum->date();
}
qCDebug(DIGIKAM_GENERAL_LOG) << "There must be a data album.";
return QDate();
}
Album* DateAlbumModel::albumForId(int id) const
{
return AlbumManager::instance()->findDAlbum(id);
}
void DateAlbumModel::setYearMonthMap(const QMap<YearMonth, int>& yearMonthMap)
{
AlbumIterator it(rootAlbum());
QHash<int, int> albumToCountHash;
while (it.current())
{
DAlbum* const dalbum = static_cast<DAlbum*>(*it);<--- Variable 'dalbum' can be declared as pointer to const
QDate date = dalbum->date();
switch (dalbum->range())
{
case DAlbum::Month:
{
QMap<YearMonth, int>::const_iterator it2 = yearMonthMap.constFind(YearMonth(date.year(), date.month()));
if (it2 != yearMonthMap.constEnd())
{
albumToCountHash.insert((*it)->id(), it2.value());
}
break;
}
case DAlbum::Year:
{
// a year itself cannot contain images and therefore always has count 0
albumToCountHash.insert((*it)->id(), 0);
break;
}
default:
{
qCDebug(DIGIKAM_GENERAL_LOG) << "Untreated DAlbum range " << dalbum->range();
albumToCountHash.insert((*it)->id(), 0);
break;
}
}
++it;
}
setCountHash(albumToCountHash);
}
} // namespace Digikam
|