From bcff5d21ca712300d329c08cbaaa6ba864a15cc2 Mon Sep 17 00:00:00 2001 From: Eivind Kvedalen Date: Sat, 16 Jan 2016 10:42:28 +0100 Subject: [PATCH] Spreadsheet GUI: Issue #2402: Check for existing aliases in Properties dialog box. --- src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp | 26 +++++++------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp b/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp index 4cb67c8869..b963bfb20b 100644 --- a/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp +++ b/src/Mod/Spreadsheet/Gui/PropertiesDialog.cpp @@ -204,33 +204,25 @@ void PropertiesDialog::aliasChanged(const QString & text) { QPalette palette = ui->alias->palette(); + aliasOk = true; + + if (sheet->getAddressFromAlias(Base::Tools::toStdString(text)).size() > 0) + aliasOk = false; + if (text.indexOf(QRegExp(QString::fromLatin1("^[A-Za-z][_A-Za-z0-9]*$"))) >= 0) { try { CellAddress address(text.toUtf8().constData()); - - palette.setColor(QPalette::Text, Qt::red); aliasOk = false; - alias = ""; - } - catch (...) { - aliasOk = true; - palette.setColor(QPalette::Text, Qt::black); - alias = Base::Tools::toStdString(text); } + catch (...) { } } else { - if (text.isEmpty()) { - aliasOk = true; - palette.setColor(QPalette::Text, Qt::black); - } - else { + if (!text.isEmpty()) aliasOk = false; - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - palette.setColor(QPalette::Text, Qt::red); - } - alias = ""; } + alias = aliasOk ? Base::Tools::toStdString(text) : ""; + palette.setColor(QPalette::Text, aliasOk ? Qt::black : Qt::red); ui->alias->setPalette(palette); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(displayUnitOk && aliasOk); }