Falkon Develop
Cross-platform Qt-based web browser
historymodel.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program 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#ifndef HISTORYMODEL_H
19#define HISTORYMODEL_H
20
21#include <QAbstractItemModel>
22#include <QSortFilterProxyModel>
23
24#include "qzcommon.h"
25#include "history.h"
26
27class QTimer;
28
29class History;
30class HistoryItem;
31
32class FALKON_EXPORT HistoryModel : public QAbstractItemModel
33{
34 Q_OBJECT
35public:
36 enum Roles {
37 IdRole = Qt::UserRole + 1,
38 TitleRole = Qt::UserRole + 2,
39 UrlRole = Qt::UserRole + 3,
40 UrlStringRole = Qt::UserRole + 4,
41 IconRole = Qt::UserRole + 5,
42 IsTopLevelRole = Qt::UserRole + 7,
43 TimestampStartRole = Qt::UserRole + 8,
44 TimestampEndRole = Qt::UserRole + 9,
45 MaxRole = TimestampEndRole
46 };
47
48 explicit HistoryModel(History* history);
49
50 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
51 QVariant data(const QModelIndex &index, int role) const override;
52 bool setData(const QModelIndex &index, const QVariant &value, int role) override;
53
54 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
55 QModelIndex parent(const QModelIndex &child) const override;
56 Qt::ItemFlags flags(const QModelIndex &index) const override;
57
58 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
59 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
60
61 bool canFetchMore(const QModelIndex &parent) const override;
62 void fetchMore(const QModelIndex &parent) override;
63
64 bool hasChildren(const QModelIndex &parent) const override;
65
66 HistoryItem* itemFromIndex(const QModelIndex &index) const;
67
68 void removeTopLevelIndexes(const QList<QPersistentModelIndex> &indexes);
69
70private Q_SLOTS:
71 void resetHistory();
72
73 void historyEntryAdded(const HistoryEntry &entry);
74 void historyEntryDeleted(const HistoryEntry &entry);
75 void historyEntryEdited(const HistoryEntry &before, const HistoryEntry &after);
76
77private:
78 HistoryItem* findHistoryItem(const HistoryEntry &entry);
79 void checkEmptyParentItem(HistoryItem* item);
80 void init();
81
82 HistoryItem* m_rootItem;
83 HistoryItem* m_todayItem;
84 History* m_history;
85};
86
87class FALKON_EXPORT HistoryFilterModel : public QSortFilterProxyModel
88{
89 Q_OBJECT
90public:
91 explicit HistoryFilterModel(QAbstractItemModel* parent);
92 bool isPatternEmpty() const;
93
94public Q_SLOTS:
95 void setFilterFixedString(const QString &pattern);
96
97Q_SIGNALS:
100
101protected:
102 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
103
104private Q_SLOTS:
105 void startFiltering();
106
107private:
108 QString m_pattern;
109 QTimer* m_filterTimer;
110};
111
112#endif // HISTORYMODEL_H
int value(const QColor &c)
Definition: colors.cpp:238
#define FALKON_EXPORT
Definition: qzcommon.h:28
Definition: history.h:39