From c3286c124b90b070461524b950205a9278091326 Mon Sep 17 00:00:00 2001 From: Guenter Schwann Date: Thu, 21 Oct 2021 10:16:03 +0200 Subject: [PATCH] 696 Create MSCAppWidget --- src/applications/msceditor/mainwindow.cpp | 181 ++---- src/applications/msceditor/mainwindow.h | 5 - src/applications/msceditor/mainwindow.ui | 118 +--- .../mscstreaming/streamingwindow.cpp | 4 +- src/libs/libmsceditor/CMakeLists.txt | 3 + .../documenttree/documenttreeview.cpp | 1 + src/libs/libmsceditor/mscappwidget.cpp | 566 ++++++++++++++++++ src/libs/libmsceditor/mscappwidget.h | 133 ++++ src/libs/libmsceditor/mscappwidget.ui | 171 ++++++ src/libs/libmsceditor/msceditorcore.cpp | 431 +------------ src/libs/libmsceditor/msceditorcore.h | 81 +-- .../libmsceditor/tools/messagecreatortool.cpp | 3 + .../spacecreatorproject.cpp | 1 - .../spacecreatorplugin/msc/mscmainwidget.cpp | 243 +------- .../spacecreatorplugin/msc/mscmainwidget.h | 12 - .../spacecreatorplugin/msc/mscqtceditor.cpp | 3 +- 16 files changed, 969 insertions(+), 987 deletions(-) create mode 100644 src/libs/libmsceditor/mscappwidget.cpp create mode 100644 src/libs/libmsceditor/mscappwidget.h create mode 100644 src/libs/libmsceditor/mscappwidget.ui diff --git a/src/applications/msceditor/mainwindow.cpp b/src/applications/msceditor/mainwindow.cpp index 3c241e66c..1198ec199 100644 --- a/src/applications/msceditor/mainwindow.cpp +++ b/src/applications/msceditor/mainwindow.cpp @@ -33,6 +33,7 @@ #include "mainmodel.h" #include "minimap.h" #include "mscaction.h" +#include "mscappwidget.h" #include "mscchart.h" #include "msccommandsstack.h" #include "msccondition.h" @@ -44,6 +45,7 @@ #include "settingsmanager.h" #include "textviewdialog.h" #include "tools/entitydeletetool.h" +#include "tools/pointertool.h" #include "ui/graphicsviewbase.h" #include "ui_mainwindow.h" @@ -56,6 +58,7 @@ #include #include #include +#include #include namespace msc { @@ -75,6 +78,7 @@ struct MainWindow::MainWindowPrivate { IVEditorCorePtr m_ivCore { new ive::IVEditorCore() }; Ui::MainWindow *ui = nullptr; + QPointer m_mainWidget; msc::MSCEditorCore *m_core = nullptr; @@ -106,31 +110,18 @@ MainWindow::MainWindow(msc::MSCEditorCore *core, QWidget *parent) , d(new MainWindowPrivate(core, this)) { setupUi(); - d->m_core->hierarchyView()->setRenderHints( - QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); initConnections(); d->m_core->initConnections(); d->m_core->selectCurrentChart(); - d->m_core->showDocumentView(true); loadSettings(); - - d->m_core->mscToolBar()->setVisible(d->m_core->centerView()->currentWidget() == d->m_core->chartView()); - d->m_core->hierarchyToolBar()->setVisible(d->m_core->centerView()->currentWidget() == d->m_core->hierarchyView()); } MainWindow::~MainWindow() { - if (d->ui->documentTreeView->model()) { - disconnect(d->ui->documentTreeView->model(), nullptr, this, nullptr); - } disconnect(&(d->m_core->mainModel()->chartViewModel()), nullptr, this, nullptr); - - // Had this connection not dropped, the currentUndoStack() would need check - // for nullptr d, d->ui, d->m_core->chartView() - disconnect(d->m_core->mainModel()->undoStack(), &QUndoStack::indexChanged, this, &MainWindow::updateTitles); } /*! @@ -139,7 +130,7 @@ MainWindow::~MainWindow() */ QGraphicsView *MainWindow::currentView() const { - return d->m_core->chartView(); + return d->m_mainWidget->chartView(); } /*! @@ -154,7 +145,7 @@ void MainWindow::createNewDocument() d->m_core->mainModel()->chartViewModel().setPreferredChartBoxSize(prepareChartBoxSize()); d->m_core->mainModel()->initialModel(); - d->m_core->chartView()->setZoom(100); + d->m_mainWidget->chartView()->setZoom(100); } /*! @@ -243,12 +234,14 @@ void MainWindow::updateTitles() */ bool MainWindow::openMscChain(const QString &dirPath) { - if (dirPath.isEmpty()) + if (dirPath.isEmpty()) { return false; + } QDir dir(dirPath); - if (!dir.exists() || !dir.isReadable()) + if (!dir.exists() || !dir.isReadable()) { return false; + } for (const QFileInfo &file : dir.entryInfoList(mscFileFilters())) { openFileMsc(file.absoluteFilePath()); @@ -291,9 +284,9 @@ void MainWindow::saveAsMsc() */ void MainWindow::showDocumentView(bool show) { - d->m_core->showDocumentView(show); + d->m_mainWidget->showDocumentView(show); if (show) { - updateZoomBox(d->m_core->chartView()->zoom()); + updateZoomBox(d->m_mainWidget->chartView()->zoom()); } } @@ -303,59 +296,9 @@ void MainWindow::showDocumentView(bool show) */ void MainWindow::showHierarchyView(bool show) { - d->m_core->showHierarchyView(show); + d->m_mainWidget->showHierarchyView(show); if (show) { - updateZoomBox(d->m_core->hierarchyView()->zoom()); - } -} - -/*! - * \brief MainWindow::showChart Show the chart \a index - */ -void MainWindow::showChart(const QModelIndex &index) -{ - if (!index.isValid()) { - return; - } - - auto *obj = static_cast(index.internalPointer()); - if (obj == nullptr) { - return; - } - - if (auto document = dynamic_cast(obj)) { - if (!document->charts().empty()) { - d->m_core->mainModel()->chartViewModel().setCurrentChart(document->charts()[0]); - showDocumentView(true); - } - } -} - -void MainWindow::showSelection(const QModelIndex ¤t, const QModelIndex &previous) -{ - Q_UNUSED(previous) - if (!current.isValid()) { - return; - } - - auto *obj = static_cast(current.internalPointer()); - if (obj == nullptr) { - d->m_core->mainModel()->setSelectedDocument(nullptr); - return; - } - - if (auto chart = dynamic_cast(obj)) { - d->m_core->mainModel()->chartViewModel().setCurrentChart(chart); - showDocumentView(true); - } else { - showHierarchyView(true); - - if (auto document = dynamic_cast(obj)) { - d->m_core->mainModel()->setSelectedDocument(document); - d->m_core->actionPaste()->setEnabled( - QApplication::clipboard()->mimeData()->hasFormat(MainModel::MscChartMimeType) - && d->m_core->mainModel()->selectedDocument()->isAddChildEnable()); - } + updateZoomBox(d->m_mainWidget->hierarchyView()->zoom()); } } @@ -365,39 +308,36 @@ void MainWindow::showSelection(const QModelIndex ¤t, const QModelIndex &pr void MainWindow::setupUi() { d->ui->setupUi(this); - d->m_core->setViews(d->ui->centerView, d->ui->graphicsView, d->ui->hierarchyView); + d->m_mainWidget = d->m_core->mainwidget(); + d->m_mainWidget->showAsn1View(true); + setCentralWidget(d->m_mainWidget); d->m_core->addToolBars(this); - d->ui->documentTreeView->setModel(d->m_core->mainModel()->documentItemModel()); d->mscTextBrowser->setModel(d->m_core->mainModel()->mscModel()); initActions(); - d->m_core->initChartTools(); - d->m_core->initHierarchyViewActions(); - initMenus(); - initMainToolbar(); d->m_core->setupMiniMap(); // status bar d->m_zoomBox = new QComboBox(d->ui->statusBar); - for (auto x = d->m_core->chartView()->minZoomPercent(); x <= d->m_core->chartView()->maxZoomPercent(); - x += d->m_core->chartView()->zoomStepPercent()) + for (auto x = d->m_mainWidget->chartView()->minZoomPercent(); x <= d->m_core->chartView()->maxZoomPercent(); + x += d->m_mainWidget->chartView()->zoomStepPercent()) d->m_zoomBox->addItem(QString("%1 %").arg(x), x); d->m_zoomBox->setCurrentIndex(d->m_zoomBox->findData(100)); connect(d->m_zoomBox, QOverload::of(&QComboBox::currentIndexChanged), this, [&](int index) { - if (auto graphicsView = dynamic_cast(d->m_core->centerView()->currentWidget())) + if (auto graphicsView = dynamic_cast(d->m_mainWidget->centerView()->currentWidget())) graphicsView->setZoom(qobject_cast(sender())->itemData(index).toDouble()); }); - connect(d->m_core->chartView(), QOverload::of(&msc::GraphicsView::zoomChanged), this, + connect(d->m_mainWidget->chartView(), QOverload::of(&msc::GraphicsView::zoomChanged), this, &MainWindow::updateZoomBox); - connect(d->m_core->hierarchyView(), QOverload::of(&msc::GraphicsView::zoomChanged), this, + connect(d->m_mainWidget->hierarchyView(), QOverload::of(&msc::GraphicsView::zoomChanged), this, &MainWindow::updateZoomBox); statusBar()->addPermanentWidget(d->m_zoomBox); @@ -447,7 +387,7 @@ void MainWindow::initMenus() redoAction->setShortcut(QKeySequence::Redo); menu->addAction(redoAction); menu->addSeparator(); - menu->addAction(d->m_core->deleteTool()->action()); + menu->addAction(d->m_mainWidget->deleteTool()->action()); menu->addSeparator(); menu->addAction(d->m_core->createActionCopy(this)); menu->addAction(d->m_core->createActionPaste(this)); @@ -468,9 +408,7 @@ void MainWindow::initMenus() menu->addAction(d->m_core->actionMessageDeclarations()); menu->addSeparator(); auto menuWindows = menu->addMenu("Windows"); - menuWindows->addAction(dockWidgetDocumentToggleAction()); menuWindows->addAction(mscTextViewToggleAction()); - menuWindows->addAction(dockWidgetAsn1ToggleAction()); menu->addSeparator(); menu->addAction(tr("Color Scheme..."), this, &MainWindow::editColorScheme); @@ -482,48 +420,17 @@ void MainWindow::initMenus() menu->addAction(tr("About Qt"), qApp, &QApplication::aboutQt); } -void MainWindow::initMainToolbar() -{ - auto mainToolBar = d->m_core->mainToolBar(); - mainToolBar->addSeparator(); - mainToolBar->addAction(d->m_core->deleteTool()->action()); - - mainToolBar->addSeparator(); - mainToolBar->addAction(d->m_core->actionCopy()); - mainToolBar->addAction(d->m_core->actionPaste()); -} - void MainWindow::initConnections() { - connect(d->ui->documentTreeView->selectionModel(), &QItemSelectionModel::currentChanged, this, - &MainWindow::showSelection); - connect(d->ui->documentTreeView, &QTreeView::doubleClicked, this, &MainWindow::showChart); - - connect(d->m_core->mainModel(), &MainModel::selectedDocumentChanged, d->ui->documentTreeView, - &DocumentTreeView::setSelectedDocument); - - connect(d->m_core->chartView(), &msc::GraphicsView::mouseMoved, this, &MainWindow::showCoordinatesInfo); + connect(d->m_mainWidget->chartView(), &msc::GraphicsView::mouseMoved, this, &MainWindow::showCoordinatesInfo); connect(d->m_core->mainModel(), &MainModel::modelDataChanged, this, &MainWindow::updateModel); connect(d->m_core->mainModel(), &MainModel::modelUpdated, this, &MainWindow::updateModel); - connect(d->m_core->mainModel()->documentItemModel(), &msc::DocumentItemModel::dataChanged, this, - &MainWindow::showSelection); - connect(d->m_core->mainModel()->undoStack(), &QUndoStack::cleanChanged, this, &MainWindow::updateTitles); - // ASN1 view - connect(d->m_core->mainModel(), &MainModel::currentFilePathChanged, this, [&](const QString &filename) { - QFileInfo fileInfo(filename); - d->ui->asn1Widget->setDirectory(fileInfo.absolutePath()); - }); - connect(d->m_core->mainModel(), &msc::MainModel::asn1FileNameChanged, d->ui->asn1Widget, - &asn1::ASN1FileView::setFileName); - connect(d->ui->asn1Widget, &asn1::ASN1FileView::asn1Selected, this, [this]() { - msc::MscModel *model = d->m_core->mainModel()->mscModel(); - if (model->dataDefinitionString() != d->ui->asn1Widget->fileName()) { - d->m_core->commandsStack()->push(new cmd::CmdSetAsn1File(model, d->ui->asn1Widget->fileName(), "ASN.1")); - } + connect(d->m_mainWidget, &MscAppWidget::viewModeChanged, this, [this]() { + d->m_actionShowDocument->setChecked(d->m_mainWidget->viewMode() == MscAppWidget::ViewMode::CHART); }); } @@ -550,21 +457,11 @@ bool MainWindow::processCommandLineArg(shared::CommandLineParser::Positional arg return false; } -QAction *MainWindow::dockWidgetDocumentToggleAction() -{ - return d->ui->dockWidgetDocument->toggleViewAction(); -} - QAction *MainWindow::mscTextViewToggleAction() { return d->mscTextBrowser->toggleViewAction(); } -QAction *MainWindow::dockWidgetAsn1ToggleAction() -{ - return d->ui->dockWidgetAsn1->toggleViewAction(); -} - void MainWindow::keyPressEvent(QKeyEvent *e) { QMainWindow::keyPressEvent(e); @@ -572,9 +469,10 @@ void MainWindow::keyPressEvent(QKeyEvent *e) switch (e->key()) { case Qt::Key_Escape: { if (!e->isAutoRepeat()) { - if (QAction *pointerToolAction = d->m_core->mscToolBar()->actions().first()) - if (!pointerToolAction->isChecked()) - pointerToolAction->setChecked(true); + QAction *pointerToolAction = d->m_mainWidget->pointerTool()->action(); + if (!pointerToolAction->isChecked()) { + pointerToolAction->setChecked(true); + } } break; } @@ -593,7 +491,7 @@ void MainWindow::keyPressEvent(QKeyEvent *e) break; } default: { - if (msc::BaseTool *tool = d->m_core->activeTool()) + if (msc::BaseTool *tool = d->m_mainWidget->activeTool()) tool->processKeyPress(e); break; } @@ -626,7 +524,7 @@ void MainWindow::saveSettings() using namespace shared; SettingsManager::store(SettingsManager::Common::Geometry, saveGeometry()); SettingsManager::store(SettingsManager::Common::State, saveState()); - SettingsManager::store(SettingsManager::MSC::DocViewMode, d->m_core->centerView()->currentIndex() == 0); + SettingsManager::store(SettingsManager::MSC::DocViewMode, d->m_mainWidget->centerView()->currentIndex() == 0); const QString path = d->m_core->mainModel()->currentFilePath(); auto files = SettingsManager::load(SettingsManager::MSC::RecentFiles); @@ -691,19 +589,24 @@ void MainWindow::onGeometryRestored() QSizeF MainWindow::prepareChartBoxSize() const { static constexpr qreal padding = 110.; - if (centralWidget()) { - return centralWidget()->geometry().size() - QSizeF(padding, padding); + GraphicsView *chartView = d->m_mainWidget->chartView(); + if (chartView) { + return chartView->geometry().size() - QSizeF(padding, padding); } return QSizeF(); } void MainWindow::updateMscToolbarActionsEnablement() { + if (!d->m_mainWidget) { + return; + } + auto chart = d->m_core->mainModel()->chartViewModel().currentChart(); const bool hasInstance = chart && !chart->instances().isEmpty(); bool forceDefault(false); - for (QAction *act : d->m_core->mscToolBar()->actions()) { + for (QAction *act : d->m_mainWidget->chartActions()) { const msc::BaseTool::ToolType toolType(act->data().value()); switch (toolType) { case msc::BaseTool::ToolType::ActionCreator: @@ -728,10 +631,10 @@ void MainWindow::updateMscToolbarActionsEnablement() } } - d->m_core->checkGlobalComment(); + d->m_mainWidget->checkGlobalComment(); if (forceDefault) { - d->m_core->activateDefaultTool(); + d->m_mainWidget->activateDefaultTool(); } } diff --git a/src/applications/msceditor/mainwindow.h b/src/applications/msceditor/mainwindow.h index 6ff89360e..5e12d7df7 100644 --- a/src/applications/msceditor/mainwindow.h +++ b/src/applications/msceditor/mainwindow.h @@ -53,9 +53,7 @@ public: bool processCommandLineArg(shared::CommandLineParser::Positional arg, const QString &value); QPlainTextEdit *textOutputPane() const; - QAction *dockWidgetDocumentToggleAction(); QAction *mscTextViewToggleAction(); - QAction *dockWidgetAsn1ToggleAction(); public Q_SLOTS: void createNewDocument(); @@ -66,8 +64,6 @@ Q_SIGNALS: void currentGraphicsViewChanged(QGraphicsView *view); public Q_SLOTS: - void showChart(const QModelIndex &index); - void showSelection(const QModelIndex ¤t, const QModelIndex &previous); bool openFileMsc(const QString &file); void saveMsc(); void saveAsMsc(); @@ -96,7 +92,6 @@ private: void setupUi(); void initActions(); void initMenus(); - void initMainToolbar(); void initConnections(); void closeEvent(QCloseEvent *e) override; diff --git a/src/applications/msceditor/mainwindow.ui b/src/applications/msceditor/mainwindow.ui index 1add54a0f..5bd4ab450 100644 --- a/src/applications/msceditor/mainwindow.ui +++ b/src/applications/msceditor/mainwindow.ui @@ -33,28 +33,6 @@ 5 - - - - 0 - - - - - 0 - 0 - - - - - 200 - 0 - - - - - - @@ -63,107 +41,13 @@ 0 0 861 - 21 + 22 - - - Documents - - - 1 - - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - 200 - 0 - - - - - 16777215 - 16777215 - - - - QAbstractScrollArea::AdjustToContents - - - true - - - - - - - - - ASN.1 file - - - 1 - - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - - - msc::GraphicsView - QGraphicsView -
graphicsview.h
-
- - msc::ASN1FileView - QWidget -
asn1fileview.h
- 1 -
- - asn1::DocumentTreeView - QTreeView -
documenttreeview.h
-
-
diff --git a/src/applications/mscstreaming/streamingwindow.cpp b/src/applications/mscstreaming/streamingwindow.cpp index 26e29cd71..14eb3a575 100644 --- a/src/applications/mscstreaming/streamingwindow.cpp +++ b/src/applications/mscstreaming/streamingwindow.cpp @@ -67,9 +67,7 @@ StreamingWindow::StreamingWindow(msc::MSCEditorCore *plugin, QWidget *parent) , d(new StreamingWindowPrivate(plugin)) { d->ui->setupUi(this); - d->m_plugin->showToolbars(false); - d->m_plugin->setViews(nullptr, d->ui->graphicsView, nullptr); - d->m_plugin->initChartTools(); + d->ui->graphicsView->setScene(d->m_plugin->mainModel()->graphicsScene()); static constexpr qreal padding = 120.; const QSizeF defaultSize(this->size() - QSizeF(padding, padding)); diff --git a/src/libs/libmsceditor/CMakeLists.txt b/src/libs/libmsceditor/CMakeLists.txt index 4bb7d9e2b..26f3167a1 100644 --- a/src/libs/libmsceditor/CMakeLists.txt +++ b/src/libs/libmsceditor/CMakeLists.txt @@ -136,6 +136,9 @@ target_sources(${LIB_NAME} PRIVATE messagedialog.cpp messagedialog.h messagedialog.ui + mscappwidget.cpp + mscappwidget.h + mscappwidget.ui msccommandsstack.cpp msccommandsstack.h msceditor.cpp diff --git a/src/libs/libmsceditor/documenttree/documenttreeview.cpp b/src/libs/libmsceditor/documenttree/documenttreeview.cpp index e79e34b0e..36e0eb686 100644 --- a/src/libs/libmsceditor/documenttree/documenttreeview.cpp +++ b/src/libs/libmsceditor/documenttree/documenttreeview.cpp @@ -115,6 +115,7 @@ void DocumentTreeView::setSelectedDocument(msc::MscDocument *document) if (index.internalPointer() == document) { selectionModel()->select(index, QItemSelectionModel::ClearAndSelect); + setCurrentIndex(index); } for (int x = 0; x < model()->rowCount(index); ++x) { diff --git a/src/libs/libmsceditor/mscappwidget.cpp b/src/libs/libmsceditor/mscappwidget.cpp new file mode 100644 index 000000000..209fa9630 --- /dev/null +++ b/src/libs/libmsceditor/mscappwidget.cpp @@ -0,0 +1,566 @@ +/* + Copyright (C) 2021 European Space Agency - + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program. If not, see . +*/ + +#include "mscappwidget.h" + +#include "commands/cmdsetasn1file.h" +#include "documentitemmodel.h" +#include "hierarchyview/hierarchyviewmodel.h" +#include "mainmodel.h" +#include "msccommandsstack.h" +#include "msceditorcore.h" +#include "mscmodel.h" +#include "tools/actioncreatortool.h" +#include "tools/basetool.h" +#include "tools/commentcreatortool.h" +#include "tools/conditioncreatortool.h" +#include "tools/coregioncreatortool.h" +#include "tools/entitydeletetool.h" +#include "tools/instancecreatortool.h" +#include "tools/instancestoptool.h" +#include "tools/messagecreatortool.h" +#include "tools/pointertool.h" +#include "tools/timercreatortool.h" +#include "ui_mscappwidget.h" + +#include +#include +#include +#include +#include +#include + +namespace msc { + +static const char *HIERARCHY_TYPE_TAG = "hierarchyTag"; + +MscAppWidget::MscAppWidget(MSCEditorCore *mscCore, QWidget *parent) + : QWidget(parent) + , ui(new Ui::MSCAppWidget) + , m_mscCore(mscCore) +{ + ui->setupUi(this); + + ui->hierarchyView->setRenderHints( + QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); + + ui->documentToolBar->setVisible(false); + + ui->asn1Switch->setText(mainModel()->mscModel()->dataDefinitionString()); + + ui->horizontalSplitter->setStretchFactor(0, 0); + ui->horizontalSplitter->setStretchFactor(1, 1); + + m_actionCopy = m_mscCore->createActionCopy(nullptr); + m_actionPaste = m_mscCore->createActionPaste(nullptr); + + ui->documentTree->setModel(mainModel()->documentItemModel()); + ui->chartView->setScene(mainModel()->graphicsScene()); + ui->hierarchyView->setScene(mainModel()->hierarchyScene()); + + MscDocument *doc = mainModel()->selectedDocument(); + if (!doc) { + MscChart *chart = m_mscCore->mainModel()->chartViewModel().currentChart(); + if (chart) { + doc = chart->parentDocument(); + } + } + + initChartTools(); + initHierarchyViewActions(); + initConnections(); + + ui->documentTree->expandAll(); + ui->documentTree->setSelectedDocument(doc); + + showDocumentView(true); +} + +MscAppWidget::~MscAppWidget() +{ + if (ui->documentTree->model()) { + disconnect(ui->documentTree->model(), nullptr, this, nullptr); + } + if (mainModel()) { + disconnect(&(mainModel()->chartViewModel()), nullptr, this, nullptr); + disconnect(mainModel(), nullptr, this, nullptr); + disconnect(mainModel()->undoStack(), nullptr, this, nullptr); + } + delete ui; +} + +QStackedWidget *MscAppWidget::centerView() +{ + return ui->centerView; +} + +msc::GraphicsView *MscAppWidget::chartView() +{ + return ui->chartView; +} + +msc::GraphicsView *MscAppWidget::hierarchyView() +{ + return ui->hierarchyView; +} + +MscAppWidget::ViewMode MscAppWidget::viewMode() +{ + return m_viewMode; +} + +void MscAppWidget::initChartTools() +{ + if (!m_tools.isEmpty()) { + qDeleteAll(m_tools); + m_tools.clear(); + } + + m_pointerTool = new msc::PointerTool(nullptr, this); + m_tools.append(m_pointerTool); + + m_instanceCreatorTool = new msc::InstanceCreatorTool(&(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_instanceCreatorTool); + + m_instanceStopTool = new msc::InstanceStopTool(&(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_instanceStopTool); + + m_messageCreateTool = new msc::MessageCreatorTool( + msc::MscMessage::MessageType::Message, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_messageCreateTool); + + m_createCreateTool = new msc::MessageCreatorTool( + msc::MscMessage::MessageType::Create, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_createCreateTool); + + m_commentCreateTool = new msc::CommentCreatorTool(false, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_commentCreateTool); + + m_globalCommentCreateTool = new msc::CommentCreatorTool(true, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_globalCommentCreateTool); + + m_coregionCreateTool = new msc::CoregionCreatorTool(&(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_coregionCreateTool); + + m_actionCreateTool = new msc::ActionCreatorTool(&(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_actionCreateTool); + + m_conditionCreateTool = new msc::ConditionCreatorTool(false, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_conditionCreateTool); + + m_sharedConditionTool = new msc::ConditionCreatorTool(true, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_sharedConditionTool); + + m_startTimerCreateTool = + new msc::TimerCreatorTool(msc::MscTimer::TimerType::Start, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_startTimerCreateTool); + + m_stopTimerCreateTool = + new msc::TimerCreatorTool(msc::MscTimer::TimerType::Stop, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_stopTimerCreateTool); + + m_timeoutTimerCreateTool = new msc::TimerCreatorTool( + msc::MscTimer::TimerType::Timeout, &(mainModel()->chartViewModel()), nullptr, this); + m_tools.append(m_timeoutTimerCreateTool); + + QActionGroup *toolsActions = new QActionGroup(this); + toolsActions->setExclusive(false); + for (msc::BaseTool *tool : m_tools) { + QAction *toolAction = new QAction(tool->title()); + ui->chartToolBar->addAction(toolAction); + toolAction->setCheckable(true); + toolAction->setIcon(tool->icon()); + toolAction->setToolTip(tr("%1: %2").arg(tool->title(), tool->description())); + toolAction->setData(QVariant::fromValue(tool->toolType())); + toolAction->setEnabled(m_viewMode == ViewMode::CHART); + tool->setView(chartView()); + tool->setAction(toolAction); + + if (msc::BaseCreatorTool *creatorTool = qobject_cast(tool)) { + connect(creatorTool, &msc::BaseCreatorTool::created, this, [&]() { + chartView()->setFocus(); + activateDefaultTool(); + }); + connect(creatorTool, &msc::BaseCreatorTool::canceled, this, &MscAppWidget::activateDefaultTool); + } + + toolsActions->addAction(toolAction); + connect(toolAction, &QAction::toggled, this, &MscAppWidget::updateMscToolbarActionsChecked); + } + + m_defaultToolAction = toolsActions->actions().first(); + m_defaultToolAction->setVisible(false); + + m_deleteTool = new msc::EntityDeleteTool(&(mainModel()->chartViewModel()), chartView(), this); + m_deleteTool->setCurrentChart(mainModel()->chartViewModel().currentChart()); + connect(&mainModel()->chartViewModel(), &msc::ChartLayoutManager::currentChartChanged, m_deleteTool, + &msc::EntityDeleteTool::setCurrentChart); + + activateDefaultTool(); +} + +void MscAppWidget::initHierarchyViewActions() +{ + if (!m_hierarchyActions.isEmpty()) { + qDeleteAll(m_hierarchyActions); + m_hierarchyActions.clear(); + } + + auto addAction = [&](msc::MscDocument::HierarchyType type, const QString &title, const QIcon &icon) { + QAction *action = new QAction(title, this); + action->setProperty(HIERARCHY_TYPE_TAG, type); + action->setIcon(icon); + action->setToolTip(title); + action->setEnabled(m_viewMode == ViewMode::HIERARCHY); + ui->documentToolBar->addAction(action); + + m_hierarchyActions.append(action); + + connect(action, &QAction::triggered, this, [&]() { + msc::MscDocument::HierarchyType selectedType = + sender()->property(HIERARCHY_TYPE_TAG).value(); + m_mscCore->addDocument(selectedType); + }); + }; + + addAction(msc::MscDocument::HierarchyAnd, tr("Hierarchy And"), QIcon(":/icons/document_and.png")); + addAction(msc::MscDocument::HierarchyOr, tr("Hierarchy Or"), QIcon(":/icons/document_or.png")); + addAction(msc::MscDocument::HierarchyParallel, tr("Hierarchy Parallel"), QIcon(":/icons/document_parallel.png")); + addAction(msc::MscDocument::HierarchyIs, tr("Hierarchy Is"), QIcon(":/icons/document_is_scenario.png")); + addAction(msc::MscDocument::HierarchyRepeat, tr("Hierarchy Repeat"), QIcon(":/icons/document_repeat.png")); + addAction(msc::MscDocument::HierarchyException, tr("Hierarchy Exception"), QIcon(":/icons/document_exception.png")); + addAction(msc::MscDocument::HierarchyLeaf, tr("Hierarchy Leaf"), QIcon(":/icons/document_leaf.png")); +} + +void MscAppWidget::initConnections() +{ + connect(chartView(), &msc::GraphicsView::createMessageToolRequested, this, [&]() { + if (m_messageCreateTool) { + m_messageCreateTool->activate(); + } + }); + + connect(&(mainModel()->chartViewModel()), &msc::ChartLayoutManager::currentChartChanged, m_mscCore, + &MSCEditorCore::selectCurrentChart); + + connect(mainModel(), &msc::MainModel::showChartVew, this, [this]() { showDocumentView(true); }); + + connect(&(mainModel()->hierarchyViewModel()), &msc::HierarchyViewModel::selectedDocumentChanged, this, + &msc::MscAppWidget::updateHierarchyActions); + connect(this, &msc::MscAppWidget::viewModeChanged, this, &msc::MscAppWidget::updateHierarchyActions); + connect(&(mainModel()->hierarchyViewModel()), &msc::HierarchyViewModel::hierarchyTypeChanged, this, + &msc::MscAppWidget::updateHierarchyActions); + + connect(ui->documentTree->selectionModel(), &QItemSelectionModel::currentChanged, this, + &MscAppWidget::showSelection); + connect(ui->documentTree, &QTreeView::doubleClicked, this, &MscAppWidget::showChart); + + connect(mainModel(), &msc::MainModel::selectedDocumentChanged, ui->documentTree, + &msc::DocumentTreeView::setSelectedDocument); + + connect(mainModel()->documentItemModel(), &msc::DocumentItemModel::dataChanged, this, &MscAppWidget::showSelection); + + connect(mainModel(), &msc::MainModel::asn1FileNameChanged, ui->asn1Switch, &QPushButton::setText); + + // ASN1 view + connect(mainModel(), &MainModel::currentFilePathChanged, this, [&](const QString &filename) { + QFileInfo fileInfo(filename); + if (ui->asn1View->isVisible()) { + ui->asn1View->setDirectory(fileInfo.absolutePath()); + } + }); + connect(mainModel(), &msc::MainModel::asn1FileNameChanged, this, [&](const QString &asnFilename) { + if (ui->asn1View->isVisible()) { + ui->asn1View->setFileName(asnFilename); + } + }); + connect(ui->asn1View, &asn1::ASN1FileView::asn1Selected, this, [this]() { + msc::MscModel *model = mainModel()->mscModel(); + if (model->dataDefinitionString() != ui->asn1View->fileName()) { + m_mscCore->commandsStack()->push(new cmd::CmdSetAsn1File(model, ui->asn1View->fileName(), "ASN.1")); + } + }); + connect(ui->asn1Switch, &QPushButton::clicked, this, + [&]() { Q_EMIT showAsn1File(mainModel()->asn1File().absoluteFilePath()); }); + connect(ui->asn1Select, &QPushButton::clicked, this, [&]() { Q_EMIT selectAsn1(); }); + connect(ui->ivSwitch, &QPushButton::clicked, this, [&]() { Q_EMIT showInterfaceView(); }); +} + +QVector MscAppWidget::chartActions() const +{ + QVector actions; + actions.reserve(m_tools.size()); + for (msc::BaseTool *tool : m_tools) { + if (tool != m_deleteTool) + actions.append(tool->action()); + } + return actions; +} + +QVector MscAppWidget::hierarchyActions() const +{ + return m_hierarchyActions; +} + +PointerTool *MscAppWidget::pointerTool() const +{ + return m_pointerTool; +} + +EntityDeleteTool *MscAppWidget::deleteTool() +{ + return m_deleteTool; +} + +BaseTool *MscAppWidget::activeTool() const +{ + for (auto tool : m_tools) { + if (tool->isActive()) { + return tool; + } + } + + return nullptr; +} + +void MscAppWidget::showAsn1View(bool show) +{ + ui->asn1View->setVisible(show); + ui->asn1Widget->setVisible(!show); + ui->ivSwitch->setVisible(!show); +} + +void MscAppWidget::setViewMode(ViewMode mode) +{ + if (mode == m_viewMode) { + return; + } + + m_viewMode = mode; + if (m_viewMode == ViewMode::CHART) { + showDocumentView(true); + } else { + showHierarchyView(true); + } + + Q_EMIT viewModeChanged(m_viewMode); +} + +void MscAppWidget::showDocumentView(bool show) +{ + if (show) { + if (ui->centerView->currentWidget() == ui->chartView) { + return; + } + + ui->centerView->setCurrentWidget(ui->chartView); + + if (ui->documentToolBar) { + ui->documentToolBar->hide(); + } + if (ui->chartToolBar) { + ui->chartToolBar->show(); + } + for (QAction *action : chartActions()) { + action->setEnabled(true); + checkGlobalComment(); + } + for (QAction *action : hierarchyActions()) { + action->setEnabled(false); + } + + m_actionCopy->setEnabled(true); + msc::MscChart *chart = m_mscCore->mainModel()->chartViewModel().currentChart(); + QClipboard *clipboard = QApplication::clipboard(); + const QMimeData *mimeData = clipboard->mimeData(); + const bool clipBoardHasMscChart = mimeData ? mimeData->hasFormat(MainModel::MscChartMimeType) : false; + if (m_actionPaste) { + m_actionPaste->setEnabled(clipBoardHasMscChart && chart && chart->instances().isEmpty()); + } + if (m_actionCopy) { + m_actionCopy->setEnabled(true); + } + + m_deleteTool->setView(ui->chartView); + m_deleteTool->setCurrentChart(chart); + + setViewMode(ViewMode::CHART); + } else { + showHierarchyView(true); + } +} + +void MscAppWidget::showHierarchyView(bool show) +{ + if (show) { + if (ui->centerView->currentWidget() == ui->hierarchyView) { + return; + } + + ui->centerView->setCurrentWidget(ui->hierarchyView); + + if (ui->documentToolBar) { + ui->documentToolBar->show(); + } + if (ui->chartToolBar) { + ui->chartToolBar->hide(); + } + for (QAction *action : chartActions()) { + action->setEnabled(false); + } + for (QAction *action : hierarchyActions()) { + action->setEnabled(true); + } + + if (m_actionCopy) { + m_actionCopy->setEnabled(false); + } + if (m_actionPaste) { + m_actionPaste->setEnabled(false); + } + + m_deleteTool->setView(ui->hierarchyView); + m_deleteTool->setCurrentChart(nullptr); + + setViewMode(ViewMode::HIERARCHY); + } else { + showDocumentView(true); + } +} + +void MscAppWidget::activateDefaultTool() +{ + for (msc::BaseTool *tool : m_tools) { + if (tool != m_pointerTool) + tool->action()->setChecked(false); + } + m_pointerTool->action()->setChecked(true); +} + +void MscAppWidget::checkGlobalComment() +{ + if (!m_globalCommentCreateTool) { + return; + } + + msc::MscChart *currentChart = m_mscCore->mainModel()->chartViewModel().currentChart(); + if (!currentChart) { + m_globalCommentCreateTool->action()->setEnabled(false); + return; + } + + const bool hasInstance = currentChart && !currentChart->instances().isEmpty(); + const bool hasGlobalComment = !currentChart->commentString().isEmpty(); + m_globalCommentCreateTool->action()->setEnabled(hasInstance && !hasGlobalComment); +} + +void MscAppWidget::updateMscToolbarActionsChecked() +{ + if (QAction *senderAction = qobject_cast(sender())) { + if (senderAction->isChecked()) { + for (QAction *action : ui->chartToolBar->actions()) + if (action != senderAction) { + action->setChecked(false); + } + } + } +} + +/*! + Enables or disables the hierarchy actions, depending if a new document can be added or not + */ +void MscAppWidget::updateHierarchyActions() +{ + bool canAdd = true; + if (m_viewMode != ViewMode::HIERARCHY) { + canAdd = false; + } + MscDocument *parentDoc = mainModel()->selectedDocument(); + if (!parentDoc || !parentDoc->isAddChildEnable()) { + canAdd = false; + } + + for (QAction *action : m_hierarchyActions) { + action->setEnabled(canAdd); + } +} + +void MscAppWidget::showChart(const QModelIndex &index) +{ + if (!index.isValid()) { + return; + } + + auto *obj = static_cast(index.internalPointer()); + if (obj == nullptr) { + return; + } + + if (auto document = dynamic_cast(obj)) { + if (!document->charts().empty()) { + mainModel()->chartViewModel().setCurrentChart(document->charts()[0]); + showDocumentView(true); + } + } +} + +void MscAppWidget::showSelection(const QModelIndex ¤t, const QModelIndex &previous) +{ + Q_UNUSED(previous) + if (!current.isValid()) { + return; + } + + auto *obj = static_cast(current.internalPointer()); + if (obj == nullptr) { + mainModel()->setSelectedDocument(nullptr); + return; + } + + if (chartView()) { + static constexpr qreal padding = 110.; + QSizeF preferredSize = chartView()->size() - QSizeF(padding, padding); + mainModel()->chartViewModel().setPreferredChartBoxSize(preferredSize); + } + + auto chart = dynamic_cast(obj); + if (!chart) { + if (auto document = dynamic_cast(obj)) { + if (document && document->hierarchyType() == msc::MscDocument::HierarchyLeaf) { + if (!document->charts().isEmpty()) + chart = document->charts().at(0); + } + } + } + if (chart) { + mainModel()->chartViewModel().setCurrentChart(chart); + showDocumentView(true); + } else { + showHierarchyView(true); + + if (auto document = dynamic_cast(obj)) { + mainModel()->setSelectedDocument(document); + } + } +} + +MainModel *MscAppWidget::mainModel() const +{ + return m_mscCore->mainModel(); +} + +} // namespace msc diff --git a/src/libs/libmsceditor/mscappwidget.h b/src/libs/libmsceditor/mscappwidget.h new file mode 100644 index 000000000..881179b4f --- /dev/null +++ b/src/libs/libmsceditor/mscappwidget.h @@ -0,0 +1,133 @@ +/* + Copyright (C) 2021 European Space Agency - + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include +#include +#include +#include + +class QStackedWidget; + +namespace Ui { +class MSCAppWidget; +} + +namespace msc { +class GraphicsView; +class MainModel; +class MSCEditorCore; +class ActionCreatorTool; +class BaseTool; +class CommentCreatorTool; +class ConditionCreatorTool; +class CoregionCreatorTool; +class EntityDeleteTool; +class InstanceCreatorTool; +class InstanceStopTool; +class MessageCreatorTool; +class PointerTool; +class TimerCreatorTool; + +class MscAppWidget : public QWidget +{ + Q_OBJECT + Q_PROPERTY(msc::MscAppWidget::ViewMode viewMode READ viewMode WRITE setViewMode NOTIFY viewModeChanged) + +public: + enum class ViewMode + { + CHART, + HIERARCHY + }; + Q_ENUM(ViewMode); + + explicit MscAppWidget(MSCEditorCore *mscCore, QWidget *parent = nullptr); + ~MscAppWidget(); + + QStackedWidget *centerView(); + GraphicsView *chartView(); + GraphicsView *hierarchyView(); + + ViewMode viewMode(); + + void initChartTools(); + void initHierarchyViewActions(); + void initConnections(); + + QVector chartActions() const; + QVector hierarchyActions() const; + + msc::PointerTool *pointerTool() const; + msc::EntityDeleteTool *deleteTool(); + msc::BaseTool *activeTool() const; + + void showAsn1View(bool show); + +public Q_SLOTS: + void setViewMode(ViewMode mode); + void showDocumentView(bool show); + void showHierarchyView(bool show); + void activateDefaultTool(); + void checkGlobalComment(); + +Q_SIGNALS: + void viewModeChanged(ViewMode); + void showAsn1File(const QString &asnFilename); + void selectAsn1(); + void showInterfaceView(); + +private Q_SLOTS: + void updateMscToolbarActionsChecked(); + void updateHierarchyActions(); + void showChart(const QModelIndex &index); + void showSelection(const QModelIndex ¤t, const QModelIndex &previous); + +private: + msc::MainModel *mainModel() const; + + Ui::MSCAppWidget *ui; + QPointer m_mscCore; + ViewMode m_viewMode = ViewMode::CHART; + + QAction *m_actionCopy = nullptr; + QAction *m_actionPaste = nullptr; + QAction *m_actionMessageDeclarations = nullptr; + + QVector m_tools; + QAction *m_defaultToolAction = nullptr; + msc::EntityDeleteTool *m_deleteTool = nullptr; + msc::PointerTool *m_pointerTool = nullptr; + msc::InstanceCreatorTool *m_instanceCreatorTool = nullptr; + msc::InstanceStopTool *m_instanceStopTool = nullptr; + msc::MessageCreatorTool *m_messageCreateTool = nullptr; + msc::MessageCreatorTool *m_createCreateTool = nullptr; + msc::CommentCreatorTool *m_commentCreateTool = nullptr; + msc::CommentCreatorTool *m_globalCommentCreateTool = nullptr; + msc::CoregionCreatorTool *m_coregionCreateTool = nullptr; + msc::ActionCreatorTool *m_actionCreateTool = nullptr; + msc::ConditionCreatorTool *m_conditionCreateTool = nullptr; + msc::ConditionCreatorTool *m_sharedConditionTool = nullptr; + msc::TimerCreatorTool *m_startTimerCreateTool = nullptr; + msc::TimerCreatorTool *m_stopTimerCreateTool = nullptr; + msc::TimerCreatorTool *m_timeoutTimerCreateTool = nullptr; + + QVector m_hierarchyActions; +}; + +} // namespace msc diff --git a/src/libs/libmsceditor/mscappwidget.ui b/src/libs/libmsceditor/mscappwidget.ui new file mode 100644 index 000000000..9d665b9c4 --- /dev/null +++ b/src/libs/libmsceditor/mscappwidget.ui @@ -0,0 +1,171 @@ + + + MSCAppWidget + + + + 0 + 0 + 874 + 572 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Open the file + + + Interface view + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Open the file + + + file.asn + + + + + + + Select the ASN.1 file + + + ... + + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + 0 + + + + + + + + + + + + + + shared::ActionsBar + QWidget +
actionsbar.h
+ 1 +
+ + msc::GraphicsView + QGraphicsView +
graphicsview.h
+
+ + msc::DocumentTreeView + QTreeView +
documenttree/documenttreeview.h
+
+ + asn1::ASN1FileView + QWidget +
asn1fileview.h
+ 1 +
+
+ + +
diff --git a/src/libs/libmsceditor/msceditorcore.cpp b/src/libs/libmsceditor/msceditorcore.cpp index b2e8c1647..692d5e0d4 100644 --- a/src/libs/libmsceditor/msceditorcore.cpp +++ b/src/libs/libmsceditor/msceditorcore.cpp @@ -17,6 +17,7 @@ #include "msceditorcore.h" +#include "chartlayoutmanager.h" #include "commandlineparser.h" #include "commands/cmddeleteentity.h" #include "commands/cmddocumentcreate.h" @@ -28,6 +29,7 @@ #include "ivfunction.h" #include "mainmodel.h" #include "messagedeclarationsdialog.h" +#include "mscappwidget.h" #include "mscchart.h" #include "msccommandsstack.h" #include "mscdocument.h" @@ -35,17 +37,6 @@ #include "mscmessagedeclarationlist.h" #include "mscmodel.h" #include "systemchecks.h" -#include "tools/actioncreatortool.h" -#include "tools/basetool.h" -#include "tools/commentcreatortool.h" -#include "tools/conditioncreatortool.h" -#include "tools/coregioncreatortool.h" -#include "tools/entitydeletetool.h" -#include "tools/instancecreatortool.h" -#include "tools/instancestoptool.h" -#include "tools/messagecreatortool.h" -#include "tools/pointertool.h" -#include "tools/timercreatortool.h" #include "ui/graphicsviewbase.h" #include @@ -57,15 +48,12 @@ #include #include #include -#include #include #include #include namespace msc { -static const char *HIERARCHY_TYPE_TAG = "hierarchyTag"; - /*! * \class MSCEditorCore * \brief Has most of the code for the MSC Editor UI and the underlying library @@ -78,6 +66,14 @@ MSCEditorCore::MSCEditorCore(QObject *parent) setSystemChecker(new SystemChecks(this)); connect(m_model->commandsStack(), &msc::MscCommandsStack::nameChanged, this, &msc::MSCEditorCore::nameChanged); + + connect(&(mainModel()->chartViewModel()), &msc::ChartLayoutManager::initialNameAccepted, this, + [this](MscEntity *entity) { + if (!entity) { + return; + } + Q_EMIT nameChanged(entity, entity->name(), nullptr); + }); } MSCEditorCore::~MSCEditorCore() { } @@ -87,162 +83,9 @@ MainModel *MSCEditorCore::mainModel() const return m_model.get(); } -void MSCEditorCore::setViews( - QStackedWidget *centerView, shared::ui::GraphicsViewBase *chartView, GraphicsView *hierarchyView) -{ - m_centerView = centerView; - m_chartView = chartView; - m_hierarchyView = hierarchyView; - - if (m_chartView) { - m_chartView->setScene(mainModel()->graphicsScene()); - } - if (m_hierarchyView) { - m_hierarchyView->setScene(mainModel()->hierarchyScene()); - } -} - -QStackedWidget *MSCEditorCore::centerView() -{ - return m_centerView; -} - shared::ui::GraphicsViewBase *MSCEditorCore::chartView() { - return m_chartView; -} - -GraphicsView *MSCEditorCore::hierarchyView() -{ - return m_hierarchyView; -} - -void MSCEditorCore::initChartTools() -{ - Q_ASSERT(m_chartView != nullptr); - - if (!m_tools.isEmpty()) { - qDeleteAll(m_tools); - m_tools.clear(); - } - - m_pointerTool = new msc::PointerTool(nullptr, this); - m_tools.append(m_pointerTool); - - m_instanceCreatorTool = new msc::InstanceCreatorTool(&(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_instanceCreatorTool); - - m_instanceStopTool = new msc::InstanceStopTool(&(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_instanceStopTool); - - m_messageCreateTool = new msc::MessageCreatorTool( - msc::MscMessage::MessageType::Message, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_messageCreateTool); - - m_createCreateTool = new msc::MessageCreatorTool( - msc::MscMessage::MessageType::Create, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_createCreateTool); - - m_commentCreateTool = new msc::CommentCreatorTool(false, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_commentCreateTool); - - m_globalCommentCreateTool = new msc::CommentCreatorTool(true, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_globalCommentCreateTool); - - m_coregionCreateTool = new msc::CoregionCreatorTool(&(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_coregionCreateTool); - - m_actionCreateTool = new msc::ActionCreatorTool(&(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_actionCreateTool); - - m_conditionCreateTool = new msc::ConditionCreatorTool(false, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_conditionCreateTool); - - m_sharedConditionTool = new msc::ConditionCreatorTool(true, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_sharedConditionTool); - - m_startTimerCreateTool = - new msc::TimerCreatorTool(msc::MscTimer::TimerType::Start, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_startTimerCreateTool); - - m_stopTimerCreateTool = - new msc::TimerCreatorTool(msc::MscTimer::TimerType::Stop, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_stopTimerCreateTool); - - m_timeoutTimerCreateTool = - new msc::TimerCreatorTool(msc::MscTimer::TimerType::Timeout, &(m_model->chartViewModel()), nullptr, this); - m_tools.append(m_timeoutTimerCreateTool); - - QActionGroup *toolsActions = new QActionGroup(this); - toolsActions->setExclusive(false); - for (msc::BaseTool *tool : m_tools) { - QAction *toolAction = mscToolBar()->addAction(tool->title()); - toolAction->setCheckable(true); - toolAction->setIcon(tool->icon()); - toolAction->setToolTip(tr("%1: %2").arg(tool->title(), tool->description())); - toolAction->setData(QVariant::fromValue(tool->toolType())); - toolAction->setEnabled(m_viewMode == ViewMode::CHART); - tool->setView(m_chartView); - tool->setAction(toolAction); - - if (msc::BaseCreatorTool *creatorTool = qobject_cast(tool)) { - connect(creatorTool, &msc::BaseCreatorTool::created, this, [&]() { - m_chartView->setFocus(); - activateDefaultTool(); - }); - connect(creatorTool, &msc::BaseCreatorTool::canceled, this, &MSCEditorCore::activateDefaultTool); - } - - toolsActions->addAction(toolAction); - connect(toolAction, &QAction::toggled, this, &MSCEditorCore::updateMscToolbarActionsChecked); - } - - m_defaultToolAction = toolsActions->actions().first(); - m_defaultToolAction->setVisible(false); - - m_deleteTool = new msc::EntityDeleteTool(&(m_model->chartViewModel()), m_chartView, this); - m_deleteTool->setCurrentChart(m_model->chartViewModel().currentChart()); - connect(&m_model->chartViewModel(), &msc::ChartLayoutManager::currentChartChanged, m_deleteTool, - &msc::EntityDeleteTool::setCurrentChart); - - activateDefaultTool(); -} - -void MSCEditorCore::initHierarchyViewActions() -{ - Q_ASSERT(m_hierarchyView != nullptr); - - if (!m_hierarchyActions.isEmpty()) { - qDeleteAll(m_hierarchyActions); - m_hierarchyActions.clear(); - } - - auto addAction = [&](msc::MscDocument::HierarchyType type, const QString &title, const QIcon &icon) { - QAction *action = new QAction(title, this); - action->setProperty(HIERARCHY_TYPE_TAG, type); - action->setIcon(icon); - action->setToolTip(title); - action->setEnabled(m_viewMode == ViewMode::HIERARCHY); - if (m_hierarchyToolBar) { - m_hierarchyToolBar->addAction(action); - } - - m_hierarchyActions.append(action); - - connect(action, &QAction::triggered, this, [&]() { - msc::MscDocument::HierarchyType selectedType = - sender()->property(HIERARCHY_TYPE_TAG).value(); - addDocument(selectedType); - }); - }; - - addAction(msc::MscDocument::HierarchyAnd, tr("Hierarchy And"), QIcon(":/icons/document_and.png")); - addAction(msc::MscDocument::HierarchyOr, tr("Hierarchy Or"), QIcon(":/icons/document_or.png")); - addAction(msc::MscDocument::HierarchyParallel, tr("Hierarchy Parallel"), QIcon(":/icons/document_parallel.png")); - addAction(msc::MscDocument::HierarchyIs, tr("Hierarchy Is"), QIcon(":/icons/document_is_scenario.png")); - addAction(msc::MscDocument::HierarchyRepeat, tr("Hierarchy Repeat"), QIcon(":/icons/document_repeat.png")); - addAction(msc::MscDocument::HierarchyException, tr("Hierarchy Exception"), QIcon(":/icons/document_exception.png")); - addAction(msc::MscDocument::HierarchyLeaf, tr("Hierarchy Leaf"), QIcon(":/icons/document_leaf.png")); + return m_mainWidget->chartView(); } void MSCEditorCore::initConnections() @@ -251,18 +94,6 @@ void MSCEditorCore::initConnections() return; } - Q_ASSERT(m_chartView != nullptr); - - if (auto chartview = qobject_cast(m_chartView)) { - connect(chartview, &msc::GraphicsView::createMessageToolRequested, this, [&]() { - if (m_messageCreateTool) { - m_messageCreateTool->activate(); - } - }); - } - - connect(&(m_model->chartViewModel()), &msc::ChartLayoutManager::currentChartChanged, this, - &MSCEditorCore::selectCurrentChart); connect(&(m_model->chartViewModel()), &msc::ChartLayoutManager::initialNameAccepted, this, [this](MscEntity *entity) { if (!entity) { @@ -271,55 +102,21 @@ void MSCEditorCore::initConnections() Q_EMIT nameChanged(entity, entity->name(), nullptr); }); - connect(m_model.get(), &msc::MainModel::showChartVew, this, [this]() { showDocumentView(true); }); - - connect(&(m_model->hierarchyViewModel()), &msc::HierarchyViewModel::selectedDocumentChanged, this, - &msc::MSCEditorCore::updateHierarchyActions); - connect(this, &msc::MSCEditorCore::viewModeChanged, this, &msc::MSCEditorCore::updateHierarchyActions); - connect(&(m_model->hierarchyViewModel()), &msc::HierarchyViewModel::hierarchyTypeChanged, this, - &msc::MSCEditorCore::updateHierarchyActions); - m_connectionsDone = true; } void MSCEditorCore::addToolBars(QMainWindow *window) { window->addToolBar(mainToolBar()); - window->addToolBar(Qt::LeftToolBarArea, mscToolBar()); - window->addToolBar(Qt::LeftToolBarArea, hierarchyToolBar()); -} - -QToolBar *MSCEditorCore::mscToolBar() -{ - if (!m_mscToolBar) { - m_mscToolBar = new QToolBar(tr("MSC")); - m_mscToolBar->setObjectName("mscTools"); - m_mscToolBar->setAllowedAreas(Qt::AllToolBarAreas); - m_mscToolBar->setVisible(m_toolbarsVisible); - } - return m_mscToolBar; } -QToolBar *MSCEditorCore::hierarchyToolBar() +MscAppWidget *MSCEditorCore::mainwidget() { - if (!m_hierarchyToolBar) { - m_hierarchyToolBar = new QToolBar(tr("Hierarchy")); - m_hierarchyToolBar->setObjectName("hierarchyTools"); - m_hierarchyToolBar->setAllowedAreas(Qt::AllToolBarAreas); - m_hierarchyToolBar->setVisible(m_toolbarsVisible); - } - return m_hierarchyToolBar; -} - -void MSCEditorCore::showToolbars(bool show) -{ - m_toolbarsVisible = show; - if (m_mscToolBar) { - m_mscToolBar->setVisible(m_toolbarsVisible); - } - if (m_hierarchyToolBar) { - m_hierarchyToolBar->setVisible(m_toolbarsVisible); + if (!m_mainWidget) { + m_mainWidget = new MscAppWidget(this); + m_model->chartViewModel().preferredChartBoxSize(); } + return m_mainWidget; } void MSCEditorCore::populateCommandLineArguments(shared::CommandLineParser *parser) const @@ -329,17 +126,6 @@ void MSCEditorCore::populateCommandLineArguments(shared::CommandLineParser *pars parser->handlePositional(shared::CommandLineParser::Positional::DropUnsavedChangesSilently); } -BaseTool *MSCEditorCore::activeTool() const -{ - for (auto tool : m_tools) { - if (tool->isActive()) { - return tool; - } - } - - return nullptr; -} - QAction *MSCEditorCore::actionMessageDeclarations() { if (!m_actionMessageDeclarations) { @@ -351,22 +137,6 @@ QAction *MSCEditorCore::actionMessageDeclarations() return m_actionMessageDeclarations; } -QVector MSCEditorCore::chartActions() const -{ - QVector actions; - actions.reserve(m_tools.size()); - for (msc::BaseTool *tool : m_tools) { - if (tool != m_deleteTool) - actions.append(tool->action()); - } - return actions; -} - -QVector MSCEditorCore::hierarchyActions() const -{ - return m_hierarchyActions; -} - QAction *MSCEditorCore::createActionCopy(QMainWindow *window) { if (m_actionCopy == nullptr) { @@ -430,11 +200,6 @@ SystemChecks *MSCEditorCore::systemChecker() const return m_systemChecks; } -MSCEditorCore::ViewMode MSCEditorCore::viewMode() -{ - return m_viewMode; -} - QUndoStack *MSCEditorCore::undoStack() const { return m_model->undoStack(); @@ -604,113 +369,6 @@ bool MSCEditorCore::save() return m_model->saveMsc(m_model->currentFilePath()); } -void MSCEditorCore::setViewMode(MSCEditorCore::ViewMode mode) -{ - if (mode == m_viewMode) { - return; - } - - m_viewMode = mode; - if (m_viewMode == ViewMode::CHART) { - showDocumentView(true); - } else { - showHierarchyView(true); - } - - Q_EMIT viewModeChanged(m_viewMode); -} - -void MSCEditorCore::showDocumentView(bool show) -{ - if (show) { - if (m_centerView->currentWidget() == m_chartView) { - return; - } - - m_centerView->setCurrentWidget(m_chartView); - - if (m_hierarchyToolBar) { - m_hierarchyToolBar->hide(); - } - if (m_mscToolBar && m_toolbarsVisible) { - m_mscToolBar->show(); - } - for (QAction *action : chartActions()) { - action->setEnabled(true); - checkGlobalComment(); - } - for (QAction *action : hierarchyActions()) { - action->setEnabled(false); - } - - actionCopy()->setEnabled(true); - msc::MscChart *chart = mainModel()->chartViewModel().currentChart(); - QClipboard *clipboard = QApplication::clipboard(); - const QMimeData *mimeData = clipboard->mimeData(); - const bool clipBoardHasMscChart = mimeData ? mimeData->hasFormat(MainModel::MscChartMimeType) : false; - if (m_actionPaste) { - m_actionPaste->setEnabled(clipBoardHasMscChart && chart && chart->instances().isEmpty()); - } - if (m_actionCopy) { - m_actionCopy->setEnabled(true); - } - - m_deleteTool->setView(m_chartView); - m_deleteTool->setCurrentChart(chart); - - setViewMode(ViewMode::CHART); - } else { - showHierarchyView(true); - } -} - -void MSCEditorCore::showHierarchyView(bool show) -{ - if (show) { - if (m_centerView->currentWidget() == m_hierarchyView) { - return; - } - - m_centerView->setCurrentWidget(m_hierarchyView); - - if (m_hierarchyToolBar && m_toolbarsVisible) { - m_hierarchyToolBar->show(); - } - if (m_mscToolBar) { - m_mscToolBar->hide(); - } - for (QAction *action : chartActions()) { - action->setEnabled(false); - } - for (QAction *action : hierarchyActions()) { - action->setEnabled(true); - } - - if (m_actionCopy) { - m_actionCopy->setEnabled(false); - } - if (m_actionPaste) { - m_actionPaste->setEnabled(false); - } - - m_deleteTool->setView(m_hierarchyView); - m_deleteTool->setCurrentChart(nullptr); - - setViewMode(ViewMode::HIERARCHY); - } else { - showDocumentView(true); - } -} - -void MSCEditorCore::activateDefaultTool() -{ - for (msc::BaseTool *tool : m_tools) { - if (tool != m_pointerTool) - tool->action()->setChecked(false); - } - m_pointerTool->action()->setChecked(true); -} - /*! * \brief msc::MSCEditorCore::selectCurrentChart Set the current chart as the currently selected. */ @@ -718,27 +376,10 @@ void MSCEditorCore::selectCurrentChart() { msc::MscChart *chart = m_model->chartViewModel().currentChart(); if (chart != nullptr) { - connect(chart, &msc::MscEntity::commentChanged, this, &msc::MSCEditorCore::checkGlobalComment, + connect(chart, &msc::MscEntity::commentChanged, m_mainWidget, &msc::MscAppWidget::checkGlobalComment, Qt::UniqueConnection); } - checkGlobalComment(); -} - -void MSCEditorCore::checkGlobalComment() -{ - if (!m_globalCommentCreateTool) { - return; - } - - msc::MscChart *currentChart = m_model->chartViewModel().currentChart(); - if (!currentChart) { - m_globalCommentCreateTool->action()->setEnabled(false); - return; - } - - const bool hasInstance = currentChart && !currentChart->instances().isEmpty(); - const bool hasGlobalComment = !currentChart->commentString().isEmpty(); - m_globalCommentCreateTool->action()->setEnabled(hasInstance && !hasGlobalComment); + m_mainWidget->checkGlobalComment(); } void MSCEditorCore::openMessageDeclarationEditor(QWidget *parentwidget) @@ -766,46 +407,12 @@ void MSCEditorCore::openMessageDeclarationEditor(QWidget *parentwidget) } } -void MSCEditorCore::updateMscToolbarActionsChecked() -{ - if (!m_mscToolBar) { - return; - } - - if (QAction *senderAction = qobject_cast(sender())) - if (senderAction->isChecked()) { - for (QAction *action : m_mscToolBar->actions()) - if (action != senderAction) { - action->setChecked(false); - } - } -} - -/*! - Enables or disables the hierarchy actions, depending if a new document can be added or not - */ -void MSCEditorCore::updateHierarchyActions() -{ - bool canAdd = true; - if (m_viewMode != ViewMode::HIERARCHY) { - canAdd = false; - } - MscDocument *parentDoc = m_model->selectedDocument(); - if (!parentDoc || !parentDoc->isAddChildEnable()) { - canAdd = false; - } - - for (QAction *action : m_hierarchyActions) { - action->setEnabled(canAdd); - } -} - /*! Adds a MSC document if the hierarchy view is active and a "non-leaf" document is selected */ void MSCEditorCore::addDocument(MscDocument::HierarchyType type) { - if (m_viewMode != ViewMode::HIERARCHY) { + if (!m_mainWidget || m_mainWidget->viewMode() != MscAppWidget::ViewMode::HIERARCHY) { return; } MscDocument *parentDoc = m_model->hierarchyViewModel().selectedDocument(); diff --git a/src/libs/libmsceditor/msceditorcore.h b/src/libs/libmsceditor/msceditorcore.h index 417892d91..3e27f0a3e 100644 --- a/src/libs/libmsceditor/msceditorcore.h +++ b/src/libs/libmsceditor/msceditorcore.h @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -37,80 +36,48 @@ class UndoCommand; } namespace msc { -class ActionCreatorTool; -class BaseTool; -class CommentCreatorTool; -class ConditionCreatorTool; -class CoregionCreatorTool; -class EntityDeleteTool; -class InstanceCreatorTool; -class InstanceStopTool; class MainModel; -class MessageCreatorTool; class MscChart; class MscCommandsStack; class MscInstance; class MscMessage; class PointerTool; class SystemChecks; -class TimerCreatorTool; +class MscAppWidget; class MainWindow; class MSCEditorCore : public shared::EditorCore { Q_OBJECT - Q_PROPERTY(msc::MSCEditorCore::ViewMode viewMode READ viewMode WRITE setViewMode NOTIFY viewModeChanged) public: - enum class ViewMode - { - CHART, - HIERARCHY - }; - Q_ENUM(ViewMode); - explicit MSCEditorCore(QObject *parent = nullptr); ~MSCEditorCore(); msc::MainModel *mainModel() const; - void setViews( - QStackedWidget *centerView, shared::ui::GraphicsViewBase *chartView, msc::GraphicsView *hierarchyView); - QStackedWidget *centerView(); shared::ui::GraphicsViewBase *chartView() override; - msc::GraphicsView *hierarchyView(); - void initChartTools(); - void initHierarchyViewActions(); void initConnections(); void addToolBars(QMainWindow *window) override; - QToolBar *mscToolBar(); - QToolBar *hierarchyToolBar(); - void showToolbars(bool show); + MscAppWidget *mainwidget(); void populateCommandLineArguments(shared::CommandLineParser *parser) const override; QAction *actionCopy() { return m_actionCopy; } QAction *actionPaste() { return m_actionPaste; } - msc::EntityDeleteTool *deleteTool() { return m_deleteTool; } - msc::BaseTool *activeTool() const; QAction *actionMessageDeclarations(); - QVector chartActions() const; - QVector hierarchyActions() const; - QAction *createActionCopy(QMainWindow *window); QAction *createActionPaste(QMainWindow *window); void setSystemChecker(msc::SystemChecks *checker); msc::SystemChecks *systemChecker() const; - ViewMode viewMode(); - QUndoStack *undoStack() const override; msc::MscCommandsStack *commandsStack() const; @@ -127,64 +94,26 @@ public: bool save() override; public Q_SLOTS: - void setViewMode(ViewMode mode); - void showDocumentView(bool show); - void showHierarchyView(bool show); - void activateDefaultTool(); void selectCurrentChart(); - void checkGlobalComment(); void openMessageDeclarationEditor(QWidget *parentwidget); + void addDocument(msc::MscDocument::HierarchyType type); Q_SIGNALS: - void viewModeChanged(ViewMode); void nameChanged(QObject *entity, const QString &oldName, shared::UndoCommand *command); -private Q_SLOTS: - void updateMscToolbarActionsChecked(); - void updateHierarchyActions(); - void addDocument(msc::MscDocument::HierarchyType type); - private: QUrl helpPage() const override; std::unique_ptr m_model; msc::SystemChecks *m_systemChecks = nullptr; - ViewMode m_viewMode = ViewMode::CHART; - - QPointer m_centerView = nullptr; - QPointer m_chartView = nullptr; - QPointer m_hierarchyView = nullptr; - - QPointer m_mscToolBar = nullptr; - QPointer m_hierarchyToolBar = nullptr; - QAction *m_actionCopy = nullptr; QAction *m_actionPaste = nullptr; QAction *m_actionMessageDeclarations = nullptr; - QVector m_tools; - QAction *m_defaultToolAction = nullptr; - msc::EntityDeleteTool *m_deleteTool = nullptr; - msc::PointerTool *m_pointerTool = nullptr; - msc::InstanceCreatorTool *m_instanceCreatorTool = nullptr; - msc::InstanceStopTool *m_instanceStopTool = nullptr; - msc::MessageCreatorTool *m_messageCreateTool = nullptr; - msc::MessageCreatorTool *m_createCreateTool = nullptr; - msc::CommentCreatorTool *m_commentCreateTool = nullptr; - msc::CommentCreatorTool *m_globalCommentCreateTool = nullptr; - msc::CoregionCreatorTool *m_coregionCreateTool = nullptr; - msc::ActionCreatorTool *m_actionCreateTool = nullptr; - msc::ConditionCreatorTool *m_conditionCreateTool = nullptr; - msc::ConditionCreatorTool *m_sharedConditionTool = nullptr; - msc::TimerCreatorTool *m_startTimerCreateTool = nullptr; - msc::TimerCreatorTool *m_stopTimerCreateTool = nullptr; - msc::TimerCreatorTool *m_timeoutTimerCreateTool = nullptr; - - QVector m_hierarchyActions; - - bool m_toolbarsVisible = true; bool m_connectionsDone = false; + + MscAppWidget *m_mainWidget = nullptr; }; } diff --git a/src/libs/libmsceditor/tools/messagecreatortool.cpp b/src/libs/libmsceditor/tools/messagecreatortool.cpp index 84dd20ffd..7d7fa1308 100644 --- a/src/libs/libmsceditor/tools/messagecreatortool.cpp +++ b/src/libs/libmsceditor/tools/messagecreatortool.cpp @@ -474,6 +474,9 @@ QVariantList MessageCreatorTool::prepareMessage() void MessageCreatorTool::movePreviewItemTo(const QPointF &newScenePos) { + if (!m_messageItem) { + return; + } MessageItem::GeometryNotificationBlocker lock(m_messageItem); m_messageItem->setTail(newScenePos, ObjectAnchor::Snap::SnapTo); m_messageItem->setHead(newScenePos, ObjectAnchor::Snap::SnapTo); diff --git a/src/libs/spacecreatorsystem/spacecreatorproject.cpp b/src/libs/spacecreatorsystem/spacecreatorproject.cpp index bdbd33536..ccc1a87c9 100644 --- a/src/libs/spacecreatorsystem/spacecreatorproject.cpp +++ b/src/libs/spacecreatorsystem/spacecreatorproject.cpp @@ -109,7 +109,6 @@ MSCEditorCorePtr SpaceCreatorProject::mscData(const QString &fileName) const { if (!m_mscStore.contains(fileName)) { MSCEditorCorePtr data(new msc::MSCEditorCore()); - data->showToolbars(false); data->mainModel()->setAsn1Check(m_asnChecks.get()); data->mainModel()->loadFile(fileName); if (data->mainModel()->mscModel() && data->mainModel()->mscModel()->dataLanguage().isEmpty()) { diff --git a/src/qtcreator/spacecreatorplugin/msc/mscmainwidget.cpp b/src/qtcreator/spacecreatorplugin/msc/mscmainwidget.cpp index a7e375a2b..d39baf366 100644 --- a/src/qtcreator/spacecreatorplugin/msc/mscmainwidget.cpp +++ b/src/qtcreator/spacecreatorplugin/msc/mscmainwidget.cpp @@ -17,35 +17,19 @@ #include "mscmainwidget.h" -#include "actionsbar.h" -#include "asn1fileview.h" #include "chartlayoutmanager.h" #include "commands/cmdsetasn1file.h" -#include "documentitemmodel.h" -#include "documenttreeview.h" -#include "graphicsview.h" #include "mainmodel.h" -#include "mscchart.h" -#include "mscdocument.h" +#include "mscappwidget.h" #include "mscmodel.h" #include "spacecreatorprojectimpl.h" -#include #include #include #include -#include #include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include +#include namespace spctr { @@ -58,36 +42,13 @@ MscMainWidget::MscMainWidget(QWidget *parent) { } -MscMainWidget::~MscMainWidget() -{ - if (m_documentTree->model()) { - disconnect(m_documentTree->model(), nullptr, this, nullptr); - } - if (!m_plugin.isNull()) { - disconnect(&(m_plugin->mainModel()->chartViewModel()), nullptr, this, nullptr); - disconnect(m_plugin->mainModel(), nullptr, this, nullptr); - disconnect(m_plugin->mainModel()->undoStack(), nullptr, this, nullptr); - } -} +MscMainWidget::~MscMainWidget() { } bool MscMainWidget::init(MSCEditorCorePtr plugin, SpaceCreatorProjectImpl *project) { m_project = project; m_plugin = plugin; - if (!m_plugin->chartView()) { - init(); - m_plugin->mainModel()->chartViewModel().clearScene(); - m_plugin->mainModel()->chartViewModel().updateLayout(); - m_plugin->chartView()->setZoom(100); - } - - m_asn1Switch->setText(m_plugin->mainModel()->mscModel()->dataDefinitionString()); - - if (m_documentTree) { - m_documentTree->expandAll(); - m_documentTree->setSelectedDocument(m_plugin->mainModel()->selectedDocument()); - } - + init(); return true; } @@ -97,80 +58,6 @@ MSCEditorCorePtr MscMainWidget::mscCore() const return m_plugin; } -void MscMainWidget::showChart(const QModelIndex &index) -{ - if (!index.isValid()) { - return; - } - if (m_plugin.isNull()) { - return; - } - - auto *obj = static_cast(index.internalPointer()); - if (obj == nullptr) { - return; - } - - if (auto document = dynamic_cast(obj)) { - if (!document->charts().empty()) { - m_plugin->mainModel()->chartViewModel().setCurrentChart(document->charts()[0]); - m_plugin->showDocumentView(true); - } - } -} - -void MscMainWidget::showSelection(const QModelIndex ¤t, const QModelIndex &previous) -{ - Q_UNUSED(previous) - if (!current.isValid()) { - return; - } - if (m_plugin.isNull()) { - return; - } - - auto *obj = static_cast(current.internalPointer()); - if (obj == nullptr) { - m_plugin->mainModel()->setSelectedDocument(nullptr); - return; - } - - if (m_plugin->chartView()) { - static constexpr qreal padding = 110.; - QSizeF preferredSize = m_plugin->chartView()->size() - QSizeF(padding, padding); - m_plugin->mainModel()->chartViewModel().setPreferredChartBoxSize(preferredSize); - } - - auto chart = dynamic_cast(obj); - if (!chart) { - if (auto document = dynamic_cast(obj)) { - if (document && document->hierarchyType() == msc::MscDocument::HierarchyLeaf) { - if (!document->charts().isEmpty()) - chart = document->charts().at(0); - } - } - } - if (chart) { - m_plugin->mainModel()->chartViewModel().setCurrentChart(chart); - m_plugin->showDocumentView(true); - } else { - m_plugin->showHierarchyView(true); - - if (auto document = dynamic_cast(obj)) { - m_plugin->mainModel()->setSelectedDocument(document); - } - } -} - -/*! - Thw the chart of document tool bar depending of the view mode - */ -void MscMainWidget::onViewModeChanged() -{ - m_chartToolBar->setVisible(m_plugin->viewMode() == msc::MSCEditorCore::ViewMode::CHART); - m_documentToolBar->setVisible(m_plugin->viewMode() == msc::MSCEditorCore::ViewMode::HIERARCHY); -} - void MscMainWidget::openAsn1Dialog() { QString dir = QFileInfo(m_plugin->mainModel()->currentFilePath()).absolutePath(); @@ -184,46 +71,28 @@ void MscMainWidget::openAsn1Dialog() void MscMainWidget::init() { - if (m_documentTree || m_plugin.isNull()) { - // initialized already + if (m_plugin.isNull()) { return; } - // Graphical editors - auto editorsWidgets = new QWidget(this); - auto editorsLayout = new QHBoxLayout(editorsWidgets); - editorsLayout->setMargin(0); - editorsLayout->setSpacing(0); - editorsWidgets->setLayout(editorsLayout); - - m_chartToolBar = new shared::ActionsBar(editorsWidgets); - editorsLayout->addWidget(m_chartToolBar); - m_documentToolBar = new shared::ActionsBar(editorsWidgets); - editorsLayout->addWidget(m_documentToolBar); - connect(m_plugin.data(), &msc::MSCEditorCore::viewModeChanged, this, &spctr::MscMainWidget::onViewModeChanged); - onViewModeChanged(); - - auto centerView = new QStackedWidget(editorsWidgets); - auto graphicsView = new msc::GraphicsView(centerView); - centerView->addWidget(graphicsView); - auto hierarchyView = new msc::GraphicsView(centerView); - centerView->addWidget(hierarchyView); - editorsLayout->addWidget(centerView); + auto layout = new QHBoxLayout(this); + layout->setMargin(0); + layout->setSpacing(0); + setLayout(layout); + msc::MscAppWidget *mainWidget = m_plugin->mainwidget(); + mainWidget->showAsn1View(false); + mainWidget->setParent(this); + layout->addWidget(mainWidget); - m_plugin->setViews(centerView, graphicsView, hierarchyView); - - // Doceuments tree etc. - auto leftArea = new QWidget(this); - auto leftVerticalLayout = new QVBoxLayout(leftArea); - leftVerticalLayout->setMargin(0); - - m_documentTree = new msc::DocumentTreeView(leftArea); - m_documentTree->header()->setVisible(true); - leftVerticalLayout->addWidget(m_documentTree); - - m_ivSwitch = new QPushButton("Interface view", leftArea); - m_ivSwitch->setToolTip(tr("Open the file")); - connect(m_ivSwitch, &QPushButton::clicked, this, [this]() { + if (!mainWidget->chartView()) { + m_plugin->mainModel()->chartViewModel().clearScene(); + m_plugin->mainModel()->chartViewModel().updateLayout(); + m_plugin->chartView()->setZoom(100); + } + connect(mainWidget, &msc::MscAppWidget::showAsn1File, this, + [&](const QString &asnFilename) { Core::EditorManager::instance()->openEditor(asnFilename); }); + connect(mainWidget, &msc::MscAppWidget::selectAsn1, this, &spctr::MscMainWidget::openAsn1Dialog); + connect(mainWidget, &msc::MscAppWidget::showInterfaceView, this, [&]() { if (!m_project) { return; } @@ -232,74 +101,6 @@ void MscMainWidget::init() Core::EditorManager::instance()->openEditor(ivFiles.first()); } }); - m_ivSwitch->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); - leftVerticalLayout->addWidget(m_ivSwitch); - - auto asn1Widget = new QWidget(leftArea); - asn1Widget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - auto asn1Layout = new QHBoxLayout(asn1Widget); - asn1Layout->setMargin(0); - asn1Widget->setLayout(asn1Layout); - m_asn1Switch = new QPushButton("file.asn", asn1Widget); - m_asn1Switch->setToolTip(tr("Open the file")); - m_asn1Switch->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); - m_asn1Select = new QPushButton(tr("..."), asn1Widget); - m_asn1Select->setToolTip(tr("Select the ASN.1 file")); - connect(m_asn1Select, &QPushButton::clicked, this, &spctr::MscMainWidget::openAsn1Dialog); - m_asn1Select->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - asn1Layout->addWidget(m_asn1Switch); - asn1Layout->addWidget(m_asn1Select); - - leftVerticalLayout->addWidget(asn1Widget); - - auto horizontalSplitter = new Core::MiniSplitter(Qt::Horizontal); - horizontalSplitter->addWidget(leftArea); - horizontalSplitter->addWidget(editorsWidgets); - horizontalSplitter->setStretchFactor(0, 0); - horizontalSplitter->setStretchFactor(1, 1); - - auto viewLayout = new QHBoxLayout(this); - viewLayout->setMargin(0); - viewLayout->setSpacing(0); - setLayout(viewLayout); - viewLayout->addWidget(horizontalSplitter); - - // init - m_documentTree->setModel(m_plugin->mainModel()->documentItemModel()); - - m_plugin->createActionCopy(nullptr); - m_plugin->createActionPaste(nullptr); - m_plugin->initChartTools(); - m_plugin->initHierarchyViewActions(); - initConnections(); - m_plugin->initConnections(); - m_plugin->setupMiniMap(); - m_plugin->showDocumentView(true); - - for (QAction *chartAction : m_plugin->chartActions()) { - m_chartToolBar->addAction(chartAction); - } - for (QAction *documentAction : m_plugin->hierarchyActions()) { - m_documentToolBar->addAction(documentAction); - } -} - -void MscMainWidget::initConnections() -{ - connect(m_documentTree->selectionModel(), &QItemSelectionModel::currentChanged, this, - &MscMainWidget::showSelection); - connect(m_documentTree, &QTreeView::doubleClicked, this, &MscMainWidget::showChart); - - connect(m_plugin->mainModel(), &msc::MainModel::selectedDocumentChanged, m_documentTree, - &msc::DocumentTreeView::setSelectedDocument); - - connect(m_plugin->mainModel()->documentItemModel(), &msc::DocumentItemModel::dataChanged, this, - &MscMainWidget::showSelection); - - connect(m_plugin->mainModel(), &msc::MainModel::asn1FileNameChanged, m_asn1Switch, &QPushButton::setText); - connect(m_asn1Switch, &QPushButton::clicked, this, [&]() { - Core::EditorManager::instance()->openEditor(m_plugin->mainModel()->asn1File().absoluteFilePath()); - }); } } diff --git a/src/qtcreator/spacecreatorplugin/msc/mscmainwidget.h b/src/qtcreator/spacecreatorplugin/msc/mscmainwidget.h index b7d0f23fa..49580a0cc 100644 --- a/src/qtcreator/spacecreatorplugin/msc/mscmainwidget.h +++ b/src/qtcreator/spacecreatorplugin/msc/mscmainwidget.h @@ -56,22 +56,10 @@ public: MSCEditorCorePtr mscCore() const; private Q_SLOTS: - void showChart(const QModelIndex &index); - void showSelection(const QModelIndex ¤t, const QModelIndex &previous); - void onViewModeChanged(); void openAsn1Dialog(); private: void init(); - void initConnections(); - - shared::ActionsBar *m_chartToolBar = nullptr; - shared::ActionsBar *m_documentToolBar = nullptr; - - msc::DocumentTreeView *m_documentTree = nullptr; - QPushButton *m_ivSwitch = nullptr; - QPushButton *m_asn1Switch = nullptr; - QPushButton *m_asn1Select = nullptr; MSCEditorCorePtr m_plugin; QPointer m_project; diff --git a/src/qtcreator/spacecreatorplugin/msc/mscqtceditor.cpp b/src/qtcreator/spacecreatorplugin/msc/mscqtceditor.cpp index e98eeab68..df3d9cbec 100644 --- a/src/qtcreator/spacecreatorplugin/msc/mscqtceditor.cpp +++ b/src/qtcreator/spacecreatorplugin/msc/mscqtceditor.cpp @@ -17,6 +17,7 @@ #include "mscqtceditor.h" +#include "mscappwidget.h" #include "msceditordocument.h" #include "mscmainwidget.h" #include "spacecreatorpluginconstants.h" @@ -71,7 +72,7 @@ QWidget *MscQtCEditor::toolBar() m_toolbar->addAction(mscCore->actionUndo()); m_toolbar->addAction(mscCore->actionRedo()); m_toolbar->addSeparator(); - m_toolbar->addAction(mscCore->deleteTool()->action()); + m_toolbar->addAction(mscCore->mainwidget()->deleteTool()->action()); m_toolbar->addSeparator(); m_toolbar->addAction(mscCore->actionCopy()); m_toolbar->addAction(mscCore->actionPaste()); -- GitLab