ModelEditor: More use of Utils::FilePath

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

View File

@@ -10,7 +10,9 @@
#include "qmt/stereotype/stereotypecontroller.h"
#include <QDebug>
#include <QFile>
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);

View File

@@ -5,6 +5,8 @@
#include <QDebug>
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<QString> 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;

View File

@@ -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;
}

View File

@@ -7,6 +7,8 @@
#include "qmt/infrastructure/uid.h"
#include <utils/filepath.h>
#include <QImage>
#include <QList>
#include <QPointF>
@@ -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;
};

View File

@@ -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);

View File

@@ -7,6 +7,8 @@
#include <QObject>
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)
{

View File

@@ -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;
}

View File

@@ -6,6 +6,8 @@
#include "melement.h"
#include "qmt/infrastructure/handles.h"
#include <utils/filepath.h>
#include <QString>
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<MObject> &children() const { return m_children; }
void setChildren(const Handles<MObject> &children);
@@ -50,7 +52,7 @@ public:
private:
QString m_name;
QString m_linkedfilename;
Utils::FilePath m_linkedfilename;
Handles<MObject> m_children;
Handles<MRelation> m_relations;
};

View File

@@ -30,6 +30,8 @@
#include <QStandardItem>
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,

View File

@@ -9,6 +9,8 @@
#include <qmt/stereotype/stereotypeicon.h>
#include <qmt/style/styleengine.h>
#include <utils/filepath.h>
#include <QScopedPointer>
#include <QHash>
@@ -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,

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -58,7 +58,7 @@ inline void serialize(Archive &archive, qmt::Handles<T> &handles)
template<class Archive>
inline void save(Archive &archive, const Utils::FilePath &filePath)
{
archive.write(filePath.toString());
archive.write(filePath.toFSPathString());
}
template<class Archive>
@@ -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

View File

@@ -20,6 +20,8 @@
#include <QFile>
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);

View File

@@ -10,6 +10,8 @@
#include "qmt/infrastructure/qmtassert.h"
#include "qmt/style/style.h"
#include <utils/filepath.h>
#include <utils/algorithm.h>
#include <QHash>
@@ -19,12 +21,14 @@
#include <algorithm>
using Utils::FilePath;
namespace qmt {
namespace {
struct IconKey {
IconKey(StereotypeIcon::Element element, const QList<QString> &stereotypes, const QString &defaultIconPath,
IconKey(StereotypeIcon::Element element, const QList<QString> &stereotypes, const FilePath &defaultIconPath,
const Uid &styleUid, const QSize &size, const QMarginsF &margins, qreal lineWidth)
: m_element(element),
m_stereotypes(stereotypes),
@@ -53,7 +57,7 @@ struct IconKey {
const StereotypeIcon::Element m_element;
const QList<QString> 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<QString> &stereotypes,
const QString &defaultIconPath, const Style *style, const QSize &size,
const FilePath &defaultIconPath, const Style *style, const QSize &size,
const QMarginsF &margins, qreal lineWidth)
{
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;

View File

@@ -5,6 +5,8 @@
#include "stereotypeicon.h"
#include <utils/filepath.h>
#include <QMarginsF>
#include <QObject>
@@ -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<QString> &stereotypes,
const QString &defaultIconPath, const Style *style,
const QSize &size, const QMarginsF &margins, qreal lineWidth);
QIcon createIcon(StereotypeIcon::Element element,
const QList<QString> &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);

View File

@@ -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<CPlusPlus::Document::Include> 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 {

View File

@@ -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<const qmt::MObject *>(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<const qmt::MObject *>(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"),

View File

@@ -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());
}

View File

@@ -21,6 +21,8 @@
#include <QMimeDatabase>
#include <QImageReader>
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<qmt::MObject, QString>(m_modelElements, SelectionSingle, QString(),
&qmt::MObject::linkedFileName, &qmt::MObject::setLinkedFileName);
assignModelElement<qmt::MObject, Utils::FilePath>(
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<qmt::MObject, QString>(m_modelElements, SelectionSingle, relativeFilePath,
&qmt::MObject::linkedFileName, &qmt::MObject::setLinkedFileName);
assignModelElement<qmt::MObject, Utils::FilePath>(
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<qmt::DObject, QString>(m_diagramElements, SelectionSingle, QString(),
&qmt::DObject::imagePath, &qmt::DObject::setImagePath);
assignModelElement<qmt::DObject, Utils::FilePath>(
m_diagramElements,
SelectionSingle,
{},
&qmt::DObject::imagePath,
&qmt::DObject::setImagePath);
assignModelElement<qmt::DObject, QImage>(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<qmt::DObject, QString>(m_diagramElements, SelectionSingle, relativeFilePath,
&qmt::DObject::imagePath))
{
&& isValueChanged<qmt::DObject, Utils::FilePath>(
m_diagramElements, SelectionSingle, relativeFilePath, &qmt::DObject::imagePath)) {
QImage image;
if (image.load(path)) {
assignModelElement<qmt::DObject, QString>(m_diagramElements, SelectionSingle, relativeFilePath,
&qmt::DObject::imagePath, &qmt::DObject::setImagePath);
assignModelElement<qmt::DObject, Utils::FilePath>(
m_diagramElements,
SelectionSingle,
relativeFilePath,
&qmt::DObject::imagePath,
&qmt::DObject::setImagePath);
assignModelElement<qmt::DObject, QImage>(m_diagramElements, SelectionSingle, image,
&qmt::DObject::image, &qmt::DObject::setImage);
} else {

View File

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

View File

@@ -19,6 +19,8 @@
#include <utils/id.h>
#include <utils/fileutils.h>
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);

View File

@@ -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});

View File

@@ -36,6 +36,8 @@
#include <QPointer>
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<QueuedFile> filesQueue;
QSet<QueuedFile> 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);

View File

@@ -41,6 +41,8 @@
#include <QTimer>
#include <QAction>
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);
}

View File

@@ -30,7 +30,7 @@
#include <QMenu>
#include <QQueue>
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<qmt::MPackage *> 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<qmt::MPackage *>(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<qmt::MPackage *>(newObject) != nullptr);
if (qmt::MObject *existingObject = d->pxnodeUtilities->findSameObject(relativeElements, newObject)) {

View File

@@ -20,6 +20,8 @@
#include <typeinfo>
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<CPlusPlus::Document::Include> includes = document->resolvedIncludes();
if (includes.count() != 1)