• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

digikam

albummodel.cpp

Go to the documentation of this file.
00001 /* ============================================================
00002  *
00003  * This file is a part of digiKam project
00004  * http://www.digikam.org
00005  *
00006  * Date        : 2008-03-22
00007  * Description : Qt Model for Albums
00008  *
00009  * Copyright (C) 2008-2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
00010  *
00011  * This program is free software; you can redistribute it
00012  * and/or modify it under the terms of the GNU General
00013  * Public License as published by the Free Software Foundation;
00014  * either version 2, or (at your option)
00015  * any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * ============================================================ */
00023 
00024 #include "albummodel.moc"
00025 
00026 // KDE includes
00027 
00028 #include <kcalendarsystem.h>
00029 #include <kglobal.h>
00030 #include <klocale.h>
00031 
00032 // Local includes
00033 
00034 #include "albummanager.h"
00035 #include "albumthumbnailloader.h"
00036 
00037 namespace Digikam
00038 {
00039 
00040 AlbumModel::AlbumModel(RootAlbumBehavior rootBehavior, QObject *parent)
00041           : AbstractCheckableAlbumModel(Album::PHYSICAL,
00042                                         AlbumManager::instance()->findPAlbum(0),
00043                                         rootBehavior, parent)
00044 {
00045     m_columnHeader = i18n("My Albums");
00046     setupThumbnailLoading();
00047 }
00048 
00049 PAlbum *AlbumModel::albumForIndex(const QModelIndex& index) const
00050 {
00051     return static_cast<PAlbum*>(AbstractCheckableAlbumModel::albumForIndex(index));
00052 }
00053 
00054 QVariant AlbumModel::decorationRole(Album *album) const
00055 {
00056     // asynchronous signals are handled by parent class
00057     return AlbumThumbnailLoader::instance()->getAlbumThumbnailDirectly(static_cast<PAlbum *>(album));
00058 }
00059 
00060 Album* AlbumModel::albumForId(int id) const
00061 {
00062     return AlbumManager::instance()->findPAlbum(id);
00063 }
00064 
00065 // ------------------------------------------------------------------
00066 
00067 TagModel::TagModel(RootAlbumBehavior rootBehavior, QObject *parent)
00068         : AbstractCheckableAlbumModel(Album::TAG,
00069                                       AlbumManager::instance()->findTAlbum(0),
00070                                       rootBehavior, parent)
00071 {
00072     m_columnHeader = i18n("My Tags");
00073     setupThumbnailLoading();
00074 }
00075 
00076 TAlbum *TagModel::albumForIndex(const QModelIndex& index) const
00077 {
00078     return static_cast<TAlbum*>(AbstractCheckableAlbumModel::albumForIndex(index));
00079 }
00080 
00081 QVariant TagModel::decorationRole(Album *album) const
00082 {
00083     return AlbumThumbnailLoader::instance()->getTagThumbnailDirectly(static_cast<TAlbum *>(album), true);
00084 }
00085 
00086 Album* TagModel::albumForId(int id) const
00087 {
00088     return AlbumManager::instance()->findTAlbum(id);
00089 }
00090 
00091 // ------------------------------------------------------------------
00092 
00093 SearchModel::SearchModel(QObject *parent)
00094             : AbstractSpecificAlbumModel(Album::SEARCH,
00095                                          AlbumManager::instance()->findSAlbum(0),
00096                                          IgnoreRootAlbum, parent)
00097 {
00098 }
00099 
00100 SAlbum *SearchModel::albumForIndex(const QModelIndex& index) const
00101 {
00102     return static_cast<SAlbum*>(AbstractSpecificAlbumModel::albumForIndex(index));
00103 }
00104 
00105 void SearchModel::setSearchType(DatabaseSearch::Type type)
00106 {
00107     m_searchType = type;
00108 }
00109 
00110 void SearchModel::listNormalSearches()
00111 {
00112     m_searchType = -1;
00113 }
00114 
00115 void SearchModel::listAllSearches()
00116 {
00117     m_searchType = -2;
00118 }
00119 
00120 void SearchModel::setReplaceNames(QHash<QString, QString> replaceNames)
00121 {
00122     m_replaceNames = replaceNames;
00123 }
00124 
00125 void SearchModel::setPixmap(const QPixmap& pix)
00126 {
00127     m_pixmap = pix;
00128 }
00129 
00130 QVariant SearchModel::albumData(Album *a, int role) const
00131 {
00132     if (role == Qt::DisplayRole)
00133     {
00134         QString name = a->title();
00135         return m_replaceNames.value(name, name);
00136     }
00137     else if (role == Qt::DecorationRole)
00138         return m_pixmap;
00139 
00140     return AbstractSpecificAlbumModel::albumData(a, role);
00141 }
00142 
00143 bool SearchModel::filterAlbum(Album *album) const
00144 {
00145     if (AbstractSpecificAlbumModel::filterAlbum(album))
00146     {
00147         SAlbum *salbum = static_cast<SAlbum*>(album);
00148         if (m_searchType == -1)
00149             return salbum->isNormalSearch();
00150         else if (m_searchType == -2)
00151             return true;
00152         else
00153             return salbum->type() == (DatabaseSearch::Type)m_searchType;
00154     }
00155     return false;
00156 }
00157 
00158 // ------------------------------------------------------------------
00159 
00160 DateAlbumModel::DateAlbumModel(QObject *parent)
00161             : AbstractCountingAlbumModel(Album::DATE,
00162                                          AlbumManager::instance()->findDAlbum(0),
00163                                          IgnoreRootAlbum, parent)
00164 {
00165 }
00166 
00167 DAlbum *DateAlbumModel::albumForIndex(const QModelIndex& index) const
00168 {
00169     return static_cast<DAlbum*>(AbstractCountingAlbumModel::albumForIndex(index));
00170 }
00171 
00172 void DateAlbumModel::setPixmaps(const QPixmap& forYearAlbums, const QPixmap& forMonthAlbums)
00173 {
00174     m_yearPixmap = forYearAlbums;
00175     m_monthPixmap = forMonthAlbums;
00176 }
00177 
00178 QString DateAlbumModel::albumName(Album *album) const
00179 {
00180     DAlbum *dalbum = static_cast<DAlbum*>(album);
00181     if (dalbum->range() == DAlbum::Year)
00182         return QString::number(dalbum->date().year());
00183     else
00184         return KGlobal::locale()->calendar()->monthName(dalbum->date(), KCalendarSystem::LongName);
00185 }
00186 
00187 QVariant DateAlbumModel::decorationRole(Album *album) const
00188 {
00189     DAlbum *dalbum = static_cast<DAlbum*>(album);
00190     if (dalbum->range() == DAlbum::Year)
00191         return m_yearPixmap;
00192     else
00193         return m_monthPixmap;
00194 }
00195 
00196 Album* DateAlbumModel::albumForId(int id) const
00197 {
00198     return AlbumManager::instance()->findDAlbum(id);
00199 }
00200 
00201 void DateAlbumModel::setYearMonthMap(const QMap<YearMonth, int>& yearMonthMap)
00202 {
00203     AlbumIterator it(rootAlbum());
00204 
00205     while (it.current())
00206     {
00207         DAlbum *dalbum = static_cast<DAlbum*>(*it);
00208         QDate date = dalbum->date();
00209 
00210         if (dalbum->range() == DAlbum::Month)
00211         {
00212             QMap<YearMonth, int>::const_iterator it2 = yearMonthMap.constFind(YearMonth(date.year(), date.month()));
00213             if ( it2 != yearMonthMap.constEnd() )
00214                 setCount(*it, it2.value());
00215         }
00216         else
00217         {
00218             int count = 0;
00219             for ( QMap<YearMonth, int>::const_iterator it2 = yearMonthMap.constBegin();
00220                     it2 != yearMonthMap.constEnd(); ++it2 )
00221             {
00222                 if (it2.key().first == date.year())
00223                     count += it2.value();
00224             }
00225             setCount(*it, count);
00226         }
00227         ++it;
00228     }
00229 }
00230 
00231 } // namespace Digikam

digikam

Skip menu "digikam"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • digikam
Generated for API Reference by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal