Skip to content

Commit

Permalink
Draw red cross for non existing inherited class.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Sep 18, 2015
1 parent 2229db1 commit aceace2
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 22 deletions.
26 changes: 26 additions & 0 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.cpp
Expand Up @@ -79,6 +79,32 @@ LineAnnotation::LineAnnotation(QString annotation, GraphicsView *pGraphicsView)
connect(this, SIGNAL(updateClassAnnotation()), mpGraphicsView, SLOT(addClassAnnotation()));
}

LineAnnotation::LineAnnotation(GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
setLineType(LineAnnotation::ShapeType);
setStartComponent(0);
setEndComponent(0);
// set the default values
GraphicItem::setDefaults();
ShapeAnnotation::setDefaults();
// set users default value by reading the settings file.
ShapeAnnotation::setUserDefaults();
// create a red cross
setLineColor(QColor(255, 0, 0));
// create a red cross with points
addPoint(QPointF(-100, -100));
addPoint(QPointF(100, 100));
addPoint(QPointF(-100, 100));
addPoint(QPointF(100, -100));
addPoint(QPointF(-100, -100));
addPoint(QPointF(-100, 100));
addPoint(QPointF(100, 100));
addPoint(QPointF(100, -100));
setShapeFlags(true);
mpGraphicsView->scene()->addItem(this);
}

LineAnnotation::LineAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0)
{
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Annotations/LineAnnotation.h
Expand Up @@ -56,6 +56,7 @@ class LineAnnotation : public ShapeAnnotation
LineAnnotation(QString annotation, Component *pParent);
LineAnnotation(ShapeAnnotation *pShapeAnnotation, Component *pParent);
LineAnnotation(QString annotation, GraphicsView *pGraphicsView);
LineAnnotation(GraphicsView *pGraphicsView);
LineAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
LineAnnotation(Component *pStartComponent, GraphicsView *pGraphicsView);
LineAnnotation(QString annotation, bool inheritedShape, Component *pStartComponent, Component *pEndComponent, GraphicsView *pGraphicsView);
Expand Down
18 changes: 17 additions & 1 deletion OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -599,6 +599,12 @@ void LibraryTreeItem::handleLoaded(LibraryTreeItem *pLibraryTreeItem)
ModelWidget::InheritedClass *pInheritedClass = mpModelWidget->findInheritedClass(pLibraryTreeItem);
if (pInheritedClass) {
mpModelWidget->modelInheritedClassLoaded(pInheritedClass);
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();
// load new icon for the class.
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->loadLibraryTreeItemPixmap(this);
// update the icon in the libraries browser view.
QModelIndex index = pMainWindow->getLibraryWidget()->getLibraryTreeModel()->libraryTreeItemIndex(this);
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->emitDataChanged(index, index);
emit loaded(pLibraryTreeItem);
}
}
Expand All @@ -615,6 +621,12 @@ void LibraryTreeItem::handleUnLoaded(LibraryTreeItem *pLibraryTreeItem)
ModelWidget::InheritedClass *pInheritedClass = mpModelWidget->findInheritedClass(pLibraryTreeItem);
if (pInheritedClass) {
mpModelWidget->modelInheritedClassUnLoaded(pInheritedClass);
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();
// load new icon for the class.
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->loadLibraryTreeItemPixmap(this);
// update the icon in the libraries browser view.
QModelIndex index = pMainWindow->getLibraryWidget()->getLibraryTreeModel()->libraryTreeItemIndex(this);
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->emitDataChanged(index, index);
emit unLoaded(pLibraryTreeItem);
}
}
Expand Down Expand Up @@ -650,7 +662,11 @@ void LibraryTreeItem::handleIconUpdated()
{
if (mpModelWidget) {
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();
// load new icon for the class.
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->loadLibraryTreeItemPixmap(this);
// update the icon in the libraries browser view.
QModelIndex index = pMainWindow->getLibraryWidget()->getLibraryTreeModel()->libraryTreeItemIndex(this);
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->emitDataChanged(index, index);
emit iconUpdated();
}
}
Expand Down Expand Up @@ -1645,8 +1661,8 @@ void LibraryTreeModel::unloadClassHelper(LibraryTreeItem *pLibraryTreeItem, Libr
beginRemoveRows(libraryTreeItemIndex(pLibraryTreeItem), row, row);
pParentLibraryTreeItem->removeChild(pLibraryTreeItem);
mpLibraryWidget->getMainWindow()->getOMCProxy()->removeCachedOMCCommand(pLibraryTreeItem->getNameStructure());
pLibraryTreeItem->emitUnLoaded();
pLibraryTreeItem->setNonExisting(true);
pLibraryTreeItem->emitUnLoaded();
addNonExistingLibraryTreeItem(pLibraryTreeItem);
endRemoveRows();
}
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -233,6 +233,7 @@ class LibraryTreeModel : public QAbstractItemModel
bool unloadClass(LibraryTreeItem *pLibraryTreeItem, bool askQuestion = true);
bool unloadTLMOrTextFile(LibraryTreeItem *pLibraryTreeItem, bool askQuestion = true);
QString getUniqueTopLevelItemName(QString name, int number = 1);
void emitDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {emit dataChanged(topLeft, bottomRight);}
private:
LibraryWidget *mpLibraryWidget;
LibraryTreeItem *mpRootLibraryTreeItem;
Expand Down
82 changes: 61 additions & 21 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -1428,7 +1428,6 @@ void GraphicsView::addClassAnnotation(bool updateModelicaText)
if (mViewType == StringHandler::Icon) {
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->loadLibraryTreeItemPixmap(mpModelWidget->getLibraryTreeItem());
mpModelWidget->getLibraryTreeItem()->emitIconUpdated();
pMainWindow->getLibraryWidget()->getLibraryTreeProxyModel()->invalidate();
}
} else {
pMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0,
Expand Down Expand Up @@ -2364,22 +2363,31 @@ void ModelWidget::modelInheritedClassLoaded(InheritedClass *pInheritedClass)

/*!
* \brief ModelWidget::modelInheritedClassUnLoaded
* Removes the inherited class shapes when it is unloaded.
* Handles the case when inherited class is unloaded.
* \param pInheritedClass
*/
void ModelWidget::modelInheritedClassUnLoaded(InheritedClass *pInheritedClass)
{
foreach (ShapeAnnotation *pShapeAnnotation, pInheritedClass->mIconShapesList) {
mpIconGraphicsView->scene()->removeItem(pShapeAnnotation);
}
pInheritedClass->mIconShapesList.clear();
foreach (ShapeAnnotation *pShapeAnnotation, pInheritedClass->mDiagramShapesList) {
mpDiagramGraphicsView->scene()->removeItem(pShapeAnnotation);
}
pInheritedClass->mDiagramShapesList.clear();
parseModelInheritedClass(pInheritedClass, StringHandler::Icon);
parseModelInheritedClass(pInheritedClass, StringHandler::Diagram);
//! @note Do we really need to call GraphicsView::reOrderItems() here?
}

/*!
* \brief ModelWidget::createNonExistingInheritedShape
* Creates a red cross for non-existing inherited class shape.
* \param pGraphicsView
* \return
*/
ShapeAnnotation* ModelWidget::createNonExistingInheritedShape(GraphicsView *pGraphicsView)
{
LineAnnotation *pLineAnnotation = new LineAnnotation(pGraphicsView);
pLineAnnotation->initializeTransformation();
pLineAnnotation->drawCornerItems();
pLineAnnotation->setCornerItemsPassive();
return pLineAnnotation;
}

/*!
* \brief ModelWidget::createInheritedShape
* Creates the inherited class shape.
Expand Down Expand Up @@ -2836,29 +2844,61 @@ void ModelWidget::drawModelInheritedClasses()
}
}

/*!
* \brief ModelWidget::removeInheritedClassShapes
* Removes the inherited class shapes.
* \param pInheritedClass
*/
void ModelWidget::removeInheritedClassShapes(InheritedClass *pInheritedClass, StringHandler::ViewType viewType)
{
if (viewType == StringHandler::Icon) {
foreach (ShapeAnnotation *pShapeAnnotation, pInheritedClass->mIconShapesList) {
mpIconGraphicsView->scene()->removeItem(pShapeAnnotation);
}
pInheritedClass->mIconShapesList.clear();
} else {
foreach (ShapeAnnotation *pShapeAnnotation, pInheritedClass->mDiagramShapesList) {
mpDiagramGraphicsView->scene()->removeItem(pShapeAnnotation);
}
pInheritedClass->mDiagramShapesList.clear();
}
}

/*!
* \brief ModelWidget::parseModelInheritedClass
* Parses the inherited class shapes and draws them on the appropriate view.
* Parses the inherited class shape and draws its items on the appropriate view.
* \param pLibraryTreeItem
* \param viewType
*/
void ModelWidget::parseModelInheritedClass(InheritedClass *pInheritedClass, StringHandler::ViewType viewType)
{
removeInheritedClassShapes(pInheritedClass, viewType);
LibraryTreeItem *pLibraryTreeItem = pInheritedClass->mpLibraryTreeItem;
if (pLibraryTreeItem && !pLibraryTreeItem->isNonExisting()) {
if (pLibraryTreeItem) {
GraphicsView *pInheritedGraphicsView, *pGraphicsView;
if (viewType == StringHandler::Icon) {
pInheritedGraphicsView = pLibraryTreeItem->getModelWidget()->getIconGraphicsView();
pGraphicsView = mpIconGraphicsView;
if (pLibraryTreeItem->isNonExisting()) {
if (viewType == StringHandler::Icon) {
pGraphicsView = mpIconGraphicsView;
pInheritedClass->mIconShapesList.append(createNonExistingInheritedShape(pGraphicsView));
} else {
pGraphicsView = mpDiagramGraphicsView;
pInheritedClass->mDiagramShapesList.append(createNonExistingInheritedShape(pGraphicsView));
}
} else {
pInheritedGraphicsView = pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView();
pGraphicsView = mpDiagramGraphicsView;
}
foreach (ShapeAnnotation *pShapeAnnotation, pInheritedGraphicsView->getShapesList()) {
if (viewType == StringHandler::Icon) {
pInheritedClass->mIconShapesList.append(createInheritedShape(pShapeAnnotation, pGraphicsView));
pInheritedGraphicsView = pLibraryTreeItem->getModelWidget()->getIconGraphicsView();
pGraphicsView = mpIconGraphicsView;
} else {
pInheritedClass->mDiagramShapesList.append(createInheritedShape(pShapeAnnotation, pGraphicsView));
pInheritedGraphicsView = pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView();
pGraphicsView = mpDiagramGraphicsView;
}
// loop through the inherited class shapes
foreach (ShapeAnnotation *pShapeAnnotation, pInheritedGraphicsView->getShapesList()) {
if (viewType == StringHandler::Icon) {
pInheritedClass->mIconShapesList.append(createInheritedShape(pShapeAnnotation, pGraphicsView));
} else {
pInheritedClass->mDiagramShapesList.append(createInheritedShape(pShapeAnnotation, pGraphicsView));
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -360,6 +360,7 @@ class ModelWidget : public QWidget
void updateParentModelsText(QString className);
void modelInheritedClassLoaded(InheritedClass *pInheritedClass);
void modelInheritedClassUnLoaded(InheritedClass *pInheritedClass);
ShapeAnnotation* createNonExistingInheritedShape(GraphicsView *pGraphicsView);
ShapeAnnotation* createInheritedShape(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
void createWidgetComponents();
Component* getConnectorComponent(Component *pConnectorComponent, QString connectorName);
Expand Down Expand Up @@ -396,6 +397,7 @@ class ModelWidget : public QWidget
QList<InheritedClass*> mInheritedClassesList;
void getModelInheritedClasses(LibraryTreeItem *pLibraryTreeItem);
void drawModelInheritedClasses();
void removeInheritedClassShapes(InheritedClass *pInheritedClass, StringHandler::ViewType viewType);
void parseModelInheritedClass(InheritedClass *pInheritedClass, StringHandler::ViewType viewType);
void getModelIconDiagramShapes(QString className);
void parseModelIconDiagramShapes(QString className, QString annotationString, StringHandler::ViewType viewType);
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -901,6 +901,7 @@ void OptionsDialog::setUpDialog()
QHBoxLayout *horizontalLayout = new QHBoxLayout;
horizontalLayout->addWidget(mpOptionsList);
QScrollArea *pPagesWidgetScrollArea = new QScrollArea;
pPagesWidgetScrollArea->setWidgetResizable(true);
pPagesWidgetScrollArea->setWidget(mpPagesWidget);
horizontalLayout->addWidget(pPagesWidgetScrollArea);
// Create a layout
Expand Down

0 comments on commit aceace2

Please sign in to comment.