summaryrefslogtreecommitdiffstats
path: root/src/webengine/api/qquickwebenginehistory.cpp
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@theqtcompany.com>2015-02-12 20:17:40 +0100
committerPierre Rossi <pierre.rossi@theqtcompany.com>2015-02-18 13:17:45 +0000
commit6717d58192a9e4fb87b4721a34f3715766863851 (patch)
tree9014acec9ccde3cd2c36a89725ed8bbb215f0d82 /src/webengine/api/qquickwebenginehistory.cpp
parent4bac2cb5084c68354e43fb456e4d20d4f70b223a (diff)
Move navigationHistory out of experimental
Add an offset role to the models. Implement goBackAndForward that uses this offset. Also add a complete model, items, that includes current navigation entry (at offset 0) to allow for the Firefox-style single menu, and add that one to the nano browser example. The models are now instantiated lazily as it's unlikely the three models will be used by the same app. Change-Id: Ib551738611497c7eb9c501f045cda315968a2ada Reviewed-by: Andras Becsi <andras.becsi@theqtcompany.com>
Diffstat (limited to 'src/webengine/api/qquickwebenginehistory.cpp')
-rw-r--r--src/webengine/api/qquickwebenginehistory.cpp55
1 files changed, 50 insertions, 5 deletions
diff --git a/src/webengine/api/qquickwebenginehistory.cpp b/src/webengine/api/qquickwebenginehistory.cpp
index f8c354eac..3b6d7bb2f 100644
--- a/src/webengine/api/qquickwebenginehistory.cpp
+++ b/src/webengine/api/qquickwebenginehistory.cpp
@@ -51,6 +51,23 @@ QQuickWebEngineHistoryListModelPrivate::~QQuickWebEngineHistoryListModelPrivate(
{
}
+int QQuickWebEngineHistoryListModelPrivate::count() const
+{
+ if (!adapter())
+ return -1;
+ return adapter()->navigationEntryCount();
+}
+
+int QQuickWebEngineHistoryListModelPrivate::index(int index) const
+{
+ return index;
+}
+
+int QQuickWebEngineHistoryListModelPrivate::offsetForIndex(int index) const
+{
+ return index - adapter()->currentNavigationEntryIndex();
+}
+
WebContentsAdapter *QQuickWebEngineHistoryListModelPrivate::adapter() const
{
return view->adapter.data();
@@ -74,6 +91,11 @@ int QQuickWebEngineBackHistoryListModelPrivate::index(int i) const
return count() - 1 - i;
}
+int QQuickWebEngineBackHistoryListModelPrivate::offsetForIndex(int index) const
+{
+ return - index - 1;
+}
+
QQuickWebEngineForwardHistoryListModelPrivate::QQuickWebEngineForwardHistoryListModelPrivate(QQuickWebEngineViewPrivate *view)
: QQuickWebEngineHistoryListModelPrivate(view)
{
@@ -91,6 +113,11 @@ int QQuickWebEngineForwardHistoryListModelPrivate::index(int i) const
return adapter()->currentNavigationEntryIndex() + i + 1;
}
+int QQuickWebEngineForwardHistoryListModelPrivate::offsetForIndex(int index) const
+{
+ return index + 1;
+}
+
QQuickWebEngineHistoryListModel::QQuickWebEngineHistoryListModel()
: QAbstractListModel()
{
@@ -111,6 +138,7 @@ QHash<int, QByteArray> QQuickWebEngineHistoryListModel::roleNames() const
QHash<int, QByteArray> roles;
roles[QQuickWebEngineHistory::UrlRole] = "url";
roles[QQuickWebEngineHistory::TitleRole] = "title";
+ roles[QQuickWebEngineHistory::OffsetRole] = "offset";
return roles;
}
@@ -128,7 +156,7 @@ QVariant QQuickWebEngineHistoryListModel::data(const QModelIndex &index, int rol
if (!index.isValid())
return QVariant();
- if (role < QQuickWebEngineHistory::UrlRole || role > QQuickWebEngineHistory::TitleRole)
+ if (role < QQuickWebEngineHistory::UrlRole || role > QQuickWebEngineHistory::OffsetRole)
return QVariant();
if (role == QQuickWebEngineHistory::UrlRole)
@@ -137,6 +165,8 @@ QVariant QQuickWebEngineHistoryListModel::data(const QModelIndex &index, int rol
if (role == QQuickWebEngineHistory::TitleRole)
return QString(d->adapter()->getNavigationEntryTitle(d->index(index.row())));
+ if (role == QQuickWebEngineHistory::OffsetRole)
+ return d->offsetForIndex(index.row());
return QVariant();
}
@@ -147,8 +177,7 @@ void QQuickWebEngineHistoryListModel::reset()
}
QQuickWebEngineHistoryPrivate::QQuickWebEngineHistoryPrivate(QQuickWebEngineViewPrivate *view)
- : m_backNavigationModel(new QQuickWebEngineHistoryListModel(new QQuickWebEngineBackHistoryListModelPrivate(view)))
- , m_forwardNavigationModel(new QQuickWebEngineHistoryListModel(new QQuickWebEngineForwardHistoryListModelPrivate(view)))
+ : m_view(view)
{
}
@@ -165,23 +194,39 @@ QQuickWebEngineHistory::~QQuickWebEngineHistory()
{
}
+QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::items() const
+{
+ Q_D(const QQuickWebEngineHistory);
+ if (!d->m_navigationModel)
+ d->m_navigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineHistoryListModelPrivate(d->m_view)));
+ return d->m_navigationModel.data();
+}
+
QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::backItems() const
{
Q_D(const QQuickWebEngineHistory);
+ if (!d->m_backNavigationModel)
+ d->m_backNavigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineBackHistoryListModelPrivate(d->m_view)));
return d->m_backNavigationModel.data();
}
QQuickWebEngineHistoryListModel *QQuickWebEngineHistory::forwardItems() const
{
Q_D(const QQuickWebEngineHistory);
+ if (!d->m_forwardNavigationModel)
+ d->m_forwardNavigationModel.reset(new QQuickWebEngineHistoryListModel(new QQuickWebEngineForwardHistoryListModelPrivate(d->m_view)));
return d->m_forwardNavigationModel.data();
}
void QQuickWebEngineHistory::reset()
{
Q_D(QQuickWebEngineHistory);
- d->m_backNavigationModel->reset();
- d->m_forwardNavigationModel->reset();
+ if (d->m_navigationModel)
+ d->m_navigationModel->reset();
+ if (d->m_backNavigationModel)
+ d->m_backNavigationModel->reset();
+ if (d->m_forwardNavigationModel)
+ d->m_forwardNavigationModel->reset();
}