2
* Copyright 2015 Canonical Ltd.
4
* This file is part of webbrowser-app.
6
* webbrowser-app is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* webbrowser-app is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "history-lastvisitdate-model.h"
20
#include "history-model.h"
21
#include "history-timeframe-model.h"
24
#include <QtCore/QUrl>
27
\class HistoryLastVisitDateModel
28
\brief Proxy model that filters the contents of a history model
29
based on last visit date
31
HistoryLastVisitDateModel is a proxy model that filters the contents
32
of a history model based on the last visit date.
34
An entry in the history model matches if the last visit date equals
35
the filter visit date.
37
When no visit date is set, all entries match.
39
HistoryLastVisitDateModel::HistoryLastVisitDateModel(QObject* parent)
40
: QSortFilterProxyModel(parent)
44
HistoryTimeframeModel* HistoryLastVisitDateModel::sourceModel() const
46
return qobject_cast<HistoryTimeframeModel*>(QSortFilterProxyModel::sourceModel());
49
void HistoryLastVisitDateModel::setSourceModel(HistoryTimeframeModel* sourceModel)
51
if (sourceModel != this->sourceModel()) {
52
QSortFilterProxyModel::setSourceModel(sourceModel);
53
Q_EMIT sourceModelChanged();
57
const QDate& HistoryLastVisitDateModel::lastVisitDate() const
59
return m_lastVisitDate;
62
void HistoryLastVisitDateModel::setLastVisitDate(const QDate& lastVisitDate)
64
if (lastVisitDate != m_lastVisitDate) {
65
m_lastVisitDate = lastVisitDate;
67
Q_EMIT lastVisitDateChanged();
71
QVariantMap HistoryLastVisitDateModel::get(int i) const
74
QHash<int, QByteArray> roles = roleNames();
76
QModelIndex modelIndex = index(i, 0);
77
if (modelIndex.isValid()) {
78
Q_FOREACH(int role, roles.keys()) {
79
QString roleName = QString::fromUtf8(roles.value(role));
80
item.insert(roleName, data(modelIndex, role));
86
bool HistoryLastVisitDateModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
88
if (m_lastVisitDate.isNull()) {
91
QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
92
return m_lastVisitDate == sourceModel()->data(index, HistoryModel::LastVisitDate).toDate();