Gui: fix DAG view icon sync problem

This commit is contained in:
Zheng, Lei
2019-12-14 21:26:41 +08:00
committed by wmayer
parent f7fb8e349d
commit 64a7e24080
3 changed files with 13 additions and 14 deletions

View File

@@ -246,26 +246,21 @@ void Model::slotNewObject(const ViewProviderDocumentObject &VPDObjectIn)
auto *rectangle = (*theGraph)[virginVertex].rectangle.get();
rectangle->setEditingBrush(QBrush(Qt::yellow));
(*theGraph)[virginVertex].icon->setPixmap(VPDObjectIn.getIcon().pixmap(iconSize, iconSize));
auto icon = (*theGraph)[virginVertex].icon;
icon->setPixmap(VPDObjectIn.getIcon().pixmap(iconSize, iconSize));
(*theGraph)[virginVertex].stateIcon->setPixmap(passPixmap);
(*theGraph)[virginVertex].text->setFont(this->font());
(*theGraph)[virginVertex].connChangeIcon =
const_cast<Gui::ViewProviderDocumentObject&>(VPDObjectIn).signalChangeIcon.connect(
boost::bind(&Model::slotChangeIcon, this, boost::cref(VPDObjectIn), icon));
graphDirty = true;
//we are here before python objects are instantiated. so at this point
//the getIcon method doesn't reflect the python override.
//so we hack in a delay to get the latest icon and set it for the graphics item.
lastAddedVertex = virginVertex;
QTimer::singleShot(0, this, SLOT(iconUpdateSlot()));
lastAddedVertex = Graph::null_vertex();
}
void Model::iconUpdateSlot()
void Model::slotChangeIcon(const ViewProviderDocumentObject &VPDObjectIn, std::shared_ptr<QGraphicsPixmapItem> icon)
{
if (lastAddedVertex == Graph::null_vertex())
return;
const ViewProviderDocumentObject *VPDObject = findRecord(lastAddedVertex, *graphLink).VPDObject;
(*theGraph)[lastAddedVertex].icon->setPixmap(VPDObject->getIcon().pixmap(iconSize, iconSize));
lastAddedVertex = Graph::null_vertex();
icon->setPixmap(VPDObjectIn.getIcon().pixmap(iconSize, iconSize));
this->invalidate();
}
@@ -286,6 +281,8 @@ void Model::slotDeleteObject(const ViewProviderDocumentObject &VPDObjectIn)
if (vertex == lastAddedVertex)
lastAddedVertex = Graph::null_vertex();
(*theGraph)[vertex].connChangeIcon.disconnect();
//remove the actual vertex.
boost::clear_vertex(vertex, *theGraph);

View File

@@ -81,7 +81,6 @@ namespace Gui
void renameRejectedSlot();
void editingStartSlot();
void editingFinishedSlot();
void iconUpdateSlot(); //!< needed because python objects are not ready.
private:
Model(){}
@@ -101,6 +100,7 @@ namespace Gui
void slotChangeObject(const Gui::ViewProviderDocumentObject &VPDObjectIn, const App::Property& propertyIn);
void slotInEdit(const Gui::ViewProviderDocumentObject &VPDObjectIn);
void slotResetEdit(const Gui::ViewProviderDocumentObject &VPDObjectIn);
void slotChangeIcon(const Gui::ViewProviderDocumentObject &VPDObjectIn, std::shared_ptr<QGraphicsPixmapItem> icon);
std::shared_ptr<GraphLinkContainer> graphLink;
std::shared_ptr<Graph> theGraph;

View File

@@ -35,6 +35,7 @@
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/signals2.hpp>
#include "DAGRectItem.h"
@@ -79,6 +80,7 @@ namespace Gui
std::shared_ptr<QGraphicsPixmapItem> stateIcon; //!< visible Icon
std::shared_ptr<QGraphicsPixmapItem> icon; //!< icon
std::shared_ptr<QGraphicsTextItem> text; //!< text
boost::signals2::connection connChangeIcon;
int row; //!< row for this entry.
ColumnMask column; //!< column number containing the point.
int topoSortIndex;