on 3f5d08f help sign in
unity8/plugins/Unity/Indicators/flatmenuproxymodel.h
91 lines 2.9 kB history raw
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 */
20#ifndef FLATMENUPROXYMODEL_H
21#define FLATMENUPROXYMODEL_H
23#include <QAbstractProxyModel>
24#include <qdbusmenumodel.h>
26class SectionInfo;
28class FlatMenuProxyModel : public QAbstractProxyModel
30 Q_OBJECT
31 Q_PROPERTY(int count READ count NOTIFY countChanged)
32 Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged)
33 Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged)
34 Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged)
35 Q_PROPERTY(int status READ status NOTIFY statusChanged)
37 Q_ENUMS(Roles)
38public:
39 FlatMenuProxyModel(QAbstractItemModel *source=0);
40 ~FlatMenuProxyModel();
42 void setSourceModel(QAbstractItemModel * sourceModel);
44 Q_INVOKABLE QVariant data(int row, int role = Qt::DisplayRole) const;
46 QModelIndex mapFromSource(const QModelIndex &index) const;
47 QModelIndex mapToSource(const QModelIndex &index) const;
49 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
50 QModelIndex parent(const QModelIndex &index) const;
51 int rowCount(const QModelIndex &parent = QModelIndex()) const;
52 int count() const;
53 int columnCount(const QModelIndex &parent) const;
55 void setBusName(const QString &busName);
56 QString busName() const;
58 void setObjectPath(const QString &busName);
59 QString objectPath() const;
61 DBusEnums::BusType busType() const;
62 void setIntBusType(int type);
64 int status() const;
66public Q_SLOTS:
67 void onModelAboutToBeReset();
68 void onModelReset();
70 void start();
71 void stop();
73Q_SIGNALS:
74 void countChanged();
76 void busTypeChanged();
77 void busNameChanged();
78 void objectPathChanged();
79 void statusChanged();
81private:
82 QDBusMenuModel *m_model;
83 mutable QMap<int, QString> m_indexCache;
84 int m_rowCount;
86 int rowOffsetOf(const QModelIndex &index, int row, bool inclusive = false) const;
87 int recursiveRowCount(const QModelIndex &index) const;
88 QModelIndex index(int row, int rowCount, const QModelIndex &parent, const QString &key) const;
89};
91#endif