Gui: [skip ci] modernize QuantitySpinBox class

This commit is contained in:
wmayer
2022-07-31 13:59:28 +02:00
parent b40de7a509
commit 60c2157e54
2 changed files with 30 additions and 28 deletions

View File

@@ -315,10 +315,12 @@ QuantitySpinBox::QuantitySpinBox(QWidget *parent)
{
d_ptr->locale = locale();
this->setContextMenuPolicy(Qt::DefaultContextMenu);
QObject::connect(lineEdit(), SIGNAL(textChanged(QString)),
this, SLOT(userInput(QString)));
QObject::connect(this, SIGNAL(editingFinished()),
this, SLOT(handlePendingEmit()));
connect(lineEdit(), &QLineEdit::textChanged,
this, &QuantitySpinBox::userInput);
connect(this, &QuantitySpinBox::editingFinished,
this, [&]{
this->handlePendingEmit(true);
});
// When a style sheet is set the text margins for top/bottom must be set to avoid to squash the widget
#ifndef Q_OS_MAC
@@ -441,8 +443,8 @@ bool QuantitySpinBox::apply(const std::string & propName)
Gui::Command::doCommand(Gui::Command::Doc, "%s = %f", propName.c_str(), dValue);
return true;
}
else
return false;
return false;
}
void QuantitySpinBox::resizeEvent(QResizeEvent * event)

View File

@@ -50,7 +50,7 @@ class GuiExport QuantitySpinBox : public QAbstractSpinBox, public ExpressionSpin
public:
explicit QuantitySpinBox(QWidget *parent = nullptr);
virtual ~QuantitySpinBox();
~QuantitySpinBox() override;
/// Get the current quantity
Base::Quantity value() const;
@@ -116,20 +116,20 @@ public:
Base::Quantity valueFromText(const QString &text) const;
QString textFromValue(const Base::Quantity& val) const;
virtual void stepBy(int steps);
virtual void clear();
virtual QValidator::State validate(QString &input, int &pos) const;
virtual void fixup(QString &str) const;
void stepBy(int steps) override;
void clear() override;
QValidator::State validate(QString &input, int &pos) const override;
void fixup(QString &str) const override;
/// This is a helper function to determine the size this widget requires to fully display the text
QSize sizeForText(const QString&) const;
QSize sizeHint() const;
QSize minimumSizeHint() const;
bool event(QEvent *event);
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
bool event(QEvent *event) override;
void setNumberExpression(App::NumberExpression*);
void bind(const App::ObjectIdentifier &_path);
bool apply(const std::string &propName);
void setNumberExpression(App::NumberExpression*) override;
void bind(const App::ObjectIdentifier &_path) override;
bool apply(const std::string &propName) override;
using ExpressionSpinBox::apply;
public Q_SLOTS:
@@ -143,17 +143,17 @@ protected Q_SLOTS:
void handlePendingEmit(bool updateUnit = true);
protected:
virtual void setExpression(std::shared_ptr<App::Expression> expr);
virtual void openFormulaDialog();
virtual StepEnabled stepEnabled() const;
virtual void showEvent(QShowEvent * event);
virtual void hideEvent(QHideEvent * event);
virtual void closeEvent(QCloseEvent * event);
virtual void focusInEvent(QFocusEvent * event);
virtual void focusOutEvent(QFocusEvent * event);
virtual void keyPressEvent(QKeyEvent *event);
virtual void resizeEvent(QResizeEvent *event);
virtual void paintEvent(QPaintEvent *event);
void setExpression(std::shared_ptr<App::Expression> expr) override;
void openFormulaDialog() override;
StepEnabled stepEnabled() const override;
void showEvent(QShowEvent * event) override;
void hideEvent(QHideEvent * event) override;
void closeEvent(QCloseEvent * event) override;
void focusInEvent(QFocusEvent * event) override;
void focusOutEvent(QFocusEvent * event) override;
void keyPressEvent(QKeyEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void paintEvent(QPaintEvent *event) override;
private:
void validateInput();