Skip to content

Commit

Permalink
Updated the icon in libraries browser when graphical object is updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Sep 16, 2015
1 parent 38c4ab8 commit 79502dd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/Component/CornerItem.cpp
Expand Up @@ -100,6 +100,9 @@ void CornerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
Q_UNUSED(option);
Q_UNUSED(widget);

if (mpShapeAnnotation->getGraphicsView()->isRenderingLibraryPixmap()) {
return;
}
QPen pen;
if (mpShapeAnnotation->isInheritedShape()) {
pen.setColor(Qt::darkRed);
Expand Down
16 changes: 12 additions & 4 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -152,14 +152,17 @@ void AddComponentCommand::undo()
// if component is of connector type && containing class is Modelica type.
if (mType == StringHandler::Connector && pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::Modelica) {
// first remove the component from Icon View
mpIconComponent->setSelected(false);
mpIconGraphicsView->scene()->removeItem(mpIconComponent);
mpIconGraphicsView->scene()->removeItem(mpIconComponent->getOriginItem());
mpIconGraphicsView->deleteComponentFromList(mpIconComponent);
// now remove the component from Diagram View
mpDiagramComponent->setSelected(false);
mpDiagramGraphicsView->scene()->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->scene()->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
} else {
mpDiagramComponent->setSelected(false);
mpDiagramGraphicsView->scene()->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->scene()->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
Expand Down Expand Up @@ -191,18 +194,21 @@ void DeleteComponentCommand::redo()
// first remove the component from Icon View
mpIconComponent = mpIconGraphicsView->getComponentObject(mpComponent->getName());
if (mpIconComponent) {
mpIconComponent->setSelected(false);
mpIconGraphicsView->scene()->removeItem(mpIconComponent);
mpIconGraphicsView->scene()->removeItem(mpIconComponent->getOriginItem());
mpIconGraphicsView->deleteComponentFromList(mpIconComponent);
}
// now remove the component from Diagram View
mpDiagramComponent = mpDiagramGraphicsView->getComponentObject(mpComponent->getName());
if (mpDiagramComponent) {
mpDiagramComponent->setSelected(false);
mpDiagramGraphicsView->scene()->removeItem(mpDiagramComponent);
mpDiagramGraphicsView->scene()->removeItem(mpDiagramComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpDiagramComponent);
}
} else {
mpDiagramComponent->setSelected(false);
mpDiagramGraphicsView->scene()->removeItem(mpComponent);
mpDiagramGraphicsView->scene()->removeItem(mpComponent->getOriginItem());
mpDiagramGraphicsView->deleteComponentFromList(mpComponent);
Expand Down Expand Up @@ -268,8 +274,8 @@ void AddShapeCommand::redo()
{
mpGraphicsView->addShapeObject(mpShapeAnnotation);
mpGraphicsView->scene()->addItem(mpShapeAnnotation);
mpGraphicsView->addClassAnnotation();
mpShapeAnnotation->emitAdded();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->setCanAddClassAnnotation(true);
}

Expand All @@ -280,9 +286,10 @@ void AddShapeCommand::redo()
void AddShapeCommand::undo()
{
mpGraphicsView->deleteShapeObject(mpShapeAnnotation);
mpShapeAnnotation->setSelected(false);
mpGraphicsView->scene()->removeItem(mpShapeAnnotation);
mpGraphicsView->addClassAnnotation();
mpShapeAnnotation->emitDeleted();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->setCanAddClassAnnotation(true);
}

Expand Down Expand Up @@ -313,9 +320,10 @@ DeleteShapeCommand::DeleteShapeCommand(ShapeAnnotation *pShapeAnnotation, Graphi
void DeleteShapeCommand::redo()
{
mpGraphicsView->deleteShapeObject(mpShapeAnnotation);
mpShapeAnnotation->setSelected(false);
mpGraphicsView->scene()->removeItem(mpShapeAnnotation);
mpGraphicsView->addClassAnnotation();
mpShapeAnnotation->emitDeleted();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->setCanAddClassAnnotation(true);
}

Expand All @@ -327,7 +335,7 @@ void DeleteShapeCommand::undo()
{
mpGraphicsView->addShapeObject(mpShapeAnnotation);
mpGraphicsView->scene()->addItem(mpShapeAnnotation);
mpGraphicsView->addClassAnnotation();
mpShapeAnnotation->emitAdded();
mpGraphicsView->addClassAnnotation();
mpGraphicsView->setCanAddClassAnnotation(true);
}
16 changes: 13 additions & 3 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -494,10 +494,11 @@ LibraryTreeItem* LibraryTreeItem::child(int row)
void LibraryTreeItem::addInheritedClass(LibraryTreeItem *pLibraryTreeItem)
{
mInheritedClasses.append(pLibraryTreeItem);
connect(pLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), this, SLOT(handleLoaded(LibraryTreeItem*)));
connect(pLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), this, SLOT(handleUnLoaded(LibraryTreeItem*)));
connect(pLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), this, SLOT(handleLoaded(LibraryTreeItem*)), Qt::UniqueConnection);
connect(pLibraryTreeItem, SIGNAL(unLoaded(LibraryTreeItem*)), this, SLOT(handleUnLoaded(LibraryTreeItem*)), Qt::UniqueConnection);
connect(pLibraryTreeItem, SIGNAL(shapeAdded(LibraryTreeItem*,ShapeAnnotation*,GraphicsView*)),
this, SLOT(handleShapeAdded(LibraryTreeItem*,ShapeAnnotation*,GraphicsView*)));
this, SLOT(handleShapeAdded(LibraryTreeItem*,ShapeAnnotation*,GraphicsView*)), Qt::UniqueConnection);
connect(pLibraryTreeItem, SIGNAL(iconUpdated()), this, SLOT(handleIconUpdated()), Qt::UniqueConnection);
}

/*!
Expand Down Expand Up @@ -645,6 +646,15 @@ void LibraryTreeItem::handleShapeAdded(LibraryTreeItem *pLibraryTreeItem, ShapeA
}
}

void LibraryTreeItem::handleIconUpdated()
{
if (mpModelWidget) {
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->loadLibraryTreeItemPixmap(this);
emit iconUpdated();
}
}

/*!
* \class LibraryTreeProxyModel
* \brief A sort filter proxy model for Libraries Browser.
Expand Down
9 changes: 3 additions & 6 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -144,10 +144,7 @@ class LibraryTreeItem : public QObject
void emitLoaded() {emit loaded(this);}
void emitUnLoaded() {emit unLoaded(this);}
void emitShapeAdded(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView) {emit shapeAdded(this, pShapeAnnotation, pGraphicsView);}
void addIconShape(ShapeAnnotation *pShapeAnnotation) {mIconShapesList.append(pShapeAnnotation);}
QList<ShapeAnnotation*> getIconShapesList() {return mIconShapesList;}
void addDiagramShape(ShapeAnnotation *pShapeAnnotation) {mDiagramShapesList.append(pShapeAnnotation);}
QList<ShapeAnnotation*> getDiagramShapesList() {return mDiagramShapesList;}
void emitIconUpdated() {emit iconUpdated();}
private:
bool mIsRootItem;
LibraryTreeItem *mpParentLibraryTreeItem;
Expand All @@ -173,16 +170,16 @@ class LibraryTreeItem : public QObject
QString mClassText;
bool mExpanded;
bool mNonExisting;
QList<ShapeAnnotation*> mIconShapesList;
QList<ShapeAnnotation*> mDiagramShapesList;
signals:
void loaded(LibraryTreeItem *pLibraryTreeItem);
void unLoaded(LibraryTreeItem *pLibraryTreeItem);
void shapeAdded(LibraryTreeItem *pLibraryTreeItem, ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
void iconUpdated();
public slots:
void handleLoaded(LibraryTreeItem *pLibraryTreeItem);
void handleUnLoaded(LibraryTreeItem *pLibraryTreeItem);
void handleShapeAdded(LibraryTreeItem *pLibraryTreeItem, ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView);
void handleIconUpdated();
};

class LibraryWidget;
Expand Down
41 changes: 22 additions & 19 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -910,6 +910,7 @@ void GraphicsView::createLineShape(QPointF point)

if (!isCreatingLineShape()) {
mpLineShapeAnnotation = new LineAnnotation("", this);
setCanAddClassAnnotation(false);
mpModelWidget->getUndoStack()->push(new AddShapeCommand(mpLineShapeAnnotation, this));
setIsCreatingLineShape(true);
mpLineShapeAnnotation->addPoint(point);
Expand All @@ -927,6 +928,7 @@ void GraphicsView::createPolygonShape(QPointF point)

if (!isCreatingPolygonShape()) {
mpPolygonShapeAnnotation = new PolygonAnnotation("", this);
setCanAddClassAnnotation(false);
mpModelWidget->getUndoStack()->push(new AddShapeCommand(mpPolygonShapeAnnotation, this));
setIsCreatingPolygonShape(true);
mpPolygonShapeAnnotation->addPoint(point);
Expand All @@ -945,6 +947,7 @@ void GraphicsView::createRectangleShape(QPointF point)

if (!isCreatingRectangleShape()) {
mpRectangleShapeAnnotation = new RectangleAnnotation("", this);
setCanAddClassAnnotation(false);
mpModelWidget->getUndoStack()->push(new AddShapeCommand(mpRectangleShapeAnnotation, this));
setIsCreatingRectangleShape(true);
mpRectangleShapeAnnotation->replaceExtent(0, point);
Expand All @@ -963,9 +966,9 @@ void GraphicsView::createRectangleShape(QPointF point)
// make the toolbar button of rectangle unchecked
pMainWindow->getRectangleShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpRectangleShapeAnnotation, this);
addClassAnnotation();
setCanAddClassAnnotation(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpRectangleShapeAnnotation, this);
}
}

Expand All @@ -977,6 +980,7 @@ void GraphicsView::createEllipseShape(QPointF point)

if (!isCreatingEllipseShape()) {
mpEllipseShapeAnnotation = new EllipseAnnotation("", this);
setCanAddClassAnnotation(false);
mpModelWidget->getUndoStack()->push(new AddShapeCommand(mpEllipseShapeAnnotation, this));
setIsCreatingEllipseShape(true);
mpEllipseShapeAnnotation->replaceExtent(0, point);
Expand All @@ -995,9 +999,9 @@ void GraphicsView::createEllipseShape(QPointF point)
// make the toolbar button of ellipse unchecked
pMainWindow->getEllipseShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpEllipseShapeAnnotation, this);
addClassAnnotation();
setCanAddClassAnnotation(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpEllipseShapeAnnotation, this);
}
}

Expand All @@ -1009,6 +1013,7 @@ void GraphicsView::createTextShape(QPointF point)

if (!isCreatingTextShape()) {
mpTextShapeAnnotation = new TextAnnotation("", this);
setCanAddClassAnnotation(false);
mpModelWidget->getUndoStack()->push(new AddShapeCommand(mpTextShapeAnnotation, this));
setIsCreatingTextShape(true);
mpTextShapeAnnotation->setTextString("text");
Expand All @@ -1028,10 +1033,10 @@ void GraphicsView::createTextShape(QPointF point)
// make the toolbar button of text unchecked
pMainWindow->getTextShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpTextShapeAnnotation, this);
addClassAnnotation();
setCanAddClassAnnotation(true);
mpTextShapeAnnotation->showShapeProperties();
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpTextShapeAnnotation, this);
}
}

Expand All @@ -1043,6 +1048,7 @@ void GraphicsView::createBitmapShape(QPointF point)

if (!isCreatingBitmapShape()) {
mpBitmapShapeAnnotation = new BitmapAnnotation(mpModelWidget->getLibraryTreeItem()->getFileName(), "", this);
setCanAddClassAnnotation(false);
mpModelWidget->getUndoStack()->push(new AddShapeCommand(mpBitmapShapeAnnotation, this));
setIsCreatingBitmapShape(true);
mpBitmapShapeAnnotation->replaceExtent(0, point);
Expand Down Expand Up @@ -1367,20 +1373,18 @@ void GraphicsView::addClassAnnotation(bool updateModelicaText)
Just set the canAddClassAnnotation flag to false to make sure this function is only used once.
We enable back this function in the key release event.
*/
if (canAddClassAnnotation())
if (canAddClassAnnotation()) {
setCanAddClassAnnotation(false);
else
} else {
return;
}
/* Build the annotation string */
MainWindow *pMainWindow = mpModelWidget->getModelWidgetContainer()->getMainWindow();
QString annotationString;
annotationString.append("annotate=");
if (mViewType == StringHandler::Icon)
{
if (mViewType == StringHandler::Icon) {
annotationString.append("Icon(");
}
else if (mViewType == StringHandler::Diagram)
{
} else if (mViewType == StringHandler::Diagram) {
annotationString.append("Diagram(");
}
// add the coordinate system first
Expand All @@ -1398,14 +1402,11 @@ void GraphicsView::addClassAnnotation(bool updateModelicaText)
annotationString.append(", grid=").append("{").append(QString::number(grid.x())).append(", ").append(QString::number(grid.y())).append("})");
// add the graphics annotations
int counter = 0;
if (mShapesList.size() > 0)
{
if (mShapesList.size() > 0) {
annotationString.append(", graphics={");
foreach (ShapeAnnotation *pShapeAnnotation, mShapesList)
{
foreach (ShapeAnnotation *pShapeAnnotation, mShapesList) {
/* Don't add the inherited shape to the addClassAnnotation. */
if (pShapeAnnotation->isInheritedShape())
{
if (pShapeAnnotation->isInheritedShape()) {
counter++;
continue;
}
Expand All @@ -1425,7 +1426,9 @@ void GraphicsView::addClassAnnotation(bool updateModelicaText)
mpModelWidget->setModelModified();
/* When something is added/changed in the icon layer then update the LibraryTreeItem in the Library Browser */
if (mViewType == StringHandler::Icon) {
// pMainWindow->getLibraryWidget()->loadLibraryComponent(mpModelWidget->getLibraryTreeItem());
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 @@ -1745,9 +1748,9 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
// make the toolbar button of line unchecked
pMainWindow->getLineShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpLineShapeAnnotation, this);
addClassAnnotation();
setCanAddClassAnnotation(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpLineShapeAnnotation, this);
return;
} else if (isCreatingPolygonShape()) {
// finish creating the polygon
Expand All @@ -1763,9 +1766,9 @@ void GraphicsView::mouseDoubleClickEvent(QMouseEvent *event)
// make the toolbar button of polygon unchecked
pMainWindow->getPolygonShapeAction()->setChecked(false);
pMainWindow->getConnectModeAction()->setChecked(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpPolygonShapeAnnotation, this);
addClassAnnotation();
setCanAddClassAnnotation(true);
mpModelWidget->getLibraryTreeItem()->emitShapeAdded(mpPolygonShapeAnnotation, this);
return;
}
ShapeAnnotation *pShapeAnnotation = dynamic_cast<ShapeAnnotation*>(itemAt(event->pos()));
Expand Down

0 comments on commit 79502dd

Please sign in to comment.