[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 4e106902f1
commit ca13b24673
3 changed files with 40 additions and 14 deletions

View File

@@ -19,7 +19,7 @@
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Contents</string>
<string>&amp;Content:</string>
</property>
<property name="buddy">
<cstring>cellContent</cstring>
@@ -36,7 +36,7 @@
<item row="0" column="2">
<widget class="QLabel" name="alias_label">
<property name="text">
<string>&amp;Alias</string>
<string>&amp;Alias:</string>
</property>
<property name="buddy">
<cstring>cellAlias</cstring>
@@ -49,9 +49,8 @@
<bool>false</bool>
</property>
<property name="toolTip">
<string>Refer to cell by alias, for example
Spreadsheet.my_alias_name instead of Spreadsheet.B1
</string>
<string>Refer to cell by alias, for example
Spreadsheet.my_alias_name instead of Spreadsheet.B1</string>
</property>
</widget>
</item>

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);

View File

@@ -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);