~gerboland/unity/8-refactor-wm-and-test

« back to all changes in this revision

Viewing changes to tests/qmltests/plugins/Ubuntu/ChewieUI/fake_pluginmodel.h

  • Committer: Michał Sawicz
  • Date: 2013-06-05 22:03:08 UTC
  • Revision ID: michal.sawicz@canonical.com-20130605220308-yny8fv3futtr04fg
Inital unity8 commit.

Previous history can be found at https://code.launchpad.net/~unity-team/unity/phablet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2012 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
 *      Renato Araujo Oliveira Filho <renato@canonical.com>
 
18
 */
 
19
 
 
20
#ifndef PLUGINMODEL_H
 
21
#define PLUGINMODEL_H
 
22
 
 
23
#include <QAbstractListModel>
 
24
#include <QQmlEngine>
 
25
 
 
26
 
 
27
class WidgetsMap : public QObject
 
28
{
 
29
    Q_OBJECT
 
30
public:
 
31
    WidgetsMap(QObject *parent=0)
 
32
    : QObject(parent)
 
33
    {}
 
34
 
 
35
    void append(QMap<QString, QUrl> types)
 
36
    {
 
37
        Q_FOREACH(QString key, types.keys()) {
 
38
            m_map.insert(key, types[key]);
 
39
        }
 
40
    }
 
41
    void clear() { m_map.clear(); }
 
42
 
 
43
    Q_INVOKABLE QMap<QString, QUrl> map() const { return m_map; }
 
44
    Q_INVOKABLE QUrl find(const QString &widget) const { return m_map[widget]; }
 
45
 
 
46
private:
 
47
    QMap<QString, QUrl> m_map;
 
48
};
 
49
 
 
50
 
 
51
class PluginModel : public QAbstractListModel
 
52
{
 
53
    Q_OBJECT
 
54
    Q_PROPERTY(WidgetsMap* widgetsMap READ widgetsMap NOTIFY widgetsMapChanged)
 
55
    Q_PROPERTY(int count READ count NOTIFY countChanged)
 
56
 
 
57
public:
 
58
    enum ModelRoles {
 
59
        Title = 0,
 
60
        IconSource,
 
61
        Label,
 
62
        Description,
 
63
        QMLComponent,
 
64
        InitialProperties,
 
65
        IsValid
 
66
    };
 
67
 
 
68
    PluginModel(QObject *parent=0);
 
69
    ~PluginModel();
 
70
 
 
71
    WidgetsMap* widgetsMap() const;
 
72
 
 
73
    Q_INVOKABLE void load();
 
74
    Q_INVOKABLE void unload();
 
75
 
 
76
    Q_INVOKABLE QVariantMap get(int row) const;
 
77
 
 
78
    /* QAbstractItemModel */
 
79
    QHash<int, QByteArray> roleNames() const;
 
80
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
 
81
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
 
82
    QModelIndex parent (const QModelIndex &index) const;
 
83
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
 
84
 
 
85
Q_SIGNALS:
 
86
    void widgetsMapChanged(WidgetsMap *widgetsMap);
 
87
    void countChanged();
 
88
 
 
89
private:
 
90
    WidgetsMap* m_widgetsMap;
 
91
    int count() const;
 
92
};
 
93
 
 
94
#endif