Commit 903eeaf4 authored by hjk's avatar hjk
Browse files

fancylineedit: enforce conscious choice between history or special completer



Change-Id: Ia667895b619d0bb37561dce348adb7269df2fb9c
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent ec692943
......@@ -29,6 +29,8 @@
**************************************************************************/
#include "fancylineedit.h"
#include "historycompleter.h"
#include "qtcassert.h"
#include <QEvent>
#include <QDebug>
......@@ -97,7 +99,8 @@ enum { margin = 6 };
namespace Utils {
// --------- FancyLineEditPrivate
class FancyLineEditPrivate : public QObject {
class FancyLineEditPrivate : public QObject
{
public:
explicit FancyLineEditPrivate(FancyLineEdit *parent);
......@@ -109,12 +112,14 @@ public:
bool m_menuTabFocusTrigger[2];
IconButton *m_iconbutton[2];
bool m_iconEnabled[2];
HistoryCompleter *m_completer;
QString m_historyKey;
};
FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) :
QObject(parent),
m_lineEdit(parent)
QObject(parent), m_lineEdit(parent), m_completer(0)
{
for (int i = 0; i < 2; ++i) {
m_menu[i] = 0;
......@@ -298,6 +303,19 @@ bool FancyLineEdit::hasAutoHideButton(Side side) const
return d->m_iconbutton[side]->hasAutoHide();
}
void FancyLineEdit::setHistoryKey(const QString &historyKey)
{
QTC_ASSERT(!d->m_completer, return);
d->m_historyKey = historyKey;
d->m_completer = new HistoryCompleter(this, historyKey);
}
void FancyLineEdit::setSpecialCompleter(QCompleter *completer)
{
QTC_ASSERT(!d->m_completer, return);
QLineEdit::setCompleter(completer);
}
void FancyLineEdit::setAutoHideButton(Side side, bool h)
{
d->m_iconbutton[side]->setAutoHide(h);
......
......@@ -94,6 +94,12 @@ public:
void setAutoHideButton(Side side, bool h);
bool hasAutoHideButton(Side side) const;
// Enable a history completer with a history of entries.
void setHistoryKey(const QString &historyKey);
// Sets a completer that is not a history completer.
void setSpecialCompleter(QCompleter *completer);
signals:
void buttonClicked(Utils::FancyLineEdit::Side side);
void leftButtonClicked();
......@@ -107,6 +113,10 @@ protected:
virtual void resizeEvent(QResizeEvent *e);
private:
// Unimplemented, to force the user to make a decision on
// whether to use setHistoryKey() or setSpecialCompleter().
void setCompleter(QCompleter *);
void updateMargins();
void updateButtonPositions();
friend class Utils::FancyLineEditPrivate;
......
......@@ -213,8 +213,7 @@ StartApplicationDialog::StartApplicationDialog(QWidget *parent)
d->localExecutablePathChooser = new PathChooser(this);
d->localExecutablePathChooser->setExpectedKind(PathChooser::File);
d->localExecutablePathChooser->setPromptDialogTitle(tr("Select Executable"));
d->localExecutablePathChooser->lineEdit()->setCompleter(
new HistoryCompleter(d->localExecutablePathChooser->lineEdit(), QLatin1String("LocalExecutable")));
d->localExecutablePathChooser->lineEdit()->setHistoryKey(QLatin1String("LocalExecutable"));
d->arguments = new QLineEdit(this);
d->arguments->setCompleter(
......@@ -223,8 +222,7 @@ StartApplicationDialog::StartApplicationDialog(QWidget *parent)
d->workingDirectory = new PathChooser(this);
d->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
d->workingDirectory->setPromptDialogTitle(tr("Select Working Directory"));
d->workingDirectory->lineEdit()->setCompleter(
new HistoryCompleter(d->workingDirectory->lineEdit(), QLatin1String("WorkingDirectory")));
d->workingDirectory->lineEdit()->setHistoryKey(QLatin1String("WorkingDirectory"));
d->runInTerminalCheckBox = new QCheckBox(this);
......
......@@ -105,8 +105,8 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
m_findCompleter->setModel(m_plugin->findCompletionModel());
m_replaceCompleter->setModel(m_plugin->replaceCompletionModel());
m_ui.findEdit->setCompleter(m_findCompleter);
m_ui.replaceEdit->setCompleter(m_replaceCompleter);
m_ui.findEdit->setSpecialCompleter(m_findCompleter);
m_ui.replaceEdit->setSpecialCompleter(m_replaceCompleter);
QMenu *lineEditMenu = new QMenu(m_ui.findEdit);
m_ui.findEdit->setButtonMenu(Utils::FancyLineEdit::Left, lineEditMenu);
......
......@@ -65,7 +65,7 @@ FindToolWindow::FindToolWindow(FindPlugin *plugin, QWidget *parent)
connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates()));
m_findCompleter->setModel(m_plugin->findCompletionModel());
m_ui.searchTerm->setCompleter(m_findCompleter);
m_ui.searchTerm->setSpecialCompleter(m_findCompleter);
m_ui.searchTerm->installEventFilter(this);
QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(0);
......
......@@ -120,7 +120,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
m_queryModel->setStringList(m_parameters->savedQueries);
QCompleter *completer = new QCompleter(this);
completer->setModel(m_queryModel);
m_queryLineEdit->setCompleter(completer);
m_queryLineEdit->setSpecialCompleter(completer);
filterLayout->addWidget(queryLabel);
filterLayout->addWidget(m_queryLineEdit);
filterLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
......
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