forked from qt-creator/qt-creator
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: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -172,6 +172,13 @@ FancyLineEdit::FancyLineEdit(QWidget *parent) :
|
|||||||
|
|
||||||
FancyLineEdit::~FancyLineEdit()
|
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)
|
void FancyLineEdit::setButtonVisible(Side side, bool visible)
|
||||||
@@ -297,10 +304,12 @@ bool FancyLineEdit::hasAutoHideButton(Side side) const
|
|||||||
return d->m_iconbutton[side]->hasAutoHide();
|
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);
|
QTC_ASSERT(!d->m_historyCompleter, return);
|
||||||
d->m_historyCompleter = new HistoryCompleter(historyKey, this);
|
d->m_historyCompleter = new HistoryCompleter(historyKey, this);
|
||||||
|
if (restoreLastItemFromHistory)
|
||||||
|
setText(d->m_historyCompleter->historyItem());
|
||||||
QLineEdit::setCompleter(d->m_historyCompleter);
|
QLineEdit::setCompleter(d->m_historyCompleter);
|
||||||
|
|
||||||
// Hitting <Return> in the popup first causes editingFinished()
|
// Hitting <Return> in the popup first causes editingFinished()
|
||||||
|
@@ -114,7 +114,7 @@ public:
|
|||||||
// Completion
|
// Completion
|
||||||
|
|
||||||
// Enable a history completer with a history of entries.
|
// 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.
|
// Sets a completer that is not a history completer.
|
||||||
void setSpecialCompleter(QCompleter *completer);
|
void setSpecialCompleter(QCompleter *completer);
|
||||||
|
|
||||||
|
@@ -59,6 +59,8 @@ public:
|
|||||||
|
|
||||||
QStringList list;
|
QStringList list;
|
||||||
QString historyKey;
|
QString historyKey;
|
||||||
|
bool isLastItemEmpty;
|
||||||
|
QString historyKeyIsLastItemEmpty;
|
||||||
int maxLines;
|
int maxLines;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -149,8 +151,11 @@ void HistoryCompleterPrivate::clearHistory()
|
|||||||
void HistoryCompleterPrivate::addEntry(const QString &str)
|
void HistoryCompleterPrivate::addEntry(const QString &str)
|
||||||
{
|
{
|
||||||
const QString entry = str.trimmed();
|
const QString entry = str.trimmed();
|
||||||
if (entry.isEmpty())
|
if (entry.isEmpty()) {
|
||||||
|
isLastItemEmpty = true;
|
||||||
|
theSettings->setValue(historyKeyIsLastItemEmpty, isLastItemEmpty);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
int removeIndex = list.indexOf(entry);
|
int removeIndex = list.indexOf(entry);
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
if (removeIndex != -1)
|
if (removeIndex != -1)
|
||||||
@@ -159,6 +164,8 @@ void HistoryCompleterPrivate::addEntry(const QString &str)
|
|||||||
list = list.mid(0, maxLines - 1);
|
list = list.mid(0, maxLines - 1);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
theSettings->setValue(historyKey, list);
|
theSettings->setValue(historyKey, list);
|
||||||
|
isLastItemEmpty = false;
|
||||||
|
theSettings->setValue(historyKeyIsLastItemEmpty, isLastItemEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
|
HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
|
||||||
@@ -170,6 +177,9 @@ HistoryCompleter::HistoryCompleter(const QString &historyKey, QObject *parent)
|
|||||||
|
|
||||||
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->historyKeyIsLastItemEmpty = QLatin1String("CompleterHistory/")
|
||||||
|
+ historyKey + QLatin1String(".IsLastItemEmpty");
|
||||||
|
d->isLastItemEmpty = theSettings->value(d->historyKeyIsLastItemEmpty, false).toBool();
|
||||||
|
|
||||||
setModel(d);
|
setModel(d);
|
||||||
setPopup(new HistoryLineView(d));
|
setPopup(new HistoryLineView(d));
|
||||||
@@ -180,6 +190,13 @@ bool HistoryCompleter::removeHistoryItem(int index)
|
|||||||
return d->removeRow(index);
|
return d->removeRow(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString HistoryCompleter::historyItem() const
|
||||||
|
{
|
||||||
|
if (historySize() == 0 || d->isLastItemEmpty)
|
||||||
|
return QString();
|
||||||
|
return d->list.at(0);
|
||||||
|
}
|
||||||
|
|
||||||
HistoryCompleter::~HistoryCompleter()
|
HistoryCompleter::~HistoryCompleter()
|
||||||
{
|
{
|
||||||
delete d;
|
delete d;
|
||||||
|
@@ -51,6 +51,7 @@ public:
|
|||||||
static void setSettings(QSettings *settings);
|
static void setSettings(QSettings *settings);
|
||||||
HistoryCompleter(const QString &historyKey, QObject *parent = 0);
|
HistoryCompleter(const QString &historyKey, QObject *parent = 0);
|
||||||
bool removeHistoryItem(int index);
|
bool removeHistoryItem(int index);
|
||||||
|
QString historyItem() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~HistoryCompleter();
|
~HistoryCompleter();
|
||||||
|
@@ -139,7 +139,8 @@ DeviceProcessesDialogPrivate::DeviceProcessesDialogPrivate(KitChooser *chooser,
|
|||||||
processFilterLineEdit = new FancyLineEdit(q);
|
processFilterLineEdit = new FancyLineEdit(q);
|
||||||
processFilterLineEdit->setPlaceholderText(DeviceProcessesDialog::tr("Filter"));
|
processFilterLineEdit->setPlaceholderText(DeviceProcessesDialog::tr("Filter"));
|
||||||
processFilterLineEdit->setFocus(Qt::TabFocusReason);
|
processFilterLineEdit->setFocus(Qt::TabFocusReason);
|
||||||
processFilterLineEdit->setHistoryCompleter(QLatin1String("DeviceProcessDialogFilter"));
|
processFilterLineEdit->setHistoryCompleter(QLatin1String("DeviceProcessDialogFilter"),
|
||||||
|
true /*restoreLastItemFromHistory*/);
|
||||||
processFilterLineEdit->setFiltering(true);
|
processFilterLineEdit->setFiltering(true);
|
||||||
|
|
||||||
kitChooser->populate();
|
kitChooser->populate();
|
||||||
|
Reference in New Issue
Block a user