File indexing completed on 2024-05-19 05:42:28
0001 // ct_lvtqtw_treeview.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #ifndef INCLUDED_LVTQTW_TREEVIEW 0021 #define INCLUDED_LVTQTW_TREEVIEW 0022 0023 #include <lvtqtw_export.h> 0024 0025 #include <QTreeView> 0026 0027 #include <ct_lvtmdl_basetreemodel.h> 0028 0029 #include <memory> 0030 0031 namespace Codethink::lvtqtw { 0032 0033 class LVTQTW_EXPORT TreeView : public QTreeView 0034 // Visualizes a Tree model and reacts to changes 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 // CREATORS 0040 TreeView(QWidget *parent = nullptr); 0041 // Constructor 0042 0043 ~TreeView() noexcept override; 0044 // Destructor 0045 0046 void setFilterText(const QString& txt); 0047 0048 void setModel(QAbstractItemModel *model) override; 0049 0050 // Signals, auto generated. 0051 Q_SIGNAL void branchSelected(const QModelIndex& idx); 0052 // User selected a node that contains more nodes 0053 0054 Q_SIGNAL void leafSelected(const QModelIndex& idx); 0055 // User selected a leaf node 0056 0057 Q_SIGNAL void branchMiddleClicked(const QModelIndex& idx); 0058 // User clicked on the branch with the middle mouse click 0059 0060 Q_SIGNAL void leafMiddleClicked(const QModelIndex& idx); 0061 // User clicked on the leaf with the middle mouse click 0062 0063 Q_SIGNAL void 0064 branchRightClicked(const QModelIndexList& multiSelection, const QModelIndex& clickedOn, const QPoint& pos); 0065 // User clicked on the branch with the middle mouse click 0066 0067 Q_SIGNAL void 0068 leafRightClicked(const QModelIndexList& multiSelection, const QModelIndex& clickedOn, const QPoint& pos); 0069 // User clicked on the leaf with the middle mouse click 0070 0071 protected: 0072 void mousePressEvent(QMouseEvent *ev) override; 0073 void mouseReleaseEvent(QMouseEvent *ev) override; 0074 void keyPressEvent(QKeyEvent *ev) override; 0075 0076 private: 0077 // DATA 0078 // TYPES 0079 struct TreeViewPrivate; 0080 std::unique_ptr<TreeViewPrivate> d; 0081 }; 0082 0083 } // end namespace Codethink::lvtqtw 0084 0085 #endif