"Fossies" - the Fresh Open Source Software Archive

Member "digikam-6.3.0/core/showfoto/thumbbar/showfotofiltermodel.h" (4 Sep 2019, 8136 Bytes) of package /linux/misc/digikam-6.3.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "showfotofiltermodel.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.2.0_vs_6.3.0.

    1 /* ============================================================
    2  *
    3  * This file is a part of digiKam project
    4  * https://www.digikam.org
    5  *
    6  * Date        : 30-07-2013
    7  * Description : Qt filter model for showfoto items
    8  *
    9  * Copyright (C) 2013 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
   10  *
   11  * This program is free software; you can redistribute it
   12  * and/or modify it under the terms of the GNU General
   13  * Public License as published by the Free Software Foundation;
   14  * either version 2, or (at your option)
   15  * any later version.
   16  *
   17  * This program is distributed in the hope that it will be useful,
   18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20  * GNU General Public License for more details.
   21  *
   22  * ============================================================ */
   23 
   24 #ifndef SHOW_FOTO_FILTER_MODEL_H
   25 #define SHOW_FOTO_FILTER_MODEL_H
   26 
   27 // Qt includes
   28 
   29 #include <QObject>
   30 
   31 // Local includes
   32 
   33 #include "dcategorizedsortfilterproxymodel.h"
   34 #include "showfotoimagemodel.h"
   35 #include "showfotothumbnailmodel.h"
   36 #include "showfotoitemsortsettings.h"
   37 
   38 namespace ShowFoto
   39 {
   40 
   41 class ShowfotoFilterModel;
   42 
   43 class ShowfotoSortFilterModel : public DCategorizedSortFilterProxyModel
   44 {
   45     Q_OBJECT
   46 
   47 public:
   48     explicit ShowfotoSortFilterModel(QObject* const parent = nullptr);
   49     ~ShowfotoSortFilterModel();
   50 
   51     void setSourceShowfotoModel(ShowfotoItemModel* const sourceModel);
   52     ShowfotoItemModel* sourceShowfotoModel() const;
   53 
   54     void setSourceFilterModel(ShowfotoSortFilterModel* const sourceModel);
   55     ShowfotoSortFilterModel* sourceFilterModel() const;
   56 
   57     /// Convenience methods mapped to ShowfotoItemModel.
   58     /// Mentioned indexes returned come from the source Showfoto image model.
   59     QModelIndex mapToSourceShowfotoModel(const QModelIndex& proxyIndex)                       const;
   60     QModelIndex mapFromSourceShowfotoModel(const QModelIndex& showfotoModelIndex)             const;
   61     QModelIndex mapFromDirectSourceToSourceShowfotoModel(const QModelIndex& sourceModelIndex) const;
   62 
   63     QList<QModelIndex> mapListToSource(const QList<QModelIndex>& indexes)         const;
   64     QList<QModelIndex> mapListFromSource(const QList<QModelIndex>& sourceIndexes) const;
   65 
   66     ShowfotoItemInfo        showfotoItemInfo(const QModelIndex& index)           const;
   67     qlonglong          showfotoItemId(const QModelIndex& index)                  const;
   68     QList<ShowfotoItemInfo> showfotoItemInfos(const QList<QModelIndex>& indexes) const;
   69     QList<qlonglong>   showfotoItemIds(const QList<QModelIndex>& indexes)        const;
   70 
   71     QModelIndex indexForUrl(const QUrl& fileUrl)                       const;
   72     QModelIndex indexForShowfotoItemInfo(const ShowfotoItemInfo& info) const;
   73     QModelIndex indexForShowfotoItemId(qlonglong id)                   const;
   74 
   75     /** Returns a list of all showfoto infos, sorted according to this model.
   76      *  If you do not need a sorted list, use ShowfotoItemModel's showfotoItemInfo() method.
   77      */
   78     QList<ShowfotoItemInfo> showfotoItemInfosSorted() const;
   79 
   80     /// Returns this, any chained ShowfotoFilterModel, or 0.
   81     virtual ShowfotoFilterModel* showfotoFilterModel() const;
   82 
   83 protected:
   84 
   85     virtual void setSourceModel(QAbstractItemModel* sourceModel);
   86 
   87     /// Reimplement if needed. Called only when model shall be set as (direct) sourceModel.
   88     virtual void setDirectSourceShowfotoModel(ShowfotoItemModel* const sourceModel);
   89 
   90 protected:
   91 
   92     ShowfotoSortFilterModel* m_chainedModel;
   93 };
   94 
   95 // ------------------------------------------------------------------------------------------
   96 
   97 class ShowfotoFilterModel : public ShowfotoSortFilterModel
   98 {
   99     Q_OBJECT
  100 
  101 public:
  102 
  103     enum ShowfotoFilterModelRoles
  104     {
  105         /// Returns the current categorization mode.
  106         CategorizationModeRole         = ShowfotoItemModel::FilterModelRoles + 1,
  107 
  108         /// Returns the current sort order.
  109         SortOrderRole                  = ShowfotoItemModel::FilterModelRoles + 2,
  110 
  111         /// Returns the format of the index which is used for category.
  112         CategoryFormatRole             = ShowfotoItemModel::FilterModelRoles + 3,
  113 
  114         /// Returns true if the given showfoto item is a group leader, and the group is opened.
  115         //TODO: GroupIsOpenRole        = ShowfotoItemModel::FilterModelRoles + 4
  116         ShowfotoFilterModelPointerRole = ShowfotoItemModel::FilterModelRoles + 50
  117     };
  118 
  119 public:
  120 
  121     explicit ShowfotoFilterModel(QObject* const parent = nullptr);
  122     ~ShowfotoFilterModel();
  123 
  124     ShowfotoItemSortSettings showfotoItemSortSettings() const;
  125 
  126     void setShowfotoItemSortSettings(const ShowfotoItemSortSettings& sorter);
  127 
  128     /// Enables sending ShowfotoItemInfosAdded and ShowfotoItemInfosAboutToBeRemoved.
  129     void setSendShowfotoItemInfoSignals(bool sendSignals);
  130 
  131     //TODO: Implement grouping in Showfoto tool.
  132     //bool isGroupOpen(qlonglong group) const;
  133     //bool isAllGroupsOpen() const;
  134 
  135     virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
  136     virtual ShowfotoFilterModel* showfotoFilterModel()                          const override;
  137 
  138 public Q_SLOTS:
  139 
  140     void setCategorizationMode(ShowfotoItemSortSettings::CategorizationMode mode);
  141     void setSortRole(ShowfotoItemSortSettings::SortRole role);
  142     void setSortOrder(ShowfotoItemSortSettings::SortOrder order);
  143 
  144     //TODO: Implement grouping in Showfoto tool.
  145     //void setGroupOpen(qlonglong group, bool open);
  146     //void toggleGroupOpen(qlonglong group);
  147     //void setAllGroupsOpen(bool open);
  148 
  149     /** Changes the current image filter settings and refilters. */
  150     //TODO: Implement filtering in Showfoto tool.
  151     //virtual void setItemFilterSettings(const ItemFilterSettings& settings);
  152 
  153     /** Changes the current image sort settings and resorts. */
  154     //TODO: virtual void setItemSortSettings(const ItemSortSettings& settings);
  155 
  156 Q_SIGNALS:
  157 
  158     /** These signals need to be explicitly enabled with setSendItemInfoSignals().
  159      */
  160     void showfotoItemInfosAdded(const QList<ShowfotoItemInfo>& infos);
  161     void showfotoItemInfosAboutToBeRemoved(const QList<ShowfotoItemInfo>& infos);
  162 
  163 protected Q_SLOTS:
  164 
  165     void slotRowsInserted(const QModelIndex& parent, int start, int end);
  166     void slotRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
  167 
  168 public:
  169 
  170     // Declared as public because of use in sub-classes.
  171     class ShowfotoFilterModelPrivate;
  172 
  173 protected:
  174 
  175     ShowfotoFilterModelPrivate* const d_ptr;
  176 
  177 protected:
  178 
  179     virtual void setDirectSourceShowfotoModel(ShowfotoItemModel* const sourceModel) override;
  180 
  181     //TODO: virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
  182 
  183     virtual int compareCategories(const QModelIndex& left, const QModelIndex& right) const;
  184     virtual bool subSortLessThan(const QModelIndex& left, const QModelIndex& right) const;
  185 
  186     /** Reimplement to customize category sorting,
  187      *  Return negative if category of left < category right,
  188      *  Return 0 if left and right are in the same category, else return positive.
  189      */
  190     virtual int compareInfosCategories(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const;
  191 
  192     /** Reimplement to customize sorting. Do not take categories into account here.
  193      */
  194     virtual bool infosLessThan(const ShowfotoItemInfo& left, const ShowfotoItemInfo& right) const;
  195 
  196     /** Returns a unique identifier for the category if info. The string need not be for user display.
  197      */
  198     virtual QString categoryIdentifier(const ShowfotoItemInfo& info) const;
  199 
  200 private:
  201 
  202     Q_DECLARE_PRIVATE(ShowfotoFilterModel)
  203 };
  204 
  205 // -----------------------------------------------------------------------------------------------------
  206 
  207 class NoDuplicatesShowfotoFilterModel : public ShowfotoSortFilterModel
  208 {
  209     Q_OBJECT
  210 
  211 public:
  212 
  213     explicit NoDuplicatesShowfotoFilterModel(QObject* const parent = nullptr);
  214 
  215 protected:
  216 
  217     virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const;
  218 };
  219 
  220 } // namespace ShowFoto
  221 
  222 Q_DECLARE_METATYPE(ShowFoto::ShowfotoFilterModel*)
  223 
  224 #endif // SHOW_FOTO_FILTER_MODEL_H