Commit 88f5949e authored by hjk's avatar hjk
Browse files

close down history completer interface



Change-Id: Iaeff40be410d1f0facd687632c9ce4897eb2e613
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 903eeaf4
......@@ -114,7 +114,6 @@ public:
bool m_iconEnabled[2];
HistoryCompleter *m_completer;
QString m_historyKey;
};
......@@ -306,8 +305,8 @@ bool FancyLineEdit::hasAutoHideButton(Side side) const
void FancyLineEdit::setHistoryKey(const QString &historyKey)
{
QTC_ASSERT(!d->m_completer, return);
d->m_historyKey = historyKey;
d->m_completer = new HistoryCompleter(this, historyKey);
QLineEdit::setCompleter(d->m_completer);
}
void FancyLineEdit::setSpecialCompleter(QCompleter *completer)
......
......@@ -29,6 +29,7 @@
**************************************************************************/
#include "historycompleter.h"
#include "qtcassert.h"
#include <QAbstractListModel>
......@@ -49,20 +50,17 @@ static QSettings *theSettings = 0;
class HistoryCompleterPrivate : public QAbstractListModel
{
public:
HistoryCompleterPrivate(HistoryCompleter *parent);
HistoryCompleterPrivate() : maxLines(30) {}
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
void fetchHistory();
void clearHistory();
void saveEntry(const QString &str);
bool eventFilter(QObject *obj, QEvent *event);
QStringList list;
QString historyKey;
HistoryCompleter *completer;
QWidget *lastSeenWidget;
int maxLines;
};
......@@ -86,9 +84,13 @@ public:
class HistoryLineView : public QListView
{
public:
HistoryLineView(HistoryCompleterPrivate *model_, int pixmapWith_)
: model(model_) , pixmapWidth(pixmapWith_)
{}
HistoryLineView(HistoryCompleterPrivate *model_)
: model(model_)
{
HistoryLineDelegate *delegate = new HistoryLineDelegate;
pixmapWidth = delegate->pixmap.width();
setItemDelegate(delegate);
}
private:
void mousePressEvent(QMouseEvent *event)
......@@ -111,45 +113,9 @@ private:
using namespace Internal;
HistoryCompleterPrivate::HistoryCompleterPrivate(HistoryCompleter *parent)
: QAbstractListModel(parent)
, completer(parent)
, lastSeenWidget(0)
, maxLines(30)
{
}
void HistoryCompleterPrivate::fetchHistory()
{
QTC_ASSERT(theSettings, return);
if (!completer->widget()) {
list.clear();
reset();
return;
}
list = theSettings->value(historyKey).toStringList();
reset();
}
int HistoryCompleterPrivate::rowCount(const QModelIndex &parent) const
{
if (lastSeenWidget != completer->widget()) {
if (lastSeenWidget)
lastSeenWidget->removeEventFilter(const_cast<HistoryCompleterPrivate *>(this));
completer->widget()->installEventFilter(const_cast<HistoryCompleterPrivate *>(this));
if (qobject_cast<QLineEdit *>(lastSeenWidget))
// this will result in spamming the history with garbage in some corner cases.
// not my idea.
disconnect(lastSeenWidget, SIGNAL(editingFinished()), completer, SLOT(saveHistory()));
HistoryCompleterPrivate *that = const_cast<HistoryCompleterPrivate *>(this);
that->lastSeenWidget = completer->widget();
that->fetchHistory();
if (qobject_cast<QLineEdit *>(lastSeenWidget))
connect(lastSeenWidget, SIGNAL(editingFinished()), completer, SLOT(saveHistory()));
}
if (parent.isValid())
return 0;
return list.count();
return parent.isValid() ? 0 : list.count();
}
QVariant HistoryCompleterPrivate::data(const QModelIndex &index, int role) const
......@@ -183,15 +149,6 @@ void HistoryCompleterPrivate::saveEntry(const QString &str)
return;
if (list.contains(str))
return;
if (!completer->widget())
return;
if (lastSeenWidget != completer->widget()) {
if (lastSeenWidget)
lastSeenWidget->removeEventFilter(this);
completer->widget()->installEventFilter(this);
fetchHistory();
lastSeenWidget = completer->widget();
}
beginInsertRows (QModelIndex(), list.count(), list.count());
list.prepend(str);
list = list.mid(0, maxLines);
......@@ -199,40 +156,21 @@ void HistoryCompleterPrivate::saveEntry(const QString &str)
theSettings->setValue(historyKey, list);
}
bool HistoryCompleterPrivate::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress && static_cast<QKeyEvent *>(event)->key() == Qt::Key_Down) {
completer->setCompletionPrefix(QString());
completer->complete();
}
return QAbstractListModel::eventFilter(obj,event);
}
HistoryCompleter::HistoryCompleter(QObject *parent, const QString &historyKey)
: QCompleter(parent)
, d(new HistoryCompleterPrivate(this))
HistoryCompleter::HistoryCompleter(QLineEdit *lineEdit, const QString &historyKey)
: d(new HistoryCompleterPrivate)
{
QTC_ASSERT(lineEdit, return);
QTC_ASSERT(!historyKey.isEmpty(), return);
// make an assumption to allow pressing of the down
// key, before the first model run:
// parent is likely the lineedit
QTC_ASSERT(theSettings, return);
d->historyKey = QLatin1String("CompleterHistory/") + historyKey;
parent->installEventFilter(d);
QTC_ASSERT(theSettings, return);
d->list = theSettings->value(d->historyKey).toStringList();
QLineEdit *l = qobject_cast<QLineEdit *>(parent);
if (l && d->list.count())
l->setText(d->list.at(0));
if (d->list.count())
lineEdit->setText(d->list.at(0));
setModel(d);
HistoryLineDelegate *delegate = new HistoryLineDelegate;
HistoryLineView *view = new HistoryLineView(d, delegate->pixmap.width());
setPopup(view);
view->setItemDelegate(delegate);
setPopup(new HistoryLineView(d));
lineEdit->installEventFilter(this);
}
HistoryCompleter::~HistoryCompleter()
......@@ -240,6 +178,15 @@ HistoryCompleter::~HistoryCompleter()
delete d;
}
bool HistoryCompleter::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress && static_cast<QKeyEvent *>(event)->key() == Qt::Key_Down) {
setCompletionPrefix(QString());
complete();
}
return QCompleter::eventFilter(obj, event);
}
int HistoryCompleter::historySize() const
{
return d->rowCount();
......
......@@ -36,11 +36,11 @@
#include <QCompleter>
QT_BEGIN_NAMESPACE
class QLineEdit;
class QSettings;
QT_END_NAMESPACE
namespace Utils {
namespace Internal { class HistoryCompleterPrivate; }
class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
......@@ -48,13 +48,15 @@ class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
Q_OBJECT
public:
HistoryCompleter(QObject *parent, const QString &historyKey);
static void setSettings(QSettings *settings);
HistoryCompleter(QLineEdit *lineEdit, const QString &historyKey);
private:
~HistoryCompleter();
int historySize() const;
int maximalHistorySize() const;
void setMaximalHistorySize(int numberOfEntries);
static void setSettings(QSettings *settings);
bool eventFilter(QObject *obj, QEvent *event);
public Q_SLOTS:
void clearHistory();
......
......@@ -33,7 +33,7 @@
#include <coreplugin/icore.h>
#include <utils/pathchooser.h>
#include <utils/historycompleter.h>
#include <utils/fancylineedit.h>
#include <projectexplorer/profileinformation.h>
#include <projectexplorer/profilemanager.h>
#include <projectexplorer/toolchain.h>
......@@ -295,9 +295,8 @@ void CMakeRunPage::initWidgets()
}
// Run CMake Line (with arguments)
m_argumentsLineEdit = new QLineEdit(this);
m_argumentsLineEdit->setCompleter(
new Utils::HistoryCompleter(m_argumentsLineEdit, QLatin1String("CMakeArgumentsLineEdit")));
m_argumentsLineEdit = new Utils::FancyLineEdit(this);
m_argumentsLineEdit->setHistoryKey(QLatin1String("CMakeArgumentsLineEdit"));
connect(m_argumentsLineEdit,SIGNAL(returnPressed()), this, SLOT(runCMake()));
fl->addRow(tr("Arguments:"), m_argumentsLineEdit);
......
......@@ -42,7 +42,8 @@
#include <QPlainTextEdit>
namespace Utils {
class PathChooser;
class FancyLineEdit;
class PathChooser;
}
namespace ProjectExplorer {
......@@ -144,7 +145,7 @@ private:
QPlainTextEdit *m_output;
QPushButton *m_runCMake;
Utils::QtcProcess *m_cmakeProcess;
QLineEdit *m_argumentsLineEdit;
Utils::FancyLineEdit *m_argumentsLineEdit;
Utils::PathChooser *m_cmakeExecutable;
QComboBox *m_generatorComboBox;
QLabel *m_descriptionLabel;
......
......@@ -57,7 +57,7 @@
#include <utils/savedaction.h>
#include <utils/fileutils.h>
#include <utils/historycompleter.h>
#include <utils/fancylineedit.h>
namespace Debugger {
namespace Internal {
......@@ -341,9 +341,9 @@ LogWindow::LogWindow(QWidget *parent)
QSizePolicy::MinimumExpanding);
m_commandLabel = new QLabel(tr("Command:"), this);
m_commandEdit = new QLineEdit(this);
m_commandEdit = new Utils::FancyLineEdit(this);
m_commandEdit->setFrame(false);
m_commandEdit->setCompleter(new Utils::HistoryCompleter(m_commandEdit, QLatin1String("DebuggerInput")));
m_commandEdit->setHistoryKey(QLatin1String("DebuggerInput"));
QHBoxLayout *commandBox = new QHBoxLayout;
commandBox->addWidget(m_commandLabel);
commandBox->addWidget(m_commandEdit);
......
......@@ -43,6 +43,8 @@ class QLineEdit;
class QPlainTextEdit;
QT_END_NAMESPACE
namespace Utils { class FancyLineEdit; }
namespace Debugger {
namespace Internal {
......@@ -84,7 +86,7 @@ private:
DebuggerPane *m_inputText; // scriptable input alone
QTimer m_outputTimer;
QString m_queuedOutput;
QLineEdit *m_commandEdit;
Utils::FancyLineEdit *m_commandEdit;
QLabel *m_commandLabel;
bool m_ignoreNextInputEcho;
};
......
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