forked from qt-creator/qt-creator
ModelEditor: Support model specific customization
If the model contains a configuration path to a configuration file (or a directory of configuration files) the configuration is loaded for that model only. The file path may be relative to the model file. No UI support for this feature yet. Change-Id: Ia3615da3e57fc4731926a5970ba1b2f741d64e21 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -68,15 +68,32 @@ void ConfigController::setStereotypeController(StereotypeController *stereotypeC
|
|||||||
|
|
||||||
void ConfigController::readStereotypeDefinitions(const QString &path)
|
void ConfigController::readStereotypeDefinitions(const QString &path)
|
||||||
{
|
{
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
// TODO add error handling
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
StereotypeDefinitionParser parser;
|
StereotypeDefinitionParser parser;
|
||||||
connect(&parser, &StereotypeDefinitionParser::iconParsed,
|
connect(&parser, &StereotypeDefinitionParser::iconParsed,
|
||||||
this, &ConfigController::onStereotypeIconParsed);
|
this, &ConfigController::onStereotypeIconParsed);
|
||||||
connect(&parser, &StereotypeDefinitionParser::toolbarParsed,
|
connect(&parser, &StereotypeDefinitionParser::toolbarParsed,
|
||||||
this, &ConfigController::onToolbarParsed);
|
this, &ConfigController::onToolbarParsed);
|
||||||
|
|
||||||
QDir dir(path);
|
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() << QStringLiteral("*.def"));
|
dir.setNameFilters(QStringList() << QStringLiteral("*.def"));
|
||||||
foreach (const QString &fileName, dir.entryList(QDir::Files)) {
|
fileNames = dir.entryList(QDir::Files);
|
||||||
|
} else {
|
||||||
|
// TODO add error handling
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach (const QString &fileName, fileNames) {
|
||||||
QFile file(QFileInfo(dir, fileName).absoluteFilePath());
|
QFile file(QFileInfo(dir, fileName).absoluteFilePath());
|
||||||
if (file.open(QIODevice::ReadOnly)) {
|
if (file.open(QIODevice::ReadOnly)) {
|
||||||
QString text = QString::fromUtf8(file.readAll());
|
QString text = QString::fromUtf8(file.readAll());
|
||||||
@@ -87,10 +104,13 @@ void ConfigController::readStereotypeDefinitions(const QString &path)
|
|||||||
try {
|
try {
|
||||||
parser.parse(&source);
|
parser.parse(&source);
|
||||||
} catch (StereotypeDefinitionParserError x) {
|
} catch (StereotypeDefinitionParserError x) {
|
||||||
|
// TODO add error handling
|
||||||
qDebug() << x.errorMessage() << "in line" << x.sourcePos().lineNumber();
|
qDebug() << x.errorMessage() << "in line" << x.sourcePos().lineNumber();
|
||||||
} catch (TextScannerError x) {
|
} catch (TextScannerError x) {
|
||||||
|
// TODO add error handling
|
||||||
qDebug() << x.errorMessage() << "in line" << x.sourcePos().lineNumber();
|
qDebug() << x.errorMessage() << "in line" << x.sourcePos().lineNumber();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
// TODO add error handling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,4 +60,9 @@ void Project::setRootPackage(MPackage *rootPackage)
|
|||||||
m_rootPackage = rootPackage;
|
m_rootPackage = rootPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::setConfigPath(const QString &configPath)
|
||||||
|
{
|
||||||
|
m_configPath = configPath;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace qmt
|
} // namespace qmt
|
||||||
|
|||||||
@@ -52,11 +52,14 @@ public:
|
|||||||
void setFileName(const QString &fileName);
|
void setFileName(const QString &fileName);
|
||||||
MPackage *rootPackage() const { return m_rootPackage; }
|
MPackage *rootPackage() const { return m_rootPackage; }
|
||||||
void setRootPackage(MPackage *rootPackage);
|
void setRootPackage(MPackage *rootPackage);
|
||||||
|
QString configPath() const { return m_configPath; }
|
||||||
|
void setConfigPath(const QString &configPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Uid m_uid;
|
Uid m_uid;
|
||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
MPackage *m_rootPackage;
|
MPackage *m_rootPackage;
|
||||||
|
QString m_configPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace qmt
|
} // namespace qmt
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ void serialize(Archive &archive, Project &project)
|
|||||||
archive || qark::tag(QStringLiteral("project"), project)
|
archive || qark::tag(QStringLiteral("project"), project)
|
||||||
|| qark::attr(QStringLiteral("uid"), project, &Project::uid, &Project::setUid)
|
|| qark::attr(QStringLiteral("uid"), project, &Project::uid, &Project::setUid)
|
||||||
|| qark::attr(QStringLiteral("root-package"), project, &Project::rootPackage, &Project::setRootPackage)
|
|| qark::attr(QStringLiteral("root-package"), project, &Project::rootPackage, &Project::setRootPackage)
|
||||||
|
|| qark::attr(QStringLiteral("config-path"), project, &Project::configPath, &Project::setConfigPath)
|
||||||
|| qark::end;
|
|| qark::end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include "modelsmanager.h"
|
#include "modelsmanager.h"
|
||||||
#include "extdocumentcontroller.h"
|
#include "extdocumentcontroller.h"
|
||||||
|
|
||||||
|
#include "qmt/config/configcontroller.h"
|
||||||
#include "qmt/infrastructure/ioexceptions.h"
|
#include "qmt/infrastructure/ioexceptions.h"
|
||||||
#include "qmt/model_controller/modelcontroller.h"
|
#include "qmt/model_controller/modelcontroller.h"
|
||||||
#include "qmt/model/mdiagram.h"
|
#include "qmt/model/mdiagram.h"
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
namespace ModelEditor {
|
namespace ModelEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -158,6 +160,17 @@ Core::IDocument::OpenResult ModelDocument::load(QString *errorString, const QStr
|
|||||||
return OpenResult::CannotHandle;
|
return OpenResult::CannotHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString configPath = d->documentController->projectController()->project()->configPath();
|
||||||
|
if (!configPath.isEmpty()) {
|
||||||
|
QString canonicalPath = QFileInfo(QDir(QFileInfo(fileName).path()).filePath(configPath)).canonicalFilePath();
|
||||||
|
if (!canonicalPath.isEmpty()) {
|
||||||
|
// TODO error output on reading definition files
|
||||||
|
d->documentController->configController()->readStereotypeDefinitions(canonicalPath);
|
||||||
|
} else {
|
||||||
|
// TODO error output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit contentSet();
|
emit contentSet();
|
||||||
return OpenResult::Success;
|
return OpenResult::Success;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user