Gui: Prevent unhandled exception adding properties
This commit prevents unhandled exceptions to be thrown in the Add Property dialog. When the user provides a valid name, for example 'Abc' and then an invalid name, for example 'Abc^', an exception is thrown that is caught by Qt's notify which may lead to a crash. This is caused by the fact that the editor is still bound to the old property that has been removed. The main idea was to preserve values that were provided by the user as long as possible, also when a property name changes. This design goal tried to preserve the user provided value even if the property name is not valid. Although the underlying property item is explicitly unbound in that situation, the editor is not. The solution is to also explicitly unbind the editor if there is an editor that can have bindings. Unbinding an editor does not automatically hide the f(x) symbol in the editor (leading to errors on unbound editors), so this commit also adds a bit of logic to hide the f(x) symbol when an editor is unbound.
This commit is contained in:
committed by
Chris Hennes
parent
8fda540e1a
commit
a102c8a359
@@ -804,6 +804,9 @@ bool DlgAddProperty::clearBoundProperty()
|
||||
|
||||
if (App::Property* prop = propertyItem->getFirstProperty()) {
|
||||
propertyItem->unbind();
|
||||
if (auto* eb = dynamic_cast<ExpressionBinding*>(editor.get())) {
|
||||
eb->unbind();
|
||||
}
|
||||
propertyItem->removeProperty(prop);
|
||||
container->removeDynamicProperty(prop->getName());
|
||||
closeTransaction(TransactionOption::Abort);
|
||||
|
||||
@@ -334,6 +334,12 @@ QPixmap ExpressionWidget::getIcon(const char* name, const QSize& size) const
|
||||
return icon;
|
||||
}
|
||||
|
||||
void ExpressionWidget::unbind()
|
||||
{
|
||||
iconLabel->hide();
|
||||
ExpressionBinding::unbind();
|
||||
}
|
||||
|
||||
void ExpressionWidget::makeLabel(QLineEdit* le)
|
||||
{
|
||||
defaultPalette = le->palette();
|
||||
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
virtual void bind(const App::ObjectIdentifier& _path);
|
||||
virtual void bind(const App::Property& prop);
|
||||
bool isBound() const;
|
||||
void unbind();
|
||||
virtual void unbind();
|
||||
virtual bool apply(const std::string& propName);
|
||||
virtual bool apply();
|
||||
bool hasExpression() const;
|
||||
@@ -99,6 +99,7 @@ class GuiExport ExpressionWidget: public ExpressionBinding
|
||||
public:
|
||||
ExpressionWidget();
|
||||
QPixmap getIcon(const char* name, const QSize& size) const;
|
||||
void unbind() override;
|
||||
|
||||
protected:
|
||||
void makeLabel(QLineEdit* parent);
|
||||
|
||||
Reference in New Issue
Block a user