on cfcde21 help sign in
unity8/tests/mocks/Unity/Notifications/MockNotificationModel.h
70 lines 2.0 kB history raw
1/*
2 * Copyright 2015-2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
18#ifndef MOCK_NOTIFICATION_MODEL_H
19#define MOCK_NOTIFICATION_MODEL_H
21#include <QAbstractListModel>
22#include <QSharedPointer>
23#include <QScopedPointer>
24#include "MockNotification.h"
26class MockNotification;
28class MockNotificationModel : public QAbstractListModel {
29 Q_OBJECT
30 Q_PROPERTY(int count READ getCount)
32public:
33 MockNotificationModel(QObject *parent=nullptr);
34 virtual ~MockNotificationModel();
36 int rowCount(const QModelIndex &parent) const override;
37 QVariant data(const QModelIndex &index, int role) const override;
38 QHash<int, QByteArray> roleNames() const override;
40 Q_INVOKABLE void append(MockNotification* n);
41 MockNotification* getNotification(int id) const;
43 // getRaw() is only meant to be used from QML, since QML cannot handle
44 // QSharedPointers... on C++-side only use getNotification()
45 Q_INVOKABLE MockNotification* getRaw(const int notificationId) const;
47 Q_INVOKABLE int queued() const;
48 Q_INVOKABLE void remove(const int id);
49 Q_INVOKABLE void removeFirst();
51 int getCount() const;
53Q_SIGNALS:
54 void actionInvoked(const QString &action);
56public Q_SLOTS:
57 void onCompleted(int id);
59private Q_SLOTS:
60 void onDataChanged(int id);
62Q_SIGNALS:
63 void queueSizeChanged(int newSize);
65private:
66 QList<MockNotification*> m_queue;
67 void removeInternal(int loc);
68};
70#endif