on 577eaad help sign in
unity8/plugins/Unity/genericoptionsmodel.h
77 lines 2.2 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)
37public:
38 GenericOptionsModel(QObject *parent = nullptr);
39 ~GenericOptionsModel();
41 enum Roles {
42 RoleId = Qt::UserRole,
43 RoleName,
44 RoleIconHint,
45 RoleActive
46 };
48 QHash<int, QByteArray> roleNames() const override;
49 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
50 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
52 Q_INVOKABLE void setActive(QVector<AbstractFilterOption *>::size_type idx, bool value);
53 Q_INVOKABLE void setActive(const QString &id, bool value);
55 AbstractFilterOption* getRawOption(QVector<AbstractFilterOption *>::size_type idx) const;
57public Q_SLOTS:
58 virtual void ensureTheOnlyActive(AbstractFilterOption *activeOption);
60Q_SIGNALS:
61 void activeChanged(AbstractFilterOption *option);
63protected Q_SLOTS:
64 void onOptionChanged();
65 void onActiveChanged();
67protected:
68 void addOption(AbstractFilterOption *option, int index);
69 void removeOption(int index);
70 int indexOf(const QString &option_id);
72 QVector<AbstractFilterOption *> m_options;
73};
75Q_DECLARE_METATYPE(GenericOptionsModel*)
77#endif // GENERICOPTIONSMODEL_H