File indexing completed on 2024-05-19 05:42:13
0001 // ct_lvtmdl_fieldstreemodel.cpp -*-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 #include <ct_lvtmdl_fieldstreemodel.h> 0021 0022 #include <ct_lvtmdl_modelhelpers.h> 0023 0024 #include <ct_lvtldr_nodestorage.h> 0025 #include <ct_lvtldr_typenode.h> 0026 #include <ct_lvtshr_stringhelpers.h> 0027 0028 namespace Codethink::lvtmdl { 0029 0030 FieldsTreeModel::FieldsTreeModel(){}; 0031 FieldsTreeModel::~FieldsTreeModel() = default; 0032 0033 void FieldsTreeModel::refreshData(LakosianNodes selectedNodes) 0034 { 0035 clear(); 0036 0037 if (selectedNodes.empty()) { 0038 return; 0039 } 0040 0041 using namespace Codethink::lvtldr; 0042 using namespace Codethink::lvtshr; 0043 0044 QStandardItem *root = invisibleRootItem(); 0045 0046 auto createItemFromClassNode = [](LakosianNode *node) { 0047 auto *item = new QStandardItem(); 0048 item->setText(QString::fromStdString(node->name())); 0049 item->setEditable(false); 0050 item->setIcon(QIcon(":/icons/class")); 0051 return item; 0052 }; 0053 0054 auto createItemFromString = [](std::string name) { 0055 auto *item = new QStandardItem(); 0056 item->setText(QString::fromStdString(name)); 0057 item->setEditable(false); 0058 return item; 0059 }; 0060 0061 for (const auto& lakosianNode : selectedNodes) { 0062 if (lakosianNode->type() == DiagramType::ClassType) { 0063 const auto classNode = dynamic_cast<TypeNode *>(lakosianNode); 0064 auto classItem = createItemFromClassNode(classNode); 0065 0066 auto fields = classNode->getFields(); 0067 for (auto name : fields.fieldNames) { 0068 classItem->appendRow(createItemFromString(name)); 0069 } 0070 0071 root->appendRow(classItem); 0072 } 0073 } 0074 } 0075 0076 } // end namespace Codethink::lvtmdl