File indexing completed on 2025-01-05 03:59:21
0001 /* 0002 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef MARBLE_KDESCENDANTSPROXYMODEL_H 0008 #define MARBLE_KDESCENDANTSPROXYMODEL_H 0009 0010 #include <QAbstractProxyModel> 0011 0012 #include "digikam_export.h" 0013 0014 // namespace added to avoid symbol clashes with KF6::ItemModels 0015 namespace Marble 0016 { 0017 0018 class KDescendantsProxyModelPrivate; 0019 0020 /** 0021 @brief Proxy Model for restructuring a Tree into a list. 0022 0023 A KDescendantsProxyModel may be used to alter how the items in the tree are presented. 0024 0025 Given a model which is represented as a tree: 0026 0027 The KDescendantsProxyModel restructures the sourceModel to represent it as a flat list. 0028 0029 @code 0030 // ... Create an entityTreeModel 0031 KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this); 0032 descProxy->setSourceModel(entityTree); 0033 view->setModel(descProxy); 0034 @endcode 0035 0036 KDescendantEntitiesProxyModel can also display the ancestors of the index in the source model as part of its display. 0037 0038 @code 0039 // ... Create an entityTreeModel 0040 KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this); 0041 descProxy->setSourceModel(entityTree); 0042 0043 // #### This is new 0044 descProxy->setDisplayAncestorData(true); 0045 descProxy->setDisplayAncestorSeparator(QString(" / ")); 0046 0047 view->setModel(descProxy); 0048 0049 @endcode 0050 0051 @since 4.6 0052 @author Stephen Kelly <steveire@gmail.com> 0053 */ 0054 class DIGIKAM_EXPORT KDescendantsProxyModel : public QAbstractProxyModel 0055 { 0056 Q_OBJECT 0057 0058 public: 0059 0060 /** 0061 * Creates a new descendant entities proxy model. 0062 * 0063 * @param parent The parent object. 0064 */ 0065 explicit KDescendantsProxyModel(QObject *parent = nullptr); 0066 0067 /** 0068 * Destroys the descendant entities proxy model. 0069 */ 0070 ~KDescendantsProxyModel() override; 0071 0072 /** 0073 * Sets the source @p model of the proxy. 0074 */ 0075 void setSourceModel(QAbstractItemModel *model) Q_DECL_OVERRIDE; 0076 0077 #if 0 0078 /** 0079 * @deprecated 0080 * 0081 * This method does nothing. 0082 */ 0083 void setRootIndex(const QModelIndex &index); 0084 #endif 0085 0086 /** 0087 * Set whether to show ancestor data in the model. If @p display is true, then 0088 * a source model which is displayed as 0089 * 0090 * @code 0091 * -> "Item 0-0" (this is row-depth) 0092 * -> -> "Item 0-1" 0093 * -> -> "Item 1-1" 0094 * -> -> -> "Item 0-2" 0095 * -> -> -> "Item 1-2" 0096 * -> "Item 1-0" 0097 * @endcode 0098 * 0099 * will be displayed as 0100 * 0101 * @code 0102 * -> *Item 0-0" 0103 * -> "Item 0-0 / Item 0-1" 0104 * -> "Item 0-0 / Item 1-1" 0105 * -> "Item 0-0 / Item 1-1 / Item 0-2" 0106 * -> "Item 0-0 / Item 1-1 / Item 1-2" 0107 * -> "Item 1-0" 0108 * @endcode 0109 * 0110 * If @p display is false, the proxy will show 0111 * 0112 * @code 0113 * -> *Item 0-0" 0114 * -> "Item 0-1" 0115 * -> "Item 1-1" 0116 * -> "Item 0-2" 0117 * -> "Item 1-2" 0118 * -> "Item 1-0" 0119 * @endcode 0120 * 0121 * Default is false. 0122 */ 0123 void setDisplayAncestorData(bool display); 0124 0125 /** 0126 * Whether ancestor data will be displayed. 0127 */ 0128 bool displayAncestorData() const; 0129 0130 /** 0131 * Sets the ancestor @p separator used between data of ancestors. 0132 */ 0133 void setAncestorSeparator(const QString &separator); 0134 0135 /** 0136 * Separator used between data of ancestors. 0137 */ 0138 QString ancestorSeparator() const; 0139 0140 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const Q_DECL_OVERRIDE; 0141 QModelIndex mapToSource(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE; 0142 0143 Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; 0144 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; 0145 int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 0146 QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE; 0147 0148 QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE; 0149 QStringList mimeTypes() const Q_DECL_OVERRIDE; 0150 0151 bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 0152 QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; 0153 QModelIndex parent(const QModelIndex &) const Q_DECL_OVERRIDE; 0154 int columnCount(const QModelIndex &index = QModelIndex()) const Q_DECL_OVERRIDE; 0155 0156 Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE; 0157 0158 /** 0159 Reimplemented to match all descendants. 0160 */ 0161 QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, 0162 int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const Q_DECL_OVERRIDE; 0163 0164 private: 0165 Q_DECLARE_PRIVATE(KDescendantsProxyModel) 0166 //@cond PRIVATE 0167 KDescendantsProxyModelPrivate *d_ptr; 0168 0169 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeInserted(const QModelIndex &, int, int)) 0170 Q_PRIVATE_SLOT(d_func(), void sourceRowsInserted(const QModelIndex &, int, int)) 0171 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int)) 0172 Q_PRIVATE_SLOT(d_func(), void sourceRowsRemoved(const QModelIndex &, int, int)) 0173 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)) 0174 Q_PRIVATE_SLOT(d_func(), void sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)) 0175 Q_PRIVATE_SLOT(d_func(), void sourceModelAboutToBeReset()) 0176 Q_PRIVATE_SLOT(d_func(), void sourceModelReset()) 0177 Q_PRIVATE_SLOT(d_func(), void sourceLayoutAboutToBeChanged()) 0178 Q_PRIVATE_SLOT(d_func(), void sourceLayoutChanged()) 0179 Q_PRIVATE_SLOT(d_func(), void sourceDataChanged(const QModelIndex &, const QModelIndex &)) 0180 Q_PRIVATE_SLOT(d_func(), void sourceModelDestroyed()) 0181 0182 Q_PRIVATE_SLOT(d_func(), void processPendingParents()) 0183 0184 // Make these private, they shouldn't be called by applications 0185 // virtual bool insertRows(int , int, const QModelIndex & = QModelIndex()); 0186 // virtual bool insertColumns(int, int, const QModelIndex & = QModelIndex()); 0187 // virtual bool removeRows(int, int, const QModelIndex & = QModelIndex()); 0188 // virtual bool removeColumns(int, int, const QModelIndex & = QModelIndex()); 0189 0190 //@endcond 0191 }; 0192 0193 } 0194 0195 #endif