From ca13b24673cf97d9a802da6bdccf3a584c611075 Mon Sep 17 00:00:00 2001 From: donovaly Date: Thu, 18 Jun 2020 04:08:28 +0200 Subject: [PATCH] [Spreadsheet] add visible alias check as discussed in https://forum.freecadweb.org/viewtopic.php?p=408992#p408981 visible feedback is missing for the Alias field. This PR add it and also adapts the UI label style. --- src/Mod/Spreadsheet/Gui/Sheet.ui | 9 ++--- src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp | 44 ++++++++++++++++----- src/Mod/Spreadsheet/Gui/SpreadsheetView.h | 1 + 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/Mod/Spreadsheet/Gui/Sheet.ui b/src/Mod/Spreadsheet/Gui/Sheet.ui index acd76bbf59..5704291d1e 100644 --- a/src/Mod/Spreadsheet/Gui/Sheet.ui +++ b/src/Mod/Spreadsheet/Gui/Sheet.ui @@ -19,7 +19,7 @@ - &Contents + &Content: cellContent @@ -36,7 +36,7 @@ - &Alias + &Alias: cellAlias @@ -49,9 +49,8 @@ false - Refer to cell by alias, for example -Spreadsheet.my_alias_name instead of Spreadsheet.B1 - + Refer to cell by alias, for example +Spreadsheet.my_alias_name instead of Spreadsheet.B1 diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp index 52c95c1dd7..c12056799c 100644 --- a/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp +++ b/src/Mod/Spreadsheet/Gui/SpreadsheetView.cpp @@ -35,24 +35,24 @@ # include #endif -#include "SpreadsheetView.h" -#include "SpreadsheetDelegate.h" -#include +#include +#include #include +#include +#include #include #include +#include #include #include #include -#include -#include -#include -#include +#include +#include #include #include "qtcolorpicker.h" -#include -#include +#include "SpreadsheetView.h" +#include "SpreadsheetDelegate.h" #include "ui_Sheet.h" using namespace SpreadsheetGui; @@ -99,6 +99,7 @@ SheetView::SheetView(Gui::Document *pcDocument, App::DocumentObject *docObj, QWi connect(ui->cellContent, SIGNAL(returnPressed()), this, SLOT( editingFinished() )); connect(ui->cellAlias, SIGNAL(returnPressed()), this, SLOT( editingFinished() )); + connect(ui->cellAlias, SIGNAL(textEdited(QString)), this, SLOT(aliasChanged(QString))); columnWidthChangedConnection = sheet->columnWidthChanged.connect(bind(&SheetView::resizeColumn, this, bp::_1, bp::_2)); rowHeightChangedConnection = sheet->rowHeightChanged.connect(bind(&SheetView::resizeRow, this, bp::_1, bp::_2)); @@ -370,6 +371,31 @@ void SheetView::editingFinished() } } +void SheetView::aliasChanged(const QString& text) +{ + // check live the input and highlight if the user input invalid characters + + bool aliasOk = true; + QPalette palette = ui->cellAlias->palette(); + + if (!text.isEmpty() && !sheet->isValidAlias(Base::Tools::toStdString(text))) + aliasOk = false; + + if (!aliasOk) { + // change tooltip and make text color red + ui->cellAlias->setToolTip(QObject::tr("Alias contains invalid characters!")); + palette.setColor(QPalette::Text, Qt::red); + } + else { + // go back to normal + ui->cellAlias->setToolTip( + QObject::tr("Refer to cell by alias, for example\nSpreadsheet.my_alias_name instead of Spreadsheet.B1")); + palette.setColor(QPalette::Text, Qt::black); + } + // apply the text color via the palette + ui->cellAlias->setPalette(palette); +} + void SheetView::currentChanged ( const QModelIndex & current, const QModelIndex & previous ) { Q_UNUSED(current); diff --git a/src/Mod/Spreadsheet/Gui/SpreadsheetView.h b/src/Mod/Spreadsheet/Gui/SpreadsheetView.h index f468cb058d..8e6aced3ef 100644 --- a/src/Mod/Spreadsheet/Gui/SpreadsheetView.h +++ b/src/Mod/Spreadsheet/Gui/SpreadsheetView.h @@ -83,6 +83,7 @@ public: protected Q_SLOTS: void editingFinished(); + void aliasChanged(const QString& text); void currentChanged( const QModelIndex & current, const QModelIndex & previous ); void columnResized(int col, int oldSize, int newSize); void rowResized(int row, int oldSize, int newSize);