File: recentitemsmodel.h

package info (click to toggle)
okular 4%3A25.04.2-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 36,108 kB
  • sloc: cpp: 81,483; ansic: 7,822; xml: 3,446; javascript: 435; java: 59; sh: 33; makefile: 11
file content (64 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download | duplicates (2)
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
/*
    SPDX-FileCopyrightText: 2021 Jiří Wolker <woljiri@gmail.com>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef RECENTITEMSMODEL_H
#define RECENTITEMSMODEL_H

#include <QAbstractListModel>
#include <QFileIconProvider>
#include <QList>
#include <QModelIndex>
#include <QString>
#include <QUrl>

class KConfigGroup;

/**
 * @todo write docs
 */
class RecentItemsModel : public QAbstractListModel
{
    Q_OBJECT

public:
    struct RecentItem {
        QString name;
        QUrl url;
    };

    /**
     * Default constructor
     */
    RecentItemsModel();

    /**
     * Destructor
     */
    ~RecentItemsModel() override;

    void loadEntries(const KConfigGroup &cg);
    void clearEntries();

    int maxItems() const
    {
        return m_maxItems;
    }

    RecentItemsModel::RecentItem const *getItem(const QModelIndex &) const;
    RecentItemsModel::RecentItem const *getItem(int index) const;

    // Model implementation:
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::ItemDataRole::DisplayRole) const override;

private:
    QList<RecentItemsModel::RecentItem> m_recentItems;

    int m_maxItems = 20;
    QFileIconProvider m_iconProvider;
};

#endif // RECENTITEMSMODEL_H