From db3b35cb5ded23f79684211a454ac29bf0726bea Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Sat, 13 Feb 2021 02:24:23 +0100 Subject: [PATCH] Gui: Minor cleanup Cleans up code which was touched in previous commit. * Don't call popup() twice when not needed * use nullptr instead of 0 for pointers --- src/Gui/ExpressionCompleter.cpp | 18 +++++++++--------- src/Gui/ExpressionCompleter.h | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Gui/ExpressionCompleter.cpp b/src/Gui/ExpressionCompleter.cpp index b153a7ce73..15b99eed2c 100644 --- a/src/Gui/ExpressionCompleter.cpp +++ b/src/Gui/ExpressionCompleter.cpp @@ -473,8 +473,8 @@ void ExpressionCompleter::slotUpdate(const QString & prefix, int pos) // No tokens if (tokens.size() == 0) { - if (popup()) - popup()->setVisible(false); + if (auto p = popup()) + p->setVisible(false); return; } @@ -520,8 +520,8 @@ void ExpressionCompleter::slotUpdate(const QString & prefix, int pos) // Not an unclosed string and the last character is a space if(!stringing && prefix.size() && prefix[prefixEnd-1] == QChar(32)) { - if (popup()) - popup()->setVisible(false); + if (auto p = popup()) + p->setVisible(false); return; } @@ -560,14 +560,14 @@ void ExpressionCompleter::slotUpdate(const QString & prefix, int pos) if (!completionPrefix.empty() && widget()->hasFocus()) complete(); else { - if (popup()) - popup()->setVisible(false); + if (auto p = popup()) + p->setVisible(false); } } ExpressionLineEdit::ExpressionLineEdit(QWidget *parent, bool noProperty, bool requireLeadingEqualSign) : QLineEdit(parent) - , completer(0) + , completer(nullptr) , block(true) , noProperty(noProperty) , exactMatch(false) @@ -681,7 +681,7 @@ void ExpressionLineEdit::contextMenuEvent(QContextMenuEvent *event) ExpressionTextEdit::ExpressionTextEdit(QWidget *parent) : QPlainTextEdit(parent) - , completer(0) + , completer(nullptr) , block(true) , exactMatch(false) { @@ -703,7 +703,7 @@ void ExpressionTextEdit::setDocumentObject(const App::DocumentObject * currentDo return; } - if (currentDocObj != 0) { + if (currentDocObj != nullptr) { completer = new ExpressionCompleter(currentDocObj, this); #if QT_VERSION>=QT_VERSION_CHECK(5,2,0) if (!exactMatch) diff --git a/src/Gui/ExpressionCompleter.h b/src/Gui/ExpressionCompleter.h index fc01d20517..70169bb792 100644 --- a/src/Gui/ExpressionCompleter.h +++ b/src/Gui/ExpressionCompleter.h @@ -51,7 +51,7 @@ class GuiExport ExpressionCompleter : public QCompleter Q_OBJECT public: ExpressionCompleter(const App::DocumentObject * currentDocObj, - QObject *parent = 0, bool noProperty = false); + QObject *parent = nullptr, bool noProperty = false); void getPrefixRange(int &start, int &end) const { start = prefixStart; @@ -87,7 +87,7 @@ private: class GuiExport ExpressionLineEdit : public QLineEdit { Q_OBJECT public: - ExpressionLineEdit(QWidget *parent = 0, bool noProperty = false, bool requireLeadingEqualSign = false); + ExpressionLineEdit(QWidget *parent = nullptr, bool noProperty = false, bool requireLeadingEqualSign = false); void setDocumentObject(const App::DocumentObject *currentDocObj); bool completerActive() const; void hideCompleter(); @@ -112,7 +112,7 @@ private: class GuiExport ExpressionTextEdit : public QPlainTextEdit { Q_OBJECT public: - ExpressionTextEdit(QWidget *parent = 0); + ExpressionTextEdit(QWidget *parent = nullptr); void setDocumentObject(const App::DocumentObject *currentDocObj); bool completerActive() const; void hideCompleter();