Spreadsheet Fix '=' regression in spreadsheets (#22146)
* Tools: Add ExpressionLineEdit to QtDesigner plugin * Spreadsheet: Only use validator when when prefix is not '=' --------- Co-authored-by: wmayer <wmayer@freecad.org>
This commit is contained in:
@@ -921,15 +921,15 @@ ExpressionLineEdit::ExpressionLineEdit(QWidget* parent,
|
||||
, noProperty(noProperty)
|
||||
, exactMatch(false)
|
||||
, checkInList(checkInList)
|
||||
, checkPrefix(checkPrefix)
|
||||
{
|
||||
setValidator(new ExpressionValidator(this));
|
||||
setPrefix(checkPrefix);
|
||||
connect(this, &QLineEdit::textEdited, this, &ExpressionLineEdit::slotTextChanged);
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::setPrefix(char prefix)
|
||||
{
|
||||
checkPrefix = prefix;
|
||||
setValidator(checkPrefix == '=' ? nullptr : new ExpressionValidator(this));
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::setDocumentObject(const App::DocumentObject* currentDocObj,
|
||||
|
||||
@@ -148,6 +148,8 @@ SheetView::SheetView(Gui::Document* pcDocument, App::DocumentObject* docObj, QWi
|
||||
// Set document object to create auto completer
|
||||
ui->cellContent->setDocumentObject(sheet);
|
||||
ui->cellAlias->setDocumentObject(sheet);
|
||||
|
||||
ui->cellContent->setPrefix('=');
|
||||
}
|
||||
|
||||
SheetView::~SheetView()
|
||||
|
||||
@@ -22,11 +22,13 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QColorDialog>
|
||||
#include <QCursor>
|
||||
#include <QFileDialog>
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QRegularExpression>
|
||||
#include <QRegularExpressionMatch>
|
||||
@@ -544,6 +546,66 @@ void InputField::setHistorySize(int i)
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
ExpressionLineEdit::ExpressionLineEdit(QWidget* parent)
|
||||
: QLineEdit(parent)
|
||||
, exactMatch {false}
|
||||
{
|
||||
completer = new QCompleter(this);
|
||||
connect(this, &QLineEdit::textEdited, this, &ExpressionLineEdit::slotTextChanged);
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::setExactMatch(bool enabled)
|
||||
{
|
||||
exactMatch = enabled;
|
||||
if (completer) {
|
||||
completer->setFilterMode(exactMatch ? Qt::MatchStartsWith : Qt::MatchContains);
|
||||
}
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::slotTextChanged(const QString& text)
|
||||
{
|
||||
Q_EMIT textChanged2(text, cursorPosition());
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::slotCompleteText(const QString& completionPrefix, bool isActivated)
|
||||
{
|
||||
Q_UNUSED(completionPrefix)
|
||||
Q_UNUSED(isActivated)
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::slotCompleteTextHighlighted(const QString& completionPrefix)
|
||||
{
|
||||
slotCompleteText(completionPrefix, false);
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::slotCompleteTextSelected(const QString& completionPrefix)
|
||||
{
|
||||
slotCompleteText(completionPrefix, true);
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
QLineEdit::keyPressEvent(e);
|
||||
}
|
||||
|
||||
void ExpressionLineEdit::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
QMenu* menu = createStandardContextMenu();
|
||||
|
||||
if (completer) {
|
||||
menu->addSeparator();
|
||||
QAction* match = menu->addAction(tr("Exact match"));
|
||||
match->setCheckable(true);
|
||||
match->setChecked(completer->filterMode() == Qt::MatchStartsWith);
|
||||
QObject::connect(match, &QAction::toggled, this, &Gui::ExpressionLineEdit::setExactMatch);
|
||||
}
|
||||
menu->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
menu->popup(event->globalPos());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
namespace Base
|
||||
{
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <QButtonGroup>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QCompleter>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QFontComboBox>
|
||||
#include <QGridLayout>
|
||||
@@ -386,6 +387,33 @@ private:
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class ExpressionLineEdit: public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ExpressionLineEdit(QWidget* parent = nullptr);
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotTextChanged(const QString& text);
|
||||
void slotCompleteText(const QString& completionPrefix, bool isActivated);
|
||||
void slotCompleteTextHighlighted(const QString& completionPrefix);
|
||||
void slotCompleteTextSelected(const QString& completionPrefix);
|
||||
void setExactMatch(bool enabled = true);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void contextMenuEvent(QContextMenuEvent* event) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void textChanged2(QString text, int pos);
|
||||
|
||||
private:
|
||||
QCompleter* completer;
|
||||
bool exactMatch;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class QuantitySpinBoxPrivate;
|
||||
class QuantitySpinBox: public QAbstractSpinBox
|
||||
{
|
||||
|
||||
@@ -523,6 +523,56 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class ExpressionLineEditPlugin: public QDesignerCustomWidgetInterface
|
||||
{
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
public:
|
||||
ExpressionLineEditPlugin()
|
||||
{}
|
||||
QWidget* createWidget(QWidget* parent)
|
||||
{
|
||||
return new Gui::ExpressionLineEdit(parent);
|
||||
}
|
||||
QString group() const
|
||||
{
|
||||
return QLatin1String("Input Widgets");
|
||||
}
|
||||
QIcon icon() const
|
||||
{
|
||||
return QIcon(QPixmap(inputfield_pixmap));
|
||||
}
|
||||
QString includeFile() const
|
||||
{
|
||||
return QLatin1String("Gui/InputField.h");
|
||||
}
|
||||
QString toolTip() const
|
||||
{
|
||||
return QLatin1String("Expression line edit");
|
||||
}
|
||||
QString whatsThis() const
|
||||
{
|
||||
return QLatin1String("A widget to work with expressions.");
|
||||
}
|
||||
bool isContainer() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
QString domXml() const
|
||||
{
|
||||
return "<ui language=\"c++\">\n"
|
||||
" <widget class=\"Gui::ExpressionLineEdit\" name=\"exprLineEdit\">\n"
|
||||
" <property name=\"unit\" stdset=\"0\">\n"
|
||||
" <string notr=\"true\"></string>\n"
|
||||
" </property>\n"
|
||||
" </widget>\n"
|
||||
"</ui>";
|
||||
}
|
||||
QString name() const
|
||||
{
|
||||
return QLatin1String("Gui::ExpressionLineEdit");
|
||||
}
|
||||
};
|
||||
|
||||
/* XPM */
|
||||
static const char* quantityspinbox_pixmap[] = {"22 22 6 1",
|
||||
"a c #000000",
|
||||
@@ -1653,6 +1703,7 @@ QList<QDesignerCustomWidgetInterface*> CustomWidgetPlugin::customWidgets() const
|
||||
cw.append(new FileChooserPlugin);
|
||||
cw.append(new AccelLineEditPlugin);
|
||||
cw.append(new ActionSelectorPlugin);
|
||||
cw.append(new ExpressionLineEditPlugin);
|
||||
cw.append(new InputFieldPlugin);
|
||||
cw.append(new QuantitySpinBoxPlugin);
|
||||
cw.append(new CommandIconViewPlugin);
|
||||
|
||||
Reference in New Issue
Block a user