File indexing completed on 2024-05-12 15:26:39

0001 /***************************************************************************
0002     File            : AspectTreeModel.h
0003     Project         : LabPlot
0004     Description     : Represents a tree of AbstractAspect objects as a Qt item model.
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2007-2009 by Knut Franke (knut.franke@gmx.de)
0007     Copyright            : (C) 2007-2009 by Tilman Benkert (thzs@gmx.net)
0008     Copyright            : (C) 2011-2016 Alexander Semke (alexander.semke@web.de)
0009 
0010  ***************************************************************************/
0011 
0012 /***************************************************************************
0013  *                                                                         *
0014  *  This program is free software; you can redistribute it and/or modify   *
0015  *  it under the terms of the GNU General Public License as published by   *
0016  *  the Free Software Foundation; either version 2 of the License, or      *
0017  *  (at your option) any later version.                                    *
0018  *                                                                         *
0019  *  This program is distributed in the hope that it will be useful,        *
0020  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0021  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0022  *  GNU General Public License for more details.                           *
0023  *                                                                         *
0024  *   You should have received a copy of the GNU General Public License     *
0025  *   along with this program; if not, write to the Free Software           *
0026  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0027  *   Boston, MA  02110-1301  USA                                           *
0028  *                                                                         *
0029  ***************************************************************************/
0030 #ifndef ASPECT_TREE_MODEL_H
0031 #define ASPECT_TREE_MODEL_H
0032 
0033 #include <QAbstractItemModel>
0034 
0035 enum class AspectType : quint64;
0036 class AbstractAspect;
0037 
0038 class AspectTreeModel : public QAbstractItemModel {
0039     Q_OBJECT
0040 
0041 public:
0042     explicit AspectTreeModel(AbstractAspect* root, QObject* parent=nullptr);
0043 
0044     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0045     QModelIndex parent(const QModelIndex &index) const override;
0046     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0047     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0048     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0049     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0050     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0051     Qt::ItemFlags flags(const QModelIndex &index) const override;
0052     void setSelectableAspects(const QList<AspectType>&);
0053     QModelIndex modelIndexOfAspect(const AbstractAspect*, int column=0) const;
0054     QModelIndex modelIndexOfAspect(const QString& path, int column=0) const;
0055 
0056     void setReadOnly(bool);
0057     void enablePlottableColumnsOnly(bool);
0058     void enableNumericColumnsOnly(bool);
0059     void enableNonEmptyNumericColumnsOnly(bool);
0060     void enableShowPlotDesignation(bool);
0061     void setFilterString(const QString&);
0062     void setFilterCaseSensitivity(Qt::CaseSensitivity);
0063     void setFilterMatchCompleteWord(bool);
0064 
0065 private slots:
0066     void aspectDescriptionChanged(const AbstractAspect*);
0067     void aspectAboutToBeAdded(const AbstractAspect* parent, const AbstractAspect* before, const AbstractAspect* child);
0068     void aspectAdded(const AbstractAspect* parent);
0069     void aspectAboutToBeRemoved(const AbstractAspect*);
0070     void aspectRemoved();
0071     void aspectHiddenAboutToChange(const AbstractAspect*);
0072     void aspectHiddenChanged(const AbstractAspect*);
0073     void aspectSelectedInView(const AbstractAspect*);
0074     void aspectDeselectedInView(const AbstractAspect*);
0075     void renameRequestedSlot();
0076 
0077 private:
0078     AbstractAspect* m_root;
0079     bool m_readOnly{false};
0080     bool m_folderSelectable{true};
0081     bool m_plottableColumnsOnly{false};
0082     bool m_numericColumnsOnly{false};
0083     bool m_nonEmptyNumericColumnsOnly{false};
0084     bool m_showPlotDesignation{false};
0085     QList<AspectType> m_selectableAspects;
0086 
0087     QString m_filterString;
0088     Qt::CaseSensitivity m_filterCaseSensitivity{Qt::CaseInsensitive};
0089     bool m_matchCompleteWord{false};
0090     bool containsFilterString(const AbstractAspect*) const;
0091 
0092 signals:
0093     void renameRequested(const QModelIndex&);
0094     void indexSelected(const QModelIndex&);
0095     void indexDeselected(const QModelIndex&);
0096     void hiddenAspectSelected(const AbstractAspect*);
0097     void statusInfo(const QString&);
0098 };
0099 
0100 #endif // ifndef ASPECT_TREE_MODEL_H