on c8fd873 help sign in
unity8/tests/mocks/Unity/Notifications/MockNotificationModel.h
72 lines 2.1 kB history raw
1/*
2 * Copyright 2015 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 * Authors:
17 * Mirco Mueller <mirco.mueller@canonical.com>
18 */
20#ifndef MOCK_NOTIFICATION_MODEL_H
21#define MOCK_NOTIFICATION_MODEL_H
23#include <QAbstractListModel>
24#include <QSharedPointer>
25#include <QScopedPointer>
26#include "MockNotification.h"
28class MockNotification;
30class MockNotificationModel : public QAbstractListModel {
31 Q_OBJECT
32 Q_PROPERTY(int count READ getCount)
34public:
35 MockNotificationModel(QObject *parent=nullptr);
36 virtual ~MockNotificationModel();
38 int rowCount(const QModelIndex &parent) const override;
39 QVariant data(const QModelIndex &index, int role) const override;
40 QHash<int, QByteArray> roleNames() const override;
42 Q_INVOKABLE void append(MockNotification* n);
43 MockNotification* getNotification(int id) const;
45 // getRaw() is only meant to be used from QML, since QML cannot handle
46 // QSharedPointers... on C++-side only use getNotification()
47 Q_INVOKABLE MockNotification* getRaw(const int notificationId) const;
49 Q_INVOKABLE int queued() const;
50 Q_INVOKABLE void remove(const int id);
51 Q_INVOKABLE void removeSecond();
53 int getCount() const;
55Q_SIGNALS:
56 void actionInvoked(const QString &action);
58public Q_SLOTS:
59 void onCompleted(int id);
61private Q_SLOTS:
62 void onDataChanged(int id);
64Q_SIGNALS:
65 void queueSizeChanged(int newSize);
67private:
68 QList<MockNotification*> m_queue;
69 void removeInternal(int loc);
70};
72#endif