File indexing completed on 2024-05-12 03:48:30
0001 /* 0002 File : TreeViewComboBox.h 0003 Project : LabPlot 0004 Description : Provides a QTreeView in a QComboBox 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2008-2016 Alexander Semke <alexander.semke@web.de> 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #ifndef TREEVIEWCOMBOBOX_H 0011 #define TREEVIEWCOMBOBOX_H 0012 0013 #include <QComboBox> 0014 0015 class AbstractAspect; 0016 class AbstractColumn; 0017 class AspectTreeModel; 0018 class QGroupBox; 0019 class QLineEdit; 0020 class QTreeView; 0021 0022 enum class AspectType : quint64; 0023 0024 class TreeViewComboBox : public QComboBox { 0025 Q_OBJECT 0026 0027 public: 0028 explicit TreeViewComboBox(QWidget* parent = nullptr); 0029 0030 void setModel(AspectTreeModel*); 0031 // void setModel(AbstractItemModel*) override; 0032 void setCurrentModelIndex(const QModelIndex&); 0033 void setAspect(const AbstractAspect*); 0034 AbstractAspect* currentAspect() const; 0035 void setColumn(const AbstractColumn*, const QString&); 0036 QModelIndex currentModelIndex() const; 0037 0038 void setTopLevelClasses(const QList<AspectType>&); 0039 void setHiddenAspects(const QList<const AbstractAspect*>&); 0040 0041 void showPopup() override; 0042 void hidePopup() override; 0043 void setInvalid(bool invalid, const QString& tooltip = QString()); 0044 0045 void useCurrentIndexText(const bool set); 0046 0047 QString currentText() const; 0048 void setText(const QString& text); 0049 0050 private: 0051 AspectTreeModel* m_model{nullptr}; 0052 QTreeView* m_treeView; 0053 QGroupBox* m_groupBox; 0054 QLineEdit* m_lineEdit; 0055 QString m_lineEditText{QLatin1String("")}; 0056 bool m_useCurrentIndexText{true}; 0057 0058 QList<AspectType> m_topLevelClasses; 0059 QList<const char*> m_selectableClasses; 0060 QList<const AbstractAspect*> m_hiddenAspects; 0061 0062 void showTopLevelOnly(const QModelIndex&); 0063 bool eventFilter(QObject*, QEvent*) override; 0064 bool filter(const QModelIndex&, const QString&); 0065 bool isTopLevel(const AbstractAspect*) const; 0066 bool isHidden(const AbstractAspect*) const; 0067 0068 void paintEvent(QPaintEvent*) override; 0069 0070 private Q_SLOTS: 0071 void treeViewIndexActivated(const QModelIndex&); 0072 void filterChanged(const QString&); 0073 0074 Q_SIGNALS: 0075 void currentModelIndexChanged(const QModelIndex&); 0076 }; 0077 0078 #endif