Commit 65e9e66e authored by Guenter Schwann's avatar Guenter Schwann
Browse files

696 Move IVAppWidget to IVEditorCore

parent 91a362d8
......@@ -27,6 +27,7 @@
#include "errorhub.h"
#include "interfacedocument.h"
#include "itemeditor/common/ivutils.h"
#include "itemeditor/graphicsview.h"
#include "ivappwidget.h"
#include "iveditorcore.h"
#include "ivexporter.h"
......
......@@ -21,8 +21,6 @@
#include "asn1modelstorage.h"
#include "asn1systemchecks.h"
#include "colors/colormanagerdialog.h"
#include "commands/cmdentitiesimport.h"
#include "commands/cmdentitiesinstantiate.h"
#include "commandsstack.h"
#include "context/action/actionsmanager.h"
#include "context/action/editor/dynactioneditor.h"
......@@ -30,10 +28,8 @@
#include "interface/objectstreeview.h"
#include "itemeditor/common/ivutils.h"
#include "itemeditor/graphicsitemhelpers.h"
#include "itemeditor/graphicsview.h"
#include "itemeditor/ivfunctiongraphicsitem.h"
#include "itemeditor/ivitemmodel.h"
#include "ivappwidget.h"
#include "ivcomment.h"
#include "ivconnection.h"
#include "ivconnectiongroup.h"
......@@ -44,7 +40,6 @@
#include "ivpropertytemplateconfig.h"
#include "ivvisualizationmodelbase.h"
#include "ivxmlreader.h"
#include "properties/ivpropertiesdialog.h"
#include "propertytemplatemanager.h"
#include "propertytemplatewidget.h"
......@@ -54,6 +49,7 @@
#include <QDialogButtonBox>
#include <QDir>
#include <QDirIterator>
#include <QGraphicsScene>
#include <QInputDialog>
#include <QLabel>
#include <QLineEdit>
......@@ -72,7 +68,6 @@ struct InterfaceDocument::InterfaceDocumentPrivate {
QString filePath;
IVAppWidget *view = nullptr;
ivm::IVPropertyTemplateConfig *dynPropConfig { nullptr };
IVItemModel *itemsModel { nullptr };
IVVisualizationModelBase *objectsVisualizationModel { nullptr };
......@@ -140,20 +135,6 @@ QGraphicsScene *InterfaceDocument::scene() const
return itemsModel()->scene();
}
shared::ui::GraphicsViewBase *InterfaceDocument::graphicsView() const
{
view();
return d->view->graphicsView();
}
IVAppWidget *InterfaceDocument::view() const
{
if (!d->view) {
d->view = new IVAppWidget(const_cast<InterfaceDocument *>(this));
}
return d->view;
}
QUndoStack *InterfaceDocument::undoStack() const
{
Q_ASSERT(d->commandsStack);
......@@ -220,7 +201,7 @@ bool InterfaceDocument::loadAvailableComponents()
QString InterfaceDocument::getComponentName(const QStringList &exportNames)
{
QString name = exportNames.join(QLatin1Char('_'));
auto dialog = new QDialog(qobject_cast<QWidget *>(window()));
auto dialog = new QDialog();
dialog->setWindowTitle(tr("Export"));
auto layout = new QVBoxLayout;
layout->addWidget(new QLabel(tr("Enter the name for exporting component:"), dialog));
......@@ -269,6 +250,11 @@ QList<shared::VEObject *> InterfaceDocument::prepareSelectedObjectsForExport(QSt
return objects;
}
ivm::IVPropertyTemplateConfig *InterfaceDocument::dynPropConfig() const
{
return d->dynPropConfig;
}
bool InterfaceDocument::exportSelectedFunctions()
{
QString name;
......@@ -480,7 +466,6 @@ IVItemModel *InterfaceDocument::itemsModel() const
{
if (!d->itemsModel) {
d->itemsModel = new IVItemModel(d->objectsModel, d->commandsStack, const_cast<InterfaceDocument *>(this));
connect(d->itemsModel, &IVItemModel::itemDoubleClicked, this, &InterfaceDocument::onItemDoubleClicked);
connect(d->itemsModel, &IVItemModel::itemsSelected, this, &InterfaceDocument::onSceneSelectionChanged);
}
......@@ -548,11 +533,22 @@ void InterfaceDocument::setAsn1Check(Asn1Acn::Asn1SystemChecks *check)
&ive::InterfaceDocument::checkAllInterfacesForAsn1Compliance, Qt::QueuedConnection);
}
Asn1Acn::Asn1SystemChecks *InterfaceDocument::asn1Check() const
{
return d->asnCheck;
;
}
void InterfaceDocument::setIvCheck(ivm::AbstractSystemChecks *checks)
{
d->ivCheck = checks;
}
ivm::AbstractSystemChecks *InterfaceDocument::ivCheck() const
{
return d->ivCheck;
}
QString InterfaceDocument::supportedFileExtensions() const
{
return QStringLiteral("*.xml");
......@@ -625,42 +621,11 @@ void InterfaceDocument::setObjects(const QVector<ivm::IVObject *> &objects)
{
d->objectsModel->initFromObjects(objects);
d->objectsModel->setRootObject({});
if (d->view) {
d->view->centerView();
}
}
void InterfaceDocument::onItemDoubleClicked(const shared::Id &id)
{
if (id.isNull()) {
return;
}
if (auto entity = d->objectsModel->getObject(id)) {
if (entity->isFunction()) {
if (auto fn = entity->as<ivm::IVFunction *>()) {
if (fn->hasNestedChildren()) {
itemsModel()->changeRootItem(id);
return;
}
}
}
showPropertyEditor(id);
}
}
void InterfaceDocument::onItemCreated(const shared::Id &id)
{
if (id.isNull()) {
return;
}
showPropertyEditor(id);
}
void InterfaceDocument::onAttributesManagerRequested()
{
auto dialog = new shared::PropertyTemplateManager({ d->dynPropConfig }, window());
auto dialog = new shared::PropertyTemplateManager({ d->dynPropConfig }, nullptr);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->open();
}
......@@ -682,7 +647,7 @@ void InterfaceDocument::prepareEntityNameForEditing(const shared::Id &id)
void InterfaceDocument::onColorSchemeMenuInvoked()
{
shared::ColorManagerDialog *dialog = new shared::ColorManagerDialog(window());
shared::ColorManagerDialog *dialog = new shared::ColorManagerDialog(nullptr);
dialog->setFilterGroup("IVE");
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->open();
......@@ -690,7 +655,7 @@ void InterfaceDocument::onColorSchemeMenuInvoked()
void InterfaceDocument::onDynContextEditorMenuInvoked()
{
auto dialog = new DynActionEditor(window());
auto dialog = new DynActionEditor(nullptr);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->open();
......@@ -699,84 +664,11 @@ void InterfaceDocument::onDynContextEditorMenuInvoked()
}
}
void InterfaceDocument::showPropertyEditor(const shared::Id &id)
{
Q_ASSERT(d->asnCheck);
Q_ASSERT(d->commandsStack);
if (id.isNull()) {
return;
}
ivm::IVObject *obj = d->objectsModel->getObject(id);
if (!obj || obj->type() == ivm::IVObject::Type::InterfaceGroup || obj->type() == ivm::IVObject::Type::Connection) {
return;
}
ive::IVPropertiesDialog dialog(d->dynPropConfig, obj, d->ivCheck, d->asnCheck, d->commandsStack, graphicsView());
dialog.init();
dialog.exec();
}
void InterfaceDocument::showInfoMessage(const QString &title, const QString &message)
{
QMessageBox::information(qobject_cast<QWidget *>(parent()), title, message);
}
void InterfaceDocument::importEntity(const shared::Id &id, const QPointF &sceneDropPoint)
{
const auto obj = d->importModel->getObject(id);
if (!obj) {
return;
}
const auto existingFunctionNames = d->objectsModel->nestedFunctionNames();
const auto intersectedNames = d->importModel->nestedFunctionNames(obj->as<const ivm::IVFunctionType *>())
.intersect(existingFunctionNames);
if (!intersectedNames.isEmpty()) {
const QString msg = tr("Chosen entity [%1] couldn't be imported because of Function names conflict(s): %2")
.arg(obj->titleUI(), intersectedNames.toList().join(QLatin1Char('\n')));
shared::ErrorHub::addError(shared::ErrorItem::Error, msg);
return;
}
QGraphicsItem *itemAtScenePos = scene()->itemAt(sceneDropPoint, graphicsView()->transform());
while (itemAtScenePos && itemAtScenePos->type() != IVFunctionGraphicsItem::Type) {
itemAtScenePos = itemAtScenePos->parentItem();
}
QBuffer buffer;
if (!buffer.open(QIODevice::WriteOnly)) {
shared::ErrorHub::addError(
shared::ErrorItem::Error, tr("Can't open buffer for exporting: %1").arg(buffer.errorString()));
return;
}
if (!exporter()->exportObjects({ obj }, &buffer)) {
shared::ErrorHub::addError(shared::ErrorItem::Error, tr("Error during component export"));
return;
}
buffer.close();
ivm::IVFunctionType *parentObject = gi::functionObject(itemAtScenePos);
auto cmdImport = new cmd::CmdEntitiesImport(
buffer.data(), parentObject, d->objectsModel, sceneDropPoint, QFileInfo(path()).absolutePath());
d->commandsStack->push(cmdImport);
}
void InterfaceDocument::instantiateEntity(const shared::Id &id, const QPointF &sceneDropPoint)
{
const auto obj = d->sharedModel->getObject(id);
if (!obj || obj->type() != ivm::IVObject::Type::FunctionType) {
return;
}
QGraphicsItem *itemAtScenePos = scene()->itemAt(sceneDropPoint, graphicsView()->transform());
while (itemAtScenePos && itemAtScenePos->type() != IVFunctionGraphicsItem::Type) {
itemAtScenePos = itemAtScenePos->parentItem();
}
ivm::IVFunctionType *parentObject = gi::functionObject(itemAtScenePos);
auto cmdInstantiate = new cmd::CmdEntitiesInstantiate(
obj->as<ivm::IVFunctionType *>(), parentObject, d->objectsModel, sceneDropPoint);
d->commandsStack->push(cmdInstantiate);
}
static inline bool exportObjects(
IVExporter *exporter, const QList<shared::VEObject *> &objects, const QString &filePath)
{
......@@ -866,7 +758,7 @@ bool InterfaceDocument::exportImpl(QString &targetPath, const QList<shared::VEOb
QDir targetDir(targetPath);
if (QFile::exists(targetDir.filePath(shared::kDefaultInterfaceViewFileName))) {
if (!resolveNameConflict(targetPath, window())) {
if (!resolveNameConflict(targetPath, nullptr)) {
return false;
} else {
targetDir.setPath(targetPath);
......@@ -927,15 +819,7 @@ bool InterfaceDocument::loadImpl(const QString &path)
void InterfaceDocument::showNIYGUI(const QString &title)
{
QString header = title.isEmpty() ? "NIY" : title;
QMessageBox::information(window(), header, "Not implemented yet!");
}
QWidget *InterfaceDocument::window()
{
if (d->view) {
return d->view->window();
}
return nullptr;
QMessageBox::information(nullptr, header, "Not implemented yet!");
}
void InterfaceDocument::onSceneSelectionChanged(const QList<shared::Id> &selectedObjects)
......
......@@ -18,15 +18,16 @@
#pragma once
#include "common.h"
#include "itemeditor/graphicsview.h"
#include <QAction>
#include <QPointer>
#include <QQueue>
class QMenu;
class QUndoStack;
class QGraphicsScene;
class QItemSelection;
class QItemSelectionModel;
class QMenu;
class QUndoStack;
namespace Asn1Acn {
class Asn1ModelStorage;
......@@ -39,9 +40,10 @@ class VEObject;
namespace ivm {
class AbstractSystemChecks;
class IVObject;
class IVInterface;
class IVModel;
class IVObject;
class IVPropertyTemplateConfig;
}
namespace ive {
......@@ -74,8 +76,6 @@ public:
IVExporter *exporter() const;
QGraphicsScene *scene() const;
shared::ui::GraphicsViewBase *graphicsView() const;
ive::IVAppWidget *view() const;
QUndoStack *undoStack() const;
cmd::CommandsStack *commandsStack() const;
......@@ -114,7 +114,9 @@ public:
IVVisualizationModelBase *sharedVisualisationModel() const;
void setAsn1Check(Asn1Acn::Asn1SystemChecks *check);
Asn1Acn::Asn1SystemChecks *asn1Check() const;
void setIvCheck(ivm::AbstractSystemChecks *checks);
ivm::AbstractSystemChecks *ivCheck() const;
QString supportedFileExtensions() const;
......@@ -123,6 +125,8 @@ public:
QList<shared::VEObject *> prepareSelectedObjectsForExport(QString &name, bool silent = false);
ivm::IVPropertyTemplateConfig *dynPropConfig() const;
Q_SIGNALS:
void dirtyChanged(bool dirty);
void titleChanged();
......@@ -137,15 +141,9 @@ public Q_SLOTS:
void onColorSchemeMenuInvoked();
void onDynContextEditorMenuInvoked();
void onItemDoubleClicked(const shared::Id &id);
void onItemCreated(const shared::Id &id);
void onDataTypesMenuInvoked();
void prepareEntityNameForEditing(const shared::Id &id);
void showPropertyEditor(const shared::Id &id);
void showInfoMessage(const QString &title, const QString &message);
void importEntity(const shared::Id &id, const QPointF &sceneDropPoint);
void instantiateEntity(const shared::Id &id, const QPointF &sceneDropPoint);
private:
bool exportImpl(QString &targetPath, const QList<shared::VEObject *> &objects);
......
......@@ -18,6 +18,7 @@
#include "ivappwidget.h"
#include "commands/cmdentitiesimport.h"
#include "commands/cmdentitiesinstantiate.h"
#include "commandsstack.h"
#include "context/action/actionsmanager.h"
#include "errorhub.h"
......@@ -29,6 +30,7 @@
#include "ivcreatortool.h"
#include "ivexporter.h"
#include "ivvisualizationmodelbase.h"
#include "properties/ivpropertiesdialog.h"
#include "ui_ivappwidget.h"
#include <QAction>
......@@ -58,6 +60,8 @@ IVAppWidget::IVAppWidget(InterfaceDocument *doc, QWidget *parent)
initImportView();
initSharedView();
connect(m_document->itemsModel(), &IVItemModel::itemDoubleClicked, this, &IVAppWidget::onItemDoubleClicked);
QTimer::singleShot(0, this, [&]() {
for (QAction *action : initActions()) {
ui->toolBar->addAction(action);
......@@ -169,6 +173,110 @@ void IVAppWidget::pasteItems(const QPointF &sceneDropPoint)
m_document->commandsStack()->push(cmdImport);
}
void IVAppWidget::showPropertyEditor(const shared::Id &id)
{
Q_ASSERT(m_document);
if (id.isNull()) {
return;
}
ivm::IVObject *obj = m_document->objectsModel()->getObject(id);
if (!obj || obj->type() == ivm::IVObject::Type::InterfaceGroup || obj->type() == ivm::IVObject::Type::Connection) {
return;
}
ive::IVPropertiesDialog dialog(m_document->dynPropConfig(), obj, m_document->ivCheck(), m_document->asn1Check(),
m_document->commandsStack(), graphicsView());
dialog.init();
dialog.exec();
}
void IVAppWidget::importEntity(const shared::Id &id, const QPointF &sceneDropPoint)
{
Q_ASSERT(m_document);
const auto obj = m_document->importModel()->getObject(id);
if (!obj) {
return;
}
const auto existingFunctionNames = m_document->objectsModel()->nestedFunctionNames();
const auto intersectedNames = m_document->importModel()
->nestedFunctionNames(obj->as<const ivm::IVFunctionType *>())
.intersect(existingFunctionNames);
if (!intersectedNames.isEmpty()) {
const QString msg = tr("Chosen entity [%1] couldn't be imported because of Function names conflict(s): %2")
.arg(obj->titleUI(), intersectedNames.toList().join(QLatin1Char('\n')));
shared::ErrorHub::addError(shared::ErrorItem::Error, msg);
return;
}
QGraphicsItem *itemAtScenePos = m_document->scene()->itemAt(sceneDropPoint, graphicsView()->transform());
while (itemAtScenePos && itemAtScenePos->type() != IVFunctionGraphicsItem::Type) {
itemAtScenePos = itemAtScenePos->parentItem();
}
QBuffer buffer;
if (!buffer.open(QIODevice::WriteOnly)) {
shared::ErrorHub::addError(
shared::ErrorItem::Error, tr("Can't open buffer for exporting: %1").arg(buffer.errorString()));
return;
}
if (!m_document->exporter()->exportObjects({ obj }, &buffer)) {
shared::ErrorHub::addError(shared::ErrorItem::Error, tr("Error during component export"));
return;
}
buffer.close();
ivm::IVFunctionType *parentObject = gi::functionObject(itemAtScenePos);
auto cmdImport = new cmd::CmdEntitiesImport(buffer.data(), parentObject, m_document->objectsModel(), sceneDropPoint,
QFileInfo(m_document->path()).absolutePath());
m_document->commandsStack()->push(cmdImport);
}
void IVAppWidget::instantiateEntity(const shared::Id &id, const QPointF &sceneDropPoint)
{
Q_ASSERT(m_document);
const auto obj = m_document->sharedModel()->getObject(id);
if (!obj || obj->type() != ivm::IVObject::Type::FunctionType) {
return;
}
QGraphicsItem *itemAtScenePos = m_document->scene()->itemAt(sceneDropPoint, graphicsView()->transform());
while (itemAtScenePos && itemAtScenePos->type() != IVFunctionGraphicsItem::Type) {
itemAtScenePos = itemAtScenePos->parentItem();
}
ivm::IVFunctionType *parentObject = gi::functionObject(itemAtScenePos);
auto cmdInstantiate = new cmd::CmdEntitiesInstantiate(
obj->as<ivm::IVFunctionType *>(), parentObject, m_document->objectsModel(), sceneDropPoint);
m_document->commandsStack()->push(cmdInstantiate);
}
void IVAppWidget::onItemDoubleClicked(const shared::Id &id)
{
if (id.isNull()) {
return;
}
if (auto entity = m_document->objectsModel()->getObject(id)) {
if (entity->isFunction()) {
if (auto fn = entity->as<ivm::IVFunction *>()) {
if (fn->hasNestedChildren()) {
m_document->itemsModel()->changeRootItem(id);
return;
}
}
}
showPropertyEditor(id);
}
}
void IVAppWidget::onItemCreated(const shared::Id &id)
{
if (id.isNull()) {
return;
}
showPropertyEditor(id);
}
void IVAppWidget::pasteItems()
{
const QPoint viewportCursorPos = graphicsView()->viewport()->mapFromGlobal(QCursor::pos());
......@@ -193,9 +301,8 @@ void IVAppWidget::initGraphicsView()
m_actZoomOut->setEnabled(!qFuzzyCompare(percent, ui->graphicsView->minZoomPercent()));
});
connect(ui->graphicsView, &GraphicsView::importEntity, m_document.data(), &InterfaceDocument::importEntity);
connect(ui->graphicsView, &GraphicsView::instantiateEntity, m_document.data(),
&InterfaceDocument::instantiateEntity);
connect(ui->graphicsView, &GraphicsView::importEntity, this, &IVAppWidget::importEntity);
connect(ui->graphicsView, &GraphicsView::instantiateEntity, this, &IVAppWidget::instantiateEntity);
connect(ui->graphicsView, &GraphicsView::copyItems, this, &IVAppWidget::copyItems);
connect(ui->graphicsView, &GraphicsView::cutItems, this, &IVAppWidget::cutItems);
connect(ui->graphicsView, &GraphicsView::pasteItems, this, qOverload<>(&IVAppWidget::pasteItems));
......@@ -246,7 +353,7 @@ QVector<QAction *> IVAppWidget::initActions()
auto actionGroup = new QActionGroup(this);
actionGroup->setExclusive(true);
m_tool = new IVCreatorTool(m_document);
m_tool = new IVCreatorTool(graphicsView(), m_document);
connect(m_tool, &IVCreatorTool::created, this, [this, actionGroup]() {
if (QAction *currentAction = actionGroup->checkedAction()) {
currentAction->setChecked(false);
......@@ -255,7 +362,7 @@ QVector<QAction *> IVAppWidget::initActions()
});
connect(m_tool, &IVCreatorTool::functionCreated, m_document.data(), &InterfaceDocument::prepareEntityNameForEditing,
Qt::QueuedConnection);
connect(m_tool, &IVCreatorTool::propertyEditorRequest, m_document.data(), &InterfaceDocument::showPropertyEditor,
connect(m_tool, &IVCreatorTool::propertyEditorRequest, this, &IVAppWidget::showPropertyEditor,
Qt::QueuedConnection);
connect(m_tool, &IVCreatorTool::informUser, m_document.data(), &InterfaceDocument::showInfoMessage);
connect(m_tool, &IVCreatorTool::copyActionTriggered, this, &IVAppWidget::copyItems);
......
......@@ -17,6 +17,8 @@
#pragma once
#include "common.h"
#include <QAction>
#include <QPointer>
#include <QVector>
......@@ -52,6 +54,12 @@ private Q_SLOTS:
void cutItems();
void pasteItems();
void pasteItems(const QPointF &sceneDropPoint);
void showPropertyEditor(const shared::Id &id);
void importEntity(const shared::Id &id, const QPointF &sceneDropPoint);
void instantiateEntity(const shared::Id &id, const QPointF &sceneDropPoint);
void onItemDoubleClicked(const shared::Id &id);
void onItemCreated(const shared::Id &id);
private:
void initGraphicsView();
......
......@@ -70,8 +70,8 @@ static const qreal kPreviewItemPenWidth = 2.;
namespace ive {
IVCreatorTool::IVCreatorTool(InterfaceDocument *doc)
: shared::ui::CreatorTool(doc->graphicsView(), doc->itemsModel(), doc)
IVCreatorTool::IVCreatorTool(QGraphicsView *view, InterfaceDocument *doc)
: shared::ui::CreatorTool(view, doc->itemsModel(), doc)
, m_doc(doc)
{
}
......
......@@ -36,7 +36,7 @@ class IVCreatorTool : public shared::ui::CreatorTool
Q_OBJECT
public:
IVCreatorTool(InterfaceDocument *doc);
IVCreatorTool(QGraphicsView* view, InterfaceDocument *doc);
~IVCreatorTool() override;
enum ToolType
......
......@@ -30,6 +30,7 @@
#include "graphicsviewutils.h"
#include "interfacedocument.h"
#include "itemeditor/common/ivutils.h"
#include "itemeditor/graphicsview.h"
#include "ivappwidget.h"
#include "ivconnection.h"
#include "ivcore/abstractsystemchecks.h"
......@@ -85,12 +86,16 @@ InterfaceDocument *IVEditorCore::document() const
shared::ui::GraphicsViewBase *IVEditorCore::chartView()
{
return m_document->graphicsView();
mainwidget();
return m_mainWidget->graphicsView();
}
QWidget *IVEditorCore::mainwidget()
{
return m_document->view();
if (!m_mainWidget) {
m_mainWidget = new IVAppWidget(m_document);
}
return m_mainWidget;
}
void IVEditorCore::addToolBars(QMainWindow *window)
......@@ -455,7 +460,8 @@ ivm::AbstractSystemChecks *IVEditorCore::dvChecks() const
void IVEditorCore::centerOnView()