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

0001 // ct_lvtqtc_packageentity.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_packageentity.h>
0021 
0022 #include <ct_lvtldr_lakosiannode.h>
0023 
0024 #include <preferences.h>
0025 
0026 namespace Codethink::lvtqtc {
0027 
0028 PackageEntity::PackageEntity(lvtldr::LakosianNode *node, lvtshr::LoaderInfo info):
0029     LakosEntity(getUniqueId(node->id()), node, info)
0030 {
0031     updateTooltip();
0032     setText(node->name());
0033 
0034     if (!node->parent() || node->parent()->type() == lvtshr::DiagramType::RepositoryType) {
0035         // Top level package (Package group or standalone)
0036         setNumOutlines(3);
0037     } else if (!node->parent()->parent() || node->parent()->parent()->type() == lvtshr::DiagramType::RepositoryType) {
0038         // Package inside package group
0039         setNumOutlines(2);
0040     } else {
0041         // Subpackages
0042         setNumOutlines(1);
0043 
0044         QPen currentPen = pen();
0045         currentPen.setStyle(Qt::PenStyle::DashLine);
0046         setPen(currentPen);
0047         forceHideLevelNumbers();
0048     }
0049 
0050     setFont(Preferences::pkgFont());
0051     connect(Preferences::self(), &Preferences::pkgFontChanged, this, [this] {
0052         setFont(Preferences::pkgFont());
0053     });
0054 
0055     connect(this, &LakosEntity::formFactorChanged, this, [this] {
0056         if (isExpanded()) {
0057             truncateTitle(EllipsisTextItem::Truncate::No);
0058         } else {
0059             truncateTitle(EllipsisTextItem::Truncate::Yes);
0060         }
0061     });
0062 }
0063 
0064 void PackageEntity::updateTooltip()
0065 {
0066     makeToolTip("(no namespace)");
0067 }
0068 
0069 std::string PackageEntity::getUniqueId(const long long id)
0070 {
0071     return "source_package#" + std::to_string(id);
0072 }
0073 
0074 lvtshr::DiagramType PackageEntity::instanceType() const
0075 {
0076     return lvtshr::DiagramType::PackageType;
0077 }
0078 
0079 } // end namespace Codethink::lvtqtc