on c3e124d help sign in
unity8/plugins/Unity/genericoptionsmodel.h
77 lines 2.1 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Pawel Stolowski <pawel.stolowski@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
20#ifndef GENERICOPTIONSMODEL_H
21#define GENERICOPTIONSMODEL_H
23// Qt
24#include <QObject>
25#include <QAbstractListModel>
26#include <QHash>
27#include <QVector>
29class AbstractFilterOption;
31class Q_DECL_EXPORT GenericOptionsModel : public QAbstractListModel
33 Q_OBJECT
35 Q_ENUMS(Roles)
37Q_SIGNALS:
38 void activeChanged(AbstractFilterOption *option);
40public:
41 GenericOptionsModel(QObject *parent = nullptr);
42 ~GenericOptionsModel();
44 enum Roles {
45 RoleId = Qt::UserRole,
46 RoleName,
47 RoleIconHint,
48 RoleActive
49 };
51 QHash<int, QByteArray> roleNames() const override;
52 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
53 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
55 AbstractFilterOption* getRawOption(QVector<AbstractFilterOption *>::size_type idx) const;
57public Q_SLOTS:
58 virtual void ensureTheOnlyActive(AbstractFilterOption *activeOption);
60protected Q_SLOTS:
61 void onOptionChanged();
62 void onActiveChanged();
64protected:
65 void addOption(AbstractFilterOption *option, int index);
66 void removeOption(int index);
67 int indexOf(const QString &option_id);
69 QVector<AbstractFilterOption *> m_options;
70private:
71 void setupRoles();
72 QHash<int, QByteArray> m_roles;
73};
75Q_DECLARE_METATYPE(GenericOptionsModel*)
77#endif // GENERICOPTIONSMODEL_H