2014-02-07 22:48:30 +01:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2014-02-07 22:48:30 +01:00
|
|
|
* Copyright (C) 2014 David Rosca <nowrep@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#ifndef BOOKMARKSMODEL_H
|
|
|
|
#define BOOKMARKSMODEL_H
|
|
|
|
|
|
|
|
#include <QAbstractItemModel>
|
2014-02-09 15:44:38 +01:00
|
|
|
#include <QSortFilterProxyModel>
|
2014-02-07 22:48:30 +01:00
|
|
|
|
2014-02-26 20:03:20 +01:00
|
|
|
#include "qzcommon.h"
|
2014-02-07 22:48:30 +01:00
|
|
|
|
2014-02-09 15:44:38 +01:00
|
|
|
class QTimer;
|
|
|
|
|
2014-02-07 22:48:30 +01:00
|
|
|
class Bookmarks;
|
|
|
|
class BookmarkItem;
|
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT BookmarksModel : public QAbstractItemModel
|
2014-02-07 22:48:30 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum Roles {
|
|
|
|
TypeRole = Qt::UserRole + 1,
|
|
|
|
UrlRole = Qt::UserRole + 2,
|
2014-02-09 15:44:38 +01:00
|
|
|
UrlStringRole = Qt::UserRole + 3,
|
|
|
|
TitleRole = Qt::UserRole + 4,
|
2016-12-11 10:24:10 +01:00
|
|
|
IconRole = Qt::UserRole + 5,
|
|
|
|
DescriptionRole = Qt::UserRole + 6,
|
|
|
|
KeywordRole = Qt::UserRole + 7,
|
|
|
|
VisitCountRole = Qt::UserRole + 8,
|
|
|
|
ExpandedRole = Qt::UserRole + 9,
|
|
|
|
SidebarExpandedRole = Qt::UserRole + 10,
|
2014-02-09 15:44:38 +01:00
|
|
|
MaxRole = SidebarExpandedRole
|
2014-02-07 22:48:30 +01:00
|
|
|
};
|
|
|
|
|
2014-02-14 21:13:08 +01:00
|
|
|
explicit BookmarksModel(BookmarkItem* root, Bookmarks* bookmarks, QObject* parent = 0);
|
2014-02-07 22:48:30 +01:00
|
|
|
|
|
|
|
void addBookmark(BookmarkItem* parent, int row, BookmarkItem* item);
|
|
|
|
void removeBookmark(BookmarkItem* item);
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
|
|
int rowCount(const QModelIndex &parent) const;
|
|
|
|
int columnCount(const QModelIndex &parent) const;
|
|
|
|
bool hasChildren(const QModelIndex &parent) const;
|
|
|
|
|
|
|
|
Qt::DropActions supportedDropActions() const;
|
|
|
|
QStringList mimeTypes() const;
|
|
|
|
QMimeData* mimeData(const QModelIndexList &indexes) const;
|
|
|
|
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
|
|
|
|
|
|
|
|
QModelIndex parent(const QModelIndex &child) const;
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
2014-02-09 15:07:19 +01:00
|
|
|
QModelIndex index(BookmarkItem* item, int column = 0) const;
|
2014-02-07 22:48:30 +01:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
BookmarkItem* item(const QModelIndex &index) const;
|
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
private Q_SLOTS:
|
2014-02-07 22:48:30 +01:00
|
|
|
void bookmarkChanged(BookmarkItem* item);
|
|
|
|
|
|
|
|
private:
|
2014-02-14 21:13:08 +01:00
|
|
|
BookmarkItem* m_root;
|
2014-02-07 22:48:30 +01:00
|
|
|
Bookmarks* m_bookmarks;
|
2014-02-09 15:44:38 +01:00
|
|
|
};
|
|
|
|
|
2017-08-25 17:11:29 +02:00
|
|
|
class FALKON_EXPORT BookmarksFilterModel : public QSortFilterProxyModel
|
2014-02-09 15:44:38 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit BookmarksFilterModel(QAbstractItemModel* parent);
|
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
public Q_SLOTS:
|
2014-02-09 15:44:38 +01:00
|
|
|
void setFilterFixedString(const QString &pattern);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
2014-02-07 22:48:30 +01:00
|
|
|
|
2018-02-25 13:33:07 +01:00
|
|
|
private Q_SLOTS:
|
2014-02-09 15:44:38 +01:00
|
|
|
void startFiltering();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_pattern;
|
|
|
|
QTimer* m_filterTimer;
|
2014-02-07 22:48:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BOOKMARKSMODEL_H
|