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

digikam

abstractalbummodel.h

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        : 2009-03-23
00007  * Description : Qt Model for Albums - abstract base classes
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 #ifndef ABSTRACTALBUMMODEL_H
00025 #define ABSTRACTALBUMMODEL_H
00026 
00027 // Qt includes
00028 
00029 #include <QAbstractItemModel>
00030 #include <QHash>
00031 #include <QPixmap>
00032 #include <QSet>
00033 
00034 // Local includes
00035 
00036 #include "album.h"
00037 
00038 namespace Digikam
00039 {
00040 
00041 class Album;
00042 class AlbumManager;
00043 class AlbumModelDragDropHandler;
00044 class AlbumModelPriv;
00045 
00046 class AbstractAlbumModel : public QAbstractItemModel
00047 {
00048     Q_OBJECT
00049 
00050 public:
00051 
00058     enum RootAlbumBehavior
00059     {
00062         IncludeRootAlbum,
00065         IgnoreRootAlbum
00066     };
00067 
00068     enum AlbumDataRole
00069     {
00071         AlbumTypeRole = Qt::UserRole,
00073         AlbumPointerRole = Qt::UserRole + 1
00074     };
00075 
00081     AbstractAlbumModel(Album::Type albumType, Album *rootAlbum, RootAlbumBehavior rootBehavior = IncludeRootAlbum,
00082                        QObject *parent = 0);
00083     ~AbstractAlbumModel();
00084 
00085     virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
00086     virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00087     virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
00088     virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
00089     virtual Qt::ItemFlags flags(const QModelIndex& index) const;
00090     virtual bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
00091     virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
00092     virtual QModelIndex parent(const QModelIndex& index) const;
00093 
00094     virtual Qt::DropActions supportedDropActions() const;
00095     virtual QStringList mimeTypes() const;
00096     virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
00097     virtual QMimeData * mimeData(const QModelIndexList& indexes) const;
00098 
00100     void setDragDropHandler(AlbumModelDragDropHandler *handler);
00101 
00103     AlbumModelDragDropHandler *dragDropHandler() const;
00104 
00106     Album *albumForIndex(const QModelIndex& index) const;
00109     QModelIndex indexForAlbum(Album *album) const;
00110 
00111     Album *rootAlbum() const;
00113     QModelIndex rootAlbumIndex() const;
00114 
00116     Album::Type albumType() const;
00117 
00118 Q_SIGNALS:
00119 
00123     void rootAlbumAvailable();
00124 
00125 protected:
00126 
00127     // these can be reimplemented in a subclass
00129     virtual QVariant albumData(Album *a, int role) const;
00131     virtual QVariant decorationRole(Album *a) const;
00133     virtual QString columnHeader() const;
00135     virtual Qt::ItemFlags itemFlags(Album *album) const;
00138     virtual bool filterAlbum(Album *album) const;
00140     virtual void albumCleared(Album* /*album*/) {};
00142     virtual void allAlbumsCleared() {};
00143 
00146     void setEnableDrag(bool enable);
00147     void setEnableDrop(bool enable);
00148 
00149 protected Q_SLOTS:
00150 
00151     void slotAlbumAboutToBeAdded(Album *album, Album *parent, Album *prev);
00152     void slotAlbumAdded(Album *);
00153     void slotAlbumAboutToBeDeleted(Album *album);
00154     void slotAlbumHasBeenDeleted(void *);
00155     void slotAlbumsCleared();
00156     void slotAlbumIconChanged(Album* album);
00157     void slotAlbumRenamed(Album *album);
00158 
00159 private:
00160 
00161     AlbumModelPriv* const d;
00162 };
00163 
00164 // ------------------------------------------------------------------
00165 
00166 class AbstractSpecificAlbumModel : public AbstractAlbumModel
00167 {
00168     Q_OBJECT
00169 
00170 public:
00171 
00173     AbstractSpecificAlbumModel(Album::Type albumType, Album *rootAlbum,
00174                                RootAlbumBehavior rootBehavior = IncludeRootAlbum,
00175                                QObject *parent = 0);
00176 
00177 protected:
00178 
00179     virtual QString  columnHeader() const;
00180     void setColumnHeader(const QString& header);
00181 
00183     void setupThumbnailLoading();
00184     void emitDataChangedForChildren(Album *album);
00185 
00186 protected Q_SLOTS:
00187 
00188     void slotGotThumbnailFromIcon(Album *album, const QPixmap& thumbnail);
00189     void slotThumbnailLost(Album *album);
00190     void slotReloadThumbnails();
00191 
00192 protected:
00193 
00194     QString m_columnHeader;
00195 };
00196 
00197 // ------------------------------------------------------------------
00198 
00199 class AbstractCountingAlbumModel : public AbstractSpecificAlbumModel
00200 {
00201     Q_OBJECT
00202 
00203 public:
00204 
00206 
00207     AbstractCountingAlbumModel(Album::Type albumType, Album *rootAlbum,
00208                                RootAlbumBehavior rootBehavior = IncludeRootAlbum,
00209                                QObject *parent = 0);
00210 
00211 public Q_SLOTS:
00212 
00214     void setShowCount(bool show);
00215     bool showCount() const;
00216 
00220     void setCountMap(const QMap<int, int>& idCountMap);
00221 
00225     void excludeChildrenCount(const QModelIndex& index);
00228     void includeChildrenCount(const QModelIndex& index);
00229 
00230 protected:
00231 
00233     virtual Album* albumForId(int id) const = 0;
00234 
00236     virtual QString albumName(Album *a) const;
00237 
00238     // Reimplemented from parent classes
00239     virtual QVariant albumData(Album *a, int role) const;
00240     virtual void albumCleared(Album *album);
00241     virtual void allAlbumsCleared();
00242 
00244     void setCount(Album *album, int count);
00245 
00246 private:
00247 
00248     void updateCount(Album *album);
00249 
00250 private:
00251 
00252     bool            m_showCount;
00253     QMap<int, int>  m_countMap;
00254     QHash<int, int> m_countHashReady;
00255     QSet<int>       m_includeChildrenAlbums;
00256 };
00257 
00258 // ------------------------------------------------------------------
00259 
00260 class AbstractCheckableAlbumModel : public AbstractCountingAlbumModel
00261 {
00262     Q_OBJECT
00263 
00264 public:
00265 
00268 
00269     AbstractCheckableAlbumModel(Album::Type albumType, Album *rootAlbum,
00270                                 RootAlbumBehavior rootBehavior = IncludeRootAlbum,
00271                                 QObject *parent = 0);
00272 
00274     void setCheckable(bool isCheckable);
00275     bool isCheckable() const;
00278     void setTristate(bool isTristate);
00279     bool isTristate() const;
00280 
00282     bool isChecked(Album *album) const;
00284     Qt::CheckState checkState(Album *album) const;
00285 
00287     void setChecked(Album *album, bool isChecked);
00289     void setCheckState(Album *album, Qt::CheckState state);
00291     void toggleChecked(Album *album);
00292 
00294     QList<Album *> checkedAlbums() const;
00295 
00297     void resetCheckedAlbums();
00298 
00299 Q_SIGNALS:
00300 
00303     void checkStateChanged(Album *album, Qt::CheckState checkState);
00304 
00305 protected:
00306 
00307     virtual QVariant albumData(Album *a, int role) const;
00308     virtual Qt::ItemFlags flags(const QModelIndex& index) const;
00309     virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
00310 
00311     virtual void albumCleared(Album *album);
00312     virtual void allAlbumsCleared();
00313 
00314 private:
00315 
00316     Qt::ItemFlags                 m_extraFlags;
00317     QHash<Album*, Qt::CheckState> m_checkedAlbums;
00318 };
00319 
00320 } // namespace Digikam
00321 
00322 #endif // ABSTRACTALBUMMODEL_H

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