Skip to content

Commit

Permalink
clean up some redundant code (#7073)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jan 14, 2021
1 parent 007380c commit eb3c4d8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -4136,7 +4136,7 @@ void MainWindow::switchToPlottingPerspective()
}
// if we have DiagramWindow then draw items on it based on the current ModelWidget
if (pModelWidget && mpPlotWindowContainer->getDiagramSubWindowFromMdi()) {
mpPlotWindowContainer->getDiagramWindow()->drawDiagram(mpModelWidgetContainer->getCurrentModelWidget());
mpPlotWindowContainer->getDiagramWindow()->drawDiagram(pModelWidget);
}
mpVariablesDockWidget->show();
// show/hide toolbars
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -8276,7 +8276,7 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
/* ticket:4983 Update the documentation browser when a new ModelWidget is selected.
* Provided that the Documentation Browser is already visible.
*/
if (mpLastActiveSubWindow == pSubWindow) {
if (!pSubWindow || mpLastActiveSubWindow == pSubWindow) {
return;
}
mpLastActiveSubWindow = pSubWindow;
Expand Down
35 changes: 19 additions & 16 deletions OMEdit/OMEditLIB/Plotting/DiagramWindow.cpp
Expand Up @@ -65,18 +65,9 @@ DiagramWindow::DiagramWindow(QWidget *parent) : QWidget(parent)
*/
void DiagramWindow::drawDiagram(ModelWidget *pModelWidget)
{
// Stop any running visualization when we are going to draw a diagram.
MainWindow::instance()->getVariablesWidget()->rewindVisualization();

if (pModelWidget && pModelWidget->getDiagramGraphicsView()) {
setWindowTitle(pModelWidget->getLibraryTreeItem()->getName());
if (mpGraphicsView) {
mpGraphicsScene->deleteLater();
mpGraphicsScene = 0;
mpMainLayout->removeWidget(mpGraphicsView);
mpGraphicsView->deleteLater();
mpGraphicsView = 0;
}
deleteGraphicsViewAndScene();
mpGraphicsScene = new GraphicsScene(StringHandler::Diagram, pModelWidget);
mpGraphicsView = new GraphicsView(StringHandler::Diagram, pModelWidget, true);
mpGraphicsView->setScene(mpGraphicsScene);
Expand Down Expand Up @@ -138,24 +129,36 @@ void DiagramWindow::drawDiagram(ModelWidget *pModelWidget)

/*!
* \brief DiagramWindow::removeDiagram
* When the corresponsing ModelWidget is about to delete then clear the DiagramWindow.
* When the corresponding ModelWidget is about to delete then clear the DiagramWindow.
* \param pModelWidget
*/
void DiagramWindow::removeDiagram(ModelWidget *pModelWidget)
{
if (mpGraphicsView && mpGraphicsView->getModelWidget() == pModelWidget) {
// Stop any running visualization when we are going to draw a diagram.
MainWindow::instance()->getVariablesWidget()->rewindVisualization();
// set the window title to default
setWindowTitle("Diagram");
// clear the GraphicsView and delete it
deleteGraphicsViewAndScene();
}
}

/*!
* \brief DiagramWindow::deleteGraphicsViewAndScene
* Clears the GraphicsView and deletes it and GraphicsScene.
*/
void DiagramWindow::deleteGraphicsViewAndScene()
{
// Stop any running visualization
MainWindow::instance()->getVariablesWidget()->rewindVisualization();
if (mpGraphicsView) {
mpGraphicsView->clearGraphicsView();
mpGraphicsScene->deleteLater();
mpGraphicsScene = 0;
mpMainLayout->removeWidget(mpGraphicsView);
mpGraphicsView->deleteLater();
mpGraphicsView = 0;
}
if (mpGraphicsScene) {
mpGraphicsScene->deleteLater();
mpGraphicsScene = 0;
}
}

/*!
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditLIB/Plotting/DiagramWindow.h
Expand Up @@ -53,6 +53,8 @@ class DiagramWindow : public QWidget
GraphicsScene *mpGraphicsScene;
GraphicsView *mpGraphicsView;
QVBoxLayout *mpMainLayout;

void deleteGraphicsViewAndScene();
protected:
virtual void closeEvent(QCloseEvent *event) override;
};
Expand Down

0 comments on commit eb3c4d8

Please sign in to comment.