Commit 08cc1e7d authored by hjk's avatar hjk
Browse files

historycompleter: make key explicit



Change-Id: I1560e379639a02a2decf46c4e6b015bd6042c6b7
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent ebad441d
......@@ -44,6 +44,8 @@
namespace Utils {
namespace Internal {
static QSettings *theSettings = 0;
class HistoryCompleterPrivate : public QAbstractListModel
{
public:
......@@ -61,7 +63,6 @@ public:
QString historyKey;
HistoryCompleter *completer;
QWidget *lastSeenWidget;
QSettings *settings;
int maxLines;
};
......@@ -114,20 +115,19 @@ HistoryCompleterPrivate::HistoryCompleterPrivate(HistoryCompleter *parent)
: QAbstractListModel(parent)
, completer(parent)
, lastSeenWidget(0)
, settings(0)
, maxLines(30)
{
}
void HistoryCompleterPrivate::fetchHistory()
{
QTC_ASSERT(settings, return);
QTC_ASSERT(theSettings, return);
if (!completer->widget()) {
list.clear();
reset();
return;
}
list = settings->value(historyKey).toStringList();
list = theSettings->value(historyKey).toStringList();
reset();
}
......@@ -165,7 +165,7 @@ bool HistoryCompleterPrivate::removeRows(int row, int count, const QModelIndex &
{
beginRemoveRows (parent, row, row + count);
list.removeAt(row);
settings->setValue(historyKey, list);
theSettings->setValue(historyKey, list);
endRemoveRows();
return true;
}
......@@ -178,6 +178,7 @@ void HistoryCompleterPrivate::clearHistory()
void HistoryCompleterPrivate::saveEntry(const QString &str)
{
QTC_ASSERT(theSettings, return);
if (str.isEmpty())
return;
if (list.contains(str))
......@@ -195,7 +196,7 @@ void HistoryCompleterPrivate::saveEntry(const QString &str)
list.prepend(str);
list = list.mid(0, maxLines);
endInsertRows();
settings->setValue(historyKey, list);
theSettings->setValue(historyKey, list);
}
bool HistoryCompleterPrivate::eventFilter(QObject *obj, QEvent *event)
......@@ -207,26 +208,21 @@ bool HistoryCompleterPrivate::eventFilter(QObject *obj, QEvent *event)
return QAbstractListModel::eventFilter(obj,event);
}
HistoryCompleter::HistoryCompleter(QSettings *settings, QObject *parent, const QString &historyKey)
HistoryCompleter::HistoryCompleter(QObject *parent, const QString &historyKey)
: QCompleter(parent)
, d(new HistoryCompleterPrivate(this))
{
QTC_ASSERT(settings, return);
d->settings = settings;
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
if (historyKey.isEmpty())
d->historyKey = parent->objectName();
else
d->historyKey = historyKey;
if (d->historyKey.isEmpty())
return;
d->historyKey = QLatin1String("CompleterHistory/") + d->historyKey;
d->historyKey = QLatin1String("CompleterHistory/") + historyKey;
parent->installEventFilter(d);
d->list = d->settings->value(d->historyKey).toStringList();
QTC_ASSERT(theSettings, return);
d->list = theSettings->value(d->historyKey).toStringList();
QLineEdit *l = qobject_cast<QLineEdit *>(parent);
if (l && d->list.count())
......@@ -269,4 +265,9 @@ void HistoryCompleter::saveHistory()
d->saveEntry(completionPrefix());
}
void HistoryCompleter::setSettings(QSettings *settings)
{
Internal::theSettings = settings;
}
} // namespace Utils
......@@ -48,13 +48,14 @@ class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
Q_OBJECT
public:
HistoryCompleter(QSettings *settings, QObject *parent,
const QString &historyKey = QString());
HistoryCompleter(QObject *parent, const QString &historyKey);
~HistoryCompleter();
int historySize() const;
int maximalHistorySize() const;
void setMaximalHistorySize(int numberOfEntries);
static void setSettings(QSettings *settings);
public Q_SLOTS:
void clearHistory();
void saveHistory();
......
......@@ -296,9 +296,8 @@ void CMakeRunPage::initWidgets()
// Run CMake Line (with arguments)
m_argumentsLineEdit = new QLineEdit(this);
m_argumentsLineEdit->setObjectName(QLatin1String("CMakeArgumentsLineEdit"));
m_argumentsLineEdit->setCompleter(
new Utils::HistoryCompleter(Core::ICore::settings(), m_argumentsLineEdit));
new Utils::HistoryCompleter(m_argumentsLineEdit, QLatin1String("CMakeArgumentsLineEdit")));
connect(m_argumentsLineEdit,SIGNAL(returnPressed()), this, SLOT(runCMake()));
fl->addRow(tr("Arguments:"), m_argumentsLineEdit);
......
......@@ -82,6 +82,7 @@
#include <coreplugin/icorelistener.h>
#include <coreplugin/inavigationwidgetfactory.h>
#include <coreplugin/settingsdatabase.h>
#include <utils/historycompleter.h>
#include <utils/pathchooser.h>
#include <utils/stylehelper.h>
#include <utils/stringutils.h>
......@@ -175,6 +176,8 @@ MainWindow::MainWindow() :
(void) new DocumentManager(this);
OutputPaneManager::create();
Utils::HistoryCompleter::setSettings(m_settings);
setWindowTitle(tr("Qt Creator"));
#ifndef Q_OS_MAC
QApplication::setWindowIcon(QIcon(QLatin1String(Constants::ICON_QTLOGO_128)));
......
......@@ -210,22 +210,21 @@ StartApplicationDialog::StartApplicationDialog(QWidget *parent)
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowTitle(tr("Start Debugger"));
QSettings *settings = ICore::settings();
d->localExecutablePathChooser = new PathChooser(this);
d->localExecutablePathChooser->setExpectedKind(PathChooser::File);
d->localExecutablePathChooser->setPromptDialogTitle(tr("Select Executable"));
d->localExecutablePathChooser->lineEdit()->setCompleter(
new HistoryCompleter(settings, d->localExecutablePathChooser->lineEdit()));
new HistoryCompleter(d->localExecutablePathChooser->lineEdit(), QLatin1String("LocalExecutable")));
d->arguments = new QLineEdit(this);
d->arguments->setCompleter(new HistoryCompleter(settings, d->arguments));
d->arguments->setCompleter(
new HistoryCompleter(d->arguments, QLatin1String("CommandlineArguments")));
d->workingDirectory = new PathChooser(this);
d->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
d->workingDirectory->setPromptDialogTitle(tr("Select Working Directory"));
d->workingDirectory->lineEdit()->setCompleter(
new HistoryCompleter(settings, d->workingDirectory->lineEdit()));
new HistoryCompleter(d->workingDirectory->lineEdit(), QLatin1String("WorkingDirectory")));
d->runInTerminalCheckBox = new QCheckBox(this);
......@@ -667,25 +666,24 @@ public:
StartRemoteEngineDialog::StartRemoteEngineDialog(QWidget *parent)
: QDialog(parent), d(new StartRemoteEngineDialogPrivate)
{
QSettings *settings = ICore::settings();
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setWindowTitle(tr("Start Remote Engine"));
d->host = new QLineEdit(this);
d->host->setText(QString());
d->host->setCompleter(new HistoryCompleter(settings, d->host));
d->host->setCompleter(new HistoryCompleter(d->host, QLatin1String("HostName")));
d->username = new QLineEdit(this);
d->username->setCompleter(new HistoryCompleter(settings, d->username));
d->username->setCompleter(new HistoryCompleter(d->username, QLatin1String("UserName")));
d->password = new QLineEdit(this);
d->password->setEchoMode(QLineEdit::Password);
d->enginePath = new QLineEdit(this);
d->enginePath->setCompleter(new HistoryCompleter(settings, d->enginePath));
d->enginePath->setCompleter(new HistoryCompleter(d->enginePath, QLatin1String("EnginePath")));
d->inferiorPath = new QLineEdit(this);
d->inferiorPath->setCompleter(new HistoryCompleter(settings, d->inferiorPath));
d->inferiorPath->setCompleter(new HistoryCompleter(d->inferiorPath, QLatin1String("InferiorPath")));
d->buttonBox = new QDialogButtonBox(this);
d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
......
......@@ -343,9 +343,7 @@ LogWindow::LogWindow(QWidget *parent)
m_commandLabel = new QLabel(tr("Command:"), this);
m_commandEdit = new QLineEdit(this);
m_commandEdit->setFrame(false);
m_commandEdit->setObjectName(QLatin1String("DebuggerInput"));
m_commandEdit->setCompleter(new Utils::HistoryCompleter(
Core::ICore::settings(), m_commandEdit));
m_commandEdit->setCompleter(new Utils::HistoryCompleter(m_commandEdit, QLatin1String("DebuggerInput")));
QHBoxLayout *commandBox = new QHBoxLayout;
commandBox->addWidget(m_commandLabel);
commandBox->addWidget(m_commandEdit);
......
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