diff --git a/src/libs/modelinglib/qmt/config/configcontroller.cpp b/src/libs/modelinglib/qmt/config/configcontroller.cpp index 2337c6873b2..c584bce1c2c 100644 --- a/src/libs/modelinglib/qmt/config/configcontroller.cpp +++ b/src/libs/modelinglib/qmt/config/configcontroller.cpp @@ -10,7 +10,9 @@ #include "qmt/stereotype/stereotypecontroller.h" #include -#include + +using Utils::FilePath; +using Utils::FilePaths; namespace qmt { @@ -36,7 +38,7 @@ void ConfigController::setStereotypeController(StereotypeController *stereotypeC d->m_stereotypeController = stereotypeController; } -void ConfigController::readStereotypeDefinitions(const Utils::FilePath &path) +void ConfigController::readStereotypeDefinitions(const FilePath &path) { if (path.isEmpty()) { // TODO add error handling @@ -51,7 +53,7 @@ void ConfigController::readStereotypeDefinitions(const Utils::FilePath &path) connect(&parser, &StereotypeDefinitionParser::toolbarParsed, this, &ConfigController::onToolbarParsed); - Utils::FilePaths paths; + FilePaths paths; if (path.isFile()) { paths.append(path); } else if (path.isDir()) { @@ -60,11 +62,10 @@ void ConfigController::readStereotypeDefinitions(const Utils::FilePath &path) // TODO add error handling return; } - for (const auto &filePath : std::as_const(paths)) { - QFile file(filePath.toString()); - if (file.open(QIODevice::ReadOnly)) { - QString text = QString::fromUtf8(file.readAll()); - file.close(); + for (const FilePath &filePath : std::as_const(paths)) { + auto data = filePath.fileContents(); + if (data.has_value()) { + QString text = QString::fromUtf8(data.value()); StringTextSource source; source.setSourceId(1); source.setText(text); diff --git a/src/libs/modelinglib/qmt/controller/namecontroller.cpp b/src/libs/modelinglib/qmt/controller/namecontroller.cpp index a6ffe99d58d..2f9506d3fe5 100644 --- a/src/libs/modelinglib/qmt/controller/namecontroller.cpp +++ b/src/libs/modelinglib/qmt/controller/namecontroller.cpp @@ -5,6 +5,8 @@ #include +using Utils::FilePath; + namespace qmt { 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 elementName; @@ -63,12 +65,12 @@ QString NameController::convertElementNameToBaseFileName(const QString &elementN return baseFileName; } -Utils::FilePath NameController::calcRelativePath(const Utils::FilePath &absoluteFileName, - const Utils::FilePath &anchorPath) +FilePath NameController::calcRelativePath(const FilePath &absoluteFileName, + const FilePath &anchorPath) { // TODO try using Utils::FilePath::relativePath - QString absoluteFilePath = absoluteFileName.toString(); - QString anchorPathString = anchorPath.toString(); + QString absoluteFilePath = absoluteFileName.path(); + QString anchorPathString = anchorPath.path(); int secondLastSlashIndex = -1; int slashIndex = -1; int i = 0; @@ -100,7 +102,7 @@ Utils::FilePath NameController::calcRelativePath(const Utils::FilePath &absolute relativePath = absoluteFilePath.mid(slashIndex + 1); } - return Utils::FilePath::fromString(relativePath); + return FilePath::fromString(relativePath); } QString NameController::calcElementNameSearchId(const QString &elementName) @@ -113,7 +115,7 @@ QString NameController::calcElementNameSearchId(const QString &elementName) return searchId; } -QStringList NameController::buildElementsPath(const Utils::FilePath &filePath, +QStringList NameController::buildElementsPath(const FilePath &filePath, bool ignoreLastFilePathPart) { QList relativeElements; @@ -123,7 +125,7 @@ QStringList NameController::buildElementsPath(const Utils::FilePath &filePath, if (ignoreLastFilePathPart || split.last().isEmpty()) --splitEnd; 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); } return relativeElements; diff --git a/src/libs/modelinglib/qmt/diagram/dobject.cpp b/src/libs/modelinglib/qmt/diagram/dobject.cpp index 68e954b8572..543e6af30fc 100644 --- a/src/libs/modelinglib/qmt/diagram/dobject.cpp +++ b/src/libs/modelinglib/qmt/diagram/dobject.cpp @@ -6,11 +6,11 @@ #include "dvisitor.h" #include "dconstvisitor.h" +using Utils::FilePath; + namespace qmt { -DObject::DObject() -{ -} +DObject::DObject() {} DObject::DObject(const DObject &rhs) : DElement(rhs), @@ -129,7 +129,7 @@ bool DObject::hasImage() const return !m_image.isNull(); } -void DObject::setImagePath(const QString &path) +void DObject::setImagePath(const FilePath &path) { m_imagePath = path; } diff --git a/src/libs/modelinglib/qmt/diagram/dobject.h b/src/libs/modelinglib/qmt/diagram/dobject.h index bf43edea12e..7364f157499 100644 --- a/src/libs/modelinglib/qmt/diagram/dobject.h +++ b/src/libs/modelinglib/qmt/diagram/dobject.h @@ -7,6 +7,8 @@ #include "qmt/infrastructure/uid.h" +#include + #include #include #include @@ -81,8 +83,8 @@ public: void setVisualEmphasized(bool visualEmphasized); bool hasLinkedFile() const { return m_hasLinkedFile; } void setLinkedFile(bool linkedFile); - QString imagePath() const { return m_imagePath; } - void setImagePath(const QString &path); + Utils::FilePath imagePath() const { return m_imagePath; } + void setImagePath(const Utils::FilePath &path); bool hasImage() const; QImage image() const { return m_image; } void setImage(const QImage &image); @@ -104,7 +106,7 @@ private: bool m_isAutoSized = true; bool m_isVisualEmphasized = false; bool m_hasLinkedFile = false; - QString m_imagePath; + Utils::FilePath m_imagePath; QImage m_image; }; diff --git a/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp b/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp index 12ec26048ea..696fc305583 100644 --- a/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp +++ b/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp @@ -32,6 +32,8 @@ #include "../../modelinglibtr.h" +using Utils::FilePath; + namespace qmt { DocumentController::DocumentController(QObject *parent) : @@ -231,7 +233,7 @@ MDiagram *DocumentController::findOrCreateRootDiagram() return rootDiagram; } -void DocumentController::createNewProject(const Utils::FilePath &fileName) +void DocumentController::createNewProject(const FilePath &fileName) { m_diagramsManager->removeAllDiagrams(); m_treeModel->setModelController(nullptr); @@ -244,7 +246,7 @@ void DocumentController::createNewProject(const Utils::FilePath &fileName) m_modelController->setRootPackage(m_projectController->project()->rootPackage()); } -void DocumentController::loadProject(const Utils::FilePath &fileName) +void DocumentController::loadProject(const FilePath &fileName) { m_diagramsManager->removeAllDiagrams(); m_treeModel->setModelController(nullptr); diff --git a/src/libs/modelinglib/qmt/infrastructure/ioexceptions.cpp b/src/libs/modelinglib/qmt/infrastructure/ioexceptions.cpp index 04778cd0e31..bb11a4d566e 100644 --- a/src/libs/modelinglib/qmt/infrastructure/ioexceptions.cpp +++ b/src/libs/modelinglib/qmt/infrastructure/ioexceptions.cpp @@ -7,6 +7,8 @@ #include +using Utils::FilePath; + namespace qmt { 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), m_fileName(fileName), m_lineNumber(lineNumber) { } -FileNotFoundException::FileNotFoundException(const Utils::FilePath &fileName) +FileNotFoundException::FileNotFoundException(const FilePath &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) { } -FileWriteError::FileWriteError(const Utils::FilePath &fileName, int lineNumber) +FileWriteError::FileWriteError(const FilePath &fileName, int 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) { } -IllegalXmlFile::IllegalXmlFile(const Utils::FilePath &fileName, int lineNumber) +IllegalXmlFile::IllegalXmlFile(const FilePath &fileName, int 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.") .arg(version), fileName, lineNumber) { diff --git a/src/libs/modelinglib/qmt/model/mobject.cpp b/src/libs/modelinglib/qmt/model/mobject.cpp index 1e6bf8d0b35..f5b4e2b36fe 100644 --- a/src/libs/modelinglib/qmt/model/mobject.cpp +++ b/src/libs/modelinglib/qmt/model/mobject.cpp @@ -8,6 +8,8 @@ #include "mvisitor.h" #include "mconstvisitor.h" +using Utils::FilePath; + namespace qmt { MObject::MObject() @@ -46,7 +48,7 @@ void MObject::setName(const QString &name) m_name = name; } -void MObject::setLinkedFileName(const QString &linkedfilename) +void MObject::setLinkedFileName(const FilePath &linkedfilename) { m_linkedfilename = linkedfilename; } diff --git a/src/libs/modelinglib/qmt/model/mobject.h b/src/libs/modelinglib/qmt/model/mobject.h index 33a475ed6ee..29d10da4ba0 100644 --- a/src/libs/modelinglib/qmt/model/mobject.h +++ b/src/libs/modelinglib/qmt/model/mobject.h @@ -6,6 +6,8 @@ #include "melement.h" #include "qmt/infrastructure/handles.h" +#include + #include namespace qmt { @@ -23,8 +25,8 @@ public: QString name() const { return m_name; } void setName(const QString &name); - QString linkedFileName() const { return m_linkedfilename; } - void setLinkedFileName(const QString &linkedfilename); + Utils::FilePath linkedFileName() const { return m_linkedfilename; } + void setLinkedFileName(const Utils::FilePath &linkedfilename); const Handles &children() const { return m_children; } void setChildren(const Handles &children); @@ -50,7 +52,7 @@ public: private: QString m_name; - QString m_linkedfilename; + Utils::FilePath m_linkedfilename; Handles m_children; Handles m_relations; }; diff --git a/src/libs/modelinglib/qmt/model_ui/treemodel.cpp b/src/libs/modelinglib/qmt/model_ui/treemodel.cpp index 3e8d5a59b69..23d589a6540 100644 --- a/src/libs/modelinglib/qmt/model_ui/treemodel.cpp +++ b/src/libs/modelinglib/qmt/model_ui/treemodel.cpp @@ -30,6 +30,8 @@ #include +using Utils::FilePath; + namespace qmt { class TreeModel::ModelItem : public QStandardItem @@ -807,7 +809,7 @@ QString TreeModel::createRelationLabel(const MRelation *relation) } 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); return m_stereotypeController->createIcon(stereotypeIconElement, stereotypes, defaultIconPath, style, diff --git a/src/libs/modelinglib/qmt/model_ui/treemodel.h b/src/libs/modelinglib/qmt/model_ui/treemodel.h index add325a94ab..5ea35963489 100644 --- a/src/libs/modelinglib/qmt/model_ui/treemodel.h +++ b/src/libs/modelinglib/qmt/model_ui/treemodel.h @@ -9,6 +9,8 @@ #include #include +#include + #include #include @@ -93,8 +95,9 @@ private: QString createObjectLabel(const MObject *object); QString createRelationLabel(const MRelation *relation); QIcon createIcon(StereotypeIcon::Element stereotypeIconElement, - StyleEngine::ElementType styleElementType, const QStringList &stereotypes, - const QString &defaultIconPath); + StyleEngine::ElementType styleElementType, + const QStringList &stereotypes, + const Utils::FilePath &defaultIconPath); enum Busy { NotBusy, diff --git a/src/libs/modelinglib/qmt/project/project.cpp b/src/libs/modelinglib/qmt/project/project.cpp index bc0ed449a3e..2e08adc6dfe 100644 --- a/src/libs/modelinglib/qmt/project/project.cpp +++ b/src/libs/modelinglib/qmt/project/project.cpp @@ -3,6 +3,8 @@ #include "project.h" +using Utils::FilePath; + namespace qmt { Project::Project() @@ -23,7 +25,7 @@ bool Project::hasFileName() const return !m_fileName.isEmpty(); } -void Project::setFileName(const Utils::FilePath &fileName) +void Project::setFileName(const FilePath &fileName) { m_fileName = fileName; } @@ -33,7 +35,7 @@ void Project::setRootPackage(MPackage *rootPackage) m_rootPackage = rootPackage; } -void Project::setConfigPath(const Utils::FilePath &configPath) +void Project::setConfigPath(const FilePath &configPath) { m_configPath = configPath; } diff --git a/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp b/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp index f5d5225d036..47eb01138eb 100644 --- a/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp +++ b/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp @@ -10,6 +10,8 @@ #include "../../modelinglibtr.h" +using Utils::FilePath; + namespace qmt { 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()); auto rootPackage = new MPackage(); @@ -43,7 +45,7 @@ void ProjectController::newProject(const Utils::FilePath &fileName) emit changed(); } -void ProjectController::setFileName(const Utils::FilePath &fileName) +void ProjectController::setFileName(const FilePath &fileName) { if (fileName != m_project->fileName()) { m_project->setFileName(fileName); @@ -82,7 +84,7 @@ void ProjectController::save() emit changed(); } -void ProjectController::saveAs(const Utils::FilePath &fileName) +void ProjectController::saveAs(const FilePath &fileName) { setFileName(fileName); save(); diff --git a/src/libs/modelinglib/qmt/serializer/infrastructureserializer.h b/src/libs/modelinglib/qmt/serializer/infrastructureserializer.h index 2313ab8aba1..59103b3fa92 100644 --- a/src/libs/modelinglib/qmt/serializer/infrastructureserializer.h +++ b/src/libs/modelinglib/qmt/serializer/infrastructureserializer.h @@ -58,7 +58,7 @@ inline void serialize(Archive &archive, qmt::Handles &handles) template inline void save(Archive &archive, const Utils::FilePath &filePath) { - archive.write(filePath.toString()); + archive.write(filePath.toFSPathString()); } template @@ -66,7 +66,7 @@ inline void load(Archive &archive, Utils::FilePath &filePath) { QString s; archive.read(&s); - filePath = Utils::FilePath::fromString(s); + filePath = Utils::FilePath::fromUserInput(s); } } // namespace qark diff --git a/src/libs/modelinglib/qmt/serializer/projectserializer.cpp b/src/libs/modelinglib/qmt/serializer/projectserializer.cpp index ecb5538f0cb..832d47309b6 100644 --- a/src/libs/modelinglib/qmt/serializer/projectserializer.cpp +++ b/src/libs/modelinglib/qmt/serializer/projectserializer.cpp @@ -20,6 +20,8 @@ #include +using Utils::FilePath; + namespace qark { 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); - QFile file(fileName.toString()); + QFile file(fileName.toFSPathString()); if (!file.open(QIODevice::WriteOnly)) throw FileCreationException(fileName); @@ -84,11 +86,11 @@ QByteArray ProjectSerializer::save(const Project *project) return buffer; } -void ProjectSerializer::load(const Utils::FilePath &fileName, Project *project) +void ProjectSerializer::load(const FilePath &fileName, Project *project) { QMT_ASSERT(project, return); - QFile file(fileName.toString()); + QFile file(fileName.toFSPathString()); if (!file.open(QIODevice::ReadOnly)) throw FileNotFoundException(fileName); diff --git a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp index f557e80c4b7..2f679df1177 100644 --- a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp +++ b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp @@ -10,6 +10,8 @@ #include "qmt/infrastructure/qmtassert.h" #include "qmt/style/style.h" + +#include #include #include @@ -19,12 +21,14 @@ #include +using Utils::FilePath; + namespace qmt { namespace { struct IconKey { - IconKey(StereotypeIcon::Element element, const QList &stereotypes, const QString &defaultIconPath, + IconKey(StereotypeIcon::Element element, const QList &stereotypes, const FilePath &defaultIconPath, const Uid &styleUid, const QSize &size, const QMarginsF &margins, qreal lineWidth) : m_element(element), m_stereotypes(stereotypes), @@ -53,7 +57,7 @@ struct IconKey { const StereotypeIcon::Element m_element; const QList m_stereotypes; - const QString m_defaultIconPath; + const FilePath m_defaultIconPath; const Uid m_styleUid; const QSize m_size; const QMarginsF m_margins; @@ -157,7 +161,7 @@ CustomRelation StereotypeController::findCustomRelationByStereotype(const QStrin } QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QList &stereotypes, - const QString &defaultIconPath, const Style *style, const QSize &size, + const FilePath &defaultIconPath, const Style *style, const QSize &size, const QMarginsF &margins, qreal 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); } if (icon.isNull() && !defaultIconPath.isEmpty()) - icon = QIcon(defaultIconPath); + icon = QIcon(defaultIconPath.toFSPathString()); d->m_iconMap.insert(key, icon); return icon; diff --git a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.h b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.h index 45bc3bbd18f..49acc5f9373 100644 --- a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.h +++ b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.h @@ -5,6 +5,8 @@ #include "stereotypeicon.h" +#include + #include #include @@ -34,9 +36,13 @@ public: StereotypeIcon findStereotypeIcon(const QString &stereotypeIconId) const; CustomRelation findCustomRelation(const QString &customRelationId) const; CustomRelation findCustomRelationByStereotype(const QString &steoreotype) const; - QIcon createIcon(StereotypeIcon::Element element, const QList &stereotypes, - const QString &defaultIconPath, const Style *style, - const QSize &size, const QMarginsF &margins, qreal lineWidth); + QIcon createIcon(StereotypeIcon::Element element, + const QList &stereotypes, + const Utils::FilePath &defaultIconPath, + const Style *style, + const QSize &size, + const QMarginsF &margins, + qreal lineWidth); void addStereotypeIcon(const StereotypeIcon &stereotypeIcon); void addCustomRelation(const CustomRelation &customRelation); diff --git a/src/plugins/modeleditor/componentviewcontroller.cpp b/src/plugins/modeleditor/componentviewcontroller.cpp index b370c10d2d1..cb98ca21edd 100644 --- a/src/plugins/modeleditor/componentviewcontroller.cpp +++ b/src/plugins/modeleditor/componentviewcontroller.cpp @@ -31,6 +31,7 @@ using namespace ProjectExplorer; using namespace Utils; +using Utils::FilePath; namespace ModelEditor { namespace Internal { @@ -52,9 +53,9 @@ private: 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); - 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) @@ -154,7 +155,7 @@ void UpdateIncludeDependenciesVisitor::visitMComponent(qmt::MComponent *componen if (document) { const QList includes = document->resolvedIncludes(); for (const CPlusPlus::Document::Include &include : includes) { - Utils::FilePath includeFilePath = include.resolvedFileName(); + FilePath includeFilePath = include.resolvedFileName(); // replace proxy header with real one CPlusPlus::Document::Ptr includeDocument = snapshot.document(includeFilePath); if (includeDocument) { @@ -221,7 +222,7 @@ void UpdateIncludeDependenciesVisitor::collectElementPaths(const ProjectExplorer QString elementName = qmt::NameController::convertFileNameToElementName(fileNode->filePath()); QFileInfo fileInfo = fileNode->filePath().toFileInfo(); 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)); }); folderNode->forEachFolderNode([&](FolderNode *subNode) { @@ -309,7 +310,7 @@ void ComponentViewController::doCreateComponentModel(const QString &filePath, qm { for (const QString &fileName : QDir(filePath).entryList(QDir::Files)) { 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; bool isSource = false; CppEditor::ProjectFile::Kind kind = CppEditor::ProjectFile::classify(file); @@ -341,7 +342,7 @@ void ComponentViewController::doCreateComponentModel(const QString &filePath, qm } if (component) { 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)) { delete component; } else { diff --git a/src/plugins/modeleditor/elementtasks.cpp b/src/plugins/modeleditor/elementtasks.cpp index c13f96e39ca..7bbdd7b3e0b 100644 --- a/src/plugins/modeleditor/elementtasks.cpp +++ b/src/plugins/modeleditor/elementtasks.cpp @@ -40,6 +40,7 @@ using namespace Core; using namespace CppEditor; +using Utils::FilePath; namespace ModelEditor { namespace Internal { @@ -401,11 +402,11 @@ void ElementTasks::createAndOpenDiagram(const qmt::DElement *element, const qmt: 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()) { - Utils::FilePath projectName = d->documentController->projectController()->project()->fileName(); + FilePath projectName = d->documentController->projectController()->project()->fileName(); filepath = projectName.absolutePath().resolvePath(filepath).canonicalPath(); } return filepath; @@ -414,7 +415,7 @@ Utils::FilePath ElementTasks::linkedFile(const qmt::MObject *mobject) const bool ElementTasks::hasLinkedFile(const qmt::MElement *element) const { if (auto mobject = dynamic_cast(element)) { - Utils::FilePath filepath = linkedFile(mobject); + FilePath filepath = linkedFile(mobject); if (!filepath.isEmpty()) return filepath.exists(); } @@ -434,16 +435,16 @@ bool ElementTasks::hasLinkedFile(const qmt::DElement *element, const qmt::MDiagr void ElementTasks::openLinkedFile(const qmt::MElement *element) { if (auto mobject = dynamic_cast(element)) { - Utils::FilePath filepath = linkedFile(mobject); + FilePath filepath = linkedFile(mobject); if (!filepath.isEmpty()) { if (filepath.exists()) { Core::EditorFactories list = Core::IEditorFactory::preferredEditorFactories(filepath); if (list.empty() || (list.count() <= 1 && list.at(0)->id() == "Core.BinaryEditor")) { // intentionally ignore return code - (void) Core::EditorManager::instance()->openExternalEditor(filepath, "CorePlugin.OpenWithSystemEditor"); + (void) Core::EditorManager::openExternalEditor(filepath, "CorePlugin.OpenWithSystemEditor"); } else { // intentionally ignore return code - (void) Core::EditorManager::instance()->openEditor(filepath); + (void) Core::EditorManager::openEditor(filepath); } } else { QMessageBox::critical(Core::ICore::dialogParent(), Tr::tr("Opening File"), diff --git a/src/plugins/modeleditor/extdocumentcontroller.cpp b/src/plugins/modeleditor/extdocumentcontroller.cpp index ad2940c05f2..f62d1c173bb 100644 --- a/src/plugins/modeleditor/extdocumentcontroller.cpp +++ b/src/plugins/modeleditor/extdocumentcontroller.cpp @@ -9,6 +9,8 @@ #include "qmt/project_controller/projectcontroller.h" #include "qmt/tasks/diagramscenecontroller.h" +using Utils::FilePath; + namespace ModelEditor { namespace Internal { @@ -49,7 +51,7 @@ PxNodeController *ExtDocumentController::pxNodeController() const return d->pxNodeController; } -void ExtDocumentController::onProjectFileNameChanged(const Utils::FilePath &fileName) +void ExtDocumentController::onProjectFileNameChanged(const FilePath &fileName) { d->pxNodeController->setAnchorFolder(fileName.path()); } diff --git a/src/plugins/modeleditor/extpropertiesmview.cpp b/src/plugins/modeleditor/extpropertiesmview.cpp index 68dac749f1e..b105554e6fc 100644 --- a/src/plugins/modeleditor/extpropertiesmview.cpp +++ b/src/plugins/modeleditor/extpropertiesmview.cpp @@ -21,6 +21,8 @@ #include #include +using Utils::FilePath; + namespace ModelEditor { namespace Internal { @@ -52,7 +54,7 @@ static QString imageNameFilterString() /// Constructs an absolute FilePath from \a relativePath which /// 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) { QDir anchorDir = QFileInfo(anchor.path()).absoluteDir(); @@ -122,13 +124,13 @@ void ExtPropertiesMView::visitMObjectBehind(const qmt::MObject *object) } if (isSingleSelection) { if (!m_filelinkPathChooser->hasFocus()) { - QString path = object->linkedFileName(); + Utils::FilePath path = object->linkedFileName(); if (path.isEmpty()) { m_filelinkPathChooser->setPath(QString()); } else { - Utils::FilePath relativePath = Utils::FilePath::fromString(path); + Utils::FilePath relativePath = path; Utils::FilePath projectPath = project->fileName(); - QString filePath = absoluteFromRelativePath(relativePath, projectPath).toString(); + QString filePath = absoluteFromRelativePath(relativePath, projectPath).toFSPathString(); m_filelinkPathChooser->setPath(filePath); } } @@ -157,12 +159,12 @@ void ExtPropertiesMView::visitDObjectBefore(const qmt::DObject *object) } if (isSingleSelection) { if (!m_imagePathChooser->hasFocus()) { - QString path = object->imagePath(); + Utils::FilePath path = object->imagePath(); if (path.isEmpty()) { m_imagePathChooser->setPath(QString()); } else { - Utils::FilePath relativePath = Utils::FilePath::fromString(path); - QString filePath = absoluteFromRelativePath(relativePath, project->fileName()).toString(); + Utils::FilePath relativePath = path; + QString filePath = absoluteFromRelativePath(relativePath, project->fileName()).toFSPathString(); m_imagePathChooser->setPath(filePath); } } @@ -202,16 +204,24 @@ void ExtPropertiesMView::onFileLinkPathChanged(const QString &path) { qmt::Project *project = m_projectController->project(); if (path.isEmpty()) { - assignModelElement(m_modelElements, SelectionSingle, QString(), - &qmt::MObject::linkedFileName, &qmt::MObject::setLinkedFileName); + assignModelElement( + m_modelElements, + SelectionSingle, + {}, + &qmt::MObject::linkedFileName, + &qmt::MObject::setLinkedFileName); } else { // make path relative to current project's directory Utils::FilePath filePath = Utils::FilePath::fromString(path); Utils::FilePath projectPath = project->fileName().absolutePath(); - QString relativeFilePath = filePath.relativePathFrom(projectPath).toString(); + Utils::FilePath relativeFilePath = filePath.relativePathFrom(projectPath); if (!relativeFilePath.isEmpty()) { - assignModelElement(m_modelElements, SelectionSingle, relativeFilePath, - &qmt::MObject::linkedFileName, &qmt::MObject::setLinkedFileName); + assignModelElement( + 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(); if (path.isEmpty()) { - assignModelElement(m_diagramElements, SelectionSingle, QString(), - &qmt::DObject::imagePath, &qmt::DObject::setImagePath); + assignModelElement( + m_diagramElements, + SelectionSingle, + {}, + &qmt::DObject::imagePath, + &qmt::DObject::setImagePath); assignModelElement(m_diagramElements, SelectionSingle, QImage(), &qmt::DObject::image, &qmt::DObject::setImage); } else { // make path relative to current project's directory Utils::FilePath filePath = Utils::FilePath::fromString(path); Utils::FilePath projectPath = project->fileName().absolutePath(); - QString relativeFilePath = filePath.relativePathFrom(projectPath).toString(); + Utils::FilePath relativeFilePath = filePath.relativePathFrom(projectPath); if (!relativeFilePath.isEmpty() - && isValueChanged(m_diagramElements, SelectionSingle, relativeFilePath, - &qmt::DObject::imagePath)) - { + && isValueChanged( + m_diagramElements, SelectionSingle, relativeFilePath, &qmt::DObject::imagePath)) { QImage image; if (image.load(path)) { - assignModelElement(m_diagramElements, SelectionSingle, relativeFilePath, - &qmt::DObject::imagePath, &qmt::DObject::setImagePath); + assignModelElement( + m_diagramElements, + SelectionSingle, + relativeFilePath, + &qmt::DObject::imagePath, + &qmt::DObject::setImagePath); assignModelElement(m_diagramElements, SelectionSingle, image, &qmt::DObject::image, &qmt::DObject::setImage); } else { diff --git a/src/plugins/modeleditor/jsextension.cpp b/src/plugins/modeleditor/jsextension.cpp index 60f00a113a5..455814a49f5 100644 --- a/src/plugins/modeleditor/jsextension.cpp +++ b/src/plugins/modeleditor/jsextension.cpp @@ -5,7 +5,9 @@ #include -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); } diff --git a/src/plugins/modeleditor/modeldocument.cpp b/src/plugins/modeleditor/modeldocument.cpp index cc0ac3aa7da..00630341f98 100644 --- a/src/plugins/modeleditor/modeldocument.cpp +++ b/src/plugins/modeleditor/modeldocument.cpp @@ -19,6 +19,8 @@ #include #include +using Utils::FilePath; + namespace ModelEditor { namespace Internal { @@ -43,8 +45,8 @@ ModelDocument::~ModelDocument() } Core::IDocument::OpenResult ModelDocument::open(QString *errorString, - const Utils::FilePath &filePath, - const Utils::FilePath &realFilePath) + const FilePath &filePath, + const FilePath &realFilePath) { Q_UNUSED(filePath) @@ -52,7 +54,7 @@ Core::IDocument::OpenResult ModelDocument::open(QString *errorString, 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) { *errorString = Tr::tr("No model loaded. Cannot save."); @@ -117,7 +119,7 @@ ExtDocumentController *ModelDocument::documentController() const 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); 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; } - Utils::FilePath configPath = d->documentController->projectController()->project()->configPath(); + FilePath configPath = d->documentController->projectController()->project()->configPath(); if (!configPath.isEmpty()) { - Utils::FilePath canonicalPath =fileName.absolutePath().resolvePath(configPath); + FilePath canonicalPath =fileName.absolutePath().resolvePath(configPath); if (!canonicalPath.isEmpty()) { // TODO error output on reading definition files d->documentController->configController()->readStereotypeDefinitions(canonicalPath); diff --git a/src/plugins/modeleditor/modeleditor.cpp b/src/plugins/modeleditor/modeleditor.cpp index a518be67d0f..dcf2c5b5185 100644 --- a/src/plugins/modeleditor/modeleditor.cpp +++ b/src/plugins/modeleditor/modeleditor.cpp @@ -615,7 +615,7 @@ void ModelEditor::exportToImage(bool selectedElements) QString fileName = FileUtils::getSaveFilePath( nullptr, 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()) { qmt::DocumentController *documentController = d->document->documentController(); qmt::DiagramSceneModel *sceneModel = documentController->diagramsManager()->diagramSceneModel(diagram); @@ -1150,8 +1150,13 @@ void ModelEditor::initToolbars() if (!tool.m_stereotype.isEmpty() && stereotypeIconElement != qmt::StereotypeIcon::ElementAny) { const qmt::Style *style = documentController->styleController()->adaptStyle(styleEngineElementType); icon = stereotypeController->createIcon( - stereotypeIconElement, {tool.m_stereotype}, - QString(), style, QSize(128, 128), QMarginsF(6.0, 4.0, 6.0, 8.0), 8.0); + stereotypeIconElement, + {tool.m_stereotype}, + {}, + style, + QSize(128, 128), + QMarginsF(6.0, 4.0, 6.0, 8.0), + 8.0); if (!icon.isNull()) { QString stereotypeIconId = stereotypeController->findStereotypeIconId( stereotypeIconElement, {tool.m_stereotype}); diff --git a/src/plugins/modeleditor/modelindexer.cpp b/src/plugins/modeleditor/modelindexer.cpp index ed15c27036f..a6de1c4008c 100644 --- a/src/plugins/modeleditor/modelindexer.cpp +++ b/src/plugins/modeleditor/modelindexer.cpp @@ -36,6 +36,8 @@ #include using namespace ProjectExplorer; +using Utils::FilePath; +using Utils::FilePaths; namespace ModelEditor { namespace Internal { @@ -275,7 +277,7 @@ void ModelIndexer::IndexerThread::onFilesQueued() qmt::ProjectSerializer projectSerializer; qmt::Project project; try { - projectSerializer.load(Utils::FilePath::fromString(queuedFile.file()), &project); + projectSerializer.load(FilePath::fromString(queuedFile.file()), &project); } catch (const qmt::Exception &e) { qWarning() << e.errorMessage(); return; @@ -375,13 +377,13 @@ void ModelIndexer::scanProject(ProjectExplorer::Project *project) return; // TODO harmonize following code with findFirstModel()? - const Utils::FilePaths files = project->files(ProjectExplorer::Project::SourceFiles); + const FilePaths files = project->files(ProjectExplorer::Project::SourceFiles); QQueue filesQueue; QSet filesSet; const Utils::MimeType modelMimeType = Utils::mimeTypeForName(Constants::MIME_TYPE_MODEL); if (modelMimeType.isValid()) { - for (const Utils::FilePath &file : files) { + for (const FilePath &file : files) { if (modelMimeType.suffixes().contains(file.completeSuffix())) { QueuedFile queuedFile(file.toString(), project, file.lastModified()); filesQueue.append(queuedFile); @@ -466,10 +468,10 @@ QString ModelIndexer::findFirstModel(ProjectExplorer::FolderNode *folderNode, 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); - for (const Utils::FilePath &file : files) { + for (const FilePath &file : files) { const QString fileString = file.toString(); // remove file from queue QueuedFile queuedFile(fileString, project); diff --git a/src/plugins/modeleditor/modelsmanager.cpp b/src/plugins/modeleditor/modelsmanager.cpp index bd85e38695e..02c481fa5dd 100644 --- a/src/plugins/modeleditor/modelsmanager.cpp +++ b/src/plugins/modeleditor/modelsmanager.cpp @@ -41,6 +41,8 @@ #include #include +using Utils::FilePath; + namespace ModelEditor { namespace Internal { @@ -236,7 +238,7 @@ void ModelsManager::onOpenDiagramFromProjectExplorer() 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()) Core::EditorManager::openEditor(modelFile); } diff --git a/src/plugins/modeleditor/pxnodecontroller.cpp b/src/plugins/modeleditor/pxnodecontroller.cpp index c83934db0f0..50bbf901e6d 100644 --- a/src/plugins/modeleditor/pxnodecontroller.cpp +++ b/src/plugins/modeleditor/pxnodecontroller.cpp @@ -30,7 +30,7 @@ #include #include -using namespace Utils; +using Utils::FilePath; namespace ModelEditor { namespace Internal { @@ -146,7 +146,7 @@ void PxNodeController::addFileSystemEntry(const QString &filePath, int line, int { QMT_ASSERT(diagram, return); - QString elementName = qmt::NameController::convertFileNameToElementName(Utils::FilePath::fromString(filePath)); + QString elementName = qmt::NameController::convertFileNameToElementName(FilePath::fromString(filePath)); QFileInfo fileInfo(filePath); if (fileInfo.exists() && fileInfo.isFile()) { @@ -212,7 +212,7 @@ qmt::MDiagram *PxNodeController::findDiagramForExplorerNode(const ProjectExplore return nullptr; 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 roots; roots.append(d->diagramSceneController->modelController()->rootPackage()); @@ -322,7 +322,7 @@ void PxNodeController::onMenuActionTriggered(PxNodeController::MenuAction *actio package->setStereotypes({action->stereotype}); d->diagramSceneController->modelController()->undoController()->beginMergeSequence(Tr::tr("Create Component Model")); 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)) { delete package; package = dynamic_cast(existingObject); @@ -346,8 +346,8 @@ void PxNodeController::onMenuActionTriggered(PxNodeController::MenuAction *actio item->setName(action->elementName); item->setVariety(action->stereotype); item->setVarietyEditable(false); - Utils::FilePath filePath = Utils::FilePath::fromString(action->filePath); - item->setLinkedFileName(filePath.relativePathFrom(Utils::FilePath::fromString(d->anchorFolder)).toString()); + FilePath filePath = FilePath::fromString(action->filePath); + item->setLinkedFileName(filePath.relativePathFrom(FilePath::fromString(d->anchorFolder))); newObject = item; dropInCurrentDiagram = true; break; @@ -363,7 +363,7 @@ void PxNodeController::onMenuActionTriggered(PxNodeController::MenuAction *actio } else { qmt::MObject *parentForDiagram = nullptr; QStringList relativeElements = qmt::NameController::buildElementsPath( - Utils::FilePath::fromString( + FilePath::fromString( d->pxnodeUtilities->calcRelativePath(filePath, d->anchorFolder)), dynamic_cast(newObject) != nullptr); if (qmt::MObject *existingObject = d->pxnodeUtilities->findSameObject(relativeElements, newObject)) { diff --git a/src/plugins/modeleditor/pxnodeutilities.cpp b/src/plugins/modeleditor/pxnodeutilities.cpp index 08de4bdb05f..5b8b27c8307 100644 --- a/src/plugins/modeleditor/pxnodeutilities.cpp +++ b/src/plugins/modeleditor/pxnodeutilities.cpp @@ -20,6 +20,8 @@ #include +using Utils::FilePath; + namespace ModelEditor { namespace Internal { @@ -51,8 +53,8 @@ QString PxNodeUtilities::calcRelativePath(const ProjectExplorer::Node *node, ? node->filePath().toFileInfo().path() : node->filePath().toString(); - return qmt::NameController::calcRelativePath(Utils::FilePath::fromString(nodePath), - Utils::FilePath::fromString(anchorFolder)).toString(); + return qmt::NameController::calcRelativePath(FilePath::fromString(nodePath), + FilePath::fromString(anchorFolder)).toString(); } QString PxNodeUtilities::calcRelativePath(const QString &filePath, const QString &anchorFolder) @@ -64,8 +66,8 @@ QString PxNodeUtilities::calcRelativePath(const QString &filePath, const QString path = fileInfo.path(); else path = filePath; - return qmt::NameController::calcRelativePath(Utils::FilePath::fromString(path), - Utils::FilePath::fromString(anchorFolder)).toString(); + return qmt::NameController::calcRelativePath(FilePath::fromString(path), + FilePath::fromString(anchorFolder)).toString(); } qmt::MPackage *PxNodeUtilities::createBestMatchingPackagePath( @@ -220,7 +222,7 @@ bool PxNodeUtilities::isProxyHeader(const QString &file) const { 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) { QList includes = document->resolvedIncludes(); if (includes.count() != 1)