ModelEditor: Use Utils::FilePath

More replacements of QString with Utils::FilePath and removal of
QFileInfo and QDir will follow.

Change-Id: Iceec1c009c562bd9a05f9ab1d1a9f83ad48a4467
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jochen Becher
2024-05-05 19:40:09 +02:00
parent 99acd3247f
commit 76f2b6d5e1
31 changed files with 191 additions and 164 deletions

View File

@@ -9,11 +9,8 @@
#include "qmt/stereotype/stereotypecontroller.h" #include "qmt/stereotype/stereotypecontroller.h"
#include <QDir>
#include <QFileInfo>
#include <QFile>
#include <QDebug> #include <QDebug>
#include <QFile>
namespace qmt { namespace qmt {
@@ -39,7 +36,7 @@ void ConfigController::setStereotypeController(StereotypeController *stereotypeC
d->m_stereotypeController = stereotypeController; d->m_stereotypeController = stereotypeController;
} }
void ConfigController::readStereotypeDefinitions(const QString &path) void ConfigController::readStereotypeDefinitions(const Utils::FilePath &path)
{ {
if (path.isEmpty()) { if (path.isEmpty()) {
// TODO add error handling // TODO add error handling
@@ -54,22 +51,17 @@ void ConfigController::readStereotypeDefinitions(const QString &path)
connect(&parser, &StereotypeDefinitionParser::toolbarParsed, connect(&parser, &StereotypeDefinitionParser::toolbarParsed,
this, &ConfigController::onToolbarParsed); this, &ConfigController::onToolbarParsed);
QStringList fileNames; Utils::FilePaths paths;
QDir dir; if (path.isFile()) {
QFileInfo fileInfo(path); paths.append(path);
if (fileInfo.isFile()) { } else if (path.isDir()) {
dir.setPath(fileInfo.path()); paths = path.dirEntries({ { "*.def" } });
fileNames.append(fileInfo.fileName());
} else if (fileInfo.isDir()) {
dir.setPath(path);
dir.setNameFilters(QStringList("*.def"));
fileNames = dir.entryList(QDir::Files);
} else { } else {
// TODO add error handling // TODO add error handling
return; return;
} }
for (const QString &fileName : std::as_const(fileNames)) { for (const auto &filePath : std::as_const(paths)) {
QFile file(QFileInfo(dir, fileName).absoluteFilePath()); QFile file(filePath.toString());
if (file.open(QIODevice::ReadOnly)) { if (file.open(QIODevice::ReadOnly)) {
QString text = QString::fromUtf8(file.readAll()); QString text = QString::fromUtf8(file.readAll());
file.close(); file.close();

View File

@@ -5,6 +5,8 @@
#include "qmt/infrastructure/qmt_global.h" #include "qmt/infrastructure/qmt_global.h"
#include <utils/filepath.h>
#include <QObject> #include <QObject>
namespace qmt { namespace qmt {
@@ -24,7 +26,7 @@ public:
void setStereotypeController(StereotypeController *stereotypeController); void setStereotypeController(StereotypeController *stereotypeController);
void readStereotypeDefinitions(const QString &path); void readStereotypeDefinitions(const Utils::FilePath &path);
private: private:
void onStereotypeIconParsed(const StereotypeIcon &stereotypeIcon); void onStereotypeIconParsed(const StereotypeIcon &stereotypeIcon);

View File

@@ -3,7 +3,6 @@
#include "namecontroller.h" #include "namecontroller.h"
#include <QFileInfo>
#include <QDebug> #include <QDebug>
namespace qmt { namespace qmt {
@@ -17,10 +16,9 @@ NameController::~NameController()
{ {
} }
QString NameController::convertFileNameToElementName(const QString &fileName) QString NameController::convertFileNameToElementName(const Utils::FilePath &fileName)
{ {
QFileInfo fileInfo(fileName); QString baseName = fileName.baseName().trimmed();
QString baseName = fileInfo.baseName().trimmed();
QString elementName; QString elementName;
bool makeTitlecase = true; bool makeTitlecase = true;
bool insertSpace = false; bool insertSpace = false;
@@ -65,13 +63,19 @@ QString NameController::convertElementNameToBaseFileName(const QString &elementN
return baseFileName; return baseFileName;
} }
QString NameController::calcRelativePath(const QString &absoluteFileName, const QString &anchorPath) Utils::FilePath NameController::calcRelativePath(const Utils::FilePath &absoluteFileName,
const Utils::FilePath &anchorPath)
{ {
// TODO try using Utils::FilePath::relativePath
QString absoluteFilePath = absoluteFileName.toString();
QString anchorPathString = anchorPath.toString();
int secondLastSlashIndex = -1; int secondLastSlashIndex = -1;
int slashIndex = -1; int slashIndex = -1;
int i = 0; int i = 0;
while (i < absoluteFileName.size() && i < anchorPath.size() && absoluteFileName.at(i) == anchorPath.at(i)) { while (i < absoluteFilePath.size() && i < anchorPathString.size()
if (absoluteFileName.at(i) == QLatin1Char('/')) { && absoluteFilePath.at(i) == anchorPathString.at(i))
{
if (absoluteFilePath.at(i) == QLatin1Char('/')) {
secondLastSlashIndex = slashIndex; secondLastSlashIndex = slashIndex;
slashIndex = i; slashIndex = i;
} }
@@ -81,22 +85,22 @@ QString NameController::calcRelativePath(const QString &absoluteFileName, const
QString relativePath; QString relativePath;
if (slashIndex < 0) { if (slashIndex < 0) {
relativePath = absoluteFileName; relativePath = absoluteFilePath;
} else if (i >= absoluteFileName.size()) { } else if (i >= absoluteFilePath.size()) {
// absoluteFileName is a substring of anchor path. // absoluteFileName is a substring of anchor path.
if (slashIndex == i - 1) { if (slashIndex == i - 1) {
if (secondLastSlashIndex < 0) if (secondLastSlashIndex < 0)
relativePath = absoluteFileName; relativePath = absoluteFilePath;
else else
relativePath = absoluteFileName.mid(secondLastSlashIndex + 1); relativePath = absoluteFilePath.mid(secondLastSlashIndex + 1);
} else { } else {
relativePath = absoluteFileName.mid(slashIndex + 1); relativePath = absoluteFilePath.mid(slashIndex + 1);
} }
} else { } else {
relativePath = absoluteFileName.mid(slashIndex + 1); relativePath = absoluteFilePath.mid(slashIndex + 1);
} }
return relativePath; return Utils::FilePath::fromString(relativePath);
} }
QString NameController::calcElementNameSearchId(const QString &elementName) QString NameController::calcElementNameSearchId(const QString &elementName)
@@ -109,16 +113,17 @@ QString NameController::calcElementNameSearchId(const QString &elementName)
return searchId; return searchId;
} }
QStringList NameController::buildElementsPath(const QString &filePath, bool ignoreLastFilePathPart) QStringList NameController::buildElementsPath(const Utils::FilePath &filePath,
bool ignoreLastFilePathPart)
{ {
QList<QString> relativeElements; QList<QString> relativeElements;
QStringList split = filePath.split("/"); QStringList split = filePath.toString().split("/");
QStringList::const_iterator splitEnd = split.constEnd(); QStringList::const_iterator splitEnd = split.constEnd();
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(*it); QString packageName = qmt::NameController::convertFileNameToElementName(Utils::FilePath::fromString(*it));
relativeElements.append(packageName); relativeElements.append(packageName);
} }
return relativeElements; return relativeElements;

View File

@@ -6,6 +6,8 @@
#include <QObject> #include <QObject>
#include "qmt/infrastructure/qmt_global.h" #include "qmt/infrastructure/qmt_global.h"
#include <utils/filepath.h>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
@@ -18,12 +20,12 @@ private:
~NameController() override; ~NameController() override;
public: public:
static QString convertFileNameToElementName(const QString &fileName); static QString convertFileNameToElementName(const Utils::FilePath &fileName);
static QString convertElementNameToBaseFileName(const QString &elementName); static QString convertElementNameToBaseFileName(const QString &elementName);
// TODO use Utils::FilePath instead static Utils::FilePath calcRelativePath(const Utils::FilePath &absoluteFileName,
static QString calcRelativePath(const QString &absoluteFileName, const QString &anchorPath); const Utils::FilePath &anchorPath);
static QString calcElementNameSearchId(const QString &elementName); static QString calcElementNameSearchId(const QString &elementName);
static QStringList buildElementsPath(const QString &filePath, bool ignoreLastFilePathPart); static QStringList buildElementsPath(const Utils::FilePath &filePath, bool ignoreLastFilePathPart);
static bool parseClassName(const QString &fullClassName, QString *umlNamespace, static bool parseClassName(const QString &fullClassName, QString *umlNamespace,
QString *className, QStringList *templateParameters); QString *className, QStringList *templateParameters);
}; };

View File

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

View File

@@ -7,6 +7,8 @@
#include "qmt/infrastructure/qmt_global.h" #include "qmt/infrastructure/qmt_global.h"
#include "qmt/model_controller/modelcontroller.h" #include "qmt/model_controller/modelcontroller.h"
#include <utils/filepath.h>
namespace qmt { namespace qmt {
class ProjectController; class ProjectController;
@@ -77,8 +79,8 @@ public:
MDiagram *findRootDiagram(); MDiagram *findRootDiagram();
MDiagram *findOrCreateRootDiagram(); MDiagram *findOrCreateRootDiagram();
void createNewProject(const QString &fileName); void createNewProject(const Utils::FilePath &fileName);
void loadProject(const QString &fileName); void loadProject(const Utils::FilePath &fileName);
private: private:
ProjectController *m_projectController = nullptr; ProjectController *m_projectController = nullptr;

View File

@@ -14,39 +14,39 @@ IOException::IOException(const QString &errorMsg)
{ {
} }
FileIOException::FileIOException(const QString &errorMsg, const QString &fileName, int lineNumber) FileIOException::FileIOException(const QString &errorMsg, const Utils::FilePath &fileName, int lineNumber)
: IOException(errorMsg), : IOException(errorMsg),
m_fileName(fileName), m_fileName(fileName),
m_lineNumber(lineNumber) m_lineNumber(lineNumber)
{ {
} }
FileNotFoundException::FileNotFoundException(const QString &fileName) FileNotFoundException::FileNotFoundException(const Utils::FilePath &fileName)
: FileIOException(Tr::tr("File not found."), fileName) : FileIOException(Tr::tr("File not found."), fileName)
{ {
} }
FileCreationException::FileCreationException(const QString &fileName) FileCreationException::FileCreationException(const Utils::FilePath &fileName)
: FileIOException(Tr::tr("Unable to create file."), fileName) : FileIOException(Tr::tr("Unable to create file."), fileName)
{ {
} }
FileWriteError::FileWriteError(const QString &fileName, int lineNumber) FileWriteError::FileWriteError(const Utils::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 QString &fileName, int lineNumber) FileReadError::FileReadError(const Utils::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 QString &fileName, int lineNumber) IllegalXmlFile::IllegalXmlFile(const Utils::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 QString &fileName, int lineNumber) UnknownFileVersion::UnknownFileVersion(int version, const Utils::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

@@ -5,6 +5,8 @@
#include "exceptions.h" #include "exceptions.h"
#include <utils/filepath.h>
namespace qmt { namespace qmt {
class IOException : public Exception class IOException : public Exception
@@ -16,51 +18,51 @@ public:
class FileIOException : public IOException class FileIOException : public IOException
{ {
public: public:
explicit FileIOException(const QString &errorMsg, const QString &fileName = QString(), explicit FileIOException(const QString &errorMsg, const Utils::FilePath &fileName = {},
int lineNumber = -1); int lineNumber = -1);
QString fileName() const { return m_fileName; } Utils::FilePath fileName() const { return m_fileName; }
int lineNumber() const { return m_lineNumber; } int lineNumber() const { return m_lineNumber; }
private: private:
QString m_fileName; Utils::FilePath m_fileName;
int m_lineNumber = -1; int m_lineNumber = -1;
}; };
class FileNotFoundException : public FileIOException class FileNotFoundException : public FileIOException
{ {
public: public:
explicit FileNotFoundException(const QString &fileName); explicit FileNotFoundException(const Utils::FilePath &fileName);
}; };
class FileCreationException : public FileIOException class FileCreationException : public FileIOException
{ {
public: public:
explicit FileCreationException(const QString &fileName); explicit FileCreationException(const Utils::FilePath &fileName);
}; };
class FileWriteError : public FileIOException class FileWriteError : public FileIOException
{ {
public: public:
explicit FileWriteError(const QString &fileName, int lineNumber = -1); explicit FileWriteError(const Utils::FilePath &fileName, int lineNumber = -1);
}; };
class FileReadError : public FileIOException class FileReadError : public FileIOException
{ {
public: public:
explicit FileReadError(const QString &fileName, int lineNumber = -1); explicit FileReadError(const Utils::FilePath &fileName, int lineNumber = -1);
}; };
class IllegalXmlFile : public FileIOException class IllegalXmlFile : public FileIOException
{ {
public: public:
explicit IllegalXmlFile(const QString &fileName, int lineNumber = -1); explicit IllegalXmlFile(const Utils::FilePath &fileName, int lineNumber = -1);
}; };
class UnknownFileVersion : public FileIOException class UnknownFileVersion : public FileIOException
{ {
public: public:
UnknownFileVersion(int version, const QString &fileName, int lineNumber = -1); UnknownFileVersion(int version, const Utils::FilePath &fileName, int lineNumber = -1);
}; };
} // namespace qmt } // namespace qmt

View File

@@ -23,7 +23,7 @@ bool Project::hasFileName() const
return !m_fileName.isEmpty(); return !m_fileName.isEmpty();
} }
void Project::setFileName(const QString &fileName) void Project::setFileName(const Utils::FilePath &fileName)
{ {
m_fileName = fileName; m_fileName = fileName;
} }
@@ -33,7 +33,7 @@ void Project::setRootPackage(MPackage *rootPackage)
m_rootPackage = rootPackage; m_rootPackage = rootPackage;
} }
void Project::setConfigPath(const QString &configPath) void Project::setConfigPath(const Utils::FilePath &configPath)
{ {
m_configPath = configPath; m_configPath = configPath;
} }

View File

@@ -5,6 +5,8 @@
#include "qmt/infrastructure/uid.h" #include "qmt/infrastructure/uid.h"
#include <utils/filepath.h>
#include <QString> #include <QString>
namespace qmt { namespace qmt {
@@ -20,18 +22,18 @@ public:
Uid uid() const { return m_uid; } Uid uid() const { return m_uid; }
void setUid(const Uid &uid); void setUid(const Uid &uid);
bool hasFileName() const; bool hasFileName() const;
QString fileName() const { return m_fileName; } Utils::FilePath fileName() const { return m_fileName; }
void setFileName(const QString &fileName); void setFileName(const Utils::FilePath &fileName);
MPackage *rootPackage() const { return m_rootPackage; } MPackage *rootPackage() const { return m_rootPackage; }
void setRootPackage(MPackage *rootPackage); void setRootPackage(MPackage *rootPackage);
QString configPath() const { return m_configPath; } Utils::FilePath configPath() const { return m_configPath; }
void setConfigPath(const QString &configPath); void setConfigPath(const Utils::FilePath &configPath);
private: private:
Uid m_uid; Uid m_uid;
QString m_fileName; Utils::FilePath m_fileName;
MPackage *m_rootPackage = nullptr; MPackage *m_rootPackage = nullptr;
QString m_configPath; Utils::FilePath m_configPath;
}; };
} // namespace qmt } // namespace qmt

View File

@@ -31,7 +31,7 @@ ProjectController::~ProjectController()
{ {
} }
void ProjectController::newProject(const QString &fileName) void ProjectController::newProject(const Utils::FilePath &fileName)
{ {
m_project.reset(new Project()); m_project.reset(new Project());
auto rootPackage = new MPackage(); auto rootPackage = new MPackage();
@@ -43,7 +43,7 @@ void ProjectController::newProject(const QString &fileName)
emit changed(); emit changed();
} }
void ProjectController::setFileName(const QString &fileName) void ProjectController::setFileName(const Utils::FilePath &fileName)
{ {
if (fileName != m_project->fileName()) { if (fileName != m_project->fileName()) {
m_project->setFileName(fileName); m_project->setFileName(fileName);
@@ -82,7 +82,7 @@ void ProjectController::save()
emit changed(); emit changed();
} }
void ProjectController::saveAs(const QString &fileName) void ProjectController::saveAs(const Utils::FilePath &fileName)
{ {
setFileName(fileName); setFileName(fileName);
save(); save();

View File

@@ -6,6 +6,8 @@
#include "qmt/infrastructure/exceptions.h" #include "qmt/infrastructure/exceptions.h"
#include "qmt/infrastructure/qmt_global.h" #include "qmt/infrastructure/qmt_global.h"
#include <utils/filepath.h>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
@@ -35,19 +37,19 @@ public:
signals: signals:
void changed(); void changed();
void fileNameChanged(const QString &fileName); void fileNameChanged(const Utils::FilePath &fileName);
public: public:
Project *project() const { return m_project.data(); } Project *project() const { return m_project.data(); }
bool isModified() const { return m_isModified; } bool isModified() const { return m_isModified; }
void newProject(const QString &fileName); void newProject(const Utils::FilePath &fileName);
void setFileName(const QString &fileName); void setFileName(const Utils::FilePath &fileName);
void setModified(); void setModified();
void load(); void load();
void save(); void save();
void saveAs(const QString &fileName); void saveAs(const Utils::FilePath &fileName);
private: private:
QScopedPointer<Project> m_project; QScopedPointer<Project> m_project;

View File

@@ -3,6 +3,8 @@
#pragma once #pragma once
#include <utils/filepath.h>
#include "qmt/infrastructure/handle.h" #include "qmt/infrastructure/handle.h"
#include "qmt/infrastructure/handles.h" #include "qmt/infrastructure/handles.h"
#include "qmt/infrastructure/uid.h" #include "qmt/infrastructure/uid.h"
@@ -51,4 +53,20 @@ inline void serialize(Archive &archive, qmt::Handles<T> &handles)
|| end; || end;
} }
// Utils::FilePath
template<class Archive>
inline void save(Archive &archive, const Utils::FilePath &filePath)
{
archive.write(filePath.toString());
}
template<class Archive>
inline void load(Archive &archive, Utils::FilePath &filePath)
{
QString s;
archive.read(&s);
filePath = Utils::FilePath::fromString(s);
}
} // namespace qark } // namespace qark

View File

@@ -48,11 +48,11 @@ ProjectSerializer::~ProjectSerializer()
{ {
} }
void ProjectSerializer::save(const QString &fileName, const Project *project) void ProjectSerializer::save(const Utils::FilePath &fileName, const Project *project)
{ {
QMT_ASSERT(project, return); QMT_ASSERT(project, return);
QFile file(fileName); QFile file(fileName.toString());
if (!file.open(QIODevice::WriteOnly)) if (!file.open(QIODevice::WriteOnly))
throw FileCreationException(fileName); throw FileCreationException(fileName);
@@ -84,11 +84,11 @@ QByteArray ProjectSerializer::save(const Project *project)
return buffer; return buffer;
} }
void ProjectSerializer::load(const QString &fileName, Project *project) void ProjectSerializer::load(const Utils::FilePath &fileName, Project *project)
{ {
QMT_ASSERT(project, return); QMT_ASSERT(project, return);
QFile file(fileName); QFile file(fileName.toString());
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
throw FileNotFoundException(fileName); throw FileNotFoundException(fileName);

View File

@@ -5,6 +5,8 @@
#include "qmt/infrastructure/qmt_global.h" #include "qmt/infrastructure/qmt_global.h"
#include <utils/filepath.h>
#include <QString> #include <QString>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -21,9 +23,9 @@ public:
ProjectSerializer(); ProjectSerializer();
~ProjectSerializer(); ~ProjectSerializer();
void save(const QString &fileName, const Project *project); void save(const Utils::FilePath &fileName, const Project *project);
QByteArray save(const Project *project); QByteArray save(const Project *project);
void load(const QString &fileName, Project *project); void load(const Utils::FilePath &fileName, Project *project);
private: private:
void write(QXmlStreamWriter *writer, const Project *project); void write(QXmlStreamWriter *writer, const Project *project);

View File

@@ -42,8 +42,6 @@
#include "../../modelinglibtr.h" #include "../../modelinglibtr.h"
#include <QMenu> #include <QMenu>
#include <QFileInfo>
#include <QDir>
#include <QQueue> #include <QQueue>
#include <QPair> #include <QPair>

View File

@@ -52,9 +52,9 @@ private:
void FindComponentFromFilePath::setFilePath(const QString &filePath) void FindComponentFromFilePath::setFilePath(const QString &filePath)
{ {
m_elementName = qmt::NameController::convertFileNameToElementName(filePath); m_elementName = qmt::NameController::convertFileNameToElementName(Utils::FilePath::fromString(filePath));
QFileInfo fileInfo(filePath); QFileInfo fileInfo(filePath);
m_elementsPath = qmt::NameController::buildElementsPath(fileInfo.path(), false); m_elementsPath = qmt::NameController::buildElementsPath(Utils::FilePath::fromString(fileInfo.path()), false);
} }
void FindComponentFromFilePath::visitMComponent(qmt::MComponent *component) void FindComponentFromFilePath::visitMComponent(qmt::MComponent *component)
@@ -218,10 +218,10 @@ void UpdateIncludeDependenciesVisitor::collectElementPaths(const ProjectExplorer
QMultiHash<QString, Node> *filePathsMap) QMultiHash<QString, Node> *filePathsMap)
{ {
folderNode->forEachFileNode([&](FileNode *fileNode) { folderNode->forEachFileNode([&](FileNode *fileNode) {
QString elementName = qmt::NameController::convertFileNameToElementName(fileNode->filePath().toString()); 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(nodePath, false); QStringList elementsPath = qmt::NameController::buildElementsPath(Utils::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 +309,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(file); QString componentName = qmt::NameController::convertFileNameToElementName(Utils::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 +341,7 @@ void ComponentViewController::doCreateComponentModel(const QString &filePath, qm
} }
if (component) { if (component) {
QStringList relativeElements = qmt::NameController::buildElementsPath( QStringList relativeElements = qmt::NameController::buildElementsPath(
d->pxnodeUtilities->calcRelativePath(file, anchorFolder), false); Utils::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

@@ -401,17 +401,22 @@ void ElementTasks::createAndOpenDiagram(const qmt::DElement *element, const qmt:
createAndOpenDiagram(melement); createAndOpenDiagram(melement);
} }
Utils::FilePath ElementTasks::linkedFile(const qmt::MObject *mobject) const
{
Utils::FilePath filepath = Utils::FilePath::fromString(mobject->linkedFileName());
if (!filepath.isEmpty()) {
Utils::FilePath projectName = d->documentController->projectController()->project()->fileName();
filepath = projectName.absolutePath().resolvePath(filepath).canonicalPath();
}
return filepath;
}
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)) {
QString filename = mobject->linkedFileName(); Utils::FilePath filepath = linkedFile(mobject);
if (!filename.isEmpty()) { if (!filepath.isEmpty())
QString projectName = d->documentController->projectController()->project()->fileName(); return filepath.exists();
Utils::FilePath relativePath = Utils::FilePath::fromString(filename);
Utils::FilePath projectPath = Utils::FilePath::fromString(projectName);
QString filepath = relativePath.resolvePath(projectPath).toString();
return QFileInfo::exists(filepath);
}
} }
return false; return false;
} }
@@ -429,25 +434,20 @@ 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)) {
QString filename = mobject->linkedFileName(); Utils::FilePath filepath = linkedFile(mobject);
if (!filename.isEmpty()) { if (!filepath.isEmpty()) {
QString projectName = d->documentController->projectController()->project()->fileName(); if (filepath.exists()) {
QString filepath; Core::EditorFactories list = Core::IEditorFactory::preferredEditorFactories(filepath);
if (QFileInfo(filename).isRelative())
filepath = QFileInfo(QFileInfo(projectName).path() + "/" + filename).canonicalFilePath();
else
filepath = filename;
if (QFileInfo::exists(filepath)) {
Core::EditorFactories list = Core::IEditorFactory::preferredEditorFactories(Utils::FilePath::fromString(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(Utils::FilePath::fromString(filepath), "CorePlugin.OpenWithSystemEditor"); (void) Core::EditorManager::instance()->openExternalEditor(filepath, "CorePlugin.OpenWithSystemEditor");
} else { } else {
// intentionally ignore return code // intentionally ignore return code
(void) Core::EditorManager::instance()->openEditor(Utils::FilePath::fromString(filepath)); (void) Core::EditorManager::instance()->openEditor(filepath);
} }
} else { } else {
QMessageBox::critical(Core::ICore::dialogParent(), Tr::tr("Opening File"), Tr::tr("File %1 does not exist.").arg(filepath)); QMessageBox::critical(Core::ICore::dialogParent(), Tr::tr("Opening File"),
Tr::tr("File %1 does not exist.").arg(filepath.toUserOutput()));
} }
} }
} }

View File

@@ -6,7 +6,12 @@
#include <QObject> #include <QObject>
#include "qmt/tasks/ielementtasks.h" #include "qmt/tasks/ielementtasks.h"
namespace qmt { class DocumentController; } #include <utils/filepath.h>
namespace qmt {
class DocumentController;
class MObject;
}
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -75,6 +80,8 @@ public:
bool handleContextMenuAction(qmt::DElement *element, qmt::MDiagram *diagram, const QString &id) override; bool handleContextMenuAction(qmt::DElement *element, qmt::MDiagram *diagram, const QString &id) override;
private: private:
Utils::FilePath linkedFile(const qmt::MObject *mobject) const;
ElementTasksPrivate *d; ElementTasksPrivate *d;
}; };

View File

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

View File

@@ -5,6 +5,8 @@
#include "qmt/document_controller/documentcontroller.h" #include "qmt/document_controller/documentcontroller.h"
#include <utils/filepath.h>
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -25,7 +27,7 @@ public:
PxNodeController *pxNodeController() const; PxNodeController *pxNodeController() const;
private: private:
void onProjectFileNameChanged(const QString &fileName); void onProjectFileNameChanged(const Utils::FilePath &fileName);
private: private:
ExtDocumentControllerPrivate *d; ExtDocumentControllerPrivate *d;

View File

@@ -83,8 +83,7 @@ void ExtPropertiesMView::visitMPackage(const qmt::MPackage *package)
m_configPath = new Utils::PathChooser(m_topWidget); m_configPath = new Utils::PathChooser(m_topWidget);
m_configPath->setPromptDialogTitle(Tr::tr("Select Custom Configuration Folder")); m_configPath->setPromptDialogTitle(Tr::tr("Select Custom Configuration Folder"));
m_configPath->setExpectedKind(Utils::PathChooser::ExistingDirectory); m_configPath->setExpectedKind(Utils::PathChooser::ExistingDirectory);
m_configPath->setInitialBrowsePathBackup( m_configPath->setInitialBrowsePathBackup(project->fileName().absolutePath());
Utils::FilePath::fromString(project->fileName()).absolutePath());
addRow(Tr::tr("Config path:"), m_configPath, "configpath"); addRow(Tr::tr("Config path:"), m_configPath, "configpath");
connect(m_configPath, &Utils::PathChooser::textChanged, connect(m_configPath, &Utils::PathChooser::textChanged,
this, &ExtPropertiesMView::onConfigPathChanged, this, &ExtPropertiesMView::onConfigPathChanged,
@@ -95,8 +94,8 @@ void ExtPropertiesMView::visitMPackage(const qmt::MPackage *package)
m_configPath->setFilePath({}); m_configPath->setFilePath({});
} else { } else {
// make path absolute (may be relative to current project's directory) // make path absolute (may be relative to current project's directory)
QDir projectDir = QFileInfo(project->fileName()).absoluteDir(); auto projectDir = project->fileName().absolutePath();
m_configPath->setPath(QFileInfo(projectDir, project->configPath()).canonicalFilePath()); m_configPath->setPath(projectDir.resolvePath(project->configPath()).toUserOutput());
} }
} }
if (!m_configPathInfo) { if (!m_configPathInfo) {
@@ -115,7 +114,7 @@ void ExtPropertiesMView::visitMObjectBehind(const qmt::MObject *object)
m_filelinkPathChooser = new Utils::PathChooser(m_topWidget); m_filelinkPathChooser = new Utils::PathChooser(m_topWidget);
m_filelinkPathChooser->setPromptDialogTitle((Tr::tr("Select File Target"))); m_filelinkPathChooser->setPromptDialogTitle((Tr::tr("Select File Target")));
m_filelinkPathChooser->setExpectedKind(Utils::PathChooser::File); m_filelinkPathChooser->setExpectedKind(Utils::PathChooser::File);
m_filelinkPathChooser->setInitialBrowsePathBackup(Utils::FilePath::fromString(QFileInfo(project->fileName()).absolutePath())); m_filelinkPathChooser->setInitialBrowsePathBackup(project->fileName().absolutePath());
addRow(Tr::tr("Linked file:"), m_filelinkPathChooser, "filelink"); addRow(Tr::tr("Linked file:"), m_filelinkPathChooser, "filelink");
connect(m_filelinkPathChooser, &Utils::PathChooser::textChanged, connect(m_filelinkPathChooser, &Utils::PathChooser::textChanged,
this, &ExtPropertiesMView::onFileLinkPathChanged, this, &ExtPropertiesMView::onFileLinkPathChanged,
@@ -128,7 +127,7 @@ void ExtPropertiesMView::visitMObjectBehind(const qmt::MObject *object)
m_filelinkPathChooser->setPath(QString()); m_filelinkPathChooser->setPath(QString());
} else { } else {
Utils::FilePath relativePath = Utils::FilePath::fromString(path); Utils::FilePath relativePath = Utils::FilePath::fromString(path);
Utils::FilePath projectPath = Utils::FilePath::fromString(project->fileName()); Utils::FilePath projectPath = project->fileName();
QString filePath = absoluteFromRelativePath(relativePath, projectPath).toString(); QString filePath = absoluteFromRelativePath(relativePath, projectPath).toString();
m_filelinkPathChooser->setPath(filePath); m_filelinkPathChooser->setPath(filePath);
} }
@@ -150,8 +149,7 @@ void ExtPropertiesMView::visitDObjectBefore(const qmt::DObject *object)
m_imagePathChooser->setPromptDialogTitle(Tr::tr("Select Image File")); m_imagePathChooser->setPromptDialogTitle(Tr::tr("Select Image File"));
m_imagePathChooser->setExpectedKind(Utils::PathChooser::File); m_imagePathChooser->setExpectedKind(Utils::PathChooser::File);
m_imagePathChooser->setPromptDialogFilter(imageNameFilterString()); m_imagePathChooser->setPromptDialogFilter(imageNameFilterString());
m_imagePathChooser->setInitialBrowsePathBackup( m_imagePathChooser->setInitialBrowsePathBackup(project->fileName().absolutePath());
Utils::FilePath::fromString(QFileInfo(project->fileName()).absolutePath()));
addRow(Tr::tr("Image:"), m_imagePathChooser, "imagepath"); addRow(Tr::tr("Image:"), m_imagePathChooser, "imagepath");
connect(m_imagePathChooser, &Utils::PathChooser::textChanged, connect(m_imagePathChooser, &Utils::PathChooser::textChanged,
this, &ExtPropertiesMView::onImagePathChanged, this, &ExtPropertiesMView::onImagePathChanged,
@@ -164,8 +162,7 @@ void ExtPropertiesMView::visitDObjectBefore(const qmt::DObject *object)
m_imagePathChooser->setPath(QString()); m_imagePathChooser->setPath(QString());
} else { } else {
Utils::FilePath relativePath = Utils::FilePath::fromString(path); Utils::FilePath relativePath = Utils::FilePath::fromString(path);
Utils::FilePath projectPath = Utils::FilePath::fromString(project->fileName()); QString filePath = absoluteFromRelativePath(relativePath, project->fileName()).toString();
QString filePath = absoluteFromRelativePath(relativePath, projectPath).toString();
m_imagePathChooser->setPath(filePath); m_imagePathChooser->setPath(filePath);
} }
} }
@@ -182,16 +179,15 @@ void ExtPropertiesMView::onConfigPathChanged(const QString &path)
qmt::Project *project = m_projectController->project(); qmt::Project *project = m_projectController->project();
if (path.isEmpty()) { if (path.isEmpty()) {
if (!project->configPath().isEmpty()) { if (!project->configPath().isEmpty()) {
project->setConfigPath(QString()); project->setConfigPath({ });
m_projectController->setModified(); m_projectController->setModified();
modified = true; modified = true;
} }
} else { } else {
// make path relative to current project's directory // make path relative to current project's directory
QFileInfo absConfigPath = Utils::FilePath::fromString(path).toFileInfo(); Utils::FilePath absConfigPath = Utils::FilePath::fromString(path).absoluteFilePath();
absConfigPath.makeAbsolute(); Utils::FilePath projectDir = project->fileName().absolutePath();
QDir projectDir = QFileInfo(project->fileName()).dir(); Utils::FilePath configPath = absConfigPath.relativePathFrom(projectDir);
QString configPath = projectDir.relativeFilePath(absConfigPath.filePath());
if (configPath != project->configPath()) { if (configPath != project->configPath()) {
project->setConfigPath(configPath); project->setConfigPath(configPath);
m_projectController->setModified(); m_projectController->setModified();
@@ -211,7 +207,7 @@ void ExtPropertiesMView::onFileLinkPathChanged(const QString &path)
} 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 = Utils::FilePath::fromString(QFileInfo(project->fileName()).path()); Utils::FilePath projectPath = project->fileName().absolutePath();
QString relativeFilePath = filePath.relativePathFrom(projectPath).toString(); QString relativeFilePath = filePath.relativePathFrom(projectPath).toString();
if (!relativeFilePath.isEmpty()) { if (!relativeFilePath.isEmpty()) {
assignModelElement<qmt::MObject, QString>(m_modelElements, SelectionSingle, relativeFilePath, assignModelElement<qmt::MObject, QString>(m_modelElements, SelectionSingle, relativeFilePath,
@@ -231,8 +227,7 @@ void ExtPropertiesMView::onImagePathChanged(const QString &path)
} 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 = Utils::FilePath::fromString( Utils::FilePath projectPath = project->fileName().absolutePath();
QFileInfo(project->fileName()).path());
QString relativeFilePath = filePath.relativePathFrom(projectPath).toString(); QString relativeFilePath = filePath.relativePathFrom(projectPath).toString();
if (!relativeFilePath.isEmpty() if (!relativeFilePath.isEmpty()
&& isValueChanged<qmt::DObject, QString>(m_diagramElements, SelectionSingle, relativeFilePath, && isValueChanged<qmt::DObject, QString>(m_diagramElements, SelectionSingle, relativeFilePath,

View File

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

View File

@@ -5,6 +5,8 @@
#include <QObject> #include <QObject>
#include <utils/filepath.h>
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -15,7 +17,7 @@ class JsExtension : public QObject
public: public:
JsExtension() {} JsExtension() {}
Q_INVOKABLE QString fileNameToElementName(const QString &file); Q_INVOKABLE QString fileNameToElementName(const Utils::FilePath &file);
Q_INVOKABLE QString elementNameToFileName(const QString &element); Q_INVOKABLE QString elementNameToFileName(const QString &element);
}; };

View File

@@ -19,9 +19,6 @@
#include <utils/id.h> #include <utils/id.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <QFileInfo>
#include <QDir>
namespace ModelEditor { namespace ModelEditor {
namespace Internal { namespace Internal {
@@ -51,7 +48,7 @@ Core::IDocument::OpenResult ModelDocument::open(QString *errorString,
{ {
Q_UNUSED(filePath) Q_UNUSED(filePath)
OpenResult result = load(errorString, realFilePath.toString()); OpenResult result = load(errorString, realFilePath);
return result; return result;
} }
@@ -62,7 +59,7 @@ bool ModelDocument::saveImpl(QString *errorString, const Utils::FilePath &filePa
return false; return false;
} }
d->documentController->projectController()->setFileName(filePath.toString()); d->documentController->projectController()->setFileName(filePath);
try { try {
d->documentController->projectController()->save(); d->documentController->projectController()->save();
} catch (const qmt::Exception &ex) { } catch (const qmt::Exception &ex) {
@@ -73,7 +70,7 @@ bool ModelDocument::saveImpl(QString *errorString, const Utils::FilePath &filePa
if (autoSave) { if (autoSave) {
d->documentController->projectController()->setModified(); d->documentController->projectController()->setModified();
} else { } else {
setFilePath(Utils::FilePath::fromString(d->documentController->projectController()->project()->fileName())); setFilePath(d->documentController->projectController()->project()->fileName());
emit changed(); emit changed();
} }
@@ -102,12 +99,13 @@ bool ModelDocument::reload(QString *errorString, Core::IDocument::ReloadFlag fla
if (flag == FlagIgnore) if (flag == FlagIgnore)
return true; return true;
try { try {
d->documentController->loadProject(filePath().toString()); d->documentController->loadProject(filePath());
} catch (const qmt::FileNotFoundException &ex) { } catch (const qmt::FileNotFoundException &ex) {
*errorString = ex.errorMessage(); *errorString = ex.errorMessage();
return false; return false;
} catch (const qmt::Exception &ex) { } catch (const qmt::Exception &ex) {
*errorString = Tr::tr("Could not open \"%1\" for reading: %2.").arg(filePath().toString()).arg(ex.errorMessage()); *errorString = Tr::tr("Could not open \"%1\" for reading: %2.")
.arg(filePath().toUserOutput(), ex.errorMessage());
return false; return false;
} }
emit contentSet(); emit contentSet();
@@ -119,25 +117,25 @@ ExtDocumentController *ModelDocument::documentController() const
return d->documentController; return d->documentController;
} }
Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const QString &fileName) Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const Utils::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);
try { try {
d->documentController->loadProject(fileName); d->documentController->loadProject(fileName);
setFilePath(Utils::FilePath::fromString(d->documentController->projectController()->project()->fileName())); setFilePath(d->documentController->projectController()->project()->fileName());
} catch (const qmt::FileNotFoundException &ex) { } catch (const qmt::FileNotFoundException &ex) {
*errorString = ex.errorMessage(); *errorString = ex.errorMessage();
return OpenResult::ReadError; return OpenResult::ReadError;
} catch (const qmt::Exception &ex) { } catch (const qmt::Exception &ex) {
*errorString = Tr::tr("Could not open \"%1\" for reading: %2.").arg(fileName).arg(ex.errorMessage()); *errorString = Tr::tr("Could not open \"%1\" for reading: %2.").arg(fileName.toUserOutput(), ex.errorMessage());
return OpenResult::CannotHandle; return OpenResult::CannotHandle;
} }
QString configPath = d->documentController->projectController()->project()->configPath(); Utils::FilePath configPath = d->documentController->projectController()->project()->configPath();
if (!configPath.isEmpty()) { if (!configPath.isEmpty()) {
QString canonicalPath = QFileInfo(QDir(QFileInfo(fileName).path()).filePath(configPath)).canonicalFilePath(); Utils::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

@@ -4,6 +4,7 @@
#pragma once #pragma once
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <utils/filepath.h>
namespace qmt { class Uid; } namespace qmt { class Uid; }
@@ -36,7 +37,7 @@ public:
ExtDocumentController *documentController() const; ExtDocumentController *documentController() const;
OpenResult load(QString *errorString, const QString &fileName); OpenResult load(QString *errorString, const Utils::FilePath &fileName);
protected: protected:
bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override; bool saveImpl(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;

View File

@@ -62,7 +62,6 @@
#include <QAction> #include <QAction>
#include <QActionGroup> #include <QActionGroup>
#include <QComboBox> #include <QComboBox>
#include <QDir>
#include <QEvent> #include <QEvent>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>

View File

@@ -275,7 +275,7 @@ void ModelIndexer::IndexerThread::onFilesQueued()
qmt::ProjectSerializer projectSerializer; qmt::ProjectSerializer projectSerializer;
qmt::Project project; qmt::Project project;
try { try {
projectSerializer.load(queuedFile.file(), &project); projectSerializer.load(Utils::FilePath::fromString(queuedFile.file()), &project);
} catch (const qmt::Exception &e) { } catch (const qmt::Exception &e) {
qWarning() << e.errorMessage(); qWarning() << e.errorMessage();
return; return;

View File

@@ -38,8 +38,6 @@
#include <projectexplorer/projecttree.h> #include <projectexplorer/projecttree.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <QFileInfo>
#include <QDir>
#include <QTimer> #include <QTimer>
#include <QAction> #include <QAction>
@@ -121,7 +119,7 @@ ExtDocumentController *ModelsManager::createModel(ModelDocument *modelDocument)
auto documentController = new ExtDocumentController(this); auto documentController = new ExtDocumentController(this);
// TODO error output on reading definition files // TODO error output on reading definition files
documentController->configController()->readStereotypeDefinitions( documentController->configController()->readStereotypeDefinitions(
Core::ICore::resourcePath("modeleditor").toString()); Core::ICore::resourcePath("modeleditor"));
d->managedModels.append(ManagedModel(documentController, modelDocument)); d->managedModels.append(ManagedModel(documentController, modelDocument));
return documentController; return documentController;

View File

@@ -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(filePath); QString elementName = qmt::NameController::convertFileNameToElementName(Utils::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(
d->pxnodeUtilities->calcRelativePath(node, d->anchorFolder), false); Utils::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(
d->pxnodeUtilities->calcRelativePath(filePath, d->anchorFolder), true); Utils::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);
@@ -363,7 +363,8 @@ 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(
d->pxnodeUtilities->calcRelativePath(filePath, d->anchorFolder), Utils::FilePath::fromString(
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)) {
delete newObject; delete newObject;

View File

@@ -51,7 +51,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(nodePath, anchorFolder); return qmt::NameController::calcRelativePath(Utils::FilePath::fromString(nodePath),
Utils::FilePath::fromString(anchorFolder)).toString();
} }
QString PxNodeUtilities::calcRelativePath(const QString &filePath, const QString &anchorFolder) QString PxNodeUtilities::calcRelativePath(const QString &filePath, const QString &anchorFolder)
@@ -63,7 +64,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(path, anchorFolder); return qmt::NameController::calcRelativePath(Utils::FilePath::fromString(path),
Utils::FilePath::fromString(anchorFolder)).toString();
} }
qmt::MPackage *PxNodeUtilities::createBestMatchingPackagePath( qmt::MPackage *PxNodeUtilities::createBestMatchingPackagePath(