Gui: Rearrange the property view context menu

This commit is contained in:
Pieter Hijma
2024-04-25 21:09:46 +02:00
parent 55968bbf6c
commit e3d4bcef3d

View File

@@ -651,18 +651,11 @@ enum MenuAction {
void PropertyEditor::contextMenuEvent(QContextMenuEvent *) {
QMenu menu;
QAction *autoExpand = menu.addAction(tr("Auto expand"));
autoExpand->setCheckable(true);
autoExpand->setChecked(autoexpand);
autoExpand->setData(QVariant(MA_AutoExpand));
QAction *showAll = menu.addAction(tr("Show all"));
showAll->setCheckable(true);
showAll->setChecked(PropertyView::showAll());
showAll->setData(QVariant(MA_ShowAll));
QAction *autoExpand = nullptr;
auto contextIndex = currentIndex();
// acquiring the selected properties
std::unordered_set<App::Property*> props;
const auto indexes = selectedIndexes();
for(const auto& index : indexes) {
@@ -678,49 +671,70 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) {
}
}
if(props.size() == 1) {
auto item = static_cast<PropertyItem*>(contextIndex.internalPointer());
auto prop = *props.begin();
if(item->isBound()
&& !prop->isDerivedFrom(App::PropertyExpressionEngine::getClassTypeId())
&& !prop->isReadOnly()
&& !prop->testStatus(App::Property::Immutable)
&& !(prop->getType() & App::Prop_ReadOnly))
// add property
if(!props.empty()) {
menu.addAction(tr("Add property"))->setData(QVariant(MA_AddProp));
if (std::all_of(props.begin(), props.end(), [](auto prop) {
return prop->testStatus(App::Property::PropDynamic)
&& !boost::starts_with(prop->getName(),prop->getGroup());
}))
{
contextIndex = propertyModel->buddy(contextIndex);
setCurrentIndex(contextIndex);
menu.addSeparator();
menu.addAction(tr("Expression..."))->setData(QVariant(MA_Expression));
menu.addAction(tr("Rename property group"))->setData(QVariant(MA_EditPropGroup));
}
}
// remove property
bool canRemove = !props.empty();
unsigned long propType = 0;
unsigned long propStatus = 0xffffffff;
for(auto prop : props) {
propType |= prop->getType();
propStatus &= prop->getStatus();
if(!prop->testStatus(App::Property::PropDynamic)
|| prop->testStatus(App::Property::LockDynamic))
{
canRemove = false;
}
}
if(canRemove)
menu.addAction(tr("Remove property"))->setData(QVariant(MA_RemoveProp));
// add a separator between adding/removing properties and the rest
if (!props.empty() || canRemove) {
menu.addSeparator();
}
// show all
QAction *showAll = menu.addAction(tr("Show all"));
showAll->setCheckable(true);
showAll->setChecked(PropertyView::showAll());
showAll->setData(QVariant(MA_ShowAll));
if(PropertyView::showAll()) {
if(!props.empty()) {
menu.addAction(tr("Add property"))->setData(QVariant(MA_AddProp));
if (std::all_of(props.begin(), props.end(), [](auto prop) {
return prop->testStatus(App::Property::PropDynamic)
&& !boost::starts_with(prop->getName(),prop->getGroup());
}))
// auto expand
autoExpand = menu.addAction(tr("Auto expand"));
autoExpand->setCheckable(true);
autoExpand->setChecked(autoexpand);
autoExpand->setData(QVariant(MA_AutoExpand));
// expression
if(props.size() == 1) {
auto item = static_cast<PropertyItem*>(contextIndex.internalPointer());
auto prop = *props.begin();
if(item->isBound()
&& !prop->isDerivedFrom(App::PropertyExpressionEngine::getClassTypeId())
&& !prop->isReadOnly()
&& !prop->testStatus(App::Property::Immutable)
&& !(prop->getType() & App::Prop_ReadOnly))
{
menu.addAction(tr("Rename property group"))->setData(QVariant(MA_EditPropGroup));
contextIndex = propertyModel->buddy(contextIndex);
setCurrentIndex(contextIndex);
// menu.addSeparator();
menu.addAction(tr("Expression..."))->setData(QVariant(MA_Expression));
}
}
bool canRemove = !props.empty();
unsigned long propType = 0;
unsigned long propStatus = 0xffffffff;
for(auto prop : props) {
propType |= prop->getType();
propStatus &= prop->getStatus();
if(!prop->testStatus(App::Property::PropDynamic)
|| prop->testStatus(App::Property::LockDynamic))
{
canRemove = false;
}
}
if(canRemove)
menu.addAction(tr("Remove property"))->setData(QVariant(MA_RemoveProp));
// the various flags
if(!props.empty()) {
menu.addSeparator();
@@ -759,9 +773,14 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) {
switch(action->data().toInt()) {
case MA_AutoExpand:
autoexpand = autoExpand->isChecked();
if (autoexpand)
expandAll();
if (autoExpand) {
// Variable autoExpand should not be null when we arrive here, but
// since we explicitly initialize the variable to nullptr, a check
// nonetheless.
autoexpand = autoExpand->isChecked();
if (autoexpand)
expandAll();
}
return;
case MA_ShowAll:
PropertyView::setShowAll(action->isChecked());