File indexing completed on 2024-05-12 15:27:42
0001 /*************************************************************************** 0002 File : TreeViewComboBox.h 0003 Project : LabPlot 0004 Description : Provides a QTreeView in a QComboBox 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2008-2016 by Alexander Semke (alexander.semke@web.de) 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #ifndef TREEVIEWCOMBOBOX_H 0030 #define TREEVIEWCOMBOBOX_H 0031 0032 #include <QComboBox> 0033 0034 class AbstractAspect; 0035 class QGroupBox; 0036 class QLineEdit; 0037 class QTreeView; 0038 0039 enum class AspectType : quint64; 0040 0041 class TreeViewComboBox : public QComboBox { 0042 Q_OBJECT 0043 0044 public: 0045 explicit TreeViewComboBox(QWidget* parent = nullptr); 0046 0047 void setModel(QAbstractItemModel*); 0048 void setCurrentModelIndex(const QModelIndex&); 0049 QModelIndex currentModelIndex() const; 0050 0051 void setTopLevelClasses(const QList<AspectType>&); 0052 void setHiddenAspects(const QList<const AbstractAspect*>&); 0053 0054 void showPopup() override; 0055 void hidePopup() override; 0056 void setInvalid(bool invalid, const QString& tooltip = QString()); 0057 0058 void useCurrentIndexText(const bool set); 0059 0060 QString currentText() const; 0061 void setText(const QString& text); 0062 0063 private: 0064 QTreeView* m_treeView; 0065 QGroupBox* m_groupBox; 0066 QLineEdit* m_lineEdit; 0067 QString m_lineEditText{""}; 0068 bool m_useCurrentIndexText{true}; 0069 0070 QList<AspectType> m_topLevelClasses; 0071 QList<const char*> m_selectableClasses; 0072 QList<const AbstractAspect*> m_hiddenAspects; 0073 0074 void showTopLevelOnly(const QModelIndex&); 0075 bool eventFilter(QObject*, QEvent*) override; 0076 bool filter(const QModelIndex&, const QString&); 0077 bool isTopLevel(const AbstractAspect*) const; 0078 bool isHidden(const AbstractAspect*) const; 0079 0080 void paintEvent(QPaintEvent *) override; 0081 0082 private slots: 0083 void treeViewIndexActivated(const QModelIndex&); 0084 void filterChanged(const QString&); 0085 0086 signals: 0087 void currentModelIndexChanged(const QModelIndex&); 0088 }; 0089 0090 #endif