App/Gui: allow change dynamic property group and documentation

Exposed as PropertyContainerPy.setGroup/DocumentationOfProperty.

Added a menu action to property view for rename dynamic property group.
This commit is contained in:
Zheng, Lei
2019-12-28 09:22:52 +08:00
committed by Chris Hennes
parent 72ae26dfee
commit 8cf3cf330b
7 changed files with 105 additions and 4 deletions

View File

@@ -31,8 +31,11 @@
# include <QDialog>
# include <QMessageBox>
# include <QCheckBox>
# include <QInputDialog>
#endif
#include <boost/algorithm/string/predicate.hpp>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <App/Application.h>
@@ -57,6 +60,7 @@ PropertyEditor::PropertyEditor(QWidget *parent)
, committing(false)
, delaybuild(false)
, binding(false)
, checkDocument(false)
{
propertyModel = new PropertyModel(this);
setModel(propertyModel);
@@ -362,8 +366,10 @@ void PropertyEditor::drawBranches(QPainter *painter, const QRect &rect, const QM
//painter->setPen(savedPen);
}
void PropertyEditor::buildUp(PropertyModel::PropertyList &&props, bool checkDocument)
void PropertyEditor::buildUp(PropertyModel::PropertyList &&props, bool _checkDocument)
{
checkDocument = _checkDocument;
if (committing) {
Base::Console().Warning("While committing the data to the property the selection has changed.\n");
delaybuild = true;
@@ -493,6 +499,7 @@ enum MenuAction {
MA_Expression,
MA_RemoveProp,
MA_AddProp,
MA_EditPropGroup,
MA_Transient,
MA_Output,
MA_NoRecompute,
@@ -532,8 +539,20 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) {
}
}
if(props.size())
if(props.size()) {
menu.addAction(tr("Add property"))->setData(QVariant(MA_AddProp));
unsigned count = 0;
for(auto prop : props) {
if(prop->testStatus(App::Property::PropDynamic)
&& !boost::starts_with(prop->getName(),prop->getGroup()))
{
++count;
} else
break;
}
if(count == props.size())
menu.addAction(tr("Rename property group"))->setData(QVariant(MA_EditPropGroup));
}
bool canRemove = !props.empty();
unsigned long propType = 0;
@@ -645,6 +664,22 @@ void PropertyEditor::contextMenuEvent(QContextMenuEvent *) {
dlg.exec();
return;
}
case MA_EditPropGroup: {
// This operation is not undoable yet.
const char *groupName = (*props.begin())->getGroup();
if(!groupName)
groupName = "Base";
QString res = QInputDialog::getText(Gui::getMainWindow(),
tr("Rename property group"), tr("Group name:"),
QLineEdit::Normal, QString::fromUtf8(groupName));
if(res.size()) {
std::string group = res.toUtf8().constData();
for(auto prop : props)
prop->getContainer()->changeDynamicProperty(prop,group.c_str(),0);
buildUp(PropertyModel::PropertyList(propList),checkDocument);
}
return;
}
case MA_RemoveProp: {
App::AutoTransaction committer("Remove property");
for(auto prop : props) {