Commit c34c5884 authored by Zavadovsky Yan's avatar Zavadovsky Yan

DeviceProcessDialog: restore last used processes filter

Restore behavior which was exist in Creator 3.1.2 stable version
and was broken after 3.2.0-beta1.

Change-Id: I18764b3fc93f78e980176597b59500affe9c7d02
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 5a75b87b
......@@ -172,6 +172,13 @@ FancyLineEdit::FancyLineEdit(QWidget *parent) :
FancyLineEdit::~FancyLineEdit()
{
if (d->m_historyCompleter) {
// When dialog with FancyLineEdit widget closed by <Escape>
// the QueuedConnection don't have enough time to call slot callback
// because edit widget and all of its connections are destroyed before
// QCoreApplicationPrivate::sendPostedEvents dispatch our queued signal.
d->m_historyCompleter->addEntry(text());
}
}
void FancyLineEdit::setButtonVisible(Side side, bool visible)
......@@ -297,10 +304,12 @@ bool FancyLineEdit::hasAutoHideButton(Side side) const
return d->m_iconbutton[side]->hasAutoHide();
}
void FancyLineEdit::setHistoryCompleter(const QString &historyKey)
void FancyLineEdit::setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory)
{
QTC_ASSERT(!d->m_historyCompleter, return);
d->m_historyCompleter = new HistoryCompleter(historyKey, this);
if (restoreLastItemFromHistory)
setText(d->m_historyCompleter->historyItem());
QLineEdit::setCompleter(d->m_historyCompleter);
// Hitting <Return> in the popup first causes editingFinished()
......
......@@ -114,7 +114,7 @@ public:
// Completion
// Enable a history completer with a history of entries.
void setHistoryCompleter(const QString &historyKey);
void setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory = false);
// Sets a completer that is not a history completer.
void setSpecialCompleter(QCompleter *completer);
......
......@@ -59,6 +59,8 @@ public:
QStringList list;
QString historyKey;
bool isLastItemEmpty;
QString historyKeyIsLastItemEmpty;
int maxLines;
};
......@@ -149,8 +151,11 @@ void HistoryCompleterPrivate::clearHistory()
void HistoryCompleterPrivate::addEntry(const QString &str)
{
const QString entry = str.trimmed();
if (entry.isEmpty())
if (entry.isEmpty()) {
isLastItemEmpty = true;
theSettings->setValue(historyKeyIsLastItemEmpty, isLastItemEmpty);
return;
}
int removeIndex = list.indexOf(entry);
beginResetModel();
if (removeIndex != -1)
......@@ -159,6 +164,8 @@ void HistoryCompleterPrivate::addEntry(const QString &str)
list = list.mid(0, maxLines - 1);
endResetModel();
theSettings->setValue(historyKey, list);
isLastItemEmpty = false;
theSettings->setValue(historyKeyIsLastItemEmpty, isLastItemEmpty);
}
HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
......@@ -170,6 +177,9 @@ HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
d->historyKey = QLatin1String("CompleterHistory/") + historyKey;
d->list = theSettings->value(d->historyKey).toStringList();
d->historyKeyIsLastItemEmpty = QLatin1String("CompleterHistory/")
+ historyKey + QLatin1String(".IsLastItemEmpty");
d->isLastItemEmpty = theSettings->value(d->historyKeyIsLastItemEmpty, false).toBool();
setModel(d);
setPopup(new HistoryLineView(d));
......@@ -180,6 +190,13 @@ bool HistoryCompleter::removeHistoryItem(int index)
return d->removeRow(index);
}
QString HistoryCompleter::historyItem() const
{
if (historySize() == 0 || d->isLastItemEmpty)
return QString();
return d->list.at(0);
}
HistoryCompleter::~HistoryCompleter()
{
delete d;
......
......@@ -51,6 +51,7 @@ public:
static void setSettings(QSettings *settings);
HistoryCompleter(const QString &historyKey, QObject *parent = 0);
bool removeHistoryItem(int index);
QString historyItem() const;
private:
~HistoryCompleter();
......
......@@ -139,7 +139,8 @@ DeviceProcessesDialogPrivate::DeviceProcessesDialogPrivate(KitChooser *chooser,
processFilterLineEdit = new FancyLineEdit(q);
processFilterLineEdit->setPlaceholderText(DeviceProcessesDialog::tr("Filter"));
processFilterLineEdit->setFocus(Qt::TabFocusReason);
processFilterLineEdit->setHistoryCompleter(QLatin1String("DeviceProcessDialogFilter"));
processFilterLineEdit->setHistoryCompleter(QLatin1String("DeviceProcessDialogFilter"),
true /*restoreLastItemFromHistory*/);
processFilterLineEdit->setFiltering(true);
kitChooser->populate();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment