PathChooser: Move setTextKeepingActiveCursor() to FancyLineEdit

We want to re-use it elsewhere.

Change-Id: Iadb03e2e85bc25f9111a8817170b9ec1f2f0a7b1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2019-02-07 14:11:31 +01:00
parent d122049aee
commit 72cb9e26a1
3 changed files with 13 additions and 11 deletions

View File

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

View File

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

View File

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