2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2015-08-31 18:06:36 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Jochen Becher
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-08-31 18:06:36 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-08-31 18:06:36 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-08-31 18:06:36 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "componentviewcontroller.h"
|
|
|
|
|
|
2018-10-07 19:08:09 +02:00
|
|
|
#include "modelutilities.h"
|
|
|
|
|
#include "packageviewcontroller.h"
|
2015-08-31 18:06:36 +02:00
|
|
|
#include "pxnodeutilities.h"
|
|
|
|
|
|
|
|
|
|
#include "qmt/controller/namecontroller.h"
|
|
|
|
|
#include "qmt/model_controller/mchildrenvisitor.h"
|
|
|
|
|
#include "qmt/model_controller/modelcontroller.h"
|
|
|
|
|
#include "qmt/model/mcomponent.h"
|
|
|
|
|
#include "qmt/model/mdependency.h"
|
|
|
|
|
#include "qmt/model/mpackage.h"
|
|
|
|
|
#include "qmt/tasks/diagramscenecontroller.h"
|
|
|
|
|
|
|
|
|
|
#include <cpptools/cppmodelmanager.h>
|
|
|
|
|
#include <cplusplus/CppDocument.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
#include <projectexplorer/projectnodes.h>
|
|
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
2017-05-27 20:05:06 +02:00
|
|
|
// TODO implement removing include dependencies that are not longer used
|
|
|
|
|
// TODO refactor add/remove relations between ancestor packages into extra controller class
|
2015-08-31 18:06:36 +02:00
|
|
|
|
|
|
|
|
namespace ModelEditor {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class FindComponentFromFilePath :
|
|
|
|
|
public qmt::MChildrenVisitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
void setFilePath(const QString &filePath);
|
|
|
|
|
qmt::MComponent *component() const { return m_bestComponent; }
|
2020-11-18 15:26:38 +01:00
|
|
|
void visitMComponent(qmt::MComponent *component) final;
|
2015-08-31 18:06:36 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString m_elementName;
|
|
|
|
|
QStringList m_elementsPath;
|
|
|
|
|
int m_maxPathLength = 0;
|
2017-07-30 22:12:58 +02:00
|
|
|
qmt::MComponent *m_bestComponent = nullptr;
|
2015-08-31 18:06:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void FindComponentFromFilePath::setFilePath(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
m_elementName = qmt::NameController::convertFileNameToElementName(filePath);
|
|
|
|
|
QFileInfo fileInfo(filePath);
|
|
|
|
|
m_elementsPath = qmt::NameController::buildElementsPath(fileInfo.path(), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindComponentFromFilePath::visitMComponent(qmt::MComponent *component)
|
|
|
|
|
{
|
2015-11-04 22:44:41 +01:00
|
|
|
if (component->name() == m_elementName) {
|
2015-08-31 18:06:36 +02:00
|
|
|
QStringList elementPath;
|
2015-11-04 22:44:41 +01:00
|
|
|
const qmt::MObject *ancestor = component->owner();
|
2015-08-31 18:06:36 +02:00
|
|
|
while (ancestor) {
|
2015-11-04 22:44:41 +01:00
|
|
|
elementPath.prepend(ancestor->name());
|
|
|
|
|
ancestor = ancestor->owner();
|
2015-08-31 18:06:36 +02:00
|
|
|
}
|
|
|
|
|
int i = elementPath.size() - 1;
|
|
|
|
|
int j = m_elementsPath.size() - 1;
|
|
|
|
|
while (i >= 0 && j >= 0 && elementPath.at(i) == m_elementsPath.at(j)) {
|
|
|
|
|
--i;
|
|
|
|
|
--j;
|
|
|
|
|
}
|
|
|
|
|
int pathLength = elementPath.size() - 1 - i;
|
|
|
|
|
if (pathLength > m_maxPathLength) {
|
|
|
|
|
m_maxPathLength = pathLength;
|
|
|
|
|
m_bestComponent = component;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
visitMObject(component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class UpdateIncludeDependenciesVisitor :
|
|
|
|
|
public qmt::MChildrenVisitor
|
|
|
|
|
{
|
|
|
|
|
class Node
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Node() = default;
|
|
|
|
|
Node(const QString &filePath, const QStringList &elementPath)
|
|
|
|
|
: m_filePath(filePath),
|
|
|
|
|
m_elementPath(elementPath)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString m_filePath;
|
|
|
|
|
QStringList m_elementPath;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public:
|
2018-10-07 19:08:09 +02:00
|
|
|
void setPackageViewController(PackageViewController *packageViewController);
|
2015-08-31 18:06:36 +02:00
|
|
|
void setModelController(qmt::ModelController *modelController);
|
2018-10-07 19:08:09 +02:00
|
|
|
void setModelUtilities(ModelUtilities *modelUtilities);
|
2017-05-26 16:09:35 +02:00
|
|
|
void updateFilePaths();
|
2020-11-18 15:26:38 +01:00
|
|
|
void visitMComponent(qmt::MComponent *component) final;
|
2015-08-31 18:06:36 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QStringList findFilePathOfComponent(const qmt::MComponent *component);
|
|
|
|
|
void collectElementPaths(const ProjectExplorer::FolderNode *folderNode, QMultiHash<QString,
|
|
|
|
|
Node> *filePathsMap);
|
|
|
|
|
qmt::MComponent *findComponentFromFilePath(const QString &filePath);
|
|
|
|
|
|
|
|
|
|
private:
|
2018-10-07 19:08:09 +02:00
|
|
|
PackageViewController *m_packageViewController = nullptr;
|
2017-07-30 22:12:58 +02:00
|
|
|
qmt::ModelController *m_modelController = nullptr;
|
2018-10-07 19:08:09 +02:00
|
|
|
ModelUtilities *m_modelUtilities = nullptr;
|
2017-05-26 16:09:35 +02:00
|
|
|
QMultiHash<QString, Node> m_filePaths;
|
2018-01-13 12:45:26 +01:00
|
|
|
QHash<QString, qmt::MComponent *> m_filePathComponentsMap;
|
2015-08-31 18:06:36 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-07 19:08:09 +02:00
|
|
|
void UpdateIncludeDependenciesVisitor::setPackageViewController(PackageViewController *packageViewController)
|
|
|
|
|
{
|
|
|
|
|
m_packageViewController = packageViewController;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 18:06:36 +02:00
|
|
|
void UpdateIncludeDependenciesVisitor::setModelController(qmt::ModelController *modelController)
|
|
|
|
|
{
|
|
|
|
|
m_modelController = modelController;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 19:08:09 +02:00
|
|
|
void UpdateIncludeDependenciesVisitor::setModelUtilities(ModelUtilities *modelUtilities)
|
|
|
|
|
{
|
|
|
|
|
m_modelUtilities = modelUtilities;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 16:09:35 +02:00
|
|
|
void UpdateIncludeDependenciesVisitor::updateFilePaths()
|
|
|
|
|
{
|
|
|
|
|
m_filePaths.clear();
|
|
|
|
|
for (const ProjectExplorer::Project *project : ProjectExplorer::SessionManager::projects()) {
|
|
|
|
|
ProjectExplorer::ProjectNode *projectNode = project->rootProjectNode();
|
|
|
|
|
if (projectNode)
|
|
|
|
|
collectElementPaths(projectNode, &m_filePaths);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 18:06:36 +02:00
|
|
|
void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *component)
|
|
|
|
|
{
|
|
|
|
|
CppTools::CppModelManager *cppModelManager = CppTools::CppModelManager::instance();
|
|
|
|
|
CPlusPlus::Snapshot snapshot = cppModelManager->snapshot();
|
|
|
|
|
|
|
|
|
|
QStringList filePaths = findFilePathOfComponent(component);
|
|
|
|
|
foreach (const QString &filePath, filePaths) {
|
|
|
|
|
CPlusPlus::Document::Ptr document = snapshot.document(filePath);
|
|
|
|
|
if (document) {
|
|
|
|
|
foreach (const CPlusPlus::Document::Include &include, document->resolvedIncludes()) {
|
|
|
|
|
QString includeFilePath = include.resolvedFileName();
|
2018-01-12 23:12:29 +01:00
|
|
|
// replace proxy header with real one
|
|
|
|
|
CPlusPlus::Document::Ptr includeDocument = snapshot.document(includeFilePath);
|
|
|
|
|
if (includeDocument) {
|
|
|
|
|
QList<CPlusPlus::Document::Include> includes = includeDocument->resolvedIncludes();
|
|
|
|
|
if (includes.count() == 1 &&
|
|
|
|
|
QFileInfo(includes.at(0).resolvedFileName()).fileName() == QFileInfo(includeFilePath).fileName())
|
|
|
|
|
{
|
|
|
|
|
includeFilePath = includes.at(0).resolvedFileName();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-31 18:06:36 +02:00
|
|
|
qmt::MComponent *includeComponent = findComponentFromFilePath(includeFilePath);
|
|
|
|
|
if (includeComponent && includeComponent != component) {
|
|
|
|
|
// add dependency between components
|
2018-10-07 19:08:09 +02:00
|
|
|
if (!m_modelUtilities->haveDependency(component, includeComponent)) {
|
2015-08-31 18:06:36 +02:00
|
|
|
auto dependency = new qmt::MDependency;
|
2015-11-04 23:34:44 +01:00
|
|
|
dependency->setFlags(qmt::MElement::ReverseEngineered);
|
2020-04-29 09:49:40 +02:00
|
|
|
dependency->setStereotypes({"include"});
|
2015-11-04 23:34:44 +01:00
|
|
|
dependency->setDirection(qmt::MDependency::AToB);
|
2015-11-04 22:44:41 +01:00
|
|
|
dependency->setSource(component->uid());
|
|
|
|
|
dependency->setTarget(includeComponent->uid());
|
2015-08-31 18:06:36 +02:00
|
|
|
m_modelController->addRelation(component, dependency);
|
|
|
|
|
}
|
2018-10-07 19:08:09 +02:00
|
|
|
m_packageViewController->createAncestorDependencies(component, includeComponent);
|
2015-08-31 18:06:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
visitMObject(component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList UpdateIncludeDependenciesVisitor::findFilePathOfComponent(const qmt::MComponent *component)
|
|
|
|
|
{
|
|
|
|
|
QStringList elementPath;
|
2015-11-04 22:44:41 +01:00
|
|
|
const qmt::MObject *ancestor = component->owner();
|
2015-08-31 18:06:36 +02:00
|
|
|
while (ancestor) {
|
2015-11-04 22:44:41 +01:00
|
|
|
elementPath.prepend(ancestor->name());
|
|
|
|
|
ancestor = ancestor->owner();
|
2015-08-31 18:06:36 +02:00
|
|
|
}
|
|
|
|
|
QStringList bestFilePaths;
|
|
|
|
|
int maxPathLength = 1;
|
2017-05-26 16:09:35 +02:00
|
|
|
foreach (const Node &node, m_filePaths.values(component->name())) {
|
2015-08-31 18:06:36 +02:00
|
|
|
int i = elementPath.size() - 1;
|
|
|
|
|
int j = node.m_elementPath.size() - 1;
|
|
|
|
|
while (i >= 0 && j >= 0 && elementPath.at(i) == node.m_elementPath.at(j)) {
|
|
|
|
|
--i;
|
|
|
|
|
--j;
|
|
|
|
|
}
|
|
|
|
|
int pathLength = elementPath.size() - 1 - i;
|
|
|
|
|
if (pathLength > maxPathLength)
|
|
|
|
|
bestFilePaths.clear();
|
|
|
|
|
if (pathLength >= maxPathLength) {
|
|
|
|
|
maxPathLength = pathLength;
|
|
|
|
|
bestFilePaths.append(node.m_filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return bestFilePaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateIncludeDependenciesVisitor::collectElementPaths(const ProjectExplorer::FolderNode *folderNode,
|
|
|
|
|
QMultiHash<QString, Node> *filePathsMap)
|
|
|
|
|
{
|
|
|
|
|
foreach (const ProjectExplorer::FileNode *fileNode, folderNode->fileNodes()) {
|
2015-10-29 17:53:47 +01:00
|
|
|
QString elementName = qmt::NameController::convertFileNameToElementName(fileNode->filePath().toString());
|
2015-10-29 18:03:28 +01:00
|
|
|
QFileInfo fileInfo = fileNode->filePath().toFileInfo();
|
2015-08-31 18:06:36 +02:00
|
|
|
QString nodePath = fileInfo.path();
|
|
|
|
|
QStringList elementsPath = qmt::NameController::buildElementsPath(nodePath, false);
|
2020-08-10 14:41:39 +02:00
|
|
|
filePathsMap->insert(elementName, Node(fileNode->filePath().toString(), elementsPath));
|
2015-08-31 18:06:36 +02:00
|
|
|
}
|
2016-11-09 12:28:25 +01:00
|
|
|
foreach (const ProjectExplorer::FolderNode *subNode, folderNode->folderNodes())
|
2015-08-31 18:06:36 +02:00
|
|
|
collectElementPaths(subNode, filePathsMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qmt::MComponent *UpdateIncludeDependenciesVisitor::findComponentFromFilePath(const QString &filePath)
|
|
|
|
|
{
|
2019-01-16 12:40:15 +01:00
|
|
|
const auto it = m_filePathComponentsMap.constFind(filePath);
|
2018-01-13 12:45:26 +01:00
|
|
|
if (it != m_filePathComponentsMap.cend())
|
|
|
|
|
return it.value();
|
|
|
|
|
|
2015-08-31 18:06:36 +02:00
|
|
|
FindComponentFromFilePath visitor;
|
|
|
|
|
visitor.setFilePath(filePath);
|
2015-11-04 22:44:41 +01:00
|
|
|
m_modelController->rootPackage()->accept(&visitor);
|
2018-01-13 12:45:26 +01:00
|
|
|
qmt::MComponent *component = visitor.component();
|
|
|
|
|
m_filePathComponentsMap.insert(filePath, component);
|
|
|
|
|
return component;
|
2015-08-31 18:06:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ComponentViewController::ComponentViewControllerPrivate {
|
|
|
|
|
public:
|
2018-10-07 19:08:09 +02:00
|
|
|
ModelUtilities *modelUtilities = nullptr;
|
|
|
|
|
PackageViewController *packageViewController = nullptr;
|
2017-07-30 22:12:58 +02:00
|
|
|
PxNodeUtilities *pxnodeUtilities = nullptr;
|
|
|
|
|
qmt::DiagramSceneController *diagramSceneController = nullptr;
|
2015-08-31 18:06:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ComponentViewController::ComponentViewController(QObject *parent)
|
|
|
|
|
: QObject(parent),
|
|
|
|
|
d(new ComponentViewControllerPrivate)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ComponentViewController::~ComponentViewController()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 19:08:09 +02:00
|
|
|
void ComponentViewController::setModelUtilities(ModelUtilities *modelUtilities)
|
|
|
|
|
{
|
|
|
|
|
d->modelUtilities = modelUtilities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentViewController::setPackageViewController(PackageViewController *packageViewController)
|
|
|
|
|
{
|
|
|
|
|
d->packageViewController = packageViewController;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 18:06:36 +02:00
|
|
|
void ComponentViewController::setPxNodeUtilties(PxNodeUtilities *pxnodeUtilities)
|
|
|
|
|
{
|
|
|
|
|
d->pxnodeUtilities = pxnodeUtilities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentViewController::setDiagramSceneController(qmt::DiagramSceneController *diagramSceneController)
|
|
|
|
|
{
|
|
|
|
|
d->diagramSceneController = diagramSceneController;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 18:37:50 +01:00
|
|
|
void ComponentViewController::createComponentModel(const QString &filePath,
|
2015-08-31 18:06:36 +02:00
|
|
|
qmt::MDiagram *diagram,
|
2017-12-22 18:37:50 +01:00
|
|
|
const QString &anchorFolder)
|
2017-05-26 16:09:35 +02:00
|
|
|
{
|
|
|
|
|
d->diagramSceneController->modelController()->startResetModel();
|
2018-01-12 23:12:29 +01:00
|
|
|
doCreateComponentModel(filePath, diagram, anchorFolder, false);
|
|
|
|
|
doCreateComponentModel(filePath, diagram, anchorFolder, true);
|
2017-05-26 16:09:35 +02:00
|
|
|
d->diagramSceneController->modelController()->finishResetModel(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ComponentViewController::updateIncludeDependencies(qmt::MPackage *rootPackage)
|
|
|
|
|
{
|
|
|
|
|
d->diagramSceneController->modelController()->startResetModel();
|
|
|
|
|
UpdateIncludeDependenciesVisitor visitor;
|
2018-10-07 19:08:09 +02:00
|
|
|
visitor.setPackageViewController(d->packageViewController);
|
2017-05-26 16:09:35 +02:00
|
|
|
visitor.setModelController(d->diagramSceneController->modelController());
|
2018-10-07 19:08:09 +02:00
|
|
|
visitor.setModelUtilities(d->modelUtilities);
|
2017-05-26 16:09:35 +02:00
|
|
|
visitor.updateFilePaths();
|
|
|
|
|
rootPackage->accept(&visitor);
|
|
|
|
|
d->diagramSceneController->modelController()->finishResetModel(true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 23:12:29 +01:00
|
|
|
void ComponentViewController::doCreateComponentModel(const QString &filePath, qmt::MDiagram *diagram,
|
|
|
|
|
const QString &anchorFolder, bool scanHeaders)
|
2015-08-31 18:06:36 +02:00
|
|
|
{
|
2017-12-22 18:37:50 +01:00
|
|
|
for (const QString &fileName : QDir(filePath).entryList(QDir::Files)) {
|
|
|
|
|
QString file = filePath + "/" + fileName;
|
|
|
|
|
QString componentName = qmt::NameController::convertFileNameToElementName(file);
|
2017-07-30 22:12:58 +02:00
|
|
|
qmt::MComponent *component = nullptr;
|
2015-08-31 18:06:36 +02:00
|
|
|
bool isSource = false;
|
2017-12-22 18:37:50 +01:00
|
|
|
CppTools::ProjectFile::Kind kind = CppTools::ProjectFile::classify(file);
|
2015-08-31 18:06:36 +02:00
|
|
|
switch (kind) {
|
|
|
|
|
case CppTools::ProjectFile::CSource:
|
|
|
|
|
case CppTools::ProjectFile::CXXSource:
|
|
|
|
|
case CppTools::ProjectFile::ObjCSource:
|
|
|
|
|
case CppTools::ProjectFile::ObjCXXSource:
|
|
|
|
|
case CppTools::ProjectFile::CudaSource:
|
|
|
|
|
case CppTools::ProjectFile::OpenCLSource:
|
2018-01-12 23:12:29 +01:00
|
|
|
isSource = !scanHeaders;
|
|
|
|
|
break;
|
|
|
|
|
case CppTools::ProjectFile::AmbiguousHeader:
|
|
|
|
|
case CppTools::ProjectFile::CHeader:
|
|
|
|
|
case CppTools::ProjectFile::CXXHeader:
|
|
|
|
|
case CppTools::ProjectFile::ObjCHeader:
|
|
|
|
|
case CppTools::ProjectFile::ObjCXXHeader:
|
2018-10-09 21:12:27 +02:00
|
|
|
isSource = scanHeaders && !d->pxnodeUtilities->isProxyHeader(file);
|
2015-08-31 18:06:36 +02:00
|
|
|
break;
|
|
|
|
|
case CppTools::ProjectFile::Unclassified:
|
2017-02-01 09:48:58 +01:00
|
|
|
case CppTools::ProjectFile::Unsupported:
|
2015-08-31 18:06:36 +02:00
|
|
|
isSource = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (isSource) {
|
|
|
|
|
component = new qmt::MComponent;
|
2015-11-04 23:34:44 +01:00
|
|
|
component->setFlags(qmt::MElement::ReverseEngineered);
|
2015-08-31 18:06:36 +02:00
|
|
|
component->setName(componentName);
|
|
|
|
|
}
|
|
|
|
|
if (component) {
|
|
|
|
|
QStringList relativeElements = qmt::NameController::buildElementsPath(
|
2017-12-22 18:37:50 +01:00
|
|
|
d->pxnodeUtilities->calcRelativePath(file, anchorFolder), false);
|
2015-08-31 18:06:36 +02:00
|
|
|
if (d->pxnodeUtilities->findSameObject(relativeElements, component)) {
|
|
|
|
|
delete component;
|
|
|
|
|
} else {
|
2017-07-30 22:12:58 +02:00
|
|
|
qmt::MPackage *requestedRootPackage = d->diagramSceneController->findSuitableParentPackage(nullptr, diagram);
|
2015-08-31 18:06:36 +02:00
|
|
|
qmt::MPackage *bestParentPackage = d->pxnodeUtilities->createBestMatchingPackagePath(requestedRootPackage, relativeElements);
|
2015-11-04 22:44:41 +01:00
|
|
|
d->diagramSceneController->modelController()->addObject(bestParentPackage, component);
|
2015-08-31 18:06:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-22 18:37:50 +01:00
|
|
|
for (const QString &fileName : QDir(filePath).entryList(QDir::Dirs|QDir::NoDotAndDotDot)) {
|
|
|
|
|
QString file = filePath + "/" + fileName;
|
2018-01-12 23:12:29 +01:00
|
|
|
doCreateComponentModel(file, diagram, anchorFolder, scanHeaders);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-31 18:06:36 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ModelEditor
|