Skip to content

Commit

Permalink
Some fixes for #2892
Browse files Browse the repository at this point in the history
Basic structure for undo/redo. Supports add/delete component now.
Make the tree item color red when it is modified.
Use the standard expand/collapse buttons for tree.
  • Loading branch information
adeas31 committed Sep 1, 2015
1 parent f583d09 commit 28c9784
Show file tree
Hide file tree
Showing 15 changed files with 702 additions and 231 deletions.
23 changes: 7 additions & 16 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -83,9 +83,6 @@ Component::Component(QString annotation, QString name, QString className, QStrin
mpOriginItem = new OriginItem();
createResizerItems();
setToolTip(QString("<b>").append(mClassName).append("</b> ").append(mName));
// if everything is fine with icon then add it to scene
mpGraphicsView->scene()->addItem(this);
mpGraphicsView->scene()->addItem(mpOriginItem);
connect(this, SIGNAL(componentTransformHasChanged()), SLOT(updatePlacementAnnotation()));
connect(this, SIGNAL(componentTransformHasChanged()), SLOT(updateOriginItem()));
}
Expand Down Expand Up @@ -1043,20 +1040,14 @@ void Component::finishResizeComponent()
}
}

/*!
* \brief Component::deleteMe
* Deletes the Component from the current view.
*/
void Component::deleteMe()
{
// delete the component from model
mpGraphicsView->deleteComponentObject(this);
deleteLater();
delete mpOriginItem;
// make the model modified
mpGraphicsView->getModelWidget()->updateModelicaText();
mpGraphicsView->getModelWidget()->setModelModified();
/* When something is deleted from the icon layer then update the LibraryTreeItem in the Library Browser */
if (mpGraphicsView->getViewType() == StringHandler::Icon) {
MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
// pMainWindow->getLibraryWidget()->loadLibraryComponent(mpGraphicsView->getModelWidget()->getLibraryTreeItem());
}
mpGraphicsView->deleteComponent(this);
}

void Component::duplicate()
Expand Down Expand Up @@ -1529,7 +1520,7 @@ 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->getDeleteAction(), SIGNAL(triggered()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView->getDuplicateAction(), SIGNAL(triggered()), this, SLOT(duplicate()), Qt::UniqueConnection);
connect(mpGraphicsView->getRotateClockwiseAction(), SIGNAL(triggered()), this, SLOT(rotateClockwise()), Qt::UniqueConnection);
connect(mpGraphicsView->getRotateClockwiseAction(), SIGNAL(triggered()), this, SIGNAL(componentTransformHasChanged()), Qt::UniqueConnection);
Expand Down Expand Up @@ -1567,7 +1558,7 @@ 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->getDeleteAction(), SIGNAL(triggered()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(mouseDelete()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView->getDuplicateAction(), SIGNAL(triggered()), this, SLOT(duplicate()));
disconnect(mpGraphicsView->getRotateClockwiseAction(), SIGNAL(triggered()), this, SLOT(rotateClockwise()));
disconnect(mpGraphicsView->getRotateClockwiseAction(), SIGNAL(triggered()), this, SIGNAL(componentTransformHasChanged()));
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -111,6 +111,7 @@ class Component : public QObject, public QGraphicsItem
Component* getRootParentComponent();
ComponentType getComponentType() {return mComponentType;}
Transformation* getTransformation();
OriginItem* getOriginItem() {return mpOriginItem;}
QAction* getParametersAction();
QAction* getAttributesAction();
QAction* getViewClassAction();
Expand Down
53 changes: 46 additions & 7 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1449,16 +1449,42 @@ void MainWindow::clearRecentFilesList()
mpWelcomePageWidget->addRecentFilesListItems();
}

/*!
* \brief MainWindow::undo
* Calls the undo command for the selected view.
*/
void MainWindow::undo()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget &&
(pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) ||
(pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible())) {
pModelWidget->getUndoStack()->undo();
}
}

/*!
* \brief MainWindow::redo
* Calls the redo command for the selected view.
*/
void MainWindow::redo()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget &&
(pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) ||
(pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible())) {
pModelWidget->getUndoStack()->redo();
}
}

void MainWindow::setShowGridLines(bool showLines)
{
mpModelWidgetContainer->setShowGridLines(showLines);
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget)
{
if (pModelWidget->getDiagramGraphicsView()->isVisible())
pModelWidget->getDiagramGraphicsView()->scene()->update();
else if (pModelWidget->getIconGraphicsView()->isVisible())
pModelWidget->getIconGraphicsView()->scene()->update();
if (pModelWidget && pModelWidget->getIconGraphicsView() && pModelWidget->getIconGraphicsView()->isVisible()) {
pModelWidget->getIconGraphicsView()->scene()->update();
} else if (pModelWidget && pModelWidget->getDiagramGraphicsView() && pModelWidget->getDiagramGraphicsView()->isVisible()) {
pModelWidget->getDiagramGraphicsView()->scene()->update();
}
}

Expand Down Expand Up @@ -2365,6 +2391,16 @@ void MainWindow::createActions()
mpQuitAction->setShortcut(QKeySequence("Ctrl+q"));
connect(mpQuitAction, SIGNAL(triggered()), SLOT(close()));
// Edit Menu
// undo action
mpUndoAction = new QAction(QIcon(":/Resources/icons/undo.svg"), tr("Undo"), this);
mpUndoAction->setShortcut(QKeySequence::Undo);
mpUndoAction->setEnabled(false);
connect(mpUndoAction, SIGNAL(triggered()), SLOT(undo()));
// redo action
mpRedoAction = new QAction(QIcon(":/Resources/icons/redo.svg"), tr("Redo"), this);
mpRedoAction->setShortcut(QKeySequence::Redo);
mpRedoAction->setEnabled(false);
connect(mpRedoAction, SIGNAL(triggered()), SLOT(redo()));
// cut action
mpCutAction = new QAction(QIcon(":/Resources/icons/cut.svg"), tr("Cut"), this);
mpCutAction->setShortcut(QKeySequence("Ctrl+x"));
Expand Down Expand Up @@ -2694,6 +2730,9 @@ void MainWindow::createMenus()
QMenu *pEditMenu = new QMenu(menuBar());
pEditMenu->setTitle(tr("&Edit"));
// add actions to Edit menu
pEditMenu->addAction(mpUndoAction);
pEditMenu->addAction(mpRedoAction);
pEditMenu->addSeparator();
pEditMenu->addAction(mpCutAction);
pEditMenu->addAction(mpCopyAction);
pEditMenu->addAction(mpPasteAction);
Expand Down Expand Up @@ -2765,7 +2804,7 @@ void MainWindow::createMenus()
menuBar()->addAction(pFMIMenu->menuAction());
// Export menu
QMenu *pExportMenu = new QMenu(menuBar());
pExportMenu->setTitle(tr("&Export"));
pExportMenu->setTitle(tr("E&xport"));
// add actions to Export menu
pExportMenu->addAction(mpExportXMLAction);
pExportMenu->addAction(mpExportFigaroAction);
Expand Down
6 changes: 6 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -125,6 +125,8 @@ class MainWindow : public QMainWindow
QAction* getSaveTotalModelAction() {return mpSaveTotalModelAction;}
QAction* getPrintModelAction();
QAction* getSaveAllAction();
QAction* getUndoAction() {return mpUndoAction;}
QAction* getRedoAction() {return mpRedoAction;}
QAction* getShowGridLinesAction();
QAction* getResetZoomAction();
QAction* getZoomInAction();
Expand Down Expand Up @@ -236,6 +238,8 @@ class MainWindow : public QMainWindow
QAction *mpPrintModelAction;
QAction *mpQuitAction;
// Edit Menu
QAction *mpUndoAction;
QAction *mpRedoAction;
QAction *mpCutAction;
QAction *mpCopyAction;
QAction *mpPasteAction;
Expand Down Expand Up @@ -336,6 +340,8 @@ public slots:
void readErrorFile(qint64 bytes);
void openRecentFile();
void clearRecentFilesList();
void undo();
void redo();
void setShowGridLines(bool On);
void resetZoom();
void zoomIn();
Expand Down

0 comments on commit 28c9784

Please sign in to comment.