File indexing completed on 2024-05-19 05:42:21
0001 // ct_lvtqtc_logicalentity.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_lvtqtc_logicalentity.h> 0021 0022 #include <ct_lvtldr_freefunctionnode.h> 0023 #include <ct_lvtldr_lakosiannode.h> 0024 #include <ct_lvtldr_typenode.h> 0025 0026 #include <QGraphicsSimpleTextItem> 0027 0028 // TODO: Create a TextItem that handles ellipsis when too big. 0029 namespace Codethink::lvtqtc { 0030 0031 struct LogicalEntity::Private { 0032 QGraphicsSimpleTextItem *typeText = nullptr; 0033 }; 0034 0035 LogicalEntity::LogicalEntity(lvtldr::LakosianNode *node, lvtshr::LoaderInfo info): 0036 LakosEntity(getUniqueId(node->id()), node, info), d(std::make_unique<Private>()) 0037 { 0038 updateTooltip(); 0039 setRoundRadius(20); 0040 setText(node->name()); 0041 d->typeText = new QGraphicsSimpleTextItem(this); 0042 0043 auto *typeNode = dynamic_cast<lvtldr::TypeNode *>(node); 0044 if (typeNode) { 0045 const QString text = [typeNode]() -> QString { 0046 switch (typeNode->kind()) { 0047 case lvtshr::UDTKind::Class: 0048 return tr("class"); 0049 case lvtshr::UDTKind::Enum: 0050 return tr("Enum"); 0051 case lvtshr::UDTKind::Struct: 0052 return tr("Struct"); 0053 case lvtshr::UDTKind::TypeAlias: 0054 return tr("Type Alias"); 0055 case lvtshr::UDTKind::Union: 0056 return tr("Union"); 0057 case lvtshr::UDTKind::Unknown: 0058 return tr("Unknown"); 0059 } 0060 return {}; 0061 }(); 0062 d->typeText->setText(text); 0063 } else { 0064 assert(dynamic_cast<lvtldr::FreeFunctionNode *>(node)); 0065 d->typeText->setText(tr("Free Function")); 0066 } 0067 0068 connect(this, &LogicalEntity::rectangleChanged, this, [this] { 0069 constexpr int SPACING = 5; 0070 d->typeText->setPos(rect().topLeft().x() + SPACING, rect().topLeft().y()); 0071 }); 0072 } 0073 0074 LogicalEntity::~LogicalEntity() = default; 0075 0076 void LogicalEntity::updateTooltip() 0077 { 0078 makeToolTip("(no parent package)"); 0079 } 0080 0081 std::string LogicalEntity::getUniqueId(const long long id) 0082 { 0083 return "class_declaration#" + std::to_string(id); 0084 } 0085 0086 std::string LogicalEntity::colorIdText() const 0087 { 0088 if (colorId().empty()) { 0089 return name() + " is not in a package"; 0090 } 0091 return name() + " is in package " + colorId(); 0092 } 0093 0094 lvtshr::DiagramType LogicalEntity::instanceType() const 0095 { 0096 return lvtshr::DiagramType::ClassType; 0097 } 0098 0099 } // end namespace Codethink::lvtqtc