forked from qt-creator/qt-creator
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:
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user