Skip to content

Commit

Permalink
Clear the selection when doing undo/redo.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Oct 19, 2015
1 parent b9ed433 commit a13a6c9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1456,6 +1456,7 @@ void MainWindow::undo()
if (pModelWidget &&
((pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) ||
(pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible()))) {
pModelWidget->clearSelection();
pModelWidget->getUndoStack()->undo();
pModelWidget->updateClassAnnotationIfNeeded();
pModelWidget->updateModelicaText();
Expand All @@ -1472,6 +1473,7 @@ void MainWindow::redo()
if (pModelWidget &&
((pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) ||
(pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible()))) {
pModelWidget->clearSelection();
pModelWidget->getUndoStack()->redo();
pModelWidget->updateClassAnnotationIfNeeded();
pModelWidget->updateModelicaText();
Expand Down
10 changes: 0 additions & 10 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -72,7 +72,6 @@ void AddShapeCommand::redo()
void AddShapeCommand::undo()
{
mpGraphicsView->deleteShapeFromList(mpShapeAnnotation);
mpShapeAnnotation->setSelected(false);
mpGraphicsView->removeItem(mpShapeAnnotation);
mpShapeAnnotation->emitDeleted();
mpGraphicsView->addClassAnnotation();
Expand Down Expand Up @@ -201,7 +200,6 @@ void RotateShapeCommand::undo()
qreal angle = oldRotation + rotateIncrement;
mpShapeAnnotation->applyRotation(angle);
}
mpShapeAnnotation->setSelected(false);
}

DeleteShapeCommand::DeleteShapeCommand(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView, QUndoCommand *pParent)
Expand All @@ -218,7 +216,6 @@ DeleteShapeCommand::DeleteShapeCommand(ShapeAnnotation *pShapeAnnotation, Graphi
void DeleteShapeCommand::redo()
{
mpGraphicsView->deleteShapeFromList(mpShapeAnnotation);
mpShapeAnnotation->setSelected(false);
mpGraphicsView->removeItem(mpShapeAnnotation);
mpShapeAnnotation->emitDeleted();
mpGraphicsView->setAddClassAnnotationNeeded(true);
Expand Down Expand Up @@ -323,20 +320,17 @@ void AddComponentCommand::undo()
pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
// first create the component for Icon View only if connector is not protected
if (!mpComponentInfo->getProtected()) {
mpIconComponent->setSelected(false);
mpIconGraphicsView->removeItem(mpIconComponent);
mpIconGraphicsView->removeItem(mpIconComponent->getOriginItem());
mpIconGraphicsView->deleteComponentFromList(mpIconComponent);
mpIconComponent->emitDeleted();
}
// now remove the component from Diagram View
mpDiagramComponent->setSelected(false);
mpDiagramGraphicsView->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
mpDiagramComponent->emitDeleted();
} else {
mpDiagramComponent->setSelected(false);
mpDiagramGraphicsView->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
Expand Down Expand Up @@ -468,7 +462,6 @@ void RotateComponentCommand::undo()
qreal angle = oldRotation + rotateIncrement;
mpComponent->applyRotation(angle);
}
mpComponent->setSelected(false);
}

DeleteComponentCommand::DeleteComponentCommand(Component *pComponent, GraphicsView *pGraphicsView, QUndoCommand *pParent)
Expand All @@ -495,7 +488,6 @@ void DeleteComponentCommand::redo()
// first remove the component from Icon View
mpIconComponent = mpIconGraphicsView->getComponentObject(mpComponent->getName());
if (mpIconComponent) {
mpIconComponent->setSelected(false);
mpIconGraphicsView->removeItem(mpIconComponent);
mpIconGraphicsView->removeItem(mpIconComponent->getOriginItem());
mpIconGraphicsView->deleteComponentFromList(mpIconComponent);
Expand All @@ -504,14 +496,12 @@ void DeleteComponentCommand::redo()
// now remove the component from Diagram View
mpDiagramComponent = mpDiagramGraphicsView->getComponentObject(mpComponent->getName());
if (mpDiagramComponent) {
mpDiagramComponent->setSelected(false);
mpDiagramGraphicsView->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
mpDiagramComponent->emitDeleted();
}
} else {
mpComponent->setSelected(false);
mpDiagramGraphicsView->removeItem(mpComponent);
mpDiagramGraphicsView->removeItem(mpComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpComponent);
Expand Down
30 changes: 29 additions & 1 deletion OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -1196,14 +1196,28 @@ void GraphicsView::zoomOut()
}
}

//! Selects all objects and connectors.
/*!
* \brief GraphicsView::selectAll
* Selects all shapes, components and connectors.
*/
void GraphicsView::selectAll()
{
foreach (QGraphicsItem *pItem, items()) {
pItem->setSelected(true);
}
}

/*!
* \brief GraphicsView::clearSelection
* Clears the selection of all shapes, components and connectors.
*/
void GraphicsView::clearSelection()
{
foreach (QGraphicsItem *pItem, items()) {
pItem->setSelected(false);
}
}

//! Adds the annotation string of Icon and Diagram layer to the model. Also creates the model icon in the tree.
//! If some custom models are cross referenced then update them accordingly.
void GraphicsView::addClassAnnotation(bool updateModelicaText)
Expand Down Expand Up @@ -2737,6 +2751,20 @@ bool ModelWidget::modelicaEditorTextChanged()
return true;
}

/*!
* \brief ModelWidget::clearSelection
* Clears the selection Icon and Diagram layers.
*/
void ModelWidget::clearSelection()
{
if (mpIconGraphicsView) {
mpIconGraphicsView->clearSelection();
}
if (mpDiagramGraphicsView) {
mpDiagramGraphicsView->clearSelection();
}
}

/*!
* \brief ModelWidget::updateClassAnnotationIfNeeded
* Updates the class annotation for both icon and diagram views if needed.
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -254,6 +254,7 @@ public slots:
void zoomIn();
void zoomOut();
void selectAll();
void clearSelection();
void addClassAnnotation(bool updateModelicaText = true);
void showGraphicsViewProperties();
void deleteItems();
Expand Down Expand Up @@ -380,6 +381,7 @@ class ModelWidget : public QWidget
void refresh();
bool validateText();
bool modelicaEditorTextChanged();
void clearSelection();
void updateClassAnnotationIfNeeded();
void updateModelicaText();
void updateUndoRedoActions();
Expand Down

0 comments on commit a13a6c9

Please sign in to comment.