summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhjk <qthjk@ovi.com>2012-08-22 15:08:38 +0200
committerhjk <qthjk@ovi.com>2012-08-23 10:57:18 +0200
commiteaee72c4afbbec907ffe6f358c2785ebf07ae7ad (patch)
tree43228f1e89a9b980beb4b2595bc52b2a1eb434f9 /src
parentc685abebafe7e08428b3f88e0a8d317ec33a3ace (diff)
downloadqt-creator-eaee72c4afbbec907ffe6f358c2785ebf07ae7ad.tar.gz
historycompleter: even less use of object names.
This allows history to be shared between similar but different line edits. Change-Id: I6ddaa686f99cf0d89e9be024ccb006d179a6bd1c Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'src')
-rw-r--r--src/libs/utils/historycompleter.cpp43
-rw-r--r--src/libs/utils/historycompleter.h11
2 files changed, 20 insertions, 34 deletions
diff --git a/src/libs/utils/historycompleter.cpp b/src/libs/utils/historycompleter.cpp
index c2c2719e4a..470cd83f15 100644
--- a/src/libs/utils/historycompleter.cpp
+++ b/src/libs/utils/historycompleter.cpp
@@ -29,19 +29,18 @@
**************************************************************************/
#include "historycompleter.h"
+#include "qtcassert.h"
#include <QAbstractListModel>
#include <QSettings>
-#include <QLineEdit>
-#include <QKeyEvent>
#include <QItemDelegate>
+#include <QKeyEvent>
+#include <QLineEdit>
#include <QListView>
#include <QPainter>
#include <QStyle>
-static const char SETTINGS_PREFIX[] = "CompleterHistory/";
-
namespace Utils {
namespace Internal {
@@ -59,7 +58,7 @@ public:
bool eventFilter(QObject *obj, QEvent *event);
QStringList list;
- QByteArray historyKey;
+ QString historyKey;
HistoryCompleter *completer;
QWidget *lastSeenWidget;
QSettings *settings;
@@ -122,15 +121,13 @@ HistoryCompleterPrivate::HistoryCompleterPrivate(HistoryCompleter *parent)
void HistoryCompleterPrivate::fetchHistory()
{
- if (!completer->widget() || !settings) {
+ QTC_ASSERT(settings, return);
+ if (!completer->widget()) {
list.clear();
reset();
return;
}
- QString objectName = completer->widget()->objectName();
- if (objectName.isEmpty())
- return;
- list = settings->value(QLatin1String(SETTINGS_PREFIX) + objectName).toStringList();
+ list = settings->value(historyKey).toStringList();
reset();
}
@@ -168,11 +165,7 @@ bool HistoryCompleterPrivate::removeRows(int row, int count, const QModelIndex &
{
beginRemoveRows (parent, row, row + count);
list.removeAt(row);
- if (settings) {
- QString objectName = completer->widget()->objectName();
- settings->setValue(QLatin1String(SETTINGS_PREFIX) + objectName, list);
- }
-
+ settings->setValue(historyKey, list);
endRemoveRows();
return true;
}
@@ -198,15 +191,11 @@ void HistoryCompleterPrivate::saveEntry(const QString &str)
fetchHistory();
lastSeenWidget = completer->widget();
}
- QString objectName = completer->widget()->objectName();
- if (objectName.isEmpty())
- return;
beginInsertRows (QModelIndex(), list.count(), list.count());
list.prepend(str);
list = list.mid(0, maxLines);
endInsertRows();
- if (settings)
- settings->setValue(QLatin1String(SETTINGS_PREFIX) + objectName, list);
+ settings->setValue(historyKey, list);
}
bool HistoryCompleterPrivate::eventFilter(QObject *obj, QEvent *event)
@@ -218,28 +207,26 @@ bool HistoryCompleterPrivate::eventFilter(QObject *obj, QEvent *event)
return QAbstractListModel::eventFilter(obj,event);
}
-HistoryCompleter::HistoryCompleter(QSettings *settings, QObject *parent, const QByteArray &historyKey)
+HistoryCompleter::HistoryCompleter(QSettings *settings, QObject *parent, const QString &historyKey)
: QCompleter(parent)
, d(new HistoryCompleterPrivate(this))
{
+ QTC_ASSERT(settings, return);
d->settings = settings;
// 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().toLatin1();
+ d->historyKey = parent->objectName();
else
d->historyKey = historyKey;
if (d->historyKey.isEmpty())
return;
+ d->historyKey = QLatin1String("CompleterHistory/") + d->historyKey;
- QWidget *p = qobject_cast<QWidget *>(parent);
- if (p) {
- p->installEventFilter(d);
- if (d->settings)
- d->list = d->settings->value(QLatin1String(SETTINGS_PREFIX) + d->historyKey).toStringList();
- }
+ parent->installEventFilter(d);
+ d->list = d->settings->value(d->historyKey).toStringList();
QLineEdit *l = qobject_cast<QLineEdit *>(parent);
if (l && d->list.count())
diff --git a/src/libs/utils/historycompleter.h b/src/libs/utils/historycompleter.h
index b1b97dd01b..3827eced31 100644
--- a/src/libs/utils/historycompleter.h
+++ b/src/libs/utils/historycompleter.h
@@ -35,13 +35,13 @@
#include <QCompleter>
-QT_FORWARD_DECLARE_CLASS(QSettings)
+QT_BEGIN_NAMESPACE
+class QSettings;
+QT_END_NAMESPACE
namespace Utils {
-namespace Internal {
- class HistoryCompleterPrivate;
-}
+namespace Internal { class HistoryCompleterPrivate; }
class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
{
@@ -49,7 +49,7 @@ class QTCREATOR_UTILS_EXPORT HistoryCompleter : public QCompleter
public:
HistoryCompleter(QSettings *settings, QObject *parent,
- const QByteArray &historyKey = QByteArray());
+ const QString &historyKey = QString());
~HistoryCompleter();
int historySize() const;
int maximalHistorySize() const;
@@ -61,7 +61,6 @@ public Q_SLOTS:
private:
Internal::HistoryCompleterPrivate *d;
-
};
} // namespace Utils