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

0001 // ct_lvtmdl_physicaltablemodels.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_physicaltablemodels.h>
0021 
0022 #include <QDebug>
0023 #include <functional>
0024 
0025 namespace Codethink::lvtmdl {
0026 
0027 // ================================
0028 // class PhysicalDepsBaseTableModel
0029 // ================================
0030 
0031 PhysicalDepsBaseTableModel::PhysicalDepsBaseTableModel(): BaseTableModel(1)
0032 {
0033     setHeader({"Name"});
0034 }
0035 
0036 void PhysicalDepsBaseTableModel::refreshData()
0037 {
0038     clear();
0039 
0040     if (fullyQualifiedName().empty()) {
0041         return;
0042     }
0043 
0044     std::vector<std::string> rows;
0045     switch (type()) {
0046     case lvtshr::DiagramType::ClassType:
0047         return;
0048     case lvtshr::DiagramType::ComponentType:
0049         rows = componentRows();
0050         break;
0051     case lvtshr::DiagramType::PackageType:
0052         rows = packageRows();
0053         break;
0054     case lvtshr::DiagramType::RepositoryType:
0055         break;
0056     case lvtshr::DiagramType::FreeFunctionType:
0057         return;
0058     case lvtshr::DiagramType::NoneType:
0059         qDebug() << "Database Inconsistent: There's no diagram type for"
0060                  << QString::fromStdString(fullyQualifiedName());
0061         break;
0062     }
0063 
0064     for (const std::string& row : rows) {
0065         addRow(row);
0066     }
0067 }
0068 
0069 // ===============================
0070 // class PhysicalProvidersTableModel
0071 // ===============================
0072 
0073 std::vector<std::string> PhysicalProvidersTableModel::componentRows()
0074 {
0075     assert(type() == lvtshr::DiagramType::ComponentType);
0076     if (fullyQualifiedName().empty()) {
0077         return {};
0078     }
0079 
0080     // TODO: Populate from lvtldr
0081     //    using DepsType = std::vector<CompPtr>;
0082     //    return getRows<lvtcdb::SourceComponent, DepsType>(fullyQualifiedName(), session(), compProviders);
0083     return {};
0084 }
0085 
0086 std::vector<std::string> PhysicalProvidersTableModel::packageRows()
0087 {
0088     assert(type() == lvtshr::DiagramType::PackageType);
0089     if (fullyQualifiedName().empty()) {
0090         return {};
0091     }
0092 
0093     // TODO: Populate from lvtldr
0094     //    using DepsType = std::vector<ptr<lvtcdb::SourcePackage>>;
0095     //    return getRows<lvtcdb::SourcePackage, DepsType>(fullyQualifiedName(), session(), pkgProviders);
0096     return {};
0097 }
0098 
0099 // ===============================
0100 // class PhysicalClientsTableModel
0101 // ===============================
0102 
0103 std::vector<std::string> PhysicalClientsTableModel::componentRows()
0104 {
0105     assert(type() == lvtshr::DiagramType::ComponentType);
0106     if (fullyQualifiedName().empty()) {
0107         return {};
0108     }
0109 
0110     // TODO: Populate from lvtldr
0111     //    using DepsType = std::vector<CompPtr>;
0112     //    return getRows<lvtcdb::SourceComponent, DepsType>(fullyQualifiedName(), session(), compClients);
0113     return {};
0114 }
0115 
0116 std::vector<std::string> PhysicalClientsTableModel::packageRows()
0117 {
0118     assert(type() == lvtshr::DiagramType::PackageType);
0119     if (fullyQualifiedName().empty()) {
0120         return {};
0121     }
0122 
0123     // TODO: Populate from lvtldr
0124     //    using DepsType = std::vector<ptr<lvtcdb::SourcePackage>>;
0125     //    return getRows<lvtcdb::SourcePackage, DepsType>(fullyQualifiedName(), session(), pkgClients);
0126     return {};
0127 }
0128 
0129 } // namespace Codethink::lvtmdl