From 64a7e2408032f9748daad4cd09991cdfe167747e Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 14 Dec 2019 21:26:41 +0800 Subject: [PATCH] Gui: fix DAG view icon sync problem --- src/Gui/DAGView/DAGModel.cpp | 23 ++++++++++------------- src/Gui/DAGView/DAGModel.h | 2 +- src/Gui/DAGView/DAGModelGraph.h | 2 ++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Gui/DAGView/DAGModel.cpp b/src/Gui/DAGView/DAGModel.cpp index 6d56aaf83b..b292d115cf 100644 --- a/src/Gui/DAGView/DAGModel.cpp +++ b/src/Gui/DAGView/DAGModel.cpp @@ -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(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 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); diff --git a/src/Gui/DAGView/DAGModel.h b/src/Gui/DAGView/DAGModel.h index e39b24dcbb..022f3c3401 100644 --- a/src/Gui/DAGView/DAGModel.h +++ b/src/Gui/DAGView/DAGModel.h @@ -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 icon); std::shared_ptr graphLink; std::shared_ptr theGraph; diff --git a/src/Gui/DAGView/DAGModelGraph.h b/src/Gui/DAGView/DAGModelGraph.h index 0376cb3b63..b605872d87 100644 --- a/src/Gui/DAGView/DAGModelGraph.h +++ b/src/Gui/DAGView/DAGModelGraph.h @@ -35,6 +35,7 @@ #include #include #include +#include #include "DAGRectItem.h" @@ -79,6 +80,7 @@ namespace Gui std::shared_ptr stateIcon; //!< visible Icon std::shared_ptr icon; //!< icon std::shared_ptr text; //!< text + boost::signals2::connection connChangeIcon; int row; //!< row for this entry. ColumnMask column; //!< column number containing the point. int topoSortIndex;