File indexing completed on 2024-05-05 16:27:57

0001 // SPDX-FileCopyrightText: 2003-2022 Jesper K. Pedersen <blackie@kde.org>
0002 //
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #ifndef TREECATEGORYMODEL_H
0006 #define TREECATEGORYMODEL_H
0007 
0008 // Local includes
0009 #include "AbstractCategoryModel.h"
0010 
0011 #include <DB/MemberMap.h>
0012 
0013 // Qt classes
0014 class QMimeData;
0015 
0016 namespace DB
0017 {
0018 
0019 class CategoryItem;
0020 
0021 }
0022 
0023 namespace Browser
0024 {
0025 
0026 /**
0027  * \brief A QAbstractItemModel subclass that represent the items of a given category as a tree
0028  *
0029  * See \ref Browser for a detailed description of how this fits in with the rest of the classes in this module
0030  *
0031  * This class implements the QAbstractItemModel interface, which is
0032  * actually what most of the methods is about. The constructor queries
0033  * the category information from the back end, and builds an internal
0034  * data structure representing the tree. It does build its own data structure for two reasons:
0035  * \li The \ref DB::CategoryItem's do not have an easy way to go from child
0036  * to parent, something that was needed by the \ref parent method. It was
0037  * considered too risky to add that to the \ref DB::CategoryItem
0038  * data structure at the time this was implemented.
0039  * \li By building its own data structure it can ensure that the data is
0040  * not changing behind the scene, something that might have happened if
0041  * this class was constructed, categories was added or removed, and the
0042  * class was asked information abouts its data.
0043  *
0044  * The drag and drop support is in some ways similar to the CategoryListView classes.
0045  * Any bugs there probably apply here as well and vice versa.
0046  */
0047 
0048 class TreeCategoryModel : public AbstractCategoryModel
0049 {
0050     Q_OBJECT
0051 
0052 public:
0053     TreeCategoryModel(const DB::CategoryPtr &category, const DB::ImageSearchInfo &info);
0054     ~TreeCategoryModel() override;
0055 
0056     int rowCount(const QModelIndex &) const override;
0057     int columnCount(const QModelIndex &) const override;
0058     QModelIndex index(int row, int column,
0059                       const QModelIndex &parent = QModelIndex()) const override;
0060     QModelIndex parent(const QModelIndex &index) const override;
0061 
0062     QString indexToName(const QModelIndex &) const override;
0063 
0064     Qt::DropActions supportedDropActions() const override;
0065     Qt::ItemFlags flags(const QModelIndex &index) const override;
0066     QStringList mimeTypes() const override;
0067     QMimeData *mimeData(const QModelIndexList &indexes) const override;
0068     bool dropMimeData(const QMimeData *data, Qt::DropAction action,
0069                       int row, int column, const QModelIndex &parent) override;
0070 
0071     struct tagData {
0072         QString tagName;
0073         QString tagGroup;
0074     };
0075 
0076 Q_SIGNALS:
0077     void dataChanged();
0078 
0079 private: // Functions
0080     struct Data;
0081     bool createData(DB::CategoryItem *parentCategoryItem, Data *parent);
0082     Data *indexToData(const QModelIndex &index) const;
0083     TreeCategoryModel::tagData getDroppedTagData(QByteArray &encodedData);
0084 
0085 private: // Variables
0086     Data *m_data;
0087     DB::MemberMap m_memberMap;
0088 };
0089 
0090 }
0091 
0092 #endif // TREECATEGORYMODEL_H
0093 
0094 // vi:expandtab:tabstop=4 shiftwidth=4: