use checkbox in menu item to display current object state and refactor the code
This commit is contained in:
@@ -68,35 +68,20 @@ void ViewProviderPart::onChanged(const App::Property* prop) {
|
||||
|
||||
void ViewProviderPart::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||
{
|
||||
App::DocumentObject* activePart = nullptr;
|
||||
auto activeDoc = Gui::Application::Instance->activeDocument();
|
||||
if(!activeDoc)
|
||||
activeDoc = getDocument();
|
||||
auto activeView = activeDoc->setActiveView(this);
|
||||
activePart = activeView->getActiveObject<App::DocumentObject*> (PARTKEY);
|
||||
|
||||
auto func = new Gui::ActionFunction(menu);
|
||||
|
||||
if (activePart == this->getObject()){
|
||||
QAction* act = menu->addAction(QObject::tr("Unset active object"));
|
||||
func->trigger(act, [this](){
|
||||
this->doubleClicked();
|
||||
QAction* act = menu->addAction(QObject::tr("Active object"));
|
||||
act->setCheckable(true);
|
||||
act->setChecked(isActivePart());
|
||||
func->trigger(act, [this](){
|
||||
this->toggleActivePart();
|
||||
});
|
||||
} else {
|
||||
QAction* act = menu->addAction(QObject::tr("Set active object"));
|
||||
func->trigger(act, [this](){
|
||||
this->doubleClicked();
|
||||
});
|
||||
}
|
||||
|
||||
ViewProviderDragger::setupContextMenu(menu, receiver, member);
|
||||
}
|
||||
|
||||
bool ViewProviderPart::doubleClicked()
|
||||
bool ViewProviderPart::isActivePart()
|
||||
{
|
||||
//make the part the active one
|
||||
|
||||
//first, check if the part is already active.
|
||||
App::DocumentObject* activePart = nullptr;
|
||||
auto activeDoc = Gui::Application::Instance->activeDocument();
|
||||
if(!activeDoc)
|
||||
@@ -108,6 +93,16 @@ bool ViewProviderPart::doubleClicked()
|
||||
activePart = activeView->getActiveObject<App::DocumentObject*> (PARTKEY);
|
||||
|
||||
if (activePart == this->getObject()){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderPart::toggleActivePart()
|
||||
{
|
||||
//make the part the active one
|
||||
if (isActivePart()){
|
||||
//active part double-clicked. Deactivate.
|
||||
Gui::Command::doCommand(Gui::Command::Gui,
|
||||
"Gui.ActiveDocument.ActiveView.setActiveObject('%s', None)",
|
||||
@@ -120,7 +115,11 @@ bool ViewProviderPart::doubleClicked()
|
||||
this->getObject()->getDocument()->getName(),
|
||||
this->getObject()->getNameInDocument());
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewProviderPart::doubleClicked()
|
||||
{
|
||||
toggleActivePart();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user