File indexing completed on 2024-10-13 04:22:12
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef _K3B_META_ITEM_MODEL_H_ 0007 #define _K3B_META_ITEM_MODEL_H_ 0008 0009 #include <QAbstractItemModel> 0010 #include <QUrl> 0011 0012 class QIcon; 0013 0014 // TODO: * Have a MetaItemView which allows one to set delegates for submodel header painting 0015 // * implement something like modelHeaderData() to get data for the root elements 0016 0017 namespace K3b { 0018 /** 0019 * Meta item model which combines multiple submodels into 0020 * one big model. 0021 * 0022 * Usage is very simple: just call addSubModel for each 0023 * model that should be added to the meta model. 0024 */ 0025 class MetaItemModel : public QAbstractItemModel 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 explicit MetaItemModel( QObject* parent = 0 ); 0031 ~MetaItemModel() override; 0032 0033 QModelIndex indexForSubModel( QAbstractItemModel* model ) const; 0034 QAbstractItemModel* subModelForIndex( const QModelIndex& index ) const; 0035 0036 /** 0037 * Map index to an index used in the submodel. The returned index 0038 * should be used carefully. 0039 */ 0040 QModelIndex mapToSubModel( const QModelIndex& index ) const; 0041 QModelIndex mapFromSubModel( const QModelIndex& index ) const; 0042 0043 /** 0044 * Returns the column count for the given index 0045 * For the root index it always return 1 0046 */ 0047 int columnCount( const QModelIndex& parent = QModelIndex() ) const override; 0048 0049 QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override; 0050 QModelIndex index( int row, int column, const QModelIndex& parent = QModelIndex() ) const override; 0051 QModelIndex parent( const QModelIndex& index ) const override; 0052 int rowCount( const QModelIndex& parent = QModelIndex() ) const override; 0053 Qt::ItemFlags flags( const QModelIndex& index ) const override; 0054 bool hasChildren( const QModelIndex& parent = QModelIndex() ) const override; 0055 bool canFetchMore( const QModelIndex& parent ) const override; 0056 void fetchMore( const QModelIndex& parent ) override; 0057 bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override; 0058 QStringList mimeTypes() const override; 0059 bool dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent ) override; 0060 bool removeRows( int row, int count, const QModelIndex& parent = QModelIndex() ) override; 0061 0062 /** 0063 * Can handle lists of indexes from a single submodel. Mixing indexes 0064 * from different submodels is not supported yet and results in the method 0065 * returning 0. 0066 */ 0067 QMimeData* mimeData( const QModelIndexList& indexes ) const override; 0068 0069 /** 0070 * The default implementation just returns the list of all drop actions 0071 * supported by any of the submodels. 0072 */ 0073 Qt::DropActions supportedDragActions() const override; 0074 0075 /** 0076 * The default implementation just returns the list of all drop actions 0077 * supported by any of the submodels. 0078 */ 0079 Qt::DropActions supportedDropActions() const override; 0080 0081 public Q_SLOTS: 0082 /** 0083 * PlacesModel takes over ownership of model. 0084 * FIXME: name and icon are weird parameters here 0085 * 0086 * \param model The submodel to be added. 0087 * \param flat If flat is set true the root items of the submodel will 0088 * be merged into the root item list of this model. Otherwise the submodel 0089 * will be added under a new root item. 0090 */ 0091 void addSubModel( const QString& name, const QIcon& icon, QAbstractItemModel* model, bool flat = false ); 0092 0093 /** 0094 * FIXME: better use an id or something? 0095 */ 0096 void removeSubModel( QAbstractItemModel* model ); 0097 0098 private Q_SLOTS: 0099 void slotRowsAboutToBeInserted( const QModelIndex&, int, int ); 0100 void slotRowsInserted( const QModelIndex&, int, int ); 0101 void slotRowsAboutToBeRemoved( const QModelIndex&, int, int ); 0102 void slotRowsRemoved( const QModelIndex&, int, int ); 0103 void slotDataChanged( const QModelIndex&, const QModelIndex& ); 0104 void slotAboutToBeReset(); 0105 void slotReset(); 0106 0107 private: 0108 class Private; 0109 Private* const d; 0110 }; 0111 } 0112 0113 #endif