Skip to content

Commit

Permalink
Merged the mouse and keyboard delete functionality
Browse files Browse the repository at this point in the history
Made ShapeAnnotation::duplicate() pure virtual.
Don't allow making transitions from non-existing classes.
Emit component added signal when duplicating a component.
  • Loading branch information
adeas31 committed Sep 12, 2019
1 parent e95f9c9 commit e613a91
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 56 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/BitmapAnnotation.h
Expand Up @@ -63,7 +63,7 @@ class BitmapAnnotation : public ShapeAnnotation
private:
Component *mpComponent;
public slots:
void duplicate();
void duplicate() override;
};

#endif // BITMAPANNOTATION_H
2 changes: 1 addition & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/EllipseAnnotation.h
Expand Up @@ -58,7 +58,7 @@ class EllipseAnnotation : public ShapeAnnotation
QString getShapeAnnotation() override;
void updateShape(ShapeAnnotation *pShapeAnnotation) override;
public slots:
void duplicate();
void duplicate() override;
};

#endif // ELLIPSEANNOTATION_H
2 changes: 1 addition & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -173,7 +173,7 @@ public slots:
void updateTransitionAnnotation(QString oldCondition, bool oldImmediate, bool oldReset, bool oldSynchronize, int oldPriority);
void redraw(const QString& annotation, std::function<void()> updateAnnotationFunction);
void updateInitialStateAnnotation();
void duplicate();
void duplicate() override;
};

class ExpandableConnectorTreeItem : public QObject
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/PolygonAnnotation.h
Expand Up @@ -65,7 +65,7 @@ class PolygonAnnotation : public ShapeAnnotation
void updateEndPoint(QPointF point);
void updateShape(ShapeAnnotation *pShapeAnnotation) override;
public slots:
void duplicate();
void duplicate() override;
};

#endif // POLYGONANNOTATION_H
2 changes: 1 addition & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/RectangleAnnotation.h
Expand Up @@ -62,7 +62,7 @@ class RectangleAnnotation : public ShapeAnnotation
QString getShapeAnnotation() override;
void updateShape(ShapeAnnotation *pShapeAnnotation) override;
public slots:
void duplicate();
void duplicate() override;
};

#endif // RECTANGLEANNOTATION_H
19 changes: 4 additions & 15 deletions OMEdit/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -1241,15 +1241,6 @@ void ShapeAnnotation::deleteMe()
}
}

/*!
* \brief ShapeAnnotation::duplicate
* Reimplemented by each child shape class to duplicate the shape.
*/
void ShapeAnnotation::duplicate()
{
/* duplicate code is implemented in each child shape class. */
}

/*!
* \brief ShapeAnnotation::bringToFront
* Brings the shape to front of all other shapes.
Expand Down Expand Up @@ -1787,10 +1778,9 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant &
/* Only allow manipulations on shapes if the class is not a system library class OR shape is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()) {
if (pLineAnnotation) {
connect(mpGraphicsView, SIGNAL(mouseManhattanize()), this, SLOT(manhattanizeShape()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(manhattanize()), this, SLOT(manhattanizeShape()), Qt::UniqueConnection);
}
connect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(deleteSignal()), this, SLOT(deleteMe()), Qt::UniqueConnection);
if (lineType == LineAnnotation::ShapeType) {
connect(mpGraphicsView, SIGNAL(mouseDuplicate()), this, SLOT(duplicate()), Qt::UniqueConnection);
connect(mpGraphicsView->getBringToFrontAction(), SIGNAL(triggered()), this, SLOT(bringToFront()), Qt::UniqueConnection);
Expand Down Expand Up @@ -1822,10 +1812,9 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant &
/* Only allow manipulations on shapes if the class is not a system library class OR shape is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()) {
if (pLineAnnotation) {
disconnect(mpGraphicsView, SIGNAL(mouseManhattanize()), this, SLOT(manhattanizeShape()));
disconnect(mpGraphicsView, SIGNAL(manhattanize()), this, SLOT(manhattanizeShape()));
}
disconnect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(deleteSignal()), this, SLOT(deleteMe()));
if (lineType == LineAnnotation::ShapeType) {
disconnect(mpGraphicsView, SIGNAL(mouseDuplicate()), this, SLOT(duplicate()));
disconnect(mpGraphicsView->getBringToFrontAction(), SIGNAL(triggered()), this, SLOT(bringToFront()));
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -207,7 +207,7 @@ class ShapeAnnotation : public QObject, public QGraphicsItem, public GraphicItem
void deleted();
public slots:
void deleteMe();
virtual void duplicate();
virtual void duplicate() = 0;
void bringToFront();
void bringForward();
void sendToBack();
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEdit/OMEditGUI/Annotations/TextAnnotation.h
Expand Up @@ -73,7 +73,7 @@ class TextAnnotation : public ShapeAnnotation
void updateTextStringHelper(QRegExp regExp);
public slots:
void updateTextString();
void duplicate();
void duplicate() override;
};

#endif // TEXTANNOTATION_H
8 changes: 3 additions & 5 deletions OMEdit/OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -2696,7 +2696,7 @@ void Component::duplicate()
mpComponentInfo->getModifiersMap(MainWindow::instance()->getOMCProxy(), mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure(), this);
ComponentInfo *pComponentInfo = new ComponentInfo(mpComponentInfo);
pComponentInfo->setName(name);
mpGraphicsView->addComponentToView(name, mpLibraryTreeItem, getOMCPlacementAnnotation(gridStep), QPointF(0, 0), pComponentInfo, true, true);
mpGraphicsView->addComponentToView(name, mpLibraryTreeItem, getOMCPlacementAnnotation(gridStep), QPointF(0, 0), pComponentInfo, true, true, true);
Component *pDiagramComponent = mpGraphicsView->getModelWidget()->getDiagramGraphicsView()->getComponentsList().last();
setSelected(false);
if (mpGraphicsView->getViewType() == StringHandler::Diagram) {
Expand Down Expand Up @@ -3115,13 +3115,12 @@ QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
setCursor(Qt::SizeAllCursor);
// Only allow manipulations on component if the class is not a system library class OR component is not an inherited component.
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedComponent()) {
connect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(deleteSignal()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseDuplicate()), this, SLOT(duplicate()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseRotateClockwise()), this, SLOT(rotateClockwise()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseFlipHorizontal()), this, SLOT(flipHorizontal()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseFlipVertical()), this, SLOT(flipVertical()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressDuplicate()), this, SLOT(duplicate()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressRotateClockwise()), this, SLOT(rotateClockwise()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(keyPressRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()), Qt::UniqueConnection);
Expand Down Expand Up @@ -3152,13 +3151,12 @@ QVariant Component::itemChange(GraphicsItemChange change, const QVariant &value)
unsetCursor();
/* Only allow manipulations on component if the class is not a system library class OR component is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedComponent()) {
disconnect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(deleteSignal()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(mouseDuplicate()), this, SLOT(duplicate()));
disconnect(mpGraphicsView, SIGNAL(mouseRotateClockwise()), this, SLOT(rotateClockwise()));
disconnect(mpGraphicsView, SIGNAL(mouseRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()));
disconnect(mpGraphicsView, SIGNAL(mouseFlipHorizontal()), this, SLOT(flipHorizontal()));
disconnect(mpGraphicsView, SIGNAL(mouseFlipVertical()), this, SLOT(flipVertical()));
disconnect(mpGraphicsView, SIGNAL(keyPressDelete()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(keyPressDuplicate()), this, SLOT(duplicate()));
disconnect(mpGraphicsView, SIGNAL(keyPressRotateClockwise()), this, SLOT(rotateClockwise()));
disconnect(mpGraphicsView, SIGNAL(keyPressRotateAntiClockwise()), this, SLOT(rotateAntiClockwise()));
Expand Down
1 change: 0 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -981,7 +981,6 @@ void LibraryTreeItem::handleShapeAdded(ShapeAnnotation *pShapeAnnotation, Graphi
*/
void LibraryTreeItem::handleComponentAdded(Component *pComponent)
{
qDebug() << "LibraryTreeItem::handleComponentAdded";
if (mpModelWidget) {
if (pComponent->getLibraryTreeItem() && pComponent->getLibraryTreeItem()->isConnector()) {
mpModelWidget->getIconGraphicsView()->addInheritedComponentToList(mpModelWidget->createInheritedComponent(pComponent, mpModelWidget->getIconGraphicsView()));
Expand Down
44 changes: 20 additions & 24 deletions OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -321,7 +321,7 @@ bool GraphicsView::addComponent(QString className, QPointF position)
pComponentInfo->setStartCommand("");
}
pComponentInfo->setModelFile(fileInfo.fileName());
addComponentToView(name, pLibraryTreeItem, "", position, pComponentInfo, true, false);
addComponentToView(name, pLibraryTreeItem, "", position, pComponentInfo, true, false, true);
return true;
}
} else {
Expand Down Expand Up @@ -397,7 +397,7 @@ bool GraphicsView::addComponent(QString className, QPointF position)
// if item is a class, model, block, connector or record. then we can drop it to the graphicsview
if ((type == StringHandler::Class) || (type == StringHandler::Model) || (type == StringHandler::Block) ||
(type == StringHandler::ExpandableConnector) || (type == StringHandler::Connector) || (type == StringHandler::Record)) {
addComponentToView(name, pLibraryTreeItem, "", position, pComponentInfo);
addComponentToView(name, pLibraryTreeItem, "", position, pComponentInfo, true, false, true);
return true;
} else {
QMessageBox::information(pMainWindow, QString(Helper::applicationName).append(" - ").append(Helper::information),
Expand All @@ -408,7 +408,7 @@ bool GraphicsView::addComponent(QString className, QPointF position)
} else if (mViewType == StringHandler::Icon) { // if dropping an item on the icon layer
// if item is a connector. then we can drop it to the graphicsview
if (type == StringHandler::Connector || type == StringHandler::ExpandableConnector) {
addComponentToView(name, pLibraryTreeItem, "", position, pComponentInfo);
addComponentToView(name, pLibraryTreeItem, "", position, pComponentInfo, true, false, true);
return true;
} else {
QMessageBox::information(pMainWindow, QString(Helper::applicationName).append(" - ").append(Helper::information),
Expand All @@ -432,15 +432,18 @@ bool GraphicsView::addComponent(QString className, QPointF position)
* \param pComponentInfo
* \param addObject
* \param openingClass
* \param emitComponentAdded
*/
void GraphicsView::addComponentToView(QString name, LibraryTreeItem *pLibraryTreeItem, QString annotation, QPointF position,
ComponentInfo *pComponentInfo, bool addObject, bool openingClass)
ComponentInfo *pComponentInfo, bool addObject, bool openingClass, bool emitComponentAdded)
{
AddComponentCommand *pAddComponentCommand;
pAddComponentCommand = new AddComponentCommand(name, pLibraryTreeItem, annotation, position, pComponentInfo, addObject, openingClass, this);
mpModelWidget->getUndoStack()->push(pAddComponentCommand);
if (!openingClass) {
if (emitComponentAdded) {
mpModelWidget->getLibraryTreeItem()->emitComponentAdded(pAddComponentCommand->getComponent());
}
if (!openingClass) {
mpModelWidget->updateModelText();
}
}
Expand Down Expand Up @@ -1784,7 +1787,7 @@ Component* GraphicsView::stateComponentAtPosition(QPoint position)
if (MainWindow::instance()->getTransitionModeAction()->isChecked() && mViewType == StringHandler::Diagram &&
!(mpModelWidget->getLibraryTreeItem()->isSystemLibrary() || isVisualizationView()) &&
((pComponent->getLibraryTreeItem() && pComponent->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica &&
pComponent->getLibraryTreeItem()->isState()))) {
!pComponent->getLibraryTreeItem()->isNonExisting() && pComponent->getLibraryTreeItem()->isState()))) {
return pComponent;
}
}
Expand Down Expand Up @@ -2339,7 +2342,7 @@ void GraphicsView::pasteItems()
}
ComponentInfo *pComponentInfo = new ComponentInfo(pComponent->getComponentInfo());
pComponentInfo->setName(name);
addComponentToView(name, pComponent->getLibraryTreeItem(), pComponent->getOMCPlacementAnnotation(QPointF(0, 0)), QPointF(0, 0), pComponentInfo, true, true);
addComponentToView(name, pComponent->getLibraryTreeItem(), pComponent->getOMCPlacementAnnotation(QPointF(0, 0)), QPointF(0, 0), pComponentInfo, true, true, true);
Component *pNewComponent = mComponentsList.last();
pNewComponent->setSelected(true);
}
Expand Down Expand Up @@ -2513,25 +2516,25 @@ void GraphicsView::showRenameDialog()

/*!
* \brief GraphicsView::manhattanizeItems
* Manhattanize the selected items by emitting GraphicsView::mouseManhattanize() SIGNAL.
* Manhattanize the selected items by emitting GraphicsView::manhattanize() SIGNAL.
*/
void GraphicsView::manhattanizeItems()
{
mpModelWidget->beginMacro("Manhattanize by mouse");
emit mouseManhattanize();
mpModelWidget->beginMacro("Manhattanize");
emit manhattanize();
mpModelWidget->updateClassAnnotationIfNeeded();
mpModelWidget->updateModelText();
mpModelWidget->endMacro();
}

/*!
* \brief GraphicsView::deleteItems
* Deletes the selected items by emitting GraphicsView::mouseDelete() SIGNAL.
* Deletes the selected items by emitting GraphicsView::deleteSignal() SIGNAL.
*/
void GraphicsView::deleteItems()
{
mpModelWidget->beginMacro("Deleting by mouse");
emit mouseDelete();
mpModelWidget->beginMacro("Delete items");
emit deleteSignal();
mpModelWidget->updateClassAnnotationIfNeeded();
mpModelWidget->updateModelText();
mpModelWidget->endMacro();
Expand Down Expand Up @@ -3113,11 +3116,7 @@ void GraphicsView::keyPressEvent(QKeyEvent *event)
bool shiftModifier = event->modifiers().testFlag(Qt::ShiftModifier);
bool controlModifier = event->modifiers().testFlag(Qt::ControlModifier);
if (event->key() == Qt::Key_Delete && isAnyItemSelectedAndEditable(event->key())) {
mpModelWidget->beginMacro("Deleting by key press");
emit keyPressDelete();
mpModelWidget->updateClassAnnotationIfNeeded();
mpModelWidget->updateModelText();
mpModelWidget->endMacro();
deleteItems();
} else if (!shiftModifier && !controlModifier && event->key() == Qt::Key_Up && isAnyItemSelectedAndEditable(event->key())) {
mpModelWidget->beginMacro("Move up by key press");
emit keyPressUp();
Expand Down Expand Up @@ -6016,8 +6015,7 @@ void ModelWidget::drawModelIconComponents()
annotation = StringHandler::removeFirstLastCurlBrackets(annotation);
annotation = QString("{%1, Placement(false,0.0,0.0,-10.0,-10.0,10.0,10.0,0.0,-,-,-,-,-,-,)}").arg(annotation);
}
mpIconGraphicsView->addComponentToView(pComponentInfo->getName(), pLibraryTreeItem, annotation, QPointF(0, 0), pComponentInfo,
false, true);
mpIconGraphicsView->addComponentToView(pComponentInfo->getName(), pLibraryTreeItem, annotation, QPointF(0, 0), pComponentInfo, false, true, false);
}
i++;
}
Expand Down Expand Up @@ -6054,8 +6052,7 @@ void ModelWidget::drawModelDiagramComponents()
annotation = StringHandler::removeFirstLastCurlBrackets(annotation);
annotation = QString("{%1, Placement(false,0.0,0.0,-10.0,-10.0,10.0,10.0,0.0,-,-,-,-,-,-,)}").arg(annotation);
}
mpDiagramGraphicsView->addComponentToView(pComponentInfo->getName(), pLibraryTreeItem, annotation, QPointF(0, 0), pComponentInfo,
false, true);
mpDiagramGraphicsView->addComponentToView(pComponentInfo->getName(), pLibraryTreeItem, annotation, QPointF(0, 0), pComponentInfo, false, true, false);
i++;
}
}
Expand Down Expand Up @@ -6267,8 +6264,7 @@ void ModelWidget::getCompositeModelSubModels()
pComponentInfo->setPosition(subModel.attribute("Position"));
pComponentInfo->setAngle321(subModel.attribute("Angle321"));
// add submodel as component to view.
mpDiagramGraphicsView->addComponentToView(subModel.attribute("Name"), pLibraryTreeItem, transformation, QPointF(0.0, 0.0),
pComponentInfo, false, true);
mpDiagramGraphicsView->addComponentToView(subModel.attribute("Name"), pLibraryTreeItem, transformation, QPointF(0.0, 0.0), pComponentInfo, false, true, false);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -197,7 +197,7 @@ class GraphicsView : public QGraphicsView
QAction* getFlipVerticalAction() {return mpFlipVerticalAction;}
bool addComponent(QString className, QPointF position);
void addComponentToView(QString name, LibraryTreeItem *pLibraryTreeItem, QString annotation, QPointF position,
ComponentInfo *pComponentInfo, bool addObject = true, bool openingClass = false);
ComponentInfo *pComponentInfo, bool addObject, bool openingClass, bool emitComponentAdded);
void addComponentToList(Component *pComponent) {mComponentsList.append(pComponent);}
void addInheritedComponentToList(Component *pComponent) {mInheritedComponentsList.append(pComponent);}
void addComponentToClass(Component *pComponent);
Expand Down Expand Up @@ -291,14 +291,13 @@ class GraphicsView : public QGraphicsView
void checkEmitUpdateSelect(const bool showPropertiesAndSelect, ShapeAnnotation* shapeAnnotation);
void copyItems(bool cut);
signals:
void mouseManhattanize();
void mouseDelete();
void manhattanize();
void deleteSignal();
void mouseDuplicate();
void mouseRotateClockwise();
void mouseRotateAntiClockwise();
void mouseFlipHorizontal();
void mouseFlipVertical();
void keyPressDelete();
void keyPressRotateClockwise();
void keyPressRotateAntiClockwise();
void keyPressFlipHorizontal();
Expand Down

0 comments on commit e613a91

Please sign in to comment.