Falkon Develop
Cross-platform Qt-based web browser
bookmarksmodel.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 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 BOOKMARKSMODEL_H
19#define BOOKMARKSMODEL_H
20
21#include <QAbstractItemModel>
22#include <QSortFilterProxyModel>
23#include <QMimeData>
24
25#include "qzcommon.h"
26
27class QTimer;
28
29class Bookmarks;
30class BookmarkItem;
31
32class FALKON_EXPORT BookmarksModel : public QAbstractItemModel
33{
34 Q_OBJECT
35
36public:
37 enum Roles {
38 TypeRole = Qt::UserRole + 1,
39 UrlRole = Qt::UserRole + 2,
40 UrlStringRole = Qt::UserRole + 3,
41 TitleRole = Qt::UserRole + 4,
42 IconRole = Qt::UserRole + 5,
43 DescriptionRole = Qt::UserRole + 6,
44 KeywordRole = Qt::UserRole + 7,
45 VisitCountRole = Qt::UserRole + 8,
46 ExpandedRole = Qt::UserRole + 9,
47 SidebarExpandedRole = Qt::UserRole + 10,
48 MaxRole = SidebarExpandedRole
49 };
50
51 explicit BookmarksModel(BookmarkItem* root, Bookmarks* bookmarks, QObject* parent = nullptr);
52
53 void addBookmark(BookmarkItem* parent, int row, BookmarkItem* item);
54 void removeBookmark(BookmarkItem* item);
55
56 Qt::ItemFlags flags(const QModelIndex &index) const override;
57 QVariant data(const QModelIndex &index, int role) const override;
58 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
59 int rowCount(const QModelIndex &parent) const override;
60 int columnCount(const QModelIndex &parent) const override;
61 bool hasChildren(const QModelIndex &parent) const override;
62
63 Qt::DropActions supportedDropActions() const override;
64 QStringList mimeTypes() const override;
65 QMimeData* mimeData(const QModelIndexList &indexes) const override;
66 bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
67
68 QModelIndex parent(const QModelIndex &child) const override;
69 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
70 QModelIndex index(BookmarkItem* item, int column = 0) const;
71
72 BookmarkItem* item(const QModelIndex &index) const;
73
74private Q_SLOTS:
75 void bookmarkChanged(BookmarkItem* item);
76
77private:
78 BookmarkItem* m_root;
79 Bookmarks* m_bookmarks;
80};
81
82class FALKON_EXPORT BookmarksFilterModel : public QSortFilterProxyModel
83{
84 Q_OBJECT
85
86public:
87 explicit BookmarksFilterModel(QAbstractItemModel* parent);
88
89public Q_SLOTS:
90 void setFilterFixedString(const QString &pattern);
91
92protected:
93 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
94
95private Q_SLOTS:
96 void startFiltering();
97
98private:
99 QString m_pattern;
100 QTimer* m_filterTimer;
101};
102
104{
105 Q_OBJECT
106
107public:
108 explicit BookmarksButtonMimeData();
109
110 BookmarkItem *item() const;
111 void setBookmarkItem(BookmarkItem *item);
112
113 bool hasFormat(const QString &format) const override;
114 QStringList formats() const override;
115
116 static QString mimeType();
117
118private:
119 BookmarkItem* m_item;
120};
121
122#endif // BOOKMARKSMODEL_H
#define FALKON_EXPORT
Definition: qzcommon.h:28