From 813e9040ac9ccb1f67f94f81a40d84dce794e925 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 16 Jun 2019 12:13:24 +0200 Subject: [PATCH] PartDesign: Refactor set/remove tip in the new Gui::ViewProvider mechanism --- src/Mod/PartDesign/Gui/ViewProvider.cpp | 60 ++++++++----------- src/Mod/PartDesign/Gui/ViewProvider.h | 20 +++---- src/Mod/PartDesign/Gui/ViewProviderLoft.cpp | 2 +- src/Mod/PartDesign/Gui/ViewProviderPipe.cpp | 2 +- .../PartDesign/Gui/ViewProviderPrimitive.cpp | 2 +- 5 files changed, 37 insertions(+), 49 deletions(-) diff --git a/src/Mod/PartDesign/Gui/ViewProvider.cpp b/src/Mod/PartDesign/Gui/ViewProvider.cpp index d49715a5ec..8c4e7710d9 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.cpp +++ b/src/Mod/PartDesign/Gui/ViewProvider.cpp @@ -189,48 +189,45 @@ void ViewProvider::updateData(const App::Property* prop) } void ViewProvider::onChanged(const App::Property* prop) { - + //if the object is inside of a body we make sure it is the only visible one on activation if(prop == &Visibility && Visibility.getValue()) { - + Part::BodyBase* body = Part::BodyBase::findBodyOf(getObject()); if(body) { - + //hide all features in the body other than this object for(App::DocumentObject* obj : body->Group.getValues()) { - + if(obj->isDerivedFrom(PartDesign::Feature::getClassTypeId()) && obj != getObject()) { Gui::ViewProvider* vp = Gui::Application::Instance->activeDocument()->getViewProvider(obj); - if(!vp) + if(!vp) return; - + Gui::ViewProviderDocumentObject* vpd = static_cast(vp); if (vpd->Visibility.getValue()) vpd->Visibility.setValue(false); } - } + } } } - + PartGui::ViewProviderPartExt::onChanged(prop); } void ViewProvider::setTipIcon(bool onoff) { isSetTipIcon = onoff; - + signalChangeIcon(); } -QIcon ViewProvider::getIcon(void) const +QIcon ViewProvider::mergeOverlayIcons (const QIcon & orig) const { - return mergeTip(Gui::BitmapFactory().pixmap(sPixmap)); -} + QIcon mergedicon = orig; -QIcon ViewProvider::mergeTip(QIcon orig) const -{ if(isSetTipIcon) { QPixmap px; - + static const char * const feature_tip_xpm[]={ "9 9 3 1", ". c None", @@ -247,18 +244,11 @@ QIcon ViewProvider::mergeTip(QIcon orig) const "...###..."}; px = QPixmap(feature_tip_xpm); - QIcon icon_mod; + mergedicon = mergePixmap(mergedicon, px, Gui::BitmapFactoryInst::BottomRight); - int w = QApplication::style()->pixelMetric(QStyle::PM_ListViewIconSize); - - icon_mod.addPixmap(Gui::BitmapFactory().merge(orig.pixmap(w, w, QIcon::Normal, QIcon::Off), - px,Gui::BitmapFactoryInst::BottomRight), QIcon::Normal, QIcon::Off); - icon_mod.addPixmap(Gui::BitmapFactory().merge(orig.pixmap(w, w, QIcon::Normal, QIcon::On ), - px,Gui::BitmapFactoryInst::BottomRight), QIcon::Normal, QIcon::Off); - return icon_mod; } - else - return orig; + + return mergedicon; } bool ViewProvider::onDelete(const std::vector &) @@ -279,14 +269,14 @@ bool ViewProvider::onDelete(const std::vector &) if (body != NULL) { // Deletion from the tree of a feature is handled by Document.removeObject, which has no clue - // about what a body is. Therefore, Bodies, although an "activable" container, know nothing + // about what a body is. Therefore, Bodies, although an "activable" container, know nothing // about what happens at Document level with the features they contain. // // The Deletion command StdCmdDelete::activated, however does notify the viewprovider corresponding // to the feature (not body) of the imminent deletion (before actually doing it). // - // Consequently, the only way of notifying a body of the imminent deletion of one of its features - // so as to do the clean up required (moving basefeature references, tip management) is from the + // Consequently, the only way of notifying a body of the imminent deletion of one of its features + // so as to do the clean up required (moving basefeature references, tip management) is from the // viewprovider, so we call it here. // // fixes (#3084) @@ -302,22 +292,22 @@ void ViewProvider::setBodyMode(bool bodymode) { std::vector props; getPropertyList(props); - + auto vp = getBodyViewProvider(); if(!vp) return; - + for(App::Property* prop : props) { - + //we keep visibility and selectibility per object if(prop == &Visibility || prop == &Selectable) continue; - + //we hide only properties which are available in the body, not special ones if(!vp->getPropertyByName(prop->getName())) continue; - + prop->setStatus(App::Property::Hidden, bodymode); } } @@ -331,7 +321,7 @@ void ViewProvider::makeTemporaryVisible(bool onoff) } Gui::ViewProvider::show(); } - else + else Gui::ViewProvider::hide(); } @@ -352,7 +342,7 @@ ViewProviderBody* ViewProvider::getBodyViewProvider() { if(vp && vp->isDerivedFrom(ViewProviderBody::getClassTypeId())) return static_cast(vp); } - + return nullptr; } diff --git a/src/Mod/PartDesign/Gui/ViewProvider.h b/src/Mod/PartDesign/Gui/ViewProvider.h index 3559f3e45f..0d9d133aa8 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.h +++ b/src/Mod/PartDesign/Gui/ViewProvider.h @@ -49,22 +49,20 @@ public: virtual bool doubleClicked(void); void updateData(const App::Property*); void onChanged(const App::Property* prop); - - virtual QIcon getIcon(void) const; - + void setTipIcon(bool onoff); - //body mode means that the object is part of a body and that the body is used to set the - //visual properties, not the features. Hence setting body mode to true will hide most + //body mode means that the object is part of a body and that the body is used to set the + //visual properties, not the features. Hence setting body mode to true will hide most //viewprovider properties. void setBodyMode(bool bodymode); - + //makes this viewprovider visible in the scene graph without changing any properties, - //not the visibility one and also not the display mode. This can be used to show the - //shape of this viewprovider from other viewproviders without doing anything to the + //not the visibility one and also not the display mode. This can be used to show the + //shape of this viewprovider from other viewproviders without doing anything to the //document and properties. void makeTemporaryVisible(bool); - + //Returns the ViewProvider of the body the feature belongs to, or NULL, if not in a body ViewProviderBody* getBodyViewProvider(); @@ -76,8 +74,8 @@ protected: virtual void unsetEdit(int ModNum); virtual bool onDelete(const std::vector &); - - virtual QIcon mergeTip(QIcon orig) const; + + virtual QIcon mergeOverlayIcons (const QIcon & orig) const override; /** * Returns a newly create dialog for the part to be placed in the task view diff --git a/src/Mod/PartDesign/Gui/ViewProviderLoft.cpp b/src/Mod/PartDesign/Gui/ViewProviderLoft.cpp index ef8a055a2e..6ae3bf5cd9 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderLoft.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderLoft.cpp @@ -174,6 +174,6 @@ QIcon ViewProviderLoft::getIcon(void) const { str += QString::fromLatin1("Subtractive_"); str += QString::fromLatin1("Loft.svg"); - return mergeTip(Gui::BitmapFactory().pixmap(str.toStdString().c_str())); + return PartDesignGui::ViewProvider::mergeOverlayIcons(Gui::BitmapFactory().pixmap(str.toStdString().c_str())); } diff --git a/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp b/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp index bcbddc0e5f..3c7fb58431 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPipe.cpp @@ -177,6 +177,6 @@ QIcon ViewProviderPipe::getIcon(void) const { str += QString::fromLatin1("Subtractive_"); str += QString::fromLatin1("Pipe.svg"); - return mergeTip(Gui::BitmapFactory().pixmap(str.toStdString().c_str())); + return PartDesignGui::ViewProvider::mergeOverlayIcons(Gui::BitmapFactory().pixmap(str.toStdString().c_str())); } diff --git a/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp b/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp index 52e74f9468..2a172bca44 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPrimitive.cpp @@ -168,5 +168,5 @@ QIcon ViewProviderPrimitive::getIcon(void) const { } str += QString::fromLatin1(".svg"); - return mergeTip(Gui::BitmapFactory().pixmap(str.toStdString().c_str())); + return PartDesignGui::ViewProvider::mergeOverlayIcons(Gui::BitmapFactory().pixmap(str.toStdString().c_str())); }