Commit 293cc570 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Modeleditor: Use a JSON-based wizard



Use a JSON wizard in favor of implementing the same thing in
code.

Change-Id: I5952bf417255fb75378e42e3e80b13c0a0d3d317
Reviewed-by: default avatarJochen Becher <jochen_becher@gmx.de>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent c2bf384a
<?xml version="1.0" encoding="UTF-8"?>
<qmt>
<project>
<uid>%{UUID1}</uid>
<root-package>
<instance>
<MPackage>
<base-MObject>
<MObject>
<base-MElement>
<MElement>
<uid>%{UUID2}</uid>
</MElement>
</base-MElement>
<name>%{Name}</name>
<children>
<handles>
<handles>
<qlist>
<item>
<handle>
<uid>%{UUID3}</uid>
<target>
<instance type="MCanvasDiagram">
<MCanvasDiagram>
<base-MDiagram>
<MDiagram>
<base-MObject>
<MObject>
<base-MElement>
<MElement>
<uid>%{UUID3}</uid>
</MElement>
</base-MElement>
<name>%{Name}</name>
</MObject>
</base-MObject>
</MDiagram>
</base-MDiagram>
</MCanvasDiagram>
</instance>
</target>
</handle>
</item>
</qlist>
</handles>
</handles>
</children>
</MObject>
</base-MObject>
</MPackage>
</instance>
</root-package>
</project>
</qmt>
{
"version": 1,
"kind": "file",
"id": "SA.Model",
"category": "O.Model",
"trDescription": "Creates a new empty model with an empty diagram.",
"trDisplayName": "Model",
"trDisplayCategory": "Modeling",
"platformIndependent": true,
"icon": "../../global/genericfilewizard.png",
"enabled": "%{JS: [ %{Plugins} ].indexOf('ModelEditor') >= 0}",
"options":
[
{ "key": "TargetPath", "value": "%{JS: Util.fileName('%{Location}/%{FileName}', '%{JS: Util.preferredSuffix('text/vnd.qtcreator.model')}')}" },
{ "key": "FileName", "value": "%{JS: Modeling.elementNameToFileName('%{Name}')}" }
],
"pages" :
[
{
"trDisplayName": "Model Name and Location",
"trShortTitle": "Location",
"typeId": "Fields",
"data":
[
{
"name": "Name",
"trDisplayName": "Model name:",
"mandatory": true,
"type": "LineEdit"
},
{
"name": "Location",
"trDisplayName": "Location:",
"type": "PathChooser",
"isComplete": "%{JS: '%{Location}' === '' || !Util.exists('%{TargetPath}')}",
"trIncompleteMessage": "\"%{JS: Util.toNativeSeparators('%{TargetPath}')}\" exists in the filesystem.",
"data":
{
"kind": "existingDirectory",
"basePath": "%{InitialPath}",
"path": "%{InitialPath}"
}
}
]
}
],
"generators" :
[
{
"typeId": "File",
"data":
{
"source": "file.qmodel",
"target": "%{TargetPath}",
"openInEditor": true,
"options":
[
{ "key": "UUID1", "value": "%{UUID}", "evaluate": true },
{ "key": "UUID2", "value": "%{UUID}", "evaluate": true },
{ "key": "UUID3", "value": "%{UUID}", "evaluate": true }
]
}
}
]
}
......@@ -39,7 +39,6 @@ SOURCES += \
modeldocument.cpp \
modeleditor.cpp \
modeleditorfactory.cpp \
modeleditor_file_wizard.cpp \
modeleditor_plugin.cpp \
modelindexer.cpp \
modelsmanager.cpp \
......@@ -62,7 +61,6 @@ HEADERS += \
modeldocument.h \
modeleditor_constants.h \
modeleditorfactory.h \
modeleditor_file_wizard.h \
modeleditor_global.h \
modeleditor.h \
modeleditor_plugin.h \
......
......@@ -43,8 +43,6 @@ QtcPlugin {
"modeleditor.cpp",
"modeleditorfactory.cpp",
"modeleditorfactory.h",
"modeleditor_file_wizard.cpp",
"modeleditor_file_wizard.h",
"modeleditor_global.h",
"modeleditor.h",
"modeleditor_plugin.cpp",
......
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "modeleditor_file_wizard.h"
#include "modeleditor_constants.h"
#include "qmt/controller/namecontroller.h"
#include "qmt/model/mcanvasdiagram.h"
#include "qmt/model/mpackage.h"
#include "qmt/serializer/projectserializer.h"
#include "qmt/project/project.h"
#include <coreplugin/basefilewizard.h>
#include <utils/filewizardpage.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
namespace ModelEditor {
namespace Internal {
FileWizardFactory::FileWizardFactory()
: Core::BaseFileWizardFactory()
{
setWizardKind(Core::IWizardFactory::FileWizard);
setCategory(QLatin1String(Constants::WIZARD_CATEGORY));
QString trCategory = QCoreApplication::translate(Constants::WIZARD_CATEGORY,
Constants::WIZARD_TR_CATEGORY);
setDisplayCategory(trCategory);
setDisplayName(tr("Model"));
setId(Constants::WIZARD_MODEL_ID);
setDescription(tr("Creates an empty model"));
setFlags(Core::IWizardFactory::PlatformIndependent);
}
Core::BaseFileWizard *FileWizardFactory::create(
QWidget *parent, const Core::WizardDialogParameters &parameters) const
{
auto wizard = new Core::BaseFileWizard(this, QVariantMap(), parent);
wizard->setWindowTitle(tr("New %1").arg(displayName()));
auto page = new Utils::FileWizardPage;
if (parameters.flags().testFlag(Core::WizardDialogParameters::ForceCapitalLetterForFileName))
page->setForceFirstCapitalLetterForFileName(true);
page->setTitle(tr("Model Name and Location"));
page->setFileNameLabel(tr("Model name:"));
page->setPathLabel(tr("Location:"));
page->setPath(parameters.defaultPath());
wizard->addPage(page);
foreach (QWizardPage *p, wizard->extensionPages())
wizard->addPage(p);
return wizard;
}
Core::GeneratedFiles FileWizardFactory::generateFiles(const QWizard *w,
QString *errorMessage) const
{
const Utils::Wizard *wizard = qobject_cast<const Utils::Wizard *>(w);
Utils::FileWizardPage *page = wizard->find<Utils::FileWizardPage>();
QTC_ASSERT(page, return Core::GeneratedFiles());
return generateFilesFromPath(page->path(), page->fileName(), errorMessage);
}
Core::GeneratedFiles FileWizardFactory::generateFilesFromPath(const QString &path,
const QString &name,
QString *errorMessage) const
{
Q_UNUSED(errorMessage);
Core::GeneratedFiles files;
const QString suffix = preferredSuffix(QLatin1String(Constants::MIME_TYPE_MODEL));
const QString fileName = Core::BaseFileWizardFactory::buildFileName(path, name, suffix);
Core::GeneratedFile file(fileName);
auto rootPackage = new qmt::MPackage();
rootPackage->setName(qmt::NameController::convertFileNameToElementName(fileName));
auto rootDiagram = new qmt::MCanvasDiagram();
rootDiagram->setName(qmt::NameController::convertFileNameToElementName(fileName));
rootPackage->addChild(rootDiagram);
qmt::Project project;
project.setRootPackage(rootPackage);
project.setFileName(fileName);
qmt::ProjectSerializer serializer;
QByteArray contents = serializer.save(&project);
file.setContents(QString::fromUtf8(contents));
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
files << file;
return files;
}
} // namespace Internal
} // namespace ModelEditor
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef MODELEDITOR_FILE_WIZARD_H
#define MODELEDITOR_FILE_WIZARD_H
#include <coreplugin/basefilewizardfactory.h>
namespace ModelEditor {
namespace Internal {
class FileWizardFactory :
public Core::BaseFileWizardFactory
{
Q_OBJECT
public:
explicit FileWizardFactory();
protected:
Core::BaseFileWizard *create(QWidget *parent,
const Core::WizardDialogParameters &parameters) const override;
Core::GeneratedFiles generateFiles(const QWizard *w, QString *errorMessage) const override;
private:
Core::GeneratedFiles generateFilesFromPath(const QString &path, const QString &name,
QString *errorMessage) const;
};
} // namespace Internal
} // namespace ModelEditor
#endif // MODELEDITOR_FILE_WIZARD_H
......@@ -34,7 +34,6 @@
#include "modelsmanager.h"
#include "settingscontroller.h"
#include "modeleditor_constants.h"
#include "modeleditor_file_wizard.h"
#include "uicontroller.h"
#include "jsextension.h"
......@@ -103,10 +102,6 @@ bool ModelEditorPlugin::initialize(const QStringList &arguments, QString *errorS
d->uiController = new UiController(this);
addAutoReleasedObject(d->uiController);
Core::IWizardFactory::registerFactoryCreator([]() {
return QList<Core::IWizardFactory *>() << new FileWizardFactory;
});
d->modelFactory = new ModelEditorFactory(d->uiController, this);
addAutoReleasedObject(d->modelFactory);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment