aboutsummaryrefslogtreecommitdiff
path: root/lib/bookmarks/bookmarksmodel.h
blob: 79bd9ce5e0606b4730cb5f8bc7040395729da909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * This file is part of smolbote. It's copyrighted by the contributors recorded
 * in the version control history of the file, available from its original
 * location: git://neueland.iserlohn-fortress.net/smolbote.git
 *
 * SPDX-License-Identifier: GPL-3.0
 */

#include "bookmarkitem.h"
#include "xbel.h"
#include <QAbstractItemModel>
#include <QIcon>
#include <QTreeView>

#ifndef BOOKMARKSMODEL_H
#define BOOKMARKSMODEL_H

class QStyle;
class BookmarksModel : public QAbstractItemModel
{
    Q_OBJECT

public:
    enum {
        OpenUrlRole = Qt::UserRole + 1
    };

    explicit BookmarksModel(QStyle *style, QObject *parent = nullptr);
    ~BookmarksModel() override;

    bool isModified() const;

    bool read(Xbel *xbel);
    bool write(Xbel *xbel);

    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    QModelIndex index(BookmarkItem *node, int column = 0) const;
    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
    QModelIndex parent(const QModelIndex &index) const override;

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QModelIndex insertItem(BookmarkItem::BookmarkItemType type, const QModelIndex &parent);

    int columnCount(const QModelIndex &parent = QModelIndex()) const override;

    Qt::ItemFlags flags(const QModelIndex &index) const override;
    QVariant data(const QModelIndex &index, int role) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;

    bool hasChildren(const QModelIndex &parent) const override;

    QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const override;

    void expandItems(QTreeView *view, BookmarkItem *root = nullptr);

private:
    QIcon folderIcon;
    QIcon bookmarkIcon;
    bool modified = false;

    BookmarkItem *m_rootItem;
};

#endif //BOOKMARKSMODEL_H