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
|
/* ============================================================
* rekonq
* ============================================================
* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
* ============================================================
* Description: rekonq bookmarks model
* ============================================================ */
#pragma once
#include "bookmarkstreeitem.hpp"
#include <QAbstractItemModel>
class BookmarksTreeModel final : public QAbstractItemModel {
Q_OBJECT
public:
enum Roles { CompletionMatchingRole = Qt::UserRole + 1 };
explicit BookmarksTreeModel(QObject *parent = nullptr);
~BookmarksTreeModel() final;
[[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
[[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
[[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
[[nodiscard]] int rowCount(const QModelIndex &index) const override;
bool removeRows(int position, int rows, const QModelIndex &parent) override;
[[nodiscard]] int columnCount(const QModelIndex &) const override { return 2; }
[[nodiscard]] Qt::DropActions supportedDropActions() const override { return Qt::MoveAction; }
[[nodiscard]] QStringList mimeTypes() const override { return {mimeType}; }
[[nodiscard]] QMimeData *mimeData(const QModelIndexList &indexes) const override;
bool dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column,
const QModelIndex &parent) override;
[[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent) const override;
[[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
[[nodiscard]] QModelIndex parentFolder(const QModelIndex &index) const;
[[nodiscard]] BookmarksTreeItem *item(const QModelIndex &index = QModelIndex()) const;
QModelIndex appendItem(BookmarksTreeItem::Types type, BookmarksTreeItem::Attributes_t data,
const QModelIndex &parent);
public slots:
QList<QString> load(QIODevice *buffer);
void save(QIODevice *buffer);
private:
const QLatin1String mimeType = QLatin1String("application/xbel");
BookmarksTreeItem *rootItem;
bool m_isModified = false;
};
|