File indexing completed on 2024-05-19 05:42:14

0001 // ct_lvtmdl_modelhelpers.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 DEFINE_CT_LVTMDL_MODELHELPERS
0021 #define DEFINE_CT_LVTMDL_MODELHELPERS
0022 
0023 #include <lvtmdl_export.h>
0024 
0025 #include <ct_lvtshr_graphenums.h>
0026 
0027 #include <QDebug>
0028 #include <QStandardItem>
0029 #include <QString>
0030 
0031 #include <memory>
0032 #include <optional>
0033 
0034 namespace Codethink::lvtldr {
0035 class LakosianNode;
0036 }
0037 
0038 namespace Codethink::lvtmdl {
0039 
0040 struct LVTMDL_EXPORT ModelRoles {
0041     enum Enum {
0042         e_Id = Qt::UserRole + 1, // represents the database id of the element
0043         e_State, // represents the lazy-load state, empty or fetched.
0044         e_IsBranch, // represents if it can carry or not child items
0045         e_QualifiedName, // represents the fully qualified name of the item (with namespaces)
0046         e_NodeType, // represents what type the node has, see
0047         e_RecursiveLakosian, // Represents if all the children of this node are lakosian
0048         e_ChildItemsLoaded, // If true, all childs are loaded. If false, must lazy load children
0049     };
0050 };
0051 
0052 struct LVTMDL_EXPORT NodeType {
0053     // Represents the type of a node in the tree model
0054     enum Enum {
0055         e_Class, // Represents a UserDefinedType
0056         e_Namespace, // Represents a NamespaceDeclaration
0057         e_Package, // Represents a SourcePackage
0058         e_Repository, // Represents a SourceRepository
0059         e_Component, // Represents a SourceComponent
0060         e_FreeFunction, // Represents a global FreeFunction
0061         e_Invalid // Only used as a return value for bad conversion
0062     };
0063 
0064     static lvtshr::DiagramType toDiagramType(NodeType::Enum type);
0065     static NodeType::Enum fromDiagramType(lvtshr::DiagramType type);
0066 };
0067 
0068 struct LVTMDL_EXPORT ModelUtil {
0069     using ShouldPopulateChildren_f = std::function<bool(Codethink::lvtldr::LakosianNode const&)>;
0070 
0071     static QStandardItem *createTreeItemFromLakosianNode(
0072         lvtldr::LakosianNode& node,
0073         std::optional<ShouldPopulateChildren_f> const& shouldPopulateChildren = std::nullopt);
0074     static void
0075     populateTreeItemChildren(lvtldr::LakosianNode& node,
0076                              QStandardItem& item,
0077                              std::optional<ShouldPopulateChildren_f> const& shouldPopulateChildren = std::nullopt);
0078 }; // namespace ModelUtil
0079 
0080 } // end namespace Codethink::lvtmdl
0081 
0082 #endif