diff options
author | Sandro S. Andrade <sandroandrade@kde.org> | 2013-06-06 17:59:01 -0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-06 23:02:35 +0200 |
commit | c71b5e1344977a555e723cdc1e69c10fa9ccdb76 (patch) | |
tree | 8770cc792b79de04afbb999df54baef5e6134cfd | |
parent | 4dabb0e30d5a263e38fec3c82ac2a7a9ba3fab73 (diff) |
Add creation of new models from scratch in qtumleditor
Change-Id: I155016a8da62376e0c0c9621f46313b7f2e8a85f
Reviewed-by: Sandro S. Andrade <sandroandrade@kde.org>
-rw-r--r-- | examples/uml/qtumleditor/mainwindow.cpp | 61 | ||||
-rw-r--r-- | examples/uml/qtumleditor/mainwindow.h | 6 | ||||
-rw-r--r-- | examples/uml/qtumleditor/mainwindow.ui | 19 | ||||
-rw-r--r-- | examples/uml/qtumleditor/newmodel.ui | 98 | ||||
-rw-r--r-- | examples/uml/qtumleditor/qtumleditor.pro | 3 | ||||
-rw-r--r-- | src/plugins/metamodels/mof/mof.json | 3 | ||||
-rw-r--r-- | src/plugins/metamodels/uml/uml.json | 5 |
7 files changed, 184 insertions, 11 deletions
diff --git a/examples/uml/qtumleditor/mainwindow.cpp b/examples/uml/qtumleditor/mainwindow.cpp index f62978df..9ea275a9 100644 --- a/examples/uml/qtumleditor/mainwindow.cpp +++ b/examples/uml/qtumleditor/mainwindow.cpp @@ -41,8 +41,10 @@ #include "mainwindow.h" #include "ui_mainwindow.h" #include "ui_aboutplugins.h" +#include "ui_newmodel.h" #include <QtCore/QTimer> +#include <QtCore/QJsonArray> #include <QtCore/QPluginLoader> #include <QtCore/QStringListModel> #include <QtCore/QStringListModel> @@ -70,16 +72,20 @@ MainWindow::MainWindow(QWidget *parent) : _wrappedObjectModel(new QWrappedObjectModel(this)), _aboutPluginsDialog(new QDialog(this)), _aboutPlugins(new Ui::AboutPlugins), + _newModelDialog(new QDialog(this)), + _newModel(new Ui::NewModel), _codeCompletionView(new QListView) { ui->setupUi(this); _codeCompletionView->setParent(ui->txeJavaScript); _codeCompletionView->hide(); - _aboutPlugins->setupUi(_aboutPluginsDialog); - ui->wrappedObjectView->setModel(_wrappedObjectModel); + _newModel->setupUi(_newModelDialog); + connect(_newModel->cboMetamodel, SIGNAL(currentIndexChanged(QString)), SLOT(metaModelChanged(QString))); + _aboutPlugins->setupUi(_aboutPluginsDialog); + QWrappedObjectPropertyModel *propertyModel = new QWrappedObjectPropertyModel(this); ui->propertyEditor->setModel(propertyModel); @@ -111,6 +117,35 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::on_actionFileNew_triggered() +{ + _newModel->lneModel->clear(); + _newModel->cboMetamodel->clear(); + int i = 0; + typedef QPair<QMetaModelPlugin *, QJsonObject> PluginData; + foreach (const PluginData &pair, _loadedPlugins.values()) { + _newModel->cboMetamodel->addItem(pair.first->metaObject()->className()); + ++i; + } + int type; + if (_newModelDialog->exec() == QDialog::Accepted) { + foreach (const PluginData &pair, _loadedPlugins.values()) { + if (pair.first->metaObject()->className() == _newModel->cboMetamodel->currentText()) + pair.first->initMetaModel(&_engine); + } + if ((type = QMetaType::type(_newModel->lstTopLevelContainers->currentItem()->text().append("*").toLatin1())) != QMetaType::UnknownType) { + const QMetaObject *metaObject = QMetaType::metaObjectForType(type); + if (metaObject) { + QWrappedObject *topLevelElement = dynamic_cast<QWrappedObject *>(metaObject->newInstance()); + if (topLevelElement) { + topLevelElement->setObjectName(_newModel->lneModel->text()); + _wrappedObjectModel->setWrappedObject(topLevelElement); + } + } + } + } +} + void MainWindow::saveXmi(QWrappedObject *rootElement) { QFile file(_currentFileName); @@ -122,8 +157,10 @@ void MainWindow::saveXmi(QWrappedObject *rootElement) QXmiWriter writer(rootElement); if (!writer.writeFile(&file)) QMessageBox::critical(this, tr("Save As"), tr("Error when writing XMI file !")); - else + else { statusBar()->showMessage("XMI file successfully saved !", 3000); + setWindowTitle(QFileInfo(file).fileName() + " - QtUml Editor"); + } } QWrappedObject *MainWindow::loadXmi() @@ -198,6 +235,20 @@ void MainWindow::on_psbJSEvaluate_clicked() ui->wrappedObjectView->updateSelected(); } +void MainWindow::metaModelChanged(QString newMetaModel) +{ + _newModel->lstTopLevelContainers->clear(); + QVariantList list; + typedef QPair<QMetaModelPlugin *, QJsonObject> PluginData; + foreach (const PluginData &pair, _loadedPlugins.values()) { + if (pair.first->metaObject()->className() == newMetaModel) + list = pair.second.value("MetaModelTopLevelClasses").toArray().toVariantList(); + } + foreach (QVariant variant, list) + _newModel->lstTopLevelContainers->addItem(variant.toString()); + _newModel->lstTopLevelContainers->setCurrentRow(0); +} + bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::KeyPress && obj == ui->txeJavaScript) { @@ -244,15 +295,13 @@ void MainWindow::loadPlugins() { QMetaModelPlugin *metaModelPlugin = 0; foreach (QString pluginPath, QCoreApplication::libraryPaths()) { - qDebug() << "Plugin path:" << pluginPath; QDir pluginsDir(pluginPath); pluginsDir.cd("metamodels"); foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); QObject *plugin = loader.instance(); - if (plugin && (metaModelPlugin = qobject_cast<QMetaModelPlugin *>(plugin))) { + if (plugin && (metaModelPlugin = qobject_cast<QMetaModelPlugin *>(plugin))) _loadedPlugins.insert(loader.metaData().value(QString::fromLatin1("MetaData")).toObject().value(QString::fromLatin1("MetaModelNamespaceUri")).toString(), QPair<QMetaModelPlugin *, QJsonObject>(metaModelPlugin, loader.metaData().value(QString::fromLatin1("MetaData")).toObject())); - } } } } diff --git a/examples/uml/qtumleditor/mainwindow.h b/examples/uml/qtumleditor/mainwindow.h index f2303662..1ad996a5 100644 --- a/examples/uml/qtumleditor/mainwindow.h +++ b/examples/uml/qtumleditor/mainwindow.h @@ -54,6 +54,7 @@ class QListView; namespace Ui { class MainWindow; class AboutPlugins; + class NewModel; } class QWrappedObject; @@ -69,12 +70,15 @@ public: ~MainWindow(); private Q_SLOTS: + void on_actionFileNew_triggered(); void on_actionFileOpen_triggered(); void on_actionFileSaveAs_triggered(); void on_actionFileSave_triggered(); void on_actionAboutPlugins_triggered(); void on_psbJSEvaluate_clicked(); + void metaModelChanged(QString newMetaModel); + protected: bool eventFilter(QObject *obj, QEvent *event); @@ -90,6 +94,8 @@ private: QHash< QString, QPair<QMetaModelPlugin *, QJsonObject> > _loadedPlugins; QDialog *_aboutPluginsDialog; Ui::AboutPlugins *_aboutPlugins; + QDialog *_newModelDialog; + Ui::NewModel *_newModel; QScriptEngine _engine; QListView *_codeCompletionView; diff --git a/examples/uml/qtumleditor/mainwindow.ui b/examples/uml/qtumleditor/mainwindow.ui index 644a1b1a..9134fbf8 100644 --- a/examples/uml/qtumleditor/mainwindow.ui +++ b/examples/uml/qtumleditor/mainwindow.ui @@ -344,5 +344,22 @@ <resources> <include location="qtumleditor.qrc"/> </resources> - <connections/> + <connections> + <connection> + <sender>actionFileQuit</sender> + <signal>triggered()</signal> + <receiver>MainWindow</receiver> + <slot>close()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>415</x> + <y>236</y> + </hint> + </hints> + </connection> + </connections> </ui> diff --git a/examples/uml/qtumleditor/newmodel.ui b/examples/uml/qtumleditor/newmodel.ui new file mode 100644 index 00000000..4493f5f2 --- /dev/null +++ b/examples/uml/qtumleditor/newmodel.ui @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>NewModel</class> + <widget class="QDialog" name="NewModel"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>453</width> + <height>217</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="lblModelName"> + <property name="text"> + <string>Model name:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="lneModel"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="lblMetamodel"> + <property name="text"> + <string>Metamodel:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QComboBox" name="cboMetamodel"/> + </item> + <item row="2" column="1"> + <widget class="QListWidget" name="lstTopLevelContainers"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="lblTopLevelContainer"> + <property name="text"> + <string>Top level container:</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>NewModel</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>NewModel</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/examples/uml/qtumleditor/qtumleditor.pro b/examples/uml/qtumleditor/qtumleditor.pro index 74fc1df2..5c248cd0 100644 --- a/examples/uml/qtumleditor/qtumleditor.pro +++ b/examples/uml/qtumleditor/qtumleditor.pro @@ -24,7 +24,8 @@ SOURCES += main.cpp \ HEADERS += mainwindow.h \ FORMS += mainwindow.ui \ - aboutplugins.ui + aboutplugins.ui \ + newmodel.ui RESOURCES += \ qtumleditor.qrc diff --git a/src/plugins/metamodels/mof/mof.json b/src/plugins/metamodels/mof/mof.json index 6b316b0a..e3d02f18 100644 --- a/src/plugins/metamodels/mof/mof.json +++ b/src/plugins/metamodels/mof/mof.json @@ -2,5 +2,6 @@ "Version": "2.4.1", "Vendor": "Qt Project", "MetaModelNamespaceUri": "http://www.omg.org/spec/MOF/20110701", - "MetaModelPrefix": "QMof" + "MetaModelPrefix": "QMof", + "MetaModelTopLevelClasses": [ "QMofPackage" ] } diff --git a/src/plugins/metamodels/uml/uml.json b/src/plugins/metamodels/uml/uml.json index 37dd715f..a755e82e 100644 --- a/src/plugins/metamodels/uml/uml.json +++ b/src/plugins/metamodels/uml/uml.json @@ -1,6 +1,7 @@ { - "Version": "2.4.1", + "Version": "2.4.1.1", "Vendor": "Qt Project", "MetaModelNamespaceUri": "http://www.omg.org/spec/UML/20110701", - "MetaModelPrefix": "QUml" + "MetaModelPrefix": "QUml", + "MetaModelTopLevelClasses": [ "QUmlModel", "QUmlPackage" ] } |