summaryrefslogtreecommitdiffstats
path: root/src/webengine/api/qquickwebenginehistory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/api/qquickwebenginehistory.cpp')
-rw-r--r--src/webengine/api/qquickwebenginehistory.cpp75
1 files changed, 62 insertions, 13 deletions
diff --git a/src/webengine/api/qquickwebenginehistory.cpp b/src/webengine/api/qquickwebenginehistory.cpp
index ffb857791..9a737fbbe 100644
--- a/src/webengine/api/qquickwebenginehistory.cpp
+++ b/src/webengine/api/qquickwebenginehistory.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
**
@@ -10,15 +10,15 @@
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
+** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl.html.
**
@@ -26,7 +26,7 @@
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
+** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
@@ -51,7 +51,24 @@ QQuickWebEngineHistoryListModelPrivate::~QQuickWebEngineHistoryListModelPrivate(
{
}
-WebContentsAdapter *QQuickWebEngineHistoryListModelPrivate::adapter() const
+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();
+}
+
+QtWebEngineCore::WebContentsAdapter *QQuickWebEngineHistoryListModelPrivate::adapter() const
{
return view->adapter.data();
}
@@ -63,6 +80,8 @@ QQuickWebEngineBackHistoryListModelPrivate::QQuickWebEngineBackHistoryListModelP
int QQuickWebEngineBackHistoryListModelPrivate::count() const
{
+ if (!adapter())
+ return -1;
return adapter()->currentNavigationEntryIndex();
}
@@ -72,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)
{
@@ -79,6 +103,8 @@ QQuickWebEngineForwardHistoryListModelPrivate::QQuickWebEngineForwardHistoryList
int QQuickWebEngineForwardHistoryListModelPrivate::count() const
{
+ if (!adapter())
+ return -1;
return adapter()->navigationEntryCount() - adapter()->currentNavigationEntryIndex() - 1;
}
@@ -87,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()
{
@@ -107,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;
}
@@ -124,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)
@@ -133,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();
}
@@ -143,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)
{
}
@@ -161,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();
}