Skip to content

Commit

Permalink
Allow to enter empty values in PropertyFloatList and PropertyIntegerL…
Browse files Browse the repository at this point in the history
…ist - issue #2535
  • Loading branch information
yorikvanhavre committed Apr 30, 2016
1 parent 9ee892e commit a38a78f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
41 changes: 21 additions & 20 deletions src/Gui/Widgets.cpp
Expand Up @@ -1151,32 +1151,33 @@ class PropertyListDialog : public QDialog
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();
}
};
Expand Down
5 changes: 4 additions & 1 deletion src/Gui/propertyeditor/PropertyItem.cpp
Expand Up @@ -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);
}

Expand Down Expand Up @@ -2120,6 +2119,8 @@ void PropertyFloatListItem::setValue(const QVariant& value)
str << *it << ",";
}
str << "]";
if (data == QString::fromUtf8("[,]"))
data = QString::fromUtf8("[]");
setPropertyValue(data);
}

Expand Down Expand Up @@ -2193,6 +2194,8 @@ void PropertyIntegerListItem::setValue(const QVariant& value)
str << *it << ",";
}
str << "]";
if (data == QString::fromUtf8("[,]"))
data = QString::fromUtf8("[]");
setPropertyValue(data);
}

Expand Down

0 comments on commit a38a78f

Please sign in to comment.