~unity-team/unity8/slim-greeter

« back to all changes in this revision

Viewing changes to tests/mocks/Unity/Notifications/MockNotificationModel.h

  • Committer: Michael Terry
  • Date: 2015-02-12 15:45:21 UTC
  • mfrom: (1432.1.178 unity8)
  • Revision ID: michael.terry@canonical.com-20150212154521-1qpg3t501ljj88lj
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

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