diff --git a/src/libs/utils/fancylineedit.cpp b/src/libs/utils/fancylineedit.cpp index 2cebbce64ca..6b5b11995ce 100644 --- a/src/libs/utils/fancylineedit.cpp +++ b/src/libs/utils/fancylineedit.cpp @@ -27,6 +27,7 @@ #include "fancylineedit.h" #include "historycompleter.h" #include "hostosinfo.h" +#include "optional.h" #include "qtcassert.h" #include "stylehelper.h" #include "utilsicons.h" @@ -175,6 +176,14 @@ FancyLineEdit::~FancyLineEdit() } } +void FancyLineEdit::setTextKeepingActiveCursor(const QString &text) +{ + optional cursor = hasFocus() ? make_optional(cursorPosition()) : nullopt; + setText(text); + if (cursor) + setCursorPosition(*cursor); +} + void FancyLineEdit::setButtonVisible(Side side, bool visible) { d->m_iconbutton[side]->setVisible(visible); diff --git a/src/libs/utils/fancylineedit.h b/src/libs/utils/fancylineedit.h index 3f40d93df26..fd0b121d88d 100644 --- a/src/libs/utils/fancylineedit.h +++ b/src/libs/utils/fancylineedit.h @@ -82,6 +82,8 @@ public: explicit FancyLineEdit(QWidget *parent = nullptr); ~FancyLineEdit() override; + void setTextKeepingActiveCursor(const QString &text); + QIcon buttonIcon(Side side) const; void setButtonIcon(Side side, const QIcon &icon); diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 45600b7aa1d..e29b0c76632 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -26,7 +26,6 @@ #include "pathchooser.h" #include "environment.h" -#include "optional.h" #include "qtcassert.h" #include "macroexpander.h" @@ -348,22 +347,14 @@ QString PathChooser::expandedDirectory(const QString &input, const Environment & return path; } -void setTextKeepingActiveCursor(QLineEdit *edit, const QString &text) -{ - optional cursor = edit->hasFocus() ? make_optional(edit->cursorPosition()) : nullopt; - edit->setText(text); - if (cursor) - edit->setCursorPosition(*cursor); -} - void PathChooser::setPath(const QString &path) { - setTextKeepingActiveCursor(d->m_lineEdit, QDir::toNativeSeparators(path)); + d->m_lineEdit->setTextKeepingActiveCursor(QDir::toNativeSeparators(path)); } void PathChooser::setFileName(const FileName &fn) { - setTextKeepingActiveCursor(d->m_lineEdit, fn.toUserOutput()); + d->m_lineEdit->setTextKeepingActiveCursor(fn.toUserOutput()); } void PathChooser::setErrorColor(const QColor &errorColor)