Skip to content

Commit

Permalink
Invoke align interfaces via context menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Apr 11, 2016
1 parent 1e8523c commit 8d2f7ad
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
27 changes: 24 additions & 3 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp
Expand Up @@ -40,6 +40,7 @@
#include "ShapePropertiesDialog.h"
#include "Commands.h"
#include "ComponentProperties.h"
#include "FetchInterfaceDataDialog.h"

/*!
* \brief GraphicItem::setDefaults
Expand Down Expand Up @@ -425,6 +426,10 @@ void ShapeAnnotation::createActions()
mpShapePropertiesAction->setStatusTip(tr("Shows the shape properties"));
connect(mpShapePropertiesAction, SIGNAL(triggered()), SLOT(showShapeProperties()));
// shape attributes
mpAlignInterfacesAction = new QAction(QIcon(":/Resources/icons/align-interfaces.svg"), Helper::alignInterfaces, mpGraphicsView);
mpAlignInterfacesAction->setStatusTip(Helper::alignInterfacesTip);
connect(mpAlignInterfacesAction, SIGNAL(triggered()), SLOT(alignInterfaces()));
// shape attributes
mpShapeAttributesAction = new QAction(Helper::attributes, mpGraphicsView);
mpShapeAttributesAction->setStatusTip(tr("Shows the shape attributes"));
connect(mpShapeAttributesAction, SIGNAL(triggered()), SLOT(showShapeAttributes()));
Expand Down Expand Up @@ -1471,7 +1476,7 @@ bool ShapeAnnotation::isLineStraight(QPointF point1, QPointF point2)
*/
void ShapeAnnotation::showShapeProperties()
{
if (!mpGraphicsView || mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::MetaModel) {
if (!mpGraphicsView || mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::MetaModel) {
return;
}
MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
Expand All @@ -1490,11 +1495,25 @@ void ShapeAnnotation::showShapeAttributes()
}
MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
LineAnnotation *pConnectionLineAnnotation = dynamic_cast<LineAnnotation*>(this);
MetaModelConnectionAttributes *pMetaModelConnectionAttributes = new MetaModelConnectionAttributes(mpGraphicsView,
pConnectionLineAnnotation, pMainWindow, true);
MetaModelConnectionAttributes *pMetaModelConnectionAttributes;
pMetaModelConnectionAttributes = new MetaModelConnectionAttributes(mpGraphicsView, pConnectionLineAnnotation, pMainWindow, true);
pMetaModelConnectionAttributes->exec();
}

/*!
* \brief ShapeAnnotation::alignInterfaces
* Slot activated when Align Interfaces option is chosen from context menu of the shape.
*/
void ShapeAnnotation::alignInterfaces()
{
if (!mpGraphicsView) {
return;
}
LineAnnotation *pConnectionLineAnnotation = dynamic_cast<LineAnnotation*>(this);
AlignInterfacesDialog *pAlignInterfacesDialog = new AlignInterfacesDialog(mpGraphicsView->getModelWidget(), pConnectionLineAnnotation);
pAlignInterfacesDialog->exec();
}

/*!
* \brief ShapeAnnotation::contextMenuEvent
* Reimplementation of contextMenuEvent.\n
Expand All @@ -1516,6 +1535,8 @@ void ShapeAnnotation::contextMenuEvent(QGraphicsSceneContextMenuEvent *pEvent)
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType()== LibraryTreeItem::MetaModel) {
menu.addAction(mpShapeAttributesAction);
menu.addSeparator();
menu.addAction(mpAlignInterfacesAction);
menu.addSeparator();
menu.addAction(mpGraphicsView->getDeleteAction());
} else {
menu.addAction(mpShapePropertiesAction);
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Annotations/ShapeAnnotation.h
Expand Up @@ -113,6 +113,7 @@ class ShapeAnnotation : public QObject, public QGraphicsItem, public GraphicItem
QPointF mOldScenePosition;
bool mIsCornerItemClicked;
QAction *mpShapePropertiesAction;
QAction *mpAlignInterfacesAction;
QAction *mpShapeAttributesAction;
public:
enum LineGeometryType {VerticalLine, HorizontalLine};
Expand Down Expand Up @@ -226,6 +227,7 @@ public slots:
LineGeometryType findLineGeometryType(QPointF point1, QPointF point2);
bool isLineStraight(QPointF point1, QPointF point2);
void showShapeProperties();
void alignInterfaces();
void showShapeAttributes();
void manhattanizeShape(bool addToStack = true);
void referenceShapeAdded();
Expand Down
23 changes: 14 additions & 9 deletions OMEdit/OMEditGUI/TLM/FetchInterfaceDataDialog.cpp
Expand Up @@ -190,8 +190,9 @@ void FetchInterfaceDataDialog::reject()
/*!
* \brief AlignInterfacesDialog::AlignInterfacesDialog
* \param pModelWidget
* \param pConnectionLineAnnotation
*/
AlignInterfacesDialog::AlignInterfacesDialog(ModelWidget *pModelWidget)
AlignInterfacesDialog::AlignInterfacesDialog(ModelWidget *pModelWidget, LineAnnotation *pConnectionLineAnnotation)
: QDialog(pModelWidget), mpModelWidget(pModelWidget)
{
setWindowTitle(QString("%1 - %2 - %3").arg(Helper::applicationName).arg(Helper::alignInterfaces)
Expand All @@ -204,16 +205,20 @@ AlignInterfacesDialog::AlignInterfacesDialog(ModelWidget *pModelWidget)
mpHorizontalLine = Utilities::getHeadingLine();
// list of interfaces
QStringList interfaces;
MetaModelEditor *pMetaModelEditor = dynamic_cast<MetaModelEditor*>(pModelWidget->getEditor());
if (pMetaModelEditor) {
QDomNodeList connections = pMetaModelEditor->getConnections();
for (int i = 0; i < connections.size(); i++) {
QDomElement connection = connections.at(i).toElement();
interfaces << connection.attribute("From")+" -> "+connection.attribute("To");
interfaces << connection.attribute("To")+" -> "+connection.attribute("From");
if (pConnectionLineAnnotation) {
interfaces << pConnectionLineAnnotation->getStartComponentName() + " -> " + pConnectionLineAnnotation->getEndComponentName();
interfaces << pConnectionLineAnnotation->getEndComponentName() + " -> " + pConnectionLineAnnotation->getStartComponentName();
} else {
MetaModelEditor *pMetaModelEditor = dynamic_cast<MetaModelEditor*>(pModelWidget->getEditor());
if (pMetaModelEditor) {
QDomNodeList connections = pMetaModelEditor->getConnections();
for (int i = 0; i < connections.size(); i++) {
QDomElement connection = connections.at(i).toElement();
interfaces << connection.attribute("From") + " -> " + connection.attribute("To");
interfaces << connection.attribute("To") + " -> " + connection.attribute("From");
}
}
}

// interfaces list
mpInterfaceListWidget = new QListWidget;
mpInterfaceListWidget->setItemDelegate(new ItemDelegate(mpInterfaceListWidget));
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/TLM/FetchInterfaceDataDialog.h
Expand Up @@ -68,7 +68,7 @@ class AlignInterfacesDialog : public QDialog
{
Q_OBJECT
public:
AlignInterfacesDialog(ModelWidget *pModelWidget);
AlignInterfacesDialog(ModelWidget *pModelWidget, LineAnnotation *pConnectionLineAnnotation = 0);
private:
ModelWidget *mpModelWidget;
Label *mpAlignInterfacesHeading;
Expand Down

0 comments on commit 8d2f7ad

Please sign in to comment.