PlasmaActivities

activitiesmodel.h
1/*
2 SPDX-FileCopyrightText: 2012, 2013, 2014 Ivan Cukic <ivan.cukic(at)kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#ifndef ACTIVITIES_ACTIVITIESMODEL_H
8#define ACTIVITIES_ACTIVITIESMODEL_H
9
10// Qt
11#include <QAbstractListModel>
12#include <QObject>
13
14// STL
15#include <memory>
16
17// Local
18#include "info.h"
19
20class QModelIndex;
22
23namespace KActivities
24{
25class ActivitiesModelPrivate;
26
27/**
28 * Data model that shows existing activities
29 */
30class PLASMA_ACTIVITIES_EXPORT ActivitiesModel : public QAbstractListModel
31{
33
34 Q_PROPERTY(QList<Info::State> shownStates READ shownStates WRITE setShownStates NOTIFY shownStatesChanged)
35
36public:
37 explicit ActivitiesModel(QObject *parent = nullptr);
38
39 /**
40 * Constructs the model and sets the shownStates
41 */
42 ActivitiesModel(QList<Info::State> shownStates, QObject *parent = nullptr);
43 ~ActivitiesModel() override;
44
45 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
46
47 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
48
49 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
50
51 QHash<int, QByteArray> roleNames() const override;
52
53 enum Roles {
54 ActivityId = Qt::UserRole, ///< UUID of the activity
55 ActivityName = Qt::UserRole + 1, ///< Activity name
56 ActivityDescription = Qt::UserRole + 2, ///< Activity description
57 ActivityIconSource = Qt::UserRole + 3, ///< Activity icon source name
58 ActivityState = Qt::UserRole + 4, ///< The current state of the activity @see Info::State
59 ActivityBackground = Qt::UserRole + 5, ///< Activity wallpaper (currently unsupported)
60 ActivityIsCurrent = Qt::UserRole + 6, ///< Is this activity the current one current
61
62 UserRole = Qt::UserRole + 32, ///< To be used by models that inherit this one
63 };
64
65public Q_SLOTS:
66 /**
67 * The model can filter the list of activities based on their state.
68 * This method sets which states should be shown.
69 */
70 void setShownStates(const QList<Info::State> &shownStates);
71
72 /**
73 * The model can filter the list of activities based on their state.
74 * This method returns which states are currently shown.
75 */
76 QList<Info::State> shownStates() const;
77
78Q_SIGNALS:
79 void shownStatesChanged(const QList<Info::State> &state);
80
81private:
82 friend class ActivitiesModelPrivate;
83 const std::unique_ptr<ActivitiesModelPrivate> d;
84};
85
86} // namespace KActivities
87
88#endif // ACTIVITIES_ACTIVITIESMODEL_H
void setShownStates(const QList< Info::State > &shownStates)
The model can filter the list of activities based on their state.
@ ActivityState
The current state of the activity.
@ UserRole
To be used by models that inherit this one.
@ ActivityDescription
Activity description.
@ ActivityIsCurrent
Is this activity the current one current.
@ ActivityId
UUID of the activity.
@ ActivityIconSource
Activity icon source name.
@ ActivityBackground
Activity wallpaper (currently unsupported)
Namespace for everything in libkactivities.
virtual QModelIndex parent(const QModelIndex &index) const const=0
QAbstractListModel(QObject *parent)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
DisplayRole
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 12:01:06 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.