File indexing completed on 2024-05-19 05:42:14
0001 // ct_lvtwdg_namespacetreemodel.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_LVTMDL_NAMESPACETREEMODEL 0021 #define INCLUDED_LVTMDL_NAMESPACETREEMODEL 0022 0023 //@PURPOSE: Defines a data model for tree views, containing the 0024 // elements of all namespaces. 0025 // 0026 //@CLASSES: 0027 // lvtmdl::NamespaceTreeModel: 0028 // 0029 //@DESCRIPTION: This component prepares the data of a 0030 // namespace to be displayed on a tree view 0031 // 0032 /// Usage: 0033 ///------ 0034 /// Create a model and pass the Dbo::Session to it, 0035 /// then plug the model onto a view. 0036 /// 0037 /// auto model = std::make_unique<NamespaceTreeModel>(); 0038 /// model->setDboSession(session); 0039 /// view->setModel(model); 0040 /// 0041 /// d->treeView->collapsed().connect(this, 0042 /// [this](const WModelIndex& idx) { 0043 /// d->model->collapse(idx); 0044 /// } 0045 /// ); 0046 /// 0047 /// d->treeView->expanded().connect(this, 0048 /// [this](const WModelIndex& idx) { 0049 /// d->model->expand(idx); 0050 /// } 0051 /// ); 0052 /// 0053 /// You should manually connect to expand and collapse 0054 /// from the treeview Expanded() and Collapsed() signals 0055 /// as we need that information to fetch the data from 0056 /// the namespaces. 0057 0058 #include <ct_lvtmdl_basetreemodel.h> 0059 0060 #include <any> 0061 #include <memory> 0062 #include <optional> 0063 0064 #include <lvtmdl_export.h> 0065 0066 namespace Codethink::lvtmdl { 0067 0068 class LVTMDL_EXPORT NamespaceTreeModel : public BaseTreeModel 0069 // This class represents the model of a namespace tree containing 0070 // all inner namespaces and classes. 0071 { 0072 Q_OBJECT 0073 // DATA TYPES 0074 struct NamespaceTreeModelPrivate; 0075 0076 public: 0077 // CREATORS 0078 NamespaceTreeModel(); 0079 // CONSTRUCTOR 0080 0081 ~NamespaceTreeModel() override; 0082 // DESTRUCTOR 0083 0084 void setRootNamespace(const std::optional<QString>& rootNamespace); 0085 // Will only load the namespaces that are internal to this namespace. 0086 0087 [[nodiscard]] std::optional<QString> rootNamespace() const; 0088 // returns the current Root Namespace 0089 0090 void reload() override; 0091 0092 [[nodiscard]] QVariant 0093 headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0094 [[nodiscard]] QString errorString() const; 0095 [[nodiscard]] bool hasError() const; 0096 0097 private: 0098 // MEMBERS 0099 std::unique_ptr<NamespaceTreeModelPrivate> d; 0100 }; 0101 0102 } // end namespace Codethink::lvtmdl 0103 0104 #endif