diff options
Diffstat (limited to 'src/libs/modelinglib')
16 files changed, 109 insertions, 84 deletions
diff --git a/src/libs/modelinglib/qmt/config/configcontroller.cpp b/src/libs/modelinglib/qmt/config/configcontroller.cpp index 4bb9b806c4..2337c6873b 100644 --- a/src/libs/modelinglib/qmt/config/configcontroller.cpp +++ b/src/libs/modelinglib/qmt/config/configcontroller.cpp @@ -9,11 +9,8 @@ #include "qmt/stereotype/stereotypecontroller.h" -#include <QDir> -#include <QFileInfo> -#include <QFile> - #include <QDebug> +#include <QFile> namespace qmt { @@ -39,7 +36,7 @@ void ConfigController::setStereotypeController(StereotypeController *stereotypeC d->m_stereotypeController = stereotypeController; } -void ConfigController::readStereotypeDefinitions(const QString &path) +void ConfigController::readStereotypeDefinitions(const Utils::FilePath &path) { if (path.isEmpty()) { // TODO add error handling @@ -54,22 +51,17 @@ void ConfigController::readStereotypeDefinitions(const QString &path) connect(&parser, &StereotypeDefinitionParser::toolbarParsed, this, &ConfigController::onToolbarParsed); - QStringList fileNames; - QDir dir; - QFileInfo fileInfo(path); - if (fileInfo.isFile()) { - dir.setPath(fileInfo.path()); - fileNames.append(fileInfo.fileName()); - } else if (fileInfo.isDir()) { - dir.setPath(path); - dir.setNameFilters(QStringList("*.def")); - fileNames = dir.entryList(QDir::Files); + Utils::FilePaths paths; + if (path.isFile()) { + paths.append(path); + } else if (path.isDir()) { + paths = path.dirEntries({ { "*.def" } }); } else { // TODO add error handling return; } - for (const QString &fileName : std::as_const(fileNames)) { - QFile file(QFileInfo(dir, fileName).absoluteFilePath()); + 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(); diff --git a/src/libs/modelinglib/qmt/config/configcontroller.h b/src/libs/modelinglib/qmt/config/configcontroller.h index 28e6d65afc..7d8af82f6e 100644 --- a/src/libs/modelinglib/qmt/config/configcontroller.h +++ b/src/libs/modelinglib/qmt/config/configcontroller.h @@ -5,6 +5,8 @@ #include "qmt/infrastructure/qmt_global.h" +#include <utils/filepath.h> + #include <QObject> namespace qmt { @@ -24,7 +26,7 @@ public: void setStereotypeController(StereotypeController *stereotypeController); - void readStereotypeDefinitions(const QString &path); + void readStereotypeDefinitions(const Utils::FilePath &path); private: void onStereotypeIconParsed(const StereotypeIcon &stereotypeIcon); diff --git a/src/libs/modelinglib/qmt/controller/namecontroller.cpp b/src/libs/modelinglib/qmt/controller/namecontroller.cpp index d910be4b12..a6ffe99d58 100644 --- a/src/libs/modelinglib/qmt/controller/namecontroller.cpp +++ b/src/libs/modelinglib/qmt/controller/namecontroller.cpp @@ -3,7 +3,6 @@ #include "namecontroller.h" -#include <QFileInfo> #include <QDebug> 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 = fileInfo.baseName().trimmed(); + QString baseName = fileName.baseName().trimmed(); QString elementName; bool makeTitlecase = true; bool insertSpace = false; @@ -65,13 +63,19 @@ QString NameController::convertElementNameToBaseFileName(const QString &elementN 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 slashIndex = -1; int i = 0; - while (i < absoluteFileName.size() && i < anchorPath.size() && absoluteFileName.at(i) == anchorPath.at(i)) { - if (absoluteFileName.at(i) == QLatin1Char('/')) { + while (i < absoluteFilePath.size() && i < anchorPathString.size() + && absoluteFilePath.at(i) == anchorPathString.at(i)) + { + if (absoluteFilePath.at(i) == QLatin1Char('/')) { secondLastSlashIndex = slashIndex; slashIndex = i; } @@ -81,22 +85,22 @@ QString NameController::calcRelativePath(const QString &absoluteFileName, const QString relativePath; if (slashIndex < 0) { - relativePath = absoluteFileName; - } else if (i >= absoluteFileName.size()) { + relativePath = absoluteFilePath; + } else if (i >= absoluteFilePath.size()) { // absoluteFileName is a substring of anchor path. if (slashIndex == i - 1) { if (secondLastSlashIndex < 0) - relativePath = absoluteFileName; + relativePath = absoluteFilePath; else - relativePath = absoluteFileName.mid(secondLastSlashIndex + 1); + relativePath = absoluteFilePath.mid(secondLastSlashIndex + 1); } else { - relativePath = absoluteFileName.mid(slashIndex + 1); + relativePath = absoluteFilePath.mid(slashIndex + 1); } } else { - relativePath = absoluteFileName.mid(slashIndex + 1); + relativePath = absoluteFilePath.mid(slashIndex + 1); } - return relativePath; + return Utils::FilePath::fromString(relativePath); } QString NameController::calcElementNameSearchId(const QString &elementName) @@ -109,16 +113,17 @@ QString NameController::calcElementNameSearchId(const QString &elementName) return searchId; } -QStringList NameController::buildElementsPath(const QString &filePath, bool ignoreLastFilePathPart) +QStringList NameController::buildElementsPath(const Utils::FilePath &filePath, + bool ignoreLastFilePathPart) { QList<QString> relativeElements; - QStringList split = filePath.split("/"); + QStringList split = filePath.toString().split("/"); QStringList::const_iterator splitEnd = split.constEnd(); if (ignoreLastFilePathPart || split.last().isEmpty()) --splitEnd; 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); } return relativeElements; diff --git a/src/libs/modelinglib/qmt/controller/namecontroller.h b/src/libs/modelinglib/qmt/controller/namecontroller.h index 03e3be30bb..bb1ff0c3e1 100644 --- a/src/libs/modelinglib/qmt/controller/namecontroller.h +++ b/src/libs/modelinglib/qmt/controller/namecontroller.h @@ -6,6 +6,8 @@ #include <QObject> #include "qmt/infrastructure/qmt_global.h" +#include <utils/filepath.h> + #include <QString> #include <QStringList> @@ -18,12 +20,12 @@ private: ~NameController() override; public: - static QString convertFileNameToElementName(const QString &fileName); + static QString convertFileNameToElementName(const Utils::FilePath &fileName); static QString convertElementNameToBaseFileName(const QString &elementName); - // TODO use Utils::FilePath instead - static QString calcRelativePath(const QString &absoluteFileName, const QString &anchorPath); + static Utils::FilePath calcRelativePath(const Utils::FilePath &absoluteFileName, + const Utils::FilePath &anchorPath); 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, QString *className, QStringList *templateParameters); }; diff --git a/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp b/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp index 68184d2fb5..12ec26048e 100644 --- a/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp +++ b/src/libs/modelinglib/qmt/document_controller/documentcontroller.cpp @@ -32,8 +32,6 @@ #include "../../modelinglibtr.h" -#include <QFileInfo> - namespace qmt { DocumentController::DocumentController(QObject *parent) : @@ -233,7 +231,7 @@ MDiagram *DocumentController::findOrCreateRootDiagram() return rootDiagram; } -void DocumentController::createNewProject(const QString &fileName) +void DocumentController::createNewProject(const Utils::FilePath &fileName) { m_diagramsManager->removeAllDiagrams(); m_treeModel->setModelController(nullptr); @@ -246,7 +244,7 @@ void DocumentController::createNewProject(const QString &fileName) m_modelController->setRootPackage(m_projectController->project()->rootPackage()); } -void DocumentController::loadProject(const QString &fileName) +void DocumentController::loadProject(const Utils::FilePath &fileName) { m_diagramsManager->removeAllDiagrams(); m_treeModel->setModelController(nullptr); diff --git a/src/libs/modelinglib/qmt/document_controller/documentcontroller.h b/src/libs/modelinglib/qmt/document_controller/documentcontroller.h index 8053d189e0..9c5188e3f7 100644 --- a/src/libs/modelinglib/qmt/document_controller/documentcontroller.h +++ b/src/libs/modelinglib/qmt/document_controller/documentcontroller.h @@ -7,6 +7,8 @@ #include "qmt/infrastructure/qmt_global.h" #include "qmt/model_controller/modelcontroller.h" +#include <utils/filepath.h> + namespace qmt { class ProjectController; @@ -77,8 +79,8 @@ public: MDiagram *findRootDiagram(); MDiagram *findOrCreateRootDiagram(); - void createNewProject(const QString &fileName); - void loadProject(const QString &fileName); + void createNewProject(const Utils::FilePath &fileName); + void loadProject(const Utils::FilePath &fileName); private: ProjectController *m_projectController = nullptr; diff --git a/src/libs/modelinglib/qmt/infrastructure/ioexceptions.cpp b/src/libs/modelinglib/qmt/infrastructure/ioexceptions.cpp index 4af8df9236..04778cd0e3 100644 --- a/src/libs/modelinglib/qmt/infrastructure/ioexceptions.cpp +++ b/src/libs/modelinglib/qmt/infrastructure/ioexceptions.cpp @@ -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), m_fileName(fileName), m_lineNumber(lineNumber) { } -FileNotFoundException::FileNotFoundException(const QString &fileName) +FileNotFoundException::FileNotFoundException(const Utils::FilePath &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) { } -FileWriteError::FileWriteError(const QString &fileName, int lineNumber) +FileWriteError::FileWriteError(const Utils::FilePath &fileName, int 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) { } -IllegalXmlFile::IllegalXmlFile(const QString &fileName, int lineNumber) +IllegalXmlFile::IllegalXmlFile(const Utils::FilePath &fileName, int 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.") .arg(version), fileName, lineNumber) { diff --git a/src/libs/modelinglib/qmt/infrastructure/ioexceptions.h b/src/libs/modelinglib/qmt/infrastructure/ioexceptions.h index aece890529..7dc91ff4ba 100644 --- a/src/libs/modelinglib/qmt/infrastructure/ioexceptions.h +++ b/src/libs/modelinglib/qmt/infrastructure/ioexceptions.h @@ -5,6 +5,8 @@ #include "exceptions.h" +#include <utils/filepath.h> + namespace qmt { class IOException : public Exception @@ -16,51 +18,51 @@ public: class FileIOException : public IOException { public: - explicit FileIOException(const QString &errorMsg, const QString &fileName = QString(), + explicit FileIOException(const QString &errorMsg, const Utils::FilePath &fileName = {}, int lineNumber = -1); - QString fileName() const { return m_fileName; } + Utils::FilePath fileName() const { return m_fileName; } int lineNumber() const { return m_lineNumber; } private: - QString m_fileName; + Utils::FilePath m_fileName; int m_lineNumber = -1; }; class FileNotFoundException : public FileIOException { public: - explicit FileNotFoundException(const QString &fileName); + explicit FileNotFoundException(const Utils::FilePath &fileName); }; class FileCreationException : public FileIOException { public: - explicit FileCreationException(const QString &fileName); + explicit FileCreationException(const Utils::FilePath &fileName); }; class FileWriteError : public FileIOException { public: - explicit FileWriteError(const QString &fileName, int lineNumber = -1); + explicit FileWriteError(const Utils::FilePath &fileName, int lineNumber = -1); }; class FileReadError : public FileIOException { public: - explicit FileReadError(const QString &fileName, int lineNumber = -1); + explicit FileReadError(const Utils::FilePath &fileName, int lineNumber = -1); }; class IllegalXmlFile : public FileIOException { public: - explicit IllegalXmlFile(const QString &fileName, int lineNumber = -1); + explicit IllegalXmlFile(const Utils::FilePath &fileName, int lineNumber = -1); }; class UnknownFileVersion : public FileIOException { public: - UnknownFileVersion(int version, const QString &fileName, int lineNumber = -1); + UnknownFileVersion(int version, const Utils::FilePath &fileName, int lineNumber = -1); }; } // namespace qmt diff --git a/src/libs/modelinglib/qmt/project/project.cpp b/src/libs/modelinglib/qmt/project/project.cpp index 098db684ef..bc0ed449a3 100644 --- a/src/libs/modelinglib/qmt/project/project.cpp +++ b/src/libs/modelinglib/qmt/project/project.cpp @@ -23,7 +23,7 @@ bool Project::hasFileName() const return !m_fileName.isEmpty(); } -void Project::setFileName(const QString &fileName) +void Project::setFileName(const Utils::FilePath &fileName) { m_fileName = fileName; } @@ -33,7 +33,7 @@ void Project::setRootPackage(MPackage *rootPackage) m_rootPackage = rootPackage; } -void Project::setConfigPath(const QString &configPath) +void Project::setConfigPath(const Utils::FilePath &configPath) { m_configPath = configPath; } diff --git a/src/libs/modelinglib/qmt/project/project.h b/src/libs/modelinglib/qmt/project/project.h index fab6bb4228..556471e9ed 100644 --- a/src/libs/modelinglib/qmt/project/project.h +++ b/src/libs/modelinglib/qmt/project/project.h @@ -5,6 +5,8 @@ #include "qmt/infrastructure/uid.h" +#include <utils/filepath.h> + #include <QString> namespace qmt { @@ -20,18 +22,18 @@ public: Uid uid() const { return m_uid; } void setUid(const Uid &uid); bool hasFileName() const; - QString fileName() const { return m_fileName; } - void setFileName(const QString &fileName); + Utils::FilePath fileName() const { return m_fileName; } + void setFileName(const Utils::FilePath &fileName); MPackage *rootPackage() const { return m_rootPackage; } void setRootPackage(MPackage *rootPackage); - QString configPath() const { return m_configPath; } - void setConfigPath(const QString &configPath); + Utils::FilePath configPath() const { return m_configPath; } + void setConfigPath(const Utils::FilePath &configPath); private: Uid m_uid; - QString m_fileName; + Utils::FilePath m_fileName; MPackage *m_rootPackage = nullptr; - QString m_configPath; + Utils::FilePath m_configPath; }; } // namespace qmt diff --git a/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp b/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp index f7a7e6d2c9..f5d5225d03 100644 --- a/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp +++ b/src/libs/modelinglib/qmt/project_controller/projectcontroller.cpp @@ -31,7 +31,7 @@ ProjectController::~ProjectController() { } -void ProjectController::newProject(const QString &fileName) +void ProjectController::newProject(const Utils::FilePath &fileName) { m_project.reset(new Project()); auto rootPackage = new MPackage(); @@ -43,7 +43,7 @@ void ProjectController::newProject(const QString &fileName) emit changed(); } -void ProjectController::setFileName(const QString &fileName) +void ProjectController::setFileName(const Utils::FilePath &fileName) { if (fileName != m_project->fileName()) { m_project->setFileName(fileName); @@ -82,7 +82,7 @@ void ProjectController::save() emit changed(); } -void ProjectController::saveAs(const QString &fileName) +void ProjectController::saveAs(const Utils::FilePath &fileName) { setFileName(fileName); save(); diff --git a/src/libs/modelinglib/qmt/project_controller/projectcontroller.h b/src/libs/modelinglib/qmt/project_controller/projectcontroller.h index 1992c72448..09cf65074a 100644 --- a/src/libs/modelinglib/qmt/project_controller/projectcontroller.h +++ b/src/libs/modelinglib/qmt/project_controller/projectcontroller.h @@ -6,6 +6,8 @@ #include "qmt/infrastructure/exceptions.h" #include "qmt/infrastructure/qmt_global.h" +#include <utils/filepath.h> + #include <QObject> #include <QString> @@ -35,19 +37,19 @@ public: signals: void changed(); - void fileNameChanged(const QString &fileName); + void fileNameChanged(const Utils::FilePath &fileName); public: Project *project() const { return m_project.data(); } bool isModified() const { return m_isModified; } - void newProject(const QString &fileName); - void setFileName(const QString &fileName); + void newProject(const Utils::FilePath &fileName); + void setFileName(const Utils::FilePath &fileName); void setModified(); void load(); void save(); - void saveAs(const QString &fileName); + void saveAs(const Utils::FilePath &fileName); private: QScopedPointer<Project> m_project; diff --git a/src/libs/modelinglib/qmt/serializer/infrastructureserializer.h b/src/libs/modelinglib/qmt/serializer/infrastructureserializer.h index e67e5af4eb..2313ab8aba 100644 --- a/src/libs/modelinglib/qmt/serializer/infrastructureserializer.h +++ b/src/libs/modelinglib/qmt/serializer/infrastructureserializer.h @@ -3,6 +3,8 @@ #pragma once +#include <utils/filepath.h> + #include "qmt/infrastructure/handle.h" #include "qmt/infrastructure/handles.h" #include "qmt/infrastructure/uid.h" @@ -51,4 +53,20 @@ inline void serialize(Archive &archive, qmt::Handles<T> &handles) || 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 diff --git a/src/libs/modelinglib/qmt/serializer/projectserializer.cpp b/src/libs/modelinglib/qmt/serializer/projectserializer.cpp index 77f231b358..ecb5538f0c 100644 --- a/src/libs/modelinglib/qmt/serializer/projectserializer.cpp +++ b/src/libs/modelinglib/qmt/serializer/projectserializer.cpp @@ -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); - QFile file(fileName); + QFile file(fileName.toString()); if (!file.open(QIODevice::WriteOnly)) throw FileCreationException(fileName); @@ -84,11 +84,11 @@ QByteArray ProjectSerializer::save(const Project *project) return buffer; } -void ProjectSerializer::load(const QString &fileName, Project *project) +void ProjectSerializer::load(const Utils::FilePath &fileName, Project *project) { QMT_ASSERT(project, return); - QFile file(fileName); + QFile file(fileName.toString()); if (!file.open(QIODevice::ReadOnly)) throw FileNotFoundException(fileName); diff --git a/src/libs/modelinglib/qmt/serializer/projectserializer.h b/src/libs/modelinglib/qmt/serializer/projectserializer.h index c6dd74bcd8..bafa407071 100644 --- a/src/libs/modelinglib/qmt/serializer/projectserializer.h +++ b/src/libs/modelinglib/qmt/serializer/projectserializer.h @@ -5,6 +5,8 @@ #include "qmt/infrastructure/qmt_global.h" +#include <utils/filepath.h> + #include <QString> QT_BEGIN_NAMESPACE @@ -21,9 +23,9 @@ public: ProjectSerializer(); ~ProjectSerializer(); - void save(const QString &fileName, const Project *project); + void save(const Utils::FilePath &fileName, const Project *project); QByteArray save(const Project *project); - void load(const QString &fileName, Project *project); + void load(const Utils::FilePath &fileName, Project *project); private: void write(QXmlStreamWriter *writer, const Project *project); diff --git a/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp b/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp index 51f414f66e..23f6ddc297 100644 --- a/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp +++ b/src/libs/modelinglib/qmt/tasks/diagramscenecontroller.cpp @@ -42,8 +42,6 @@ #include "../../modelinglibtr.h" #include <QMenu> -#include <QFileInfo> -#include <QDir> #include <QQueue> #include <QPair> |