| 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 |
*/ |
| 17 |
|
| 18 |
#ifndef MOCK_NOTIFICATION_MODEL_H |
| 19 |
#define MOCK_NOTIFICATION_MODEL_H |
| 20 |
|
| 21 |
#include <QAbstractListModel> |
| 22 |
#include <QSharedPointer> |
| 23 |
#include <QScopedPointer> |
| 24 |
#include "MockNotification.h" |
| 25 |
|
| 26 |
class MockNotification; |
| 27 |
|
| 28 |
class MockNotificationModel : public QAbstractListModel { |
| 29 |
Q_OBJECT |
| 30 |
Q_PROPERTY(int count READ getCount) |
| 31 |
|
| 32 |
public: |
| 33 |
MockNotificationModel(QObject *parent=nullptr); |
| 34 |
virtual ~MockNotificationModel(); |
| 35 |
|
| 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; |
| 39 |
|
| 40 |
Q_INVOKABLE void append(MockNotification* n); |
| 41 |
MockNotification* getNotification(int id) const; |
| 42 |
|
| 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; |
| 46 |
|
| 47 |
Q_INVOKABLE int queued() const; |
| 48 |
Q_INVOKABLE void remove(const int id); |
| 49 |
Q_INVOKABLE void removeFirst(); |
| 50 |
|
| 51 |
int getCount() const; |
| 52 |
|
| 53 |
Q_SIGNALS: |
| 54 |
void actionInvoked(const QString &action); |
| 55 |
|
| 56 |
public Q_SLOTS: |
| 57 |
void onCompleted(int id); |
| 58 |
|
| 59 |
private Q_SLOTS: |
| 60 |
void onDataChanged(int id); |
| 61 |
|
| 62 |
Q_SIGNALS: |
| 63 |
void queueSizeChanged(int newSize); |
| 64 |
|
| 65 |
private: |
| 66 |
QList<MockNotification*> m_queue; |
| 67 |
void removeInternal(int loc); |
| 68 |
}; |
| 69 |
|
| 70 |
#endif |