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 #include "albummodel_p.h"
0016 
0017 namespace Digikam
0018 {
0019 
0020 SearchModel::SearchModel(QObject* const parent)
0021     : AbstractCheckableAlbumModel(Album::SEARCH,
0022                                   AlbumManager::instance()->findSAlbum(0),
0023                                   IgnoreRootAlbum, parent)
0024 {
0025     m_columnHeader = i18n("Searches");
0026 
0027     setShowCount(false);
0028 
0029     // handle search icons
0030 
0031     albumSettingsChanged();
0032 
0033     connect(ApplicationSettings::instance(), SIGNAL(setupChanged()),
0034             this, SLOT(albumSettingsChanged()));
0035 }
0036 
0037 SAlbum* SearchModel::albumForIndex(const QModelIndex& index) const
0038 {
0039     return static_cast<SAlbum*>(AbstractCheckableAlbumModel::albumForIndex(index));
0040 }
0041 
0042 void SearchModel::setReplaceNames(const QHash<QString, QString>& replaceNames)
0043 {
0044     m_replaceNames = replaceNames;
0045 }
0046 
0047 void SearchModel::addReplaceName(const QString& technicalName, const QString& userVisibleName)
0048 {
0049     m_replaceNames.insert(technicalName, userVisibleName);
0050 }
0051 
0052 void SearchModel::setPixmapForNormalSearches(const QPixmap& pix)
0053 {
0054     m_pixmaps.insert(-1, pix);
0055 }
0056 
0057 void SearchModel::setDefaultPixmap(const QPixmap& pix)
0058 {
0059     m_pixmaps.insert(-2, pix);
0060 }
0061 
0062 void SearchModel::setPixmapForTimelineSearches(const QPixmap& pix)
0063 {
0064     m_pixmaps.insert(DatabaseSearch::TimeLineSearch, pix);
0065 }
0066 
0067 void SearchModel::setPixmapForHaarSearches(const QPixmap& pix)
0068 {
0069     m_pixmaps.insert(DatabaseSearch::HaarSearch, pix);
0070 }
0071 
0072 void SearchModel::setPixmapForMapSearches(const QPixmap& pix)
0073 {
0074     m_pixmaps.insert(DatabaseSearch::MapSearch, pix);
0075 }
0076 
0077 void SearchModel::setPixmapForDuplicatesSearches(const QPixmap& pix)
0078 {
0079     m_pixmaps.insert(DatabaseSearch::DuplicatesSearch, pix);
0080 }
0081 
0082 QVariant SearchModel::albumData(Album* a, int role) const
0083 {
0084     if      ((role == Qt::DisplayRole) || (role == AlbumTitleRole) || (role == Qt::ToolTipRole))
0085     {
0086         SAlbum* const salbum = static_cast<SAlbum*>(a);
0087         QString title        = a->title();
0088         QString displayTitle = salbum->displayTitle();
0089 
0090         return m_replaceNames.value(title, displayTitle);
0091     }
0092     else if (role == Qt::DecorationRole)
0093     {
0094         SAlbum* const salbum = static_cast<SAlbum*>(a);
0095         QPixmap pixmap       = m_pixmaps.value(salbum->searchType());
0096 
0097         if (pixmap.isNull() && salbum->isNormalSearch())
0098         {
0099             pixmap = m_pixmaps.value(-1);
0100         }
0101 
0102         if (pixmap.isNull())
0103         {
0104             pixmap = m_pixmaps.value(-2);
0105         }
0106 
0107         return pixmap;
0108     }
0109 
0110     return AbstractCheckableAlbumModel::albumData(a, role);
0111 }
0112 
0113 Album* SearchModel::albumForId(int id) const
0114 {
0115     return AlbumManager::instance()->findSAlbum(id);
0116 }
0117 
0118 void SearchModel::albumSettingsChanged()
0119 {
0120     setPixmapForMapSearches(QIcon::fromTheme(QLatin1String("globe")).pixmap(ApplicationSettings::instance()->getTreeViewIconSize()));
0121     setPixmapForHaarSearches(QIcon::fromTheme(QLatin1String("tools-wizard")).pixmap(ApplicationSettings::instance()->getTreeViewIconSize()));
0122     setPixmapForNormalSearches(QIcon::fromTheme(QLatin1String("edit-find")).pixmap(ApplicationSettings::instance()->getTreeViewIconSize()));
0123     setPixmapForTimelineSearches(QIcon::fromTheme(QLatin1String("chronometer")).pixmap(ApplicationSettings::instance()->getTreeViewIconSize()));
0124 }
0125 
0126 } // namespace Digikam