ModelEditor: More use of Utils::FilePath

Change-Id: Ib1030959ae5eea763d3b93684b68ae6ae927839b
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jochen Becher
2024-05-12 17:42:10 +02:00
parent 1afe89a54e
commit b468ea0bdd
27 changed files with 189 additions and 119 deletions

View File

@@ -10,7 +10,9 @@
#include "qmt/stereotype/stereotypecontroller.h" #include "qmt/stereotype/stereotypecontroller.h"
#include <QDebug> #include <QDebug>
#include <QFile>
using Utils::FilePath;
using Utils::FilePaths;
namespace qmt { namespace qmt {
@@ -36,7 +38,7 @@ void ConfigController::setStereotypeController(StereotypeController *stereotypeC
d->m_stereotypeController = stereotypeController; d->m_stereotypeController = stereotypeController;
} }
void ConfigController::readStereotypeDefinitions(const Utils::FilePath &path) void ConfigController::readStereotypeDefinitions(const FilePath &path)
{ {
if (path.isEmpty()) { if (path.isEmpty()) {
// TODO add error handling // TODO add error handling
@@ -51,7 +53,7 @@ void ConfigController::readStereotypeDefinitions(const Utils::FilePath &path)
connect(&parser, &StereotypeDefinitionParser::toolbarParsed, connect(&parser, &StereotypeDefinitionParser::toolbarParsed,
this, &ConfigController::onToolbarParsed); this, &ConfigController::onToolbarParsed);
Utils::FilePaths paths; FilePaths paths;
if (path.isFile()) { if (path.isFile()) {
paths.append(path); paths.append(path);
} else if (path.isDir()) { } else if (path.isDir()) {
@@ -60,11 +62,10 @@ void ConfigController::readStereotypeDefinitions(const Utils::FilePath &path)
// TODO add error handling // TODO add error handling
return; return;
} }
for (const auto &filePath : std::as_const(paths)) { for (const FilePath &filePath : std::as_const(paths)) {
QFile file(filePath.toString()); auto data = filePath.fileContents();
if (file.open(QIODevice::ReadOnly)) { if (data.has_value()) {
QString text = QString::fromUtf8(file.readAll()); QString text = QString::fromUtf8(data.value());
file.close();
StringTextSource source; StringTextSource source;
source.setSourceId(1); source.setSourceId(1);
source.setText(text); source.setText(text);

View File

@@ -5,6 +5,8 @@
#include <QDebug> #include <QDebug>
using Utils::FilePath;
namespace qmt { namespace qmt {
NameController::NameController(QObject *parent) NameController::NameController(QObject *parent)
@@ -16,7 +18,7 @@ NameController::~NameController()
{ {
} }
QString NameController::convertFileNameToElementName(const Utils::FilePath &fileName) QString NameController::convertFileNameToElementName(const FilePath &fileName)
{ {
QString baseName = fileName.baseName().trimmed(); QString baseName = fileName.baseName().trimmed();
QString elementName; QString elementName;
@@ -63,12 +65,12 @@ QString NameController::convertElementNameToBaseFileName(const QString &elementN
return baseFileName; return baseFileName;
} }
Utils::FilePath NameController::calcRelativePath(const Utils::FilePath &absoluteFileName, FilePath NameController::calcRelativePath(const FilePath &absoluteFileName,
const Utils::FilePath &anchorPath) const FilePath &anchorPath)
{ {
// TODO try using Utils::FilePath::relativePath // TODO try using Utils::FilePath::relativePath
QString absoluteFilePath = absoluteFileName.toString(); QString absoluteFilePath = absoluteFileName.path();
QString anchorPathString = anchorPath.toString(); QString anchorPathString = anchorPath.path();
int secondLastSlashIndex = -1; int secondLastSlashIndex = -1;
int slashIndex = -1; int slashIndex = -1;
int i = 0; int i = 0;
@@ -100,7 +102,7 @@ Utils::FilePath NameController::calcRelativePath(const Utils::FilePath &absolute
relativePath = absoluteFilePath.mid(slashIndex + 1); relativePath = absoluteFilePath.mid(slashIndex + 1);
} }
return Utils::FilePath::fromString(relativePath); return FilePath::fromString(relativePath);
} }
QString NameController::calcElementNameSearchId(const QString &elementName) QString NameController::calcElementNameSearchId(const QString &elementName)
@@ -113,7 +115,7 @@ QString NameController::calcElementNameSearchId(const QString &elementName)
return searchId; return searchId;
} }
QStringList NameController::buildElementsPath(const Utils::FilePath &filePath, QStringList NameController::buildElementsPath(const FilePath &filePath,
bool ignoreLastFilePathPart) bool ignoreLastFilePathPart)
{ {
QList<QString> relativeElements; QList<QString> relativeElements;
@@ -123,7 +125,7 @@ QStringList NameController::buildElementsPath(const Utils::FilePath &filePath,
if (ignoreLastFilePathPart || split.last().isEmpty()) if (ignoreLastFilePathPart || split.last().isEmpty())
--splitEnd; --splitEnd;
for (auto it = split.constBegin(); it != splitEnd; ++it) { for (auto it = split.constBegin(); it != splitEnd; ++it) {
QString packageName = qmt::NameController::convertFileNameToElementName(Utils::FilePath::fromString(*it)); QString packageName = qmt::NameController::convertFileNameToElementName(FilePath::fromString(*it));
relativeElements.append(packageName); relativeElements.append(packageName);
} }
return relativeElements; return relativeElements;

View File

@@ -6,11 +6,11 @@
#include "dvisitor.h" #include "dvisitor.h"
#include "dconstvisitor.h" #include "dconstvisitor.h"
using Utils::FilePath;
namespace qmt { namespace qmt {
DObject::DObject() DObject::DObject() {}
{
}
DObject::DObject(const DObject &rhs) DObject::DObject(const DObject &rhs)
: DElement(rhs), : DElement(rhs),
@@ -129,7 +129,7 @@ bool DObject::hasImage() const
return !m_image.isNull(); return !m_image.isNull();
} }
void DObject::setImagePath(const QString &path) void DObject::setImagePath(const FilePath &path)
{ {
m_imagePath = path; m_imagePath = path;
} }

View File

@@ -7,6 +7,8 @@
#include "qmt/infrastructure/uid.h" #include "qmt/infrastructure/uid.h"
#include <utils/filepath.h>
#include <QImage> #include <QImage>
#include <QList> #include <QList>
#include <QPointF> #include <QPointF>
@@ -81,8 +83,8 @@ public:
void setVisualEmphasized(bool visualEmphasized); void setVisualEmphasized(bool visualEmphasized);
bool hasLinkedFile() const { return m_hasLinkedFile; } bool hasLinkedFile() const { return m_hasLinkedFile; }
void setLinkedFile(bool linkedFile); void setLinkedFile(bool linkedFile);
QString imagePath() const { return m_imagePath; } Utils::FilePath imagePath() const { return m_imagePath; }
void setImagePath(const QString &path); void setImagePath(const Utils::FilePath &path);
bool hasImage() const; bool hasImage() const;
QImage image() const { return m_image; } QImage image() const { return m_image; }
void setImage(const QImage &image); void setImage(const QImage &image);
@@ -104,7 +106,7 @@ private:
bool m_isAutoSized = true; bool m_isAutoSized = true;
bool m_isVisualEmphasized = false; bool m_isVisualEmphasized = false;
bool m_hasLinkedFile = false; bool m_hasLinkedFile = false;
QString m_imagePath; Utils::FilePath m_imagePath;
QImage m_image; QImage m_image;
}; };

View File

@@ -32,6 +32,8 @@
#include "../../modelinglibtr.h" #include "../../modelinglibtr.h"
using Utils::FilePath;
namespace qmt { namespace qmt {
DocumentController::DocumentController(QObject *parent) : DocumentController::DocumentController(QObject *parent) :
@@ -231,7 +233,7 @@ MDiagram *DocumentController::findOrCreateRootDiagram()
return rootDiagram; return rootDiagram;
} }
void DocumentController::createNewProject(const Utils::FilePath &fileName) void DocumentController::createNewProject(const FilePath &fileName)
{ {
m_diagramsManager->removeAllDiagrams(); m_diagramsManager->removeAllDiagrams();
m_treeModel->setModelController(nullptr); m_treeModel->setModelController(nullptr);
@@ -244,7 +246,7 @@ void DocumentController::createNewProject(const Utils::FilePath &fileName)
m_modelController->setRootPackage(m_projectController->project()->rootPackage()); m_modelController->setRootPackage(m_projectController->project()->rootPackage());
} }
void DocumentController::loadProject(const Utils::FilePath &fileName) void DocumentController::loadProject(const FilePath &fileName)
{ {
m_diagramsManager->removeAllDiagrams(); m_diagramsManager->removeAllDiagrams();
m_treeModel->setModelController(nullptr); m_treeModel->setModelController(nullptr);

View File

@@ -7,6 +7,8 @@
#include <QObject> #include <QObject>
using Utils::FilePath;
namespace qmt { namespace qmt {
IOException::IOException(const QString &errorMsg) IOException::IOException(const QString &errorMsg)
@@ -14,39 +16,39 @@ IOException::IOException(const QString &errorMsg)
{ {
} }
FileIOException::FileIOException(const QString &errorMsg, const Utils::FilePath &fileName, int lineNumber) FileIOException::FileIOException(const QString &errorMsg, const FilePath &fileName, int lineNumber)
: IOException(errorMsg), : IOException(errorMsg),
m_fileName(fileName), m_fileName(fileName),
m_lineNumber(lineNumber) m_lineNumber(lineNumber)
{ {
} }
FileNotFoundException::FileNotFoundException(const Utils::FilePath &fileName) FileNotFoundException::FileNotFoundException(const FilePath &fileName)
: FileIOException(Tr::tr("File not found."), fileName) : FileIOException(Tr::tr("File not found."), fileName)
{ {
} }
FileCreationException::FileCreationException(const Utils::FilePath &fileName) FileCreationException::FileCreationException(const FilePath &fileName)
: FileIOException(Tr::tr("Unable to create file."), fileName) : FileIOException(Tr::tr("Unable to create file."), fileName)
{ {
} }
FileWriteError::FileWriteError(const Utils::FilePath &fileName, int lineNumber) FileWriteError::FileWriteError(const FilePath &fileName, int lineNumber)
: FileIOException(Tr::tr("Writing to file failed."), fileName, lineNumber) : FileIOException(Tr::tr("Writing to file failed."), fileName, lineNumber)
{ {
} }
FileReadError::FileReadError(const Utils::FilePath &fileName, int lineNumber) FileReadError::FileReadError(const FilePath &fileName, int lineNumber)
: FileIOException(Tr::tr("Reading from file failed."), fileName, lineNumber) : FileIOException(Tr::tr("Reading from file failed."), fileName, lineNumber)
{ {
} }
IllegalXmlFile::IllegalXmlFile(const Utils::FilePath &fileName, int lineNumber) IllegalXmlFile::IllegalXmlFile(const FilePath &fileName, int lineNumber)
: FileIOException(Tr::tr("Illegal XML file."), fileName, lineNumber) : FileIOException(Tr::tr("Illegal XML file."), fileName, lineNumber)
{ {
} }
UnknownFileVersion::UnknownFileVersion(int version, const Utils::FilePath &fileName, int lineNumber) UnknownFileVersion::UnknownFileVersion(int version, const FilePath &fileName, int lineNumber)
: FileIOException(Tr::tr("Unable to handle file version %1.") : FileIOException(Tr::tr("Unable to handle file version %1.")
.arg(version), fileName, lineNumber) .arg(version), fileName, lineNumber)
{ {

View File

@@ -8,6 +8,8 @@
#include "mvisitor.h" #include "mvisitor.h"
#include "mconstvisitor.h" #include "mconstvisitor.h"
using Utils::FilePath;
namespace qmt { namespace qmt {
MObject::MObject() MObject::MObject()
@@ -46,7 +48,7 @@ void MObject::setName(const QString &name)
m_name = name; m_name = name;
} }
void MObject::setLinkedFileName(const QString &linkedfilename) void MObject::setLinkedFileName(const FilePath &linkedfilename)
{ {
m_linkedfilename = linkedfilename; m_linkedfilename = linkedfilename;
} }

View File

@@ -6,6 +6,8 @@
#include "melement.h" #include "melement.h"
#include "qmt/infrastructure/handles.h" #include "qmt/infrastructure/handles.h"
#include <utils/filepath.h>
#include <QString> #include <QString>
namespace qmt { namespace qmt {
@@ -23,8 +25,8 @@ public:
QString name() const { return m_name; } QString name() const { return m_name; }
void setName(const QString &name); void setName(const QString &name);
QString linkedFileName() const { return m_linkedfilename; } Utils::FilePath linkedFileName() const { return m_linkedfilename; }
void setLinkedFileName(const QString &linkedfilename); void setLinkedFileName(const Utils::FilePath &linkedfilename);
const Handles<MObject> &children() const { return m_children; } const Handles<MObject> &children() const { return m_children; }
void setChildren(const Handles<MObject> &children); void setChildren(const Handles<MObject> &children);
@@ -50,7 +52,7 @@ public:
private: private:
QString m_name; QString m_name;
QString m_linkedfilename; Utils::FilePath m_linkedfilename;
Handles<MObject> m_children; Handles<MObject> m_children;
Handles<MRelation> m_relations; Handles<MRelation> m_relations;
}; };

View File

@@ -30,6 +30,8 @@
#include <QStandardItem> #include <QStandardItem>
using Utils::FilePath;
namespace qmt { namespace qmt {
class TreeModel::ModelItem : public QStandardItem class TreeModel::ModelItem : public QStandardItem
@@ -807,7 +809,7 @@ QString TreeModel::createRelationLabel(const MRelation *relation)
} }
QIcon TreeModel::createIcon(StereotypeIcon::Element stereotypeIconElement, StyleEngine::ElementType styleElementType, QIcon TreeModel::createIcon(StereotypeIcon::Element stereotypeIconElement, StyleEngine::ElementType styleElementType,
const QStringList &stereotypes, const QString &defaultIconPath) const QStringList &stereotypes, const FilePath &defaultIconPath)
{ {
const Style *style = m_styleController->adaptStyle(styleElementType); const Style *style = m_styleController->adaptStyle(styleElementType);
return m_stereotypeController->createIcon(stereotypeIconElement, stereotypes, defaultIconPath, style, return m_stereotypeController->createIcon(stereotypeIconElement, stereotypes, defaultIconPath, style,

View File

@@ -9,6 +9,8 @@
#include <qmt/stereotype/stereotypeicon.h> #include <qmt/stereotype/stereotypeicon.h>
#include <qmt/style/styleengine.h> #include <qmt/style/styleengine.h>
#include <utils/filepath.h>
#include <QScopedPointer> #include <QScopedPointer>
#include <QHash> #include <QHash>
@@ -93,8 +95,9 @@ private:
QString createObjectLabel(const MObject *object); QString createObjectLabel(const MObject *object);
QString createRelationLabel(const MRelation *relation); QString createRelationLabel(const MRelation *relation);
QIcon createIcon(StereotypeIcon::Element stereotypeIconElement, QIcon createIcon(StereotypeIcon::Element stereotypeIconElement,
StyleEngine::ElementType styleElementType, const QStringList &stereotypes, StyleEngine::ElementType styleElementType,
const QString &defaultIconPath); const QStringList &stereotypes,
const Utils::FilePath &defaultIconPath);
enum Busy { enum Busy {
NotBusy, NotBusy,

View File

@@ -3,6 +3,8 @@
#include "project.h" #include "project.h"
using Utils::FilePath;
namespace qmt { namespace qmt {
Project::Project() Project::Project()
@@ -23,7 +25,7 @@ bool Project::hasFileName() const
return !m_fileName.isEmpty(); return !m_fileName.isEmpty();
} }
void Project::setFileName(const Utils::FilePath &fileName) void Project::setFileName(const FilePath &fileName)
{ {
m_fileName = fileName; m_fileName = fileName;
} }
@@ -33,7 +35,7 @@ void Project::setRootPackage(MPackage *rootPackage)
m_rootPackage = rootPackage; m_rootPackage = rootPackage;
} }
void Project::setConfigPath(const Utils::FilePath &configPath) void Project::setConfigPath(const FilePath &configPath)
{ {
m_configPath = configPath; m_configPath = configPath;
} }

View File

@@ -10,6 +10,8 @@
#include "../../modelinglibtr.h" #include "../../modelinglibtr.h"
using Utils::FilePath;
namespace qmt { namespace qmt {
NoFileNameException::NoFileNameException() NoFileNameException::NoFileNameException()
@@ -31,7 +33,7 @@ ProjectController::~ProjectController()
{ {
} }
void ProjectController::newProject(const Utils::FilePath &fileName) void ProjectController::newProject(const FilePath &fileName)
{ {
m_project.reset(new Project()); m_project.reset(new Project());
auto rootPackage = new MPackage(); auto rootPackage = new MPackage();
@@ -43,7 +45,7 @@ void ProjectController::newProject(const Utils::FilePath &fileName)
emit changed(); emit changed();
} }
void ProjectController::setFileName(const Utils::FilePath &fileName) void ProjectController::setFileName(const FilePath &fileName)
{ {
if (fileName != m_project->fileName()) { if (fileName != m_project->fileName()) {
m_project->setFileName(fileName); m_project->setFileName(fileName);
@@ -82,7 +84,7 @@ void ProjectController::save()
emit changed(); emit changed();
} }
void ProjectController::saveAs(const Utils::FilePath &fileName) void ProjectController::saveAs(const FilePath &fileName)
{ {
setFileName(fileName); setFileName(fileName);
save(); save();

View File

@@ -58,7 +58,7 @@ inline void serialize(Archive &archive, qmt::Handles<T> &handles)
template<class Archive> template<class Archive>
inline void save(Archive &archive, const Utils::FilePath &filePath) inline void save(Archive &archive, const Utils::FilePath &filePath)
{ {
archive.write(filePath.toString()); archive.write(filePath.toFSPathString());
} }
template<class Archive> template<class Archive>
@@ -66,7 +66,7 @@ inline void load(Archive &archive, Utils::FilePath &filePath)
{ {
QString s; QString s;
archive.read(&s); archive.read(&s);
filePath = Utils::FilePath::fromString(s); filePath = Utils::FilePath::fromUserInput(s);
} }
} // namespace qark } // namespace qark

View File

@@ -20,6 +20,8 @@
#include <QFile> #include <QFile>
using Utils::FilePath;
namespace qark { namespace qark {
using namespace qmt; using namespace qmt;
@@ -48,11 +50,11 @@ ProjectSerializer::~ProjectSerializer()
{ {
} }
void ProjectSerializer::save(const Utils::FilePath &fileName, const Project *project) void ProjectSerializer::save(const FilePath &fileName, const Project *project)
{ {
QMT_ASSERT(project, return); QMT_ASSERT(project, return);
QFile file(fileName.toString()); QFile file(fileName.toFSPathString());
if (!file.open(QIODevice::WriteOnly)) if (!file.open(QIODevice::WriteOnly))
throw FileCreationException(fileName); throw FileCreationException(fileName);
@@ -84,11 +86,11 @@ QByteArray ProjectSerializer::save(const Project *project)
return buffer; return buffer;
} }
void ProjectSerializer::load(const Utils::FilePath &fileName, Project *project) void ProjectSerializer::load(const FilePath &fileName, Project *project)
{ {
QMT_ASSERT(project, return); QMT_ASSERT(project, return);
QFile file(fileName.toString()); QFile file(fileName.toFSPathString());
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
throw FileNotFoundException(fileName); throw FileNotFoundException(fileName);

View File

@@ -10,6 +10,8 @@
#include "qmt/infrastructure/qmtassert.h" #include "qmt/infrastructure/qmtassert.h"
#include "qmt/style/style.h" #include "qmt/style/style.h"
#include <utils/filepath.h>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <QHash> #include <QHash>
@@ -19,12 +21,14 @@
#include <algorithm> #include <algorithm>
using Utils::FilePath;
namespace qmt { namespace qmt {
namespace { namespace {
struct IconKey { struct IconKey {
IconKey(StereotypeIcon::Element element, const QList<QString> &stereotypes, const QString &defaultIconPath, IconKey(StereotypeIcon::Element element, const QList<QString> &stereotypes, const FilePath &defaultIconPath,
const Uid &styleUid, const QSize &size, const QMarginsF &margins, qreal lineWidth) const Uid &styleUid, const QSize &size, const QMarginsF &margins, qreal lineWidth)
: m_element(element), : m_element(element),
m_stereotypes(stereotypes), m_stereotypes(stereotypes),
@@ -53,7 +57,7 @@ struct IconKey {
const StereotypeIcon::Element m_element; const StereotypeIcon::Element m_element;
const QList<QString> m_stereotypes; const QList<QString> m_stereotypes;
const QString m_defaultIconPath; const FilePath m_defaultIconPath;
const Uid m_styleUid; const Uid m_styleUid;
const QSize m_size; const QSize m_size;
const QMarginsF m_margins; const QMarginsF m_margins;
@@ -157,7 +161,7 @@ CustomRelation StereotypeController::findCustomRelationByStereotype(const QStrin
} }
QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QList<QString> &stereotypes, QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QList<QString> &stereotypes,
const QString &defaultIconPath, const Style *style, const QSize &size, const FilePath &defaultIconPath, const Style *style, const QSize &size,
const QMarginsF &margins, qreal lineWidth) const QMarginsF &margins, qreal lineWidth)
{ {
IconKey key(element, stereotypes, defaultIconPath, style->uid(), size, margins, lineWidth); IconKey key(element, stereotypes, defaultIconPath, style->uid(), size, margins, lineWidth);
@@ -231,7 +235,7 @@ QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QL
icon = QIcon(pixmap); icon = QIcon(pixmap);
} }
if (icon.isNull() && !defaultIconPath.isEmpty()) if (icon.isNull() && !defaultIconPath.isEmpty())
icon = QIcon(defaultIconPath); icon = QIcon(defaultIconPath.toFSPathString());
d->m_iconMap.insert(key, icon); d->m_iconMap.insert(key, icon);
return icon; return icon;

View File

@@ -5,6 +5,8 @@
#include "stereotypeicon.h" #include "stereotypeicon.h"
#include <utils/filepath.h>
#include <QMarginsF> #include <QMarginsF>
#include <QObject> #include <QObject>
@@ -34,9 +36,13 @@ public:
StereotypeIcon findStereotypeIcon(const QString &stereotypeIconId) const; StereotypeIcon findStereotypeIcon(const QString &stereotypeIconId) const;
CustomRelation findCustomRelation(const QString &customRelationId) const; CustomRelation findCustomRelation(const QString &customRelationId) const;
CustomRelation findCustomRelationByStereotype(const QString &steoreotype) const; CustomRelation findCustomRelationByStereotype(const QString &steoreotype) const;
QIcon createIcon(StereotypeIcon::Element element, const QList<QString> &stereotypes, QIcon createIcon(StereotypeIcon::Element element,
const QString &defaultIconPath, const Style *style, const QList<QString> &stereotypes,
const QSize &size, const QMarginsF &margins, qreal lineWidth); const Utils::FilePath &defaultIconPath,
const Style *style,
const QSize &size,
const QMarginsF &margins,
qreal lineWidth);
void addStereotypeIcon(const StereotypeIcon &stereotypeIcon); void addStereotypeIcon(const StereotypeIcon &stereotypeIcon);
void addCustomRelation(const CustomRelation &customRelation); void addCustomRelation(const CustomRelation &customRelation);

View File

@@ -31,6 +31,7 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
using Utils::FilePath;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -52,9 +53,9 @@ private:
void FindComponentFromFilePath::setFilePath(const QString &filePath) void FindComponentFromFilePath::setFilePath(const QString &filePath)
{ {
m_elementName = qmt::NameController::convertFileNameToElementName(Utils::FilePath::fromString(filePath)); m_elementName = qmt::NameController::convertFileNameToElementName(FilePath::fromString(filePath));
QFileInfo fileInfo(filePath); QFileInfo fileInfo(filePath);
m_elementsPath = qmt::NameController::buildElementsPath(Utils::FilePath::fromString(fileInfo.path()), false); m_elementsPath = qmt::NameController::buildElementsPath(FilePath::fromString(fileInfo.path()), false);
} }
void FindComponentFromFilePath::visitMComponent(qmt::MComponent *component) void FindComponentFromFilePath::visitMComponent(qmt::MComponent *component)
@@ -154,7 +155,7 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen
if (document) { if (document) {
const QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes(); const QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes();
for (const CPlusPlus::Document::Include &include : includes) { for (const CPlusPlus::Document::Include &include : includes) {
Utils::FilePath includeFilePath = include.resolvedFileName(); FilePath includeFilePath = include.resolvedFileName();
// replace proxy header with real one // replace proxy header with real one
CPlusPlus::Document::Ptr includeDocument = snapshot.document(includeFilePath); CPlusPlus::Document::Ptr includeDocument = snapshot.document(includeFilePath);
if (includeDocument) { if (includeDocument) {
@@ -221,7 +222,7 @@ void UpdateIncludeDependenciesVisitor::collectElementPaths(const ProjectExplorer
QString elementName = qmt::NameController::convertFileNameToElementName(fileNode->filePath()); QString elementName = qmt::NameController::convertFileNameToElementName(fileNode->filePath());
QFileInfo fileInfo = fileNode->filePath().toFileInfo(); QFileInfo fileInfo = fileNode->filePath().toFileInfo();
QString nodePath = fileInfo.path(); QString nodePath = fileInfo.path();
QStringList elementsPath = qmt::NameController::buildElementsPath(Utils::FilePath::fromString(nodePath), false); QStringList elementsPath = qmt::NameController::buildElementsPath(FilePath::fromString(nodePath), false);
filePathsMap->insert(elementName, Node(fileNode->filePath().toString(), elementsPath)); filePathsMap->insert(elementName, Node(fileNode->filePath().toString(), elementsPath));
}); });
folderNode->forEachFolderNode([&](FolderNode *subNode) { folderNode->forEachFolderNode([&](FolderNode *subNode) {
@@ -309,7 +310,7 @@ void ComponentViewController::doCreateComponentModel(const QString &filePath, qm
{ {
for (const QString &fileName : QDir(filePath).entryList(QDir::Files)) { for (const QString &fileName : QDir(filePath).entryList(QDir::Files)) {
QString file = filePath + "/" + fileName; QString file = filePath + "/" + fileName;
QString componentName = qmt::NameController::convertFileNameToElementName(Utils::FilePath::fromString(file)); QString componentName = qmt::NameController::convertFileNameToElementName(FilePath::fromString(file));
qmt::MComponent *component = nullptr; qmt::MComponent *component = nullptr;
bool isSource = false; bool isSource = false;
CppEditor::ProjectFile::Kind kind = CppEditor::ProjectFile::classify(file); CppEditor::ProjectFile::Kind kind = CppEditor::ProjectFile::classify(file);
@@ -341,7 +342,7 @@ void ComponentViewController::doCreateComponentModel(const QString &filePath, qm
} }
if (component) { if (component) {
QStringList relativeElements = qmt::NameController::buildElementsPath( QStringList relativeElements = qmt::NameController::buildElementsPath(
Utils::FilePath::fromString(d->pxnodeUtilities->calcRelativePath(file, anchorFolder)), false); FilePath::fromString(d->pxnodeUtilities->calcRelativePath(file, anchorFolder)), false);
if (d->pxnodeUtilities->findSameObject(relativeElements, component)) { if (d->pxnodeUtilities->findSameObject(relativeElements, component)) {
delete component; delete component;
} else { } else {

View File

@@ -40,6 +40,7 @@
using namespace Core; using namespace Core;
using namespace CppEditor; using namespace CppEditor;
using Utils::FilePath;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -401,11 +402,11 @@ void ElementTasks::createAndOpenDiagram(const qmt::DElement *element, const qmt:
createAndOpenDiagram(melement); createAndOpenDiagram(melement);
} }
Utils::FilePath ElementTasks::linkedFile(const qmt::MObject *mobject) const FilePath ElementTasks::linkedFile(const qmt::MObject *mobject) const
{ {
Utils::FilePath filepath = Utils::FilePath::fromString(mobject->linkedFileName()); FilePath filepath = mobject->linkedFileName();
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
Utils::FilePath projectName = d->documentController->projectController()->project()->fileName(); FilePath projectName = d->documentController->projectController()->project()->fileName();
filepath = projectName.absolutePath().resolvePath(filepath).canonicalPath(); filepath = projectName.absolutePath().resolvePath(filepath).canonicalPath();
} }
return filepath; return filepath;
@@ -414,7 +415,7 @@ Utils::FilePath ElementTasks::linkedFile(const qmt::MObject *mobject) const
bool ElementTasks::hasLinkedFile(const qmt::MElement *element) const bool ElementTasks::hasLinkedFile(const qmt::MElement *element) const
{ {
if (auto mobject = dynamic_cast<const qmt::MObject *>(element)) { if (auto mobject = dynamic_cast<const qmt::MObject *>(element)) {
Utils::FilePath filepath = linkedFile(mobject); FilePath filepath = linkedFile(mobject);
if (!filepath.isEmpty()) if (!filepath.isEmpty())
return filepath.exists(); return filepath.exists();
} }
@@ -434,16 +435,16 @@ bool ElementTasks::hasLinkedFile(const qmt::DElement *element, const qmt::MDiagr
void ElementTasks::openLinkedFile(const qmt::MElement *element) void ElementTasks::openLinkedFile(const qmt::MElement *element)
{ {
if (auto mobject = dynamic_cast<const qmt::MObject *>(element)) { if (auto mobject = dynamic_cast<const qmt::MObject *>(element)) {
Utils::FilePath filepath = linkedFile(mobject); FilePath filepath = linkedFile(mobject);
if (!filepath.isEmpty()) { if (!filepath.isEmpty()) {
if (filepath.exists()) { if (filepath.exists()) {
Core::EditorFactories list = Core::IEditorFactory::preferredEditorFactories(filepath); Core::EditorFactories list = Core::IEditorFactory::preferredEditorFactories(filepath);
if (list.empty() || (list.count() <= 1 && list.at(0)->id() == "Core.BinaryEditor")) { if (list.empty() || (list.count() <= 1 && list.at(0)->id() == "Core.BinaryEditor")) {
// intentionally ignore return code // intentionally ignore return code
(void) Core::EditorManager::instance()->openExternalEditor(filepath, "CorePlugin.OpenWithSystemEditor"); (void) Core::EditorManager::openExternalEditor(filepath, "CorePlugin.OpenWithSystemEditor");
} else { } else {
// intentionally ignore return code // intentionally ignore return code
(void) Core::EditorManager::instance()->openEditor(filepath); (void) Core::EditorManager::openEditor(filepath);
} }
} else { } else {
QMessageBox::critical(Core::ICore::dialogParent(), Tr::tr("Opening File"), QMessageBox::critical(Core::ICore::dialogParent(), Tr::tr("Opening File"),

View File

@@ -9,6 +9,8 @@
#include "qmt/project_controller/projectcontroller.h" #include "qmt/project_controller/projectcontroller.h"
#include "qmt/tasks/diagramscenecontroller.h" #include "qmt/tasks/diagramscenecontroller.h"
using Utils::FilePath;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -49,7 +51,7 @@ PxNodeController *ExtDocumentController::pxNodeController() const
return d->pxNodeController; return d->pxNodeController;
} }
void ExtDocumentController::onProjectFileNameChanged(const Utils::FilePath &fileName) void ExtDocumentController::onProjectFileNameChanged(const FilePath &fileName)
{ {
d->pxNodeController->setAnchorFolder(fileName.path()); d->pxNodeController->setAnchorFolder(fileName.path());
} }

View File

@@ -21,6 +21,8 @@
#include <QMimeDatabase> #include <QMimeDatabase>
#include <QImageReader> #include <QImageReader>
using Utils::FilePath;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -52,7 +54,7 @@ static QString imageNameFilterString()
/// Constructs an absolute FilePath from \a relativePath which /// Constructs an absolute FilePath from \a relativePath which
/// is interpreted as being relative to \a anchor. /// is interpreted as being relative to \a anchor.
Utils::FilePath absoluteFromRelativePath(const Utils::FilePath &relativePath, FilePath absoluteFromRelativePath(const Utils::FilePath &relativePath,
const Utils::FilePath &anchor) const Utils::FilePath &anchor)
{ {
QDir anchorDir = QFileInfo(anchor.path()).absoluteDir(); QDir anchorDir = QFileInfo(anchor.path()).absoluteDir();
@@ -122,13 +124,13 @@ void ExtPropertiesMView::visitMObjectBehind(const qmt::MObject *object)
} }
if (isSingleSelection) { if (isSingleSelection) {
if (!m_filelinkPathChooser->hasFocus()) { if (!m_filelinkPathChooser->hasFocus()) {
QString path = object->linkedFileName(); Utils::FilePath path = object->linkedFileName();
if (path.isEmpty()) { if (path.isEmpty()) {
m_filelinkPathChooser->setPath(QString()); m_filelinkPathChooser->setPath(QString());
} else { } else {
Utils::FilePath relativePath = Utils::FilePath::fromString(path); Utils::FilePath relativePath = path;
Utils::FilePath projectPath = project->fileName(); Utils::FilePath projectPath = project->fileName();
QString filePath = absoluteFromRelativePath(relativePath, projectPath).toString(); QString filePath = absoluteFromRelativePath(relativePath, projectPath).toFSPathString();
m_filelinkPathChooser->setPath(filePath); m_filelinkPathChooser->setPath(filePath);
} }
} }
@@ -157,12 +159,12 @@ void ExtPropertiesMView::visitDObjectBefore(const qmt::DObject *object)
} }
if (isSingleSelection) { if (isSingleSelection) {
if (!m_imagePathChooser->hasFocus()) { if (!m_imagePathChooser->hasFocus()) {
QString path = object->imagePath(); Utils::FilePath path = object->imagePath();
if (path.isEmpty()) { if (path.isEmpty()) {
m_imagePathChooser->setPath(QString()); m_imagePathChooser->setPath(QString());
} else { } else {
Utils::FilePath relativePath = Utils::FilePath::fromString(path); Utils::FilePath relativePath = path;
QString filePath = absoluteFromRelativePath(relativePath, project->fileName()).toString(); QString filePath = absoluteFromRelativePath(relativePath, project->fileName()).toFSPathString();
m_imagePathChooser->setPath(filePath); m_imagePathChooser->setPath(filePath);
} }
} }
@@ -202,16 +204,24 @@ void ExtPropertiesMView::onFileLinkPathChanged(const QString &path)
{ {
qmt::Project *project = m_projectController->project(); qmt::Project *project = m_projectController->project();
if (path.isEmpty()) { if (path.isEmpty()) {
assignModelElement<qmt::MObject, QString>(m_modelElements, SelectionSingle, QString(), assignModelElement<qmt::MObject, Utils::FilePath>(
&qmt::MObject::linkedFileName, &qmt::MObject::setLinkedFileName); m_modelElements,
SelectionSingle,
{},
&qmt::MObject::linkedFileName,
&qmt::MObject::setLinkedFileName);
} else { } else {
// make path relative to current project's directory // make path relative to current project's directory
Utils::FilePath filePath = Utils::FilePath::fromString(path); Utils::FilePath filePath = Utils::FilePath::fromString(path);
Utils::FilePath projectPath = project->fileName().absolutePath(); Utils::FilePath projectPath = project->fileName().absolutePath();
QString relativeFilePath = filePath.relativePathFrom(projectPath).toString(); Utils::FilePath relativeFilePath = filePath.relativePathFrom(projectPath);
if (!relativeFilePath.isEmpty()) { if (!relativeFilePath.isEmpty()) {
assignModelElement<qmt::MObject, QString>(m_modelElements, SelectionSingle, relativeFilePath, assignModelElement<qmt::MObject, Utils::FilePath>(
&qmt::MObject::linkedFileName, &qmt::MObject::setLinkedFileName); m_modelElements,
SelectionSingle,
relativeFilePath,
&qmt::MObject::linkedFileName,
&qmt::MObject::setLinkedFileName);
} }
} }
} }
@@ -220,23 +230,30 @@ void ExtPropertiesMView::onImagePathChanged(const QString &path)
{ {
qmt::Project *project = m_projectController->project(); qmt::Project *project = m_projectController->project();
if (path.isEmpty()) { if (path.isEmpty()) {
assignModelElement<qmt::DObject, QString>(m_diagramElements, SelectionSingle, QString(), assignModelElement<qmt::DObject, Utils::FilePath>(
&qmt::DObject::imagePath, &qmt::DObject::setImagePath); m_diagramElements,
SelectionSingle,
{},
&qmt::DObject::imagePath,
&qmt::DObject::setImagePath);
assignModelElement<qmt::DObject, QImage>(m_diagramElements, SelectionSingle, QImage(), assignModelElement<qmt::DObject, QImage>(m_diagramElements, SelectionSingle, QImage(),
&qmt::DObject::image, &qmt::DObject::setImage); &qmt::DObject::image, &qmt::DObject::setImage);
} else { } else {
// make path relative to current project's directory // make path relative to current project's directory
Utils::FilePath filePath = Utils::FilePath::fromString(path); Utils::FilePath filePath = Utils::FilePath::fromString(path);
Utils::FilePath projectPath = project->fileName().absolutePath(); Utils::FilePath projectPath = project->fileName().absolutePath();
QString relativeFilePath = filePath.relativePathFrom(projectPath).toString(); Utils::FilePath relativeFilePath = filePath.relativePathFrom(projectPath);
if (!relativeFilePath.isEmpty() if (!relativeFilePath.isEmpty()
&& isValueChanged<qmt::DObject, QString>(m_diagramElements, SelectionSingle, relativeFilePath, && isValueChanged<qmt::DObject, Utils::FilePath>(
&qmt::DObject::imagePath)) m_diagramElements, SelectionSingle, relativeFilePath, &qmt::DObject::imagePath)) {
{
QImage image; QImage image;
if (image.load(path)) { if (image.load(path)) {
assignModelElement<qmt::DObject, QString>(m_diagramElements, SelectionSingle, relativeFilePath, assignModelElement<qmt::DObject, Utils::FilePath>(
&qmt::DObject::imagePath, &qmt::DObject::setImagePath); m_diagramElements,
SelectionSingle,
relativeFilePath,
&qmt::DObject::imagePath,
&qmt::DObject::setImagePath);
assignModelElement<qmt::DObject, QImage>(m_diagramElements, SelectionSingle, image, assignModelElement<qmt::DObject, QImage>(m_diagramElements, SelectionSingle, image,
&qmt::DObject::image, &qmt::DObject::setImage); &qmt::DObject::image, &qmt::DObject::setImage);
} else { } else {

View File

@@ -5,7 +5,9 @@
#include <qmt/controller/namecontroller.h> #include <qmt/controller/namecontroller.h>
QString ModelEditor::Internal::JsExtension::fileNameToElementName(const Utils::FilePath &file) using Utils::FilePath;
QString ModelEditor::Internal::JsExtension::fileNameToElementName(const FilePath &file)
{ {
return qmt::NameController::convertFileNameToElementName(file); return qmt::NameController::convertFileNameToElementName(file);
} }

View File

@@ -19,6 +19,8 @@
#include <utils/id.h> #include <utils/id.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
using Utils::FilePath;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -43,8 +45,8 @@ ModelDocument::~ModelDocument()
} }
Core::IDocument::OpenResult ModelDocument::open(QString *errorString, Core::IDocument::OpenResult ModelDocument::open(QString *errorString,
const Utils::FilePath &filePath, const FilePath &filePath,
const Utils::FilePath &realFilePath) const FilePath &realFilePath)
{ {
Q_UNUSED(filePath) Q_UNUSED(filePath)
@@ -52,7 +54,7 @@ Core::IDocument::OpenResult ModelDocument::open(QString *errorString,
return result; return result;
} }
bool ModelDocument::saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) bool ModelDocument::saveImpl(QString *errorString, const FilePath &filePath, bool autoSave)
{ {
if (!d->documentController) { if (!d->documentController) {
*errorString = Tr::tr("No model loaded. Cannot save."); *errorString = Tr::tr("No model loaded. Cannot save.");
@@ -117,7 +119,7 @@ ExtDocumentController *ModelDocument::documentController() const
return d->documentController; return d->documentController;
} }
Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const Utils::FilePath &fileName) Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const FilePath &fileName)
{ {
d->documentController = ModelEditorPlugin::modelsManager()->createModel(this); d->documentController = ModelEditorPlugin::modelsManager()->createModel(this);
connect(d->documentController, &qmt::DocumentController::changed, this, &IDocument::changed); connect(d->documentController, &qmt::DocumentController::changed, this, &IDocument::changed);
@@ -133,9 +135,9 @@ Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const Util
return OpenResult::CannotHandle; return OpenResult::CannotHandle;
} }
Utils::FilePath configPath = d->documentController->projectController()->project()->configPath(); FilePath configPath = d->documentController->projectController()->project()->configPath();
if (!configPath.isEmpty()) { if (!configPath.isEmpty()) {
Utils::FilePath canonicalPath =fileName.absolutePath().resolvePath(configPath); FilePath canonicalPath =fileName.absolutePath().resolvePath(configPath);
if (!canonicalPath.isEmpty()) { if (!canonicalPath.isEmpty()) {
// TODO error output on reading definition files // TODO error output on reading definition files
d->documentController->configController()->readStereotypeDefinitions(canonicalPath); d->documentController->configController()->readStereotypeDefinitions(canonicalPath);

View File

@@ -615,7 +615,7 @@ void ModelEditor::exportToImage(bool selectedElements)
QString fileName = FileUtils::getSaveFilePath( QString fileName = FileUtils::getSaveFilePath(
nullptr, nullptr,
selectedElements ? Tr::tr("Export Selected Elements") : Tr::tr("Export Diagram"), selectedElements ? Tr::tr("Export Selected Elements") : Tr::tr("Export Diagram"),
FilePath::fromString(d->lastExportDirPath), filter).toString(); FilePath::fromString(d->lastExportDirPath), filter).toFSPathString();
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
qmt::DocumentController *documentController = d->document->documentController(); qmt::DocumentController *documentController = d->document->documentController();
qmt::DiagramSceneModel *sceneModel = documentController->diagramsManager()->diagramSceneModel(diagram); qmt::DiagramSceneModel *sceneModel = documentController->diagramsManager()->diagramSceneModel(diagram);
@@ -1150,8 +1150,13 @@ void ModelEditor::initToolbars()
if (!tool.m_stereotype.isEmpty() && stereotypeIconElement != qmt::StereotypeIcon::ElementAny) { if (!tool.m_stereotype.isEmpty() && stereotypeIconElement != qmt::StereotypeIcon::ElementAny) {
const qmt::Style *style = documentController->styleController()->adaptStyle(styleEngineElementType); const qmt::Style *style = documentController->styleController()->adaptStyle(styleEngineElementType);
icon = stereotypeController->createIcon( icon = stereotypeController->createIcon(
stereotypeIconElement, {tool.m_stereotype}, stereotypeIconElement,
QString(), style, QSize(128, 128), QMarginsF(6.0, 4.0, 6.0, 8.0), 8.0); {tool.m_stereotype},
{},
style,
QSize(128, 128),
QMarginsF(6.0, 4.0, 6.0, 8.0),
8.0);
if (!icon.isNull()) { if (!icon.isNull()) {
QString stereotypeIconId = stereotypeController->findStereotypeIconId( QString stereotypeIconId = stereotypeController->findStereotypeIconId(
stereotypeIconElement, {tool.m_stereotype}); stereotypeIconElement, {tool.m_stereotype});

View File

@@ -36,6 +36,8 @@
#include <QPointer> #include <QPointer>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using Utils::FilePath;
using Utils::FilePaths;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -275,7 +277,7 @@ void ModelIndexer::IndexerThread::onFilesQueued()
qmt::ProjectSerializer projectSerializer; qmt::ProjectSerializer projectSerializer;
qmt::Project project; qmt::Project project;
try { try {
projectSerializer.load(Utils::FilePath::fromString(queuedFile.file()), &project); projectSerializer.load(FilePath::fromString(queuedFile.file()), &project);
} catch (const qmt::Exception &e) { } catch (const qmt::Exception &e) {
qWarning() << e.errorMessage(); qWarning() << e.errorMessage();
return; return;
@@ -375,13 +377,13 @@ void ModelIndexer::scanProject(ProjectExplorer::Project *project)
return; return;
// TODO harmonize following code with findFirstModel()? // TODO harmonize following code with findFirstModel()?
const Utils::FilePaths files = project->files(ProjectExplorer::Project::SourceFiles); const FilePaths files = project->files(ProjectExplorer::Project::SourceFiles);
QQueue<QueuedFile> filesQueue; QQueue<QueuedFile> filesQueue;
QSet<QueuedFile> filesSet; QSet<QueuedFile> filesSet;
const Utils::MimeType modelMimeType = Utils::mimeTypeForName(Constants::MIME_TYPE_MODEL); const Utils::MimeType modelMimeType = Utils::mimeTypeForName(Constants::MIME_TYPE_MODEL);
if (modelMimeType.isValid()) { if (modelMimeType.isValid()) {
for (const Utils::FilePath &file : files) { for (const FilePath &file : files) {
if (modelMimeType.suffixes().contains(file.completeSuffix())) { if (modelMimeType.suffixes().contains(file.completeSuffix())) {
QueuedFile queuedFile(file.toString(), project, file.lastModified()); QueuedFile queuedFile(file.toString(), project, file.lastModified());
filesQueue.append(queuedFile); filesQueue.append(queuedFile);
@@ -466,10 +468,10 @@ QString ModelIndexer::findFirstModel(ProjectExplorer::FolderNode *folderNode,
void ModelIndexer::forgetProject(ProjectExplorer::Project *project) void ModelIndexer::forgetProject(ProjectExplorer::Project *project)
{ {
const Utils::FilePaths files = project->files(ProjectExplorer::Project::SourceFiles); const FilePaths files = project->files(ProjectExplorer::Project::SourceFiles);
QMutexLocker locker(&d->indexerMutex); QMutexLocker locker(&d->indexerMutex);
for (const Utils::FilePath &file : files) { for (const FilePath &file : files) {
const QString fileString = file.toString(); const QString fileString = file.toString();
// remove file from queue // remove file from queue
QueuedFile queuedFile(fileString, project); QueuedFile queuedFile(fileString, project);

View File

@@ -41,6 +41,8 @@
#include <QTimer> #include <QTimer>
#include <QAction> #include <QAction>
using Utils::FilePath;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -236,7 +238,7 @@ void ModelsManager::onOpenDiagramFromProjectExplorer()
void ModelsManager::onOpenDefaultModel(const qmt::Uid &modelUid) void ModelsManager::onOpenDefaultModel(const qmt::Uid &modelUid)
{ {
const auto modelFile = Utils::FilePath::fromString(d->modelIndexer->findModel(modelUid)); const FilePath modelFile = FilePath::fromString(d->modelIndexer->findModel(modelUid));
if (!modelFile.isEmpty()) if (!modelFile.isEmpty())
Core::EditorManager::openEditor(modelFile); Core::EditorManager::openEditor(modelFile);
} }

View File

@@ -30,7 +30,7 @@
#include <QMenu> #include <QMenu>
#include <QQueue> #include <QQueue>
using namespace Utils; using Utils::FilePath;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -146,7 +146,7 @@ void PxNodeController::addFileSystemEntry(const QString &filePath, int line, int
{ {
QMT_ASSERT(diagram, return); QMT_ASSERT(diagram, return);
QString elementName = qmt::NameController::convertFileNameToElementName(Utils::FilePath::fromString(filePath)); QString elementName = qmt::NameController::convertFileNameToElementName(FilePath::fromString(filePath));
QFileInfo fileInfo(filePath); QFileInfo fileInfo(filePath);
if (fileInfo.exists() && fileInfo.isFile()) { if (fileInfo.exists() && fileInfo.isFile()) {
@@ -212,7 +212,7 @@ qmt::MDiagram *PxNodeController::findDiagramForExplorerNode(const ProjectExplore
return nullptr; return nullptr;
QStringList relativeElements = qmt::NameController::buildElementsPath( QStringList relativeElements = qmt::NameController::buildElementsPath(
Utils::FilePath::fromString(d->pxnodeUtilities->calcRelativePath(node, d->anchorFolder)), false); FilePath::fromString(d->pxnodeUtilities->calcRelativePath(node, d->anchorFolder)), false);
QQueue<qmt::MPackage *> roots; QQueue<qmt::MPackage *> roots;
roots.append(d->diagramSceneController->modelController()->rootPackage()); roots.append(d->diagramSceneController->modelController()->rootPackage());
@@ -322,7 +322,7 @@ void PxNodeController::onMenuActionTriggered(PxNodeController::MenuAction *actio
package->setStereotypes({action->stereotype}); package->setStereotypes({action->stereotype});
d->diagramSceneController->modelController()->undoController()->beginMergeSequence(Tr::tr("Create Component Model")); d->diagramSceneController->modelController()->undoController()->beginMergeSequence(Tr::tr("Create Component Model"));
QStringList relativeElements = qmt::NameController::buildElementsPath( QStringList relativeElements = qmt::NameController::buildElementsPath(
Utils::FilePath::fromString(d->pxnodeUtilities->calcRelativePath(filePath, d->anchorFolder)), true); FilePath::fromString(d->pxnodeUtilities->calcRelativePath(filePath, d->anchorFolder)), true);
if (qmt::MObject *existingObject = d->pxnodeUtilities->findSameObject(relativeElements, package)) { if (qmt::MObject *existingObject = d->pxnodeUtilities->findSameObject(relativeElements, package)) {
delete package; delete package;
package = dynamic_cast<qmt::MPackage *>(existingObject); package = dynamic_cast<qmt::MPackage *>(existingObject);
@@ -346,8 +346,8 @@ void PxNodeController::onMenuActionTriggered(PxNodeController::MenuAction *actio
item->setName(action->elementName); item->setName(action->elementName);
item->setVariety(action->stereotype); item->setVariety(action->stereotype);
item->setVarietyEditable(false); item->setVarietyEditable(false);
Utils::FilePath filePath = Utils::FilePath::fromString(action->filePath); FilePath filePath = FilePath::fromString(action->filePath);
item->setLinkedFileName(filePath.relativePathFrom(Utils::FilePath::fromString(d->anchorFolder)).toString()); item->setLinkedFileName(filePath.relativePathFrom(FilePath::fromString(d->anchorFolder)));
newObject = item; newObject = item;
dropInCurrentDiagram = true; dropInCurrentDiagram = true;
break; break;
@@ -363,7 +363,7 @@ void PxNodeController::onMenuActionTriggered(PxNodeController::MenuAction *actio
} else { } else {
qmt::MObject *parentForDiagram = nullptr; qmt::MObject *parentForDiagram = nullptr;
QStringList relativeElements = qmt::NameController::buildElementsPath( QStringList relativeElements = qmt::NameController::buildElementsPath(
Utils::FilePath::fromString( FilePath::fromString(
d->pxnodeUtilities->calcRelativePath(filePath, d->anchorFolder)), d->pxnodeUtilities->calcRelativePath(filePath, d->anchorFolder)),
dynamic_cast<qmt::MPackage *>(newObject) != nullptr); dynamic_cast<qmt::MPackage *>(newObject) != nullptr);
if (qmt::MObject *existingObject = d->pxnodeUtilities->findSameObject(relativeElements, newObject)) { if (qmt::MObject *existingObject = d->pxnodeUtilities->findSameObject(relativeElements, newObject)) {

View File

@@ -20,6 +20,8 @@
#include <typeinfo> #include <typeinfo>
using Utils::FilePath;
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -51,8 +53,8 @@ QString PxNodeUtilities::calcRelativePath(const ProjectExplorer::Node *node,
? node->filePath().toFileInfo().path() ? node->filePath().toFileInfo().path()
: node->filePath().toString(); : node->filePath().toString();
return qmt::NameController::calcRelativePath(Utils::FilePath::fromString(nodePath), return qmt::NameController::calcRelativePath(FilePath::fromString(nodePath),
Utils::FilePath::fromString(anchorFolder)).toString(); FilePath::fromString(anchorFolder)).toString();
} }
QString PxNodeUtilities::calcRelativePath(const QString &filePath, const QString &anchorFolder) QString PxNodeUtilities::calcRelativePath(const QString &filePath, const QString &anchorFolder)
@@ -64,8 +66,8 @@ QString PxNodeUtilities::calcRelativePath(const QString &filePath, const QString
path = fileInfo.path(); path = fileInfo.path();
else else
path = filePath; path = filePath;
return qmt::NameController::calcRelativePath(Utils::FilePath::fromString(path), return qmt::NameController::calcRelativePath(FilePath::fromString(path),
Utils::FilePath::fromString(anchorFolder)).toString(); FilePath::fromString(anchorFolder)).toString();
} }
qmt::MPackage *PxNodeUtilities::createBestMatchingPackagePath( qmt::MPackage *PxNodeUtilities::createBestMatchingPackagePath(
@@ -220,7 +222,7 @@ bool PxNodeUtilities::isProxyHeader(const QString &file) const
{ {
CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::snapshot(); CPlusPlus::Snapshot snapshot = CppEditor::CppModelManager::snapshot();
CPlusPlus::Document::Ptr document = snapshot.document(Utils::FilePath::fromString(file)); CPlusPlus::Document::Ptr document = snapshot.document(FilePath::fromString(file));
if (document) { if (document) {
QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes(); QList<CPlusPlus::Document::Include> includes = document->resolvedIncludes();
if (includes.count() != 1) if (includes.count() != 1)