91
99
// ------------------------------------------------------------------
93
101
SearchModel::SearchModel(QObject *parent)
94
: AbstractSpecificAlbumModel(Album::SEARCH,
102
: AbstractCheckableAlbumModel(Album::SEARCH,
95
103
AlbumManager::instance()->findSAlbum(0),
96
104
IgnoreRootAlbum, parent)
109
// handle search icons
110
albumSettingsChanged();
111
connect(AlbumSettings::instance(), SIGNAL(setupChanged()),
112
this, SLOT(albumSettingsChanged()));
100
116
SAlbum *SearchModel::albumForIndex(const QModelIndex& index) const
102
return static_cast<SAlbum*>(AbstractSpecificAlbumModel::albumForIndex(index));
105
void SearchModel::setSearchType(DatabaseSearch::Type type)
110
void SearchModel::listNormalSearches()
115
void SearchModel::listAllSearches()
118
return static_cast<SAlbum*>(AbstractCheckableAlbumModel::albumForIndex(index));
120
121
void SearchModel::setReplaceNames(QHash<QString, QString> replaceNames)
122
123
m_replaceNames = replaceNames;
125
void SearchModel::setPixmap(const QPixmap& pix)
126
void SearchModel::addReplaceName(const QString& technicalName, const QString& userVisibleName)
128
m_replaceNames.insert(technicalName, userVisibleName);
131
void SearchModel::setPixmapForNormalSearches(const QPixmap& pix)
133
m_pixmaps.insert(-1, pix);
136
void SearchModel::setDefaultPixmap(const QPixmap& pix)
138
m_pixmaps.insert(-2, pix);
141
void SearchModel::setPixmapForTimelineSearches(const QPixmap& pix)
143
m_pixmaps.insert(DatabaseSearch::TimeLineSearch, pix);
146
void SearchModel::setPixmapForHaarSearches(const QPixmap& pix)
148
m_pixmaps.insert(DatabaseSearch::HaarSearch, pix);
151
void SearchModel::setPixmapForMapSearches(const QPixmap& pix)
153
m_pixmaps.insert(DatabaseSearch::MapSearch, pix);
156
void SearchModel::setPixmapForDuplicatesSearches(const QPixmap& pix)
158
m_pixmaps.insert(DatabaseSearch::DuplicatesSearch, pix);
130
161
QVariant SearchModel::albumData(Album *a, int role) const
132
if (role == Qt::DisplayRole)
163
if (role == Qt::DisplayRole || role == AlbumTitleRole)
134
QString name = a->title();
135
return m_replaceNames.value(name, name);
165
SAlbum *salbum = static_cast<SAlbum*>(a);
166
QString title = a->title();
167
QString displayTitle = salbum->displayTitle();
168
return m_replaceNames.value(title, displayTitle);
137
170
else if (role == Qt::DecorationRole)
140
return AbstractSpecificAlbumModel::albumData(a, role);
143
bool SearchModel::filterAlbum(Album *album) const
145
if (AbstractSpecificAlbumModel::filterAlbum(album))
147
SAlbum *salbum = static_cast<SAlbum*>(album);
148
if (m_searchType == -1)
149
return salbum->isNormalSearch();
150
else if (m_searchType == -2)
153
return salbum->type() == (DatabaseSearch::Type)m_searchType;
172
SAlbum *salbum = static_cast<SAlbum*>(a);
173
QPixmap pixmap = m_pixmaps.value(salbum->searchType());
174
if (pixmap.isNull() && salbum->isNormalSearch())
176
pixmap = m_pixmaps.value(-1);
180
pixmap = m_pixmaps.value(-2);
185
return AbstractCheckableAlbumModel::albumData(a, role);
188
Album* SearchModel::albumForId(int id) const
190
return AlbumManager::instance()->findSAlbum(id);
193
void SearchModel::albumSettingsChanged()
195
setPixmapForMapSearches(SmallIcon("applications-internet", AlbumSettings::instance()->getTreeViewIconSize()));
196
setPixmapForHaarSearches(SmallIcon("tools-wizard", AlbumSettings::instance()->getTreeViewIconSize()));
197
setPixmapForNormalSearches(SmallIcon("edit-find", AlbumSettings::instance()->getTreeViewIconSize()));
198
setPixmapForTimelineSearches(SmallIcon("chronometer", AlbumSettings::instance()->getTreeViewIconSize()));
158
201
// ------------------------------------------------------------------
162
205
AlbumManager::instance()->findDAlbum(0),
163
206
IgnoreRootAlbum, parent)
208
connect(AlbumManager::instance(), SIGNAL(signalDAlbumsDirty(const QMap<YearMonth, int>&)),
209
this, SLOT(setYearMonthMap(const QMap<YearMonth, int>&)));
210
setYearMonthMap(AlbumManager::instance()->getDAlbumsCount());
167
213
DAlbum *DateAlbumModel::albumForIndex(const QModelIndex& index) const
169
215
return static_cast<DAlbum*>(AbstractCountingAlbumModel::albumForIndex(index));
218
QModelIndex DateAlbumModel::monthIndexForDate(const QDate &date) const
221
// iterate over all years
222
for (int yearIndex = 0; yearIndex < rowCount(); ++yearIndex)
224
QModelIndex year = index(yearIndex, 0);
225
DAlbum *yearAlbum = albumForIndex(year);
227
// do not search through months if we are sure, that the year already
229
if (yearAlbum && (yearAlbum->range() == DAlbum::Year)
230
&& (yearAlbum->date().year() != date.year()))
235
// search the album with the correct month
236
for (int monthIndex = 0; monthIndex < rowCount(year); ++monthIndex)
238
QModelIndex month = index(monthIndex, 0, year);
239
DAlbum *monthAlbum = albumForIndex(month);
240
if (monthAlbum && (monthAlbum->range() == DAlbum::Month)
241
&& (monthAlbum->date().year() == date.year())
242
&& (monthAlbum->date().month() == date.month()))
250
return QModelIndex();
172
254
void DateAlbumModel::setPixmaps(const QPixmap& forYearAlbums, const QPixmap& forMonthAlbums)
174
256
m_yearPixmap = forYearAlbums;
201
293
void DateAlbumModel::setYearMonthMap(const QMap<YearMonth, int>& yearMonthMap)
203
296
AlbumIterator it(rootAlbum());
298
QMap<int, int> albumToCountMap;
205
299
while (it.current())
207
301
DAlbum *dalbum = static_cast<DAlbum*>(*it);
208
302
QDate date = dalbum->date();
210
if (dalbum->range() == DAlbum::Month)
212
QMap<YearMonth, int>::const_iterator it2 = yearMonthMap.constFind(YearMonth(date.year(), date.month()));
213
if ( it2 != yearMonthMap.constEnd() )
214
setCount(*it, it2.value());
219
for ( QMap<YearMonth, int>::const_iterator it2 = yearMonthMap.constBegin();
220
it2 != yearMonthMap.constEnd(); ++it2 )
304
switch (dalbum->range())
222
if (it2.key().first == date.year())
223
count += it2.value();
308
QMap<YearMonth, int>::const_iterator it2 = yearMonthMap.constFind(YearMonth(date.year(), date.month()));
309
if ( it2 != yearMonthMap.constEnd() )
311
albumToCountMap.insert((*it)->id(), it2.value());
225
setCount(*it, count);
316
// a year itself cannot contain images and therefore always has count 0
317
albumToCountMap.insert((*it)->id(), 0);
320
kError() << "Untreated DAlbum range " << dalbum->range();
321
albumToCountMap.insert((*it)->id(), 0);
328
setCountMap(albumToCountMap);
231
332
} // namespace Digikam