forked from qt-creator/qt-creator
Don't use generic QSettings object.
We should always get the settings via Core interfaces to make sure it will keep working as expected. Change-Id: Ic3e68300ba2a2342a5d6e16ec6696710d7e6d98b Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -42,6 +42,8 @@
|
|||||||
#include <QtGui/QPainter>
|
#include <QtGui/QPainter>
|
||||||
#include <QtGui/QStyle>
|
#include <QtGui/QStyle>
|
||||||
|
|
||||||
|
static const char SETTINGS_PREFIX[] = "CompleterHistory/";
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class HistoryListModel : public QAbstractListModel
|
class HistoryListModel : public QAbstractListModel
|
||||||
@@ -94,15 +96,14 @@ HistoryListModel::HistoryListModel(HistoryCompleter *parent)
|
|||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, q(parent)
|
, q(parent)
|
||||||
, lastSeenWidget(0)
|
, lastSeenWidget(0)
|
||||||
, settings(new QSettings(parent))
|
, settings(0)
|
||||||
, maxLines(30)
|
, maxLines(30)
|
||||||
{
|
{
|
||||||
settings->beginGroup(QLatin1String("CompleterHistory"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryListModel::fetchHistory()
|
void HistoryListModel::fetchHistory()
|
||||||
{
|
{
|
||||||
if (!q->widget()) {
|
if (!q->widget() || !settings) {
|
||||||
list.clear();
|
list.clear();
|
||||||
reset();
|
reset();
|
||||||
return;
|
return;
|
||||||
@@ -110,7 +111,7 @@ void HistoryListModel::fetchHistory()
|
|||||||
QString objectName = q->widget()->objectName();
|
QString objectName = q->widget()->objectName();
|
||||||
if (objectName.isEmpty())
|
if (objectName.isEmpty())
|
||||||
return;
|
return;
|
||||||
list = settings->value(objectName).toStringList();
|
list = settings->value(QLatin1String(SETTINGS_PREFIX) + objectName).toStringList();
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,8 +149,11 @@ bool HistoryListModel::removeRows(int row, int count, const QModelIndex &parent)
|
|||||||
{
|
{
|
||||||
beginRemoveRows (parent, row, row + count);
|
beginRemoveRows (parent, row, row + count);
|
||||||
list.removeAt(row);
|
list.removeAt(row);
|
||||||
|
if (settings) {
|
||||||
QString objectName = q->widget()->objectName();
|
QString objectName = q->widget()->objectName();
|
||||||
settings->setValue(objectName, list);
|
settings->setValue(QLatin1String(SETTINGS_PREFIX) + objectName, list);
|
||||||
|
}
|
||||||
|
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -182,7 +186,8 @@ void HistoryListModel::saveEntry(const QString &str)
|
|||||||
list.prepend(str);
|
list.prepend(str);
|
||||||
list = list.mid(0, maxLines);
|
list = list.mid(0, maxLines);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
settings->setValue(objectName, list);
|
if (settings)
|
||||||
|
settings->setValue(QLatin1String(SETTINGS_PREFIX) + objectName, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HistoryListModel::eventFilter(QObject *obj, QEvent *event)
|
bool HistoryListModel::eventFilter(QObject *obj, QEvent *event)
|
||||||
@@ -195,10 +200,11 @@ bool HistoryListModel::eventFilter(QObject *obj, QEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HistoryCompleter::HistoryCompleter(QObject *parent)
|
HistoryCompleter::HistoryCompleter(QSettings *settings, QObject *parent)
|
||||||
: QCompleter(parent)
|
: QCompleter(parent)
|
||||||
, d_ptr(new HistoryCompleterPrivate(this))
|
, d_ptr(new HistoryCompleterPrivate(this))
|
||||||
{
|
{
|
||||||
|
d_ptr->model->settings = settings;
|
||||||
// make an assumption to allow pressing of the down
|
// make an assumption to allow pressing of the down
|
||||||
// key, before the first model run:
|
// key, before the first model run:
|
||||||
// parent is likely the lineedit
|
// parent is likely the lineedit
|
||||||
@@ -208,7 +214,10 @@ HistoryCompleter::HistoryCompleter(QObject *parent)
|
|||||||
QString objectName = p->objectName();
|
QString objectName = p->objectName();
|
||||||
if (objectName.isEmpty())
|
if (objectName.isEmpty())
|
||||||
return;
|
return;
|
||||||
d_ptr->model->list = d_ptr->model->settings->value(objectName).toStringList();
|
if (d_ptr->model->settings) {
|
||||||
|
d_ptr->model->list = d_ptr->model->settings->value(
|
||||||
|
QLatin1String(SETTINGS_PREFIX) + objectName).toStringList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QLineEdit *l = qobject_cast<QLineEdit *>(parent);
|
QLineEdit *l = qobject_cast<QLineEdit *>(parent);
|
||||||
@@ -222,12 +231,6 @@ HistoryCompleter::HistoryCompleter(QObject *parent)
|
|||||||
view->setItemDelegate(delegate);
|
view->setItemDelegate(delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings *HistoryCompleter::settings() const
|
|
||||||
{
|
|
||||||
Q_D(const HistoryCompleter);
|
|
||||||
return d->model->settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
int HistoryCompleter::historySize() const
|
int HistoryCompleter::historySize() const
|
||||||
{
|
{
|
||||||
Q_D(const HistoryCompleter);
|
Q_D(const HistoryCompleter);
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HistoryCompleter(QObject *parent = 0);
|
HistoryCompleter(QSettings *settings, QObject *parent);
|
||||||
QSettings *settings() const;
|
|
||||||
int historySize() const;
|
int historySize() const;
|
||||||
int maximalHistorySize() const;
|
int maximalHistorySize() const;
|
||||||
void setMaximalHistorySize(int numberOfEntries);
|
void setMaximalHistorySize(int numberOfEntries);
|
||||||
|
|||||||
@@ -444,21 +444,22 @@ void AttachExternalDialog::accept()
|
|||||||
StartExternalDialog::StartExternalDialog(QWidget *parent)
|
StartExternalDialog::StartExternalDialog(QWidget *parent)
|
||||||
: QDialog(parent), m_ui(new Ui::StartExternalDialog)
|
: QDialog(parent), m_ui(new Ui::StartExternalDialog)
|
||||||
{
|
{
|
||||||
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
m_ui->toolChainComboBox->init(true);
|
m_ui->toolChainComboBox->init(true);
|
||||||
m_ui->execFile->setExpectedKind(PathChooser::File);
|
m_ui->execFile->setExpectedKind(PathChooser::File);
|
||||||
m_ui->execFile->setPromptDialogTitle(tr("Select Executable"));
|
m_ui->execFile->setPromptDialogTitle(tr("Select Executable"));
|
||||||
m_ui->execFile->lineEdit()->setCompleter(
|
m_ui->execFile->lineEdit()->setCompleter(
|
||||||
new HistoryCompleter(m_ui->execFile->lineEdit()));
|
new HistoryCompleter(settings, m_ui->execFile->lineEdit()));
|
||||||
connect(m_ui->execFile, SIGNAL(changed(QString)), this, SLOT(changed()));
|
connect(m_ui->execFile, SIGNAL(changed(QString)), this, SLOT(changed()));
|
||||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
||||||
m_ui->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
|
m_ui->workingDirectory->setExpectedKind(PathChooser::ExistingDirectory);
|
||||||
m_ui->workingDirectory->setPromptDialogTitle(tr("Select Working Directory"));
|
m_ui->workingDirectory->setPromptDialogTitle(tr("Select Working Directory"));
|
||||||
m_ui->workingDirectory->lineEdit()->setCompleter(
|
m_ui->workingDirectory->lineEdit()->setCompleter(
|
||||||
new HistoryCompleter(m_ui->workingDirectory->lineEdit()));
|
new HistoryCompleter(settings, m_ui->workingDirectory->lineEdit()));
|
||||||
|
|
||||||
m_ui->argsEdit->setCompleter(new HistoryCompleter(m_ui->argsEdit));
|
m_ui->argsEdit->setCompleter(new HistoryCompleter(settings, m_ui->argsEdit));
|
||||||
|
|
||||||
connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
@@ -936,12 +937,13 @@ StartRemoteEngineDialog::StartRemoteEngineDialog(QWidget *parent) :
|
|||||||
QDialog(parent) ,
|
QDialog(parent) ,
|
||||||
m_ui(new Ui::StartRemoteEngineDialog)
|
m_ui(new Ui::StartRemoteEngineDialog)
|
||||||
{
|
{
|
||||||
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
m_ui->host->setCompleter(new HistoryCompleter(m_ui->host));
|
m_ui->host->setCompleter(new HistoryCompleter(settings, m_ui->host));
|
||||||
m_ui->username->setCompleter(new HistoryCompleter(m_ui->username));
|
m_ui->username->setCompleter(new HistoryCompleter(settings, m_ui->username));
|
||||||
m_ui->enginepath->setCompleter(new HistoryCompleter(m_ui->enginepath));
|
m_ui->enginepath->setCompleter(new HistoryCompleter(settings, m_ui->enginepath));
|
||||||
m_ui->inferiorpath->setCompleter(new HistoryCompleter(m_ui->inferiorpath));
|
m_ui->inferiorpath->setCompleter(new HistoryCompleter(settings, m_ui->inferiorpath));
|
||||||
connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
connect(m_ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||||
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
connect(m_ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
|
|
||||||
#include <aggregation/aggregate.h>
|
#include <aggregation/aggregate.h>
|
||||||
#include <coreplugin/findplaceholder.h>
|
#include <coreplugin/findplaceholder.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/minisplitter.h>
|
#include <coreplugin/minisplitter.h>
|
||||||
#include <find/basetextfind.h>
|
#include <find/basetextfind.h>
|
||||||
|
|
||||||
@@ -363,7 +364,8 @@ LogWindow::LogWindow(QWidget *parent)
|
|||||||
m_commandEdit = new QLineEdit(this);
|
m_commandEdit = new QLineEdit(this);
|
||||||
m_commandEdit->setFrame(false);
|
m_commandEdit->setFrame(false);
|
||||||
m_commandEdit->setObjectName("DebuggerInput");
|
m_commandEdit->setObjectName("DebuggerInput");
|
||||||
m_commandEdit->setCompleter(new Utils::HistoryCompleter(m_commandEdit));
|
m_commandEdit->setCompleter(new Utils::HistoryCompleter(
|
||||||
|
Core::ICore::instance()->settings(), m_commandEdit));
|
||||||
QHBoxLayout *commandBox = new QHBoxLayout;
|
QHBoxLayout *commandBox = new QHBoxLayout;
|
||||||
commandBox->addWidget(m_commandLabel);
|
commandBox->addWidget(m_commandLabel);
|
||||||
commandBox->addWidget(m_commandEdit);
|
commandBox->addWidget(m_commandEdit);
|
||||||
|
|||||||
Reference in New Issue
Block a user