From a38a78f6d6bd319a916ca8de87527e6d62137ec3 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Fri, 29 Apr 2016 23:00:11 -0300 Subject: [PATCH] Allow to enter empty values in PropertyFloatList and PropertyIntegerList - issue #2535 --- src/Gui/Widgets.cpp | 45 +++++++++++++------------ src/Gui/propertyeditor/PropertyItem.cpp | 5 ++- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/Gui/Widgets.cpp b/src/Gui/Widgets.cpp index 1dbc10d41..694a943e1 100644 --- a/src/Gui/Widgets.cpp +++ b/src/Gui/Widgets.cpp @@ -1151,32 +1151,33 @@ public: QStringList lines; if (edit) { QString inputText = edit->toPlainText(); - lines = inputText.split(QString::fromLatin1("\n")); + if (!inputText.isEmpty()) // let pass empty input, regardless of the type, so user can void the value + lines = inputText.split(QString::fromLatin1("\n")); } - - if (type == 1) { // floats - bool ok; - int line=1; - for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) { - it->toDouble(&ok); - if (!ok) { - QMessageBox::critical(this, tr("Invalid input"), tr("Input in line %1 is not a number").arg(line)); - return; + if (!lines.isEmpty()) { + if (type == 1) { // floats + bool ok; + int line=1; + for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) { + it->toDouble(&ok); + if (!ok) { + QMessageBox::critical(this, tr("Invalid input"), tr("Input in line %1 is not a number").arg(line)); + return; + } + } + } + else if (type == 2) { // integers + bool ok; + int line=1; + for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) { + it->toInt(&ok); + if (!ok) { + QMessageBox::critical(this, tr("Invalid input"), tr("Input in line %1 is not a number").arg(line)); + return; + } } } } - else if (type == 2) { // integers - bool ok; - int line=1; - for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) { - it->toInt(&ok); - if (!ok) { - QMessageBox::critical(this, tr("Invalid input"), tr("Input in line %1 is not a number").arg(line)); - return; - } - } - } - QDialog::accept(); } }; diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 600f844aa..2207357b5 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -2091,7 +2091,6 @@ QVariant PropertyFloatListItem::toString(const QVariant& prop) const list.append(QLatin1String("...")); } QString text = QString::fromUtf8("[%1]").arg(list.join(QLatin1String(","))); - return QVariant(text); } @@ -2120,6 +2119,8 @@ void PropertyFloatListItem::setValue(const QVariant& value) str << *it << ","; } str << "]"; + if (data == QString::fromUtf8("[,]")) + data = QString::fromUtf8("[]"); setPropertyValue(data); } @@ -2193,6 +2194,8 @@ void PropertyIntegerListItem::setValue(const QVariant& value) str << *it << ","; } str << "]"; + if (data == QString::fromUtf8("[,]")) + data = QString::fromUtf8("[]"); setPropertyValue(data); }