on xenial help sign in
Added ShowAllFilterOption.
6240b02Pawel Stolowski
plugins/Unity/CMakeLists.txt+1
@@ -43,6 +43,7 @@ set(QMLPLUGIN_SRC
43 preview.cpp
43 preview.cpp
44 previewaction.cpp
44 previewaction.cpp
45 previewinfohint.cpp
45 previewinfohint.cpp
46+ showallfilteroption.cpp
46 signalslist.cpp
47 signalslist.cpp
47 socialpreview.cpp
48 socialpreview.cpp
48 socialpreviewcomment.cpp
49 socialpreviewcomment.cpp
plugins/Unity/genericoptionsmodel.cpp+16−3
@@ -22,10 +22,18 @@
22
22
23// local
23// local
24#include "abstractfilteroption.h"
24#include "abstractfilteroption.h"
25+#include "showallfilteroption.h"
25
26
26−GenericOptionsModel::GenericOptionsModel(QObject *parent)
27+GenericOptionsModel::GenericOptionsModel(bool showAllOption, QObject *parent)
27 : QAbstractListModel(parent)
28 : QAbstractListModel(parent)
28{
29{
30+ if (showAllOption)
31+ {
32+ auto showAll = ShowAllFilterOption("TODO", this);
33+ connect(showAll, SIGNAL(activeChanged(bool)), this, SLOT(onOptionChanged()));
34+ connect(showAll, SIGNAL(activeChanged(bool)), this, SLOT(onShowAllClicked(bool)));
35+ addOption(showAll, 0);
36+ }
29}
37}
30
38
31GenericOptionsModel::~GenericOptionsModel()
39GenericOptionsModel::~GenericOptionsModel()
@@ -52,7 +60,7 @@ QVariant GenericOptionsModel::data(const QModelIndex& index, int role) const
52 return QVariant();
60 return QVariant();
53 }
61 }
54
62
55− auto filterOption = m_options[index.row()];
63+ auto filterOption = (m_showAll != nullptr && index.row() == 0) ? m_showAll : m_options[index.row()];
56 switch (role)
64 switch (role)
57 {
65 {
58 case GenericOptionsModel::RoleId:
66 case GenericOptionsModel::RoleId:
@@ -73,7 +81,7 @@ QVariant GenericOptionsModel::data(const QModelIndex& index, int role) const
73
81
74int GenericOptionsModel::rowCount(const QModelIndex& /* parent */) const
82int GenericOptionsModel::rowCount(const QModelIndex& /* parent */) const
75{
83{
76− return m_options.size ();
84+ return m_options.size;
77}
85}
78
86
79void GenericOptionsModel::setActive(int idx, bool value)
87void GenericOptionsModel::setActive(int idx, bool value)
@@ -103,6 +111,11 @@ AbstractFilterOption* GenericOptionsModel::getRawOption(QVector<AbstractFilterOp
103 return nullptr;
111 return nullptr;
104}
112}
105
113
114+void GenericOptionsModel::onShowAllClicked(bool active)
115+{
116+ ensureTheOnlyActive(m_options[0]);
117+}
118+
106void GenericOptionsModel::ensureTheOnlyActive(AbstractFilterOption *activeOption)
119void GenericOptionsModel::ensureTheOnlyActive(AbstractFilterOption *activeOption)
107{
120{
108 if (activeOption->active()) {
121 if (activeOption->active()) {
plugins/Unity/genericoptionsmodel.h+2−1
@@ -35,7 +35,7 @@ class Q_DECL_EXPORT GenericOptionsModel : public QAbstractListModel
35 Q_ENUMS(Roles)
35 Q_ENUMS(Roles)
36
36
37public:
37public:
38− GenericOptionsModel(QObject *parent = nullptr);
38+ GenericOptionsModel(bool showAllOption = false, QObject *parent = nullptr);
39 ~GenericOptionsModel();
39 ~GenericOptionsModel();
40
40
41 enum Roles {
41 enum Roles {
@@ -63,6 +63,7 @@ Q_SIGNALS:
63protected Q_SLOTS:
63protected Q_SLOTS:
64 void onOptionChanged();
64 void onOptionChanged();
65 void onActiveChanged();
65 void onActiveChanged();
66+ void onShowAllClicked(bool active);
66
67
67protected:
68protected:
68 void addOption(AbstractFilterOption *option, int index);
69 void addOption(AbstractFilterOption *option, int index);
plugins/Unity/showallfilteroption.cppnew file+58
@@ -0,0 +1,58 @@
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+ */
19+
20+// self
21+#include "showallfilteroption.h"
22+
23+#include <libintl.h>
24+
25+ShowAllFilterOption::ShowAllFilterOption(const QString &id, QObject *parent) :
26+ AbstractFilterOption(parent),
27+ m_active(false),
28+ m_id(id)
29+{
30+}
31+
32+QString ShowAllFilterOption::id() const
33+{
34+ return m_id;
35+}
36+
37+QString ShowAllFilterOption::name() const
38+{
39+ QString::fromUtf8(dgettext("unity", "All"));
40+}
41+
42+QString ShowAllFilterOption::iconHint() const
43+{
44+ return QString::Null();
45+}
46+
47+bool ShowAllFilterOption::active() const
48+{
49+ return m_active;
50+}
51+
52+void ShowAllFilterOption::setActive(bool active)
53+{
54+ if (active != m_active) {
55+ m_active = active;
56+ Q_EMIT activeChanged(m_active);
57+ }
58+}
plugins/Unity/showallfilteroption.hnew file+49
@@ -0,0 +1,49 @@
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+ */
19+
20+#ifndef SHOWALLFILTEROPTION_H
21+#define SHOWALLFILTEROPTION_H
22+
23+// local
24+#include "abstractfilteroption.h"
25+
26+class Q_DECL_EXPORT ShowAllFilterOption : public AbstractFilterOption
27+{
28+ Q_OBJECT
29+
30+public:
31+ explicit ShowAllFilterOption(const QString &id, QObject *parent = nullptr);
32+
33+ /* getters */
34+ QString id() const override;
35+ QString name() const override;
36+ QString iconHint() const override;
37+ bool active() const override;
38+
39+ /* setters */
40+ void setActive(bool active) override;
41+
42+private:
43+ bool m_active;
44+ QString m_id;
45+};
46+
47+Q_DECLARE_METATYPE(ShowAllFilterOption*)
48+
49+#endif // SHOWALLFILTEROPTION_H