forked from qt-creator/qt-creator
historycompleter: fix user experience
Make it actually remember things and allow completion if lineedit is not empty. Change-Id: Iccec6de94a8a304773dbb679e06fc68e2e496376 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -50,7 +50,7 @@ static QSettings *theSettings = 0;
|
|||||||
class HistoryCompleterPrivate : public QAbstractListModel
|
class HistoryCompleterPrivate : public QAbstractListModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HistoryCompleterPrivate() : maxLines(30) {}
|
HistoryCompleterPrivate() : maxLines(30), lineEdit(0) {}
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||||
@@ -62,6 +62,7 @@ public:
|
|||||||
QStringList list;
|
QStringList list;
|
||||||
QString historyKey;
|
QString historyKey;
|
||||||
int maxLines;
|
int maxLines;
|
||||||
|
QLineEdit *lineEdit;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HistoryLineDelegate : public QItemDelegate
|
class HistoryLineDelegate : public QItemDelegate
|
||||||
@@ -166,12 +167,15 @@ HistoryCompleter::HistoryCompleter(QLineEdit *lineEdit, const QString &historyKe
|
|||||||
|
|
||||||
d->historyKey = QLatin1String("CompleterHistory/") + historyKey;
|
d->historyKey = QLatin1String("CompleterHistory/") + historyKey;
|
||||||
d->list = theSettings->value(d->historyKey).toStringList();
|
d->list = theSettings->value(d->historyKey).toStringList();
|
||||||
|
d->lineEdit = lineEdit;
|
||||||
if (d->list.count())
|
if (d->list.count())
|
||||||
lineEdit->setText(d->list.at(0));
|
lineEdit->setText(d->list.at(0));
|
||||||
|
|
||||||
setModel(d);
|
setModel(d);
|
||||||
setPopup(new HistoryLineView(d));
|
setPopup(new HistoryLineView(d));
|
||||||
lineEdit->installEventFilter(this);
|
lineEdit->installEventFilter(this);
|
||||||
|
|
||||||
|
connect(lineEdit, SIGNAL(editingFinished()), this, SLOT(saveHistory()));
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryCompleter::~HistoryCompleter()
|
HistoryCompleter::~HistoryCompleter()
|
||||||
@@ -181,9 +185,9 @@ HistoryCompleter::~HistoryCompleter()
|
|||||||
|
|
||||||
bool HistoryCompleter::eventFilter(QObject *obj, QEvent *event)
|
bool HistoryCompleter::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::KeyPress &&
|
if (event->type() == QEvent::KeyPress
|
||||||
static_cast<QKeyEvent *>(event)->key() == Qt::Key_Down &&
|
&& static_cast<QKeyEvent *>(event)->key() == Qt::Key_Down
|
||||||
static_cast<QLineEdit *>(widget())->text().isEmpty()) {
|
&& !popup()->isVisible()) {
|
||||||
setCompletionPrefix(QString());
|
setCompletionPrefix(QString());
|
||||||
complete();
|
complete();
|
||||||
}
|
}
|
||||||
@@ -212,7 +216,7 @@ void HistoryCompleter::clearHistory()
|
|||||||
|
|
||||||
void HistoryCompleter::saveHistory()
|
void HistoryCompleter::saveHistory()
|
||||||
{
|
{
|
||||||
d->saveEntry(completionPrefix());
|
d->saveEntry(d->lineEdit->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryCompleter::setSettings(QSettings *settings)
|
void HistoryCompleter::setSettings(QSettings *settings)
|
||||||
|
Reference in New Issue
Block a user