on f45415d help sign in
unity8/plugins/Unity/Indicators/flatmenuproxymodel.h
93 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 "unityindicatorsglobal.h"
25#include <QAbstractProxyModel>
26#include <qdbusmenumodel.h>
28class SectionInfo;
30class UNITYINDICATORS_EXPORT FlatMenuProxyModel : public QAbstractProxyModel
32 Q_OBJECT
33 Q_PROPERTY(int count READ count NOTIFY countChanged)
34 Q_PROPERTY(int busType READ busType WRITE setIntBusType NOTIFY busTypeChanged)
35 Q_PROPERTY(QString busName READ busName WRITE setBusName NOTIFY busNameChanged)
36 Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath NOTIFY objectPathChanged)
37 Q_PROPERTY(int status READ status NOTIFY statusChanged)
39 Q_ENUMS(Roles)
40public:
41 FlatMenuProxyModel(QAbstractItemModel *source=0);
42 ~FlatMenuProxyModel();
44 void setSourceModel(QAbstractItemModel * sourceModel);
46 Q_INVOKABLE QVariant data(int row, int role = Qt::DisplayRole) const;
48 QModelIndex mapFromSource(const QModelIndex &index) const;
49 QModelIndex mapToSource(const QModelIndex &index) const;
51 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
52 QModelIndex parent(const QModelIndex &index) const;
53 int rowCount(const QModelIndex &parent = QModelIndex()) const;
54 int count() const;
55 int columnCount(const QModelIndex &parent) const;
57 void setBusName(const QString &busName);
58 QString busName() const;
60 void setObjectPath(const QString &busName);
61 QString objectPath() const;
63 DBusEnums::BusType busType() const;
64 void setIntBusType(int type);
66 int status() const;
68public Q_SLOTS:
69 void onModelAboutToBeReset();
70 void onModelReset();
72 void start();
73 void stop();
75Q_SIGNALS:
76 void countChanged();
78 void busTypeChanged();
79 void busNameChanged();
80 void objectPathChanged();
81 void statusChanged();
83private:
84 QDBusMenuModel *m_model;
85 mutable QMap<int, QString> m_indexCache;
86 int m_rowCount;
88 int rowOffsetOf(const QModelIndex &index, int row, bool inclusive = false) const;
89 int recursiveRowCount(const QModelIndex &index) const;
90 QModelIndex index(int row, int rowCount, const QModelIndex &parent, const QString &key) const;
91};
93#endif