File indexing completed on 2024-05-12 03:47:26

0001 /*
0002     File            : AspectTreeModel.h
0003     Project         : LabPlot
0004     Description     : Represents a tree of AbstractAspect objects as a Qt item model.
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2007-2009 Knut Franke <knut.franke@gmx.de>
0007     SPDX-FileCopyrightText: 2007-2009 Tilman Benkert <thzs@gmx.net>
0008     SPDX-FileCopyrightText: 2011-2016 Alexander Semke <alexander.semke@web.de>
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #ifndef ASPECT_TREE_MODEL_H
0013 #define ASPECT_TREE_MODEL_H
0014 
0015 #include <QAbstractItemModel>
0016 
0017 enum class AspectType : quint64;
0018 class AbstractAspect;
0019 
0020 class AspectTreeModel : public QAbstractItemModel {
0021     Q_OBJECT
0022 
0023 public:
0024     explicit AspectTreeModel(AbstractAspect* root, QObject* parent = nullptr);
0025 
0026     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
0027     QModelIndex parent(const QModelIndex& index) const override;
0028     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0029     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0030 
0031     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0032     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0033     bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
0034     Qt::ItemFlags flags(const QModelIndex& index) const override;
0035 
0036     QModelIndex modelIndexOfAspect(const AbstractAspect*, int column = 0) const;
0037     QModelIndex modelIndexOfAspect(const QString& path, int column = 0) const;
0038 
0039     void setSelectableAspects(const QList<AspectType>&);
0040     const QList<AspectType>& selectableAspects() const;
0041 
0042     void setReadOnly(bool);
0043     void enablePlottableColumnsOnly(bool);
0044     void enableNumericColumnsOnly(bool);
0045     void enableNonEmptyNumericColumnsOnly(bool);
0046     void enableShowPlotDesignation(bool);
0047     void setFilterString(const QString&);
0048     void setFilterCaseSensitivity(Qt::CaseSensitivity);
0049     void setFilterMatchCompleteWord(bool);
0050 
0051 private Q_SLOTS:
0052     void aspectDescriptionChanged(const AbstractAspect*);
0053     void aspectAboutToBeAdded(const AbstractAspect* parent, const AbstractAspect* before, const AbstractAspect* child);
0054     void aspectAdded(const AbstractAspect* parent);
0055     void aspectAboutToBeRemoved(const AbstractAspect*);
0056     void aspectRemoved();
0057     void aspectHiddenAboutToChange(const AbstractAspect*);
0058     void aspectHiddenChanged(const AbstractAspect*);
0059     void aspectSelectedInView(const AbstractAspect*);
0060     void aspectDeselectedInView(const AbstractAspect*);
0061     void renameRequestedSlot();
0062 
0063 private:
0064     AbstractAspect* m_root;
0065     bool m_readOnly{false};
0066     bool m_folderSelectable{true};
0067     bool m_plottableColumnsOnly{false};
0068     bool m_numericColumnsOnly{false};
0069     bool m_nonEmptyNumericColumnsOnly{false};
0070     bool m_showPlotDesignation{false};
0071     QList<AspectType> m_selectableAspects;
0072 
0073     QString m_filterString;
0074     Qt::CaseSensitivity m_filterCaseSensitivity{Qt::CaseInsensitive};
0075     bool m_matchCompleteWord{false};
0076     bool containsFilterString(const AbstractAspect*) const;
0077     bool m_aspectAboutToBeRemovedCalled{false};
0078 
0079 Q_SIGNALS:
0080     void renameRequested(const QModelIndex&);
0081     void indexSelected(const QModelIndex&);
0082     void indexDeselected(const QModelIndex&);
0083     void hiddenAspectSelected(const AbstractAspect*);
0084     void statusInfo(const QString&);
0085 };
0086 
0087 #endif // ifndef ASPECT_TREE_MODEL_H