~uriboni/webbrowser-app/tab-context-menu

« back to all changes in this revision

Viewing changes to src/app/webbrowser/history-lastvisitdate-model.cpp

  • Committer: CI Train Bot
  • Author(s): Arthur Mello, Ugo Riboni, Olivier Tilloy
  • Date: 2015-08-12 19:53:13 UTC
  • mfrom: (1126.1.5 wide-views-newtab-history)
  • Revision ID: ci-train-bot@canonical.com-20150812195313-u5v7kzrj8hfiacsj
Wide screen versions of the history view and new tab view, per design specification.
This adds a build dependency on qml-module-qt-labs-settings (for unit tests). Fixes: #1351157, #1481647

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
4
 * This file is part of webbrowser-app.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
#include "history-lastvisitdate-model.h"
 
20
#include "history-model.h"
 
21
#include "history-timeframe-model.h"
 
22
 
 
23
// Qt
 
24
#include <QtCore/QUrl>
 
25
 
 
26
/*!
 
27
    \class HistoryLastVisitDateModel
 
28
    \brief Proxy model that filters the contents of a history model
 
29
           based on last visit date
 
30
 
 
31
    HistoryLastVisitDateModel is a proxy model that filters the contents
 
32
    of a history model based on the last visit date.
 
33
 
 
34
    An entry in the history model matches if the last visit date equals
 
35
    the filter visit date.
 
36
 
 
37
    When no visit date is set, all entries match.
 
38
*/
 
39
HistoryLastVisitDateModel::HistoryLastVisitDateModel(QObject* parent)
 
40
    : QSortFilterProxyModel(parent)
 
41
{
 
42
}
 
43
 
 
44
HistoryTimeframeModel* HistoryLastVisitDateModel::sourceModel() const
 
45
{
 
46
    return qobject_cast<HistoryTimeframeModel*>(QSortFilterProxyModel::sourceModel());
 
47
}
 
48
 
 
49
void HistoryLastVisitDateModel::setSourceModel(HistoryTimeframeModel* sourceModel)
 
50
{
 
51
    if (sourceModel != this->sourceModel()) {
 
52
        QSortFilterProxyModel::setSourceModel(sourceModel);
 
53
        Q_EMIT sourceModelChanged();
 
54
    }
 
55
}
 
56
 
 
57
const QDate& HistoryLastVisitDateModel::lastVisitDate() const
 
58
{
 
59
    return m_lastVisitDate;
 
60
}
 
61
 
 
62
void HistoryLastVisitDateModel::setLastVisitDate(const QDate& lastVisitDate)
 
63
{
 
64
    if (lastVisitDate != m_lastVisitDate) {
 
65
        m_lastVisitDate = lastVisitDate;
 
66
        invalidate();
 
67
        Q_EMIT lastVisitDateChanged();
 
68
    }
 
69
}
 
70
 
 
71
QVariantMap HistoryLastVisitDateModel::get(int i) const
 
72
{
 
73
    QVariantMap item;
 
74
    QHash<int, QByteArray> roles = roleNames();
 
75
 
 
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));
 
81
        }
 
82
    }
 
83
    return item;
 
84
}
 
85
 
 
86
bool HistoryLastVisitDateModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
 
87
{
 
88
    if (m_lastVisitDate.isNull()) {
 
89
        return true;
 
90
    }
 
91
    QModelIndex index = sourceModel()->index(source_row, 0, source_parent);
 
92
    return m_lastVisitDate == sourceModel()->data(index, HistoryModel::LastVisitDate).toDate();
 
93
}