PartDesign: Refactor set/remove tip in the new Gui::ViewProvider mechanism
This commit is contained in:
@@ -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<ViewProviderDocumentObject*>(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<std::string> &)
|
||||
@@ -279,14 +269,14 @@ bool ViewProvider::onDelete(const std::vector<std::string> &)
|
||||
|
||||
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<App::Property*> 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<ViewProviderBody*>(vp);
|
||||
}
|
||||
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::string> &);
|
||||
|
||||
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
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user