[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.
This commit is contained in:
donovaly
2020-06-18 04:08:28 +02:00
committed by Yorik van Havre
parent abfda26483
commit 37c4c90ab0
3 changed files with 40 additions and 14 deletions

View File

@@ -35,24 +35,24 @@
# include <cmath>
#endif
#include "SpreadsheetView.h"
#include "SpreadsheetDelegate.h"
#include <Mod/Spreadsheet/App/Sheet.h>
#include <App/DocumentObject.h>
#include <App/PropertyStandard.h>
#include <App/Range.h>
#include <Base/Tools.h>
#include <boost_bind_bind.hpp>
#include <Gui/MainWindow.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/CommandT.h>
#include <Gui/Document.h>
#include <Gui/ExpressionCompleter.h>
#include <App/DocumentObject.h>
#include <App/PropertyStandard.h>
#include <Gui/Command.h>
#include <boost_bind_bind.hpp>
#include <LineEdit.h>
#include <Mod/Spreadsheet/App/Sheet.h>
#include <Mod/Spreadsheet/App/Utils.h>
#include "qtcolorpicker.h"
#include <LineEdit.h>
#include <Base/Tools.h>
#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);