on xenial help sign in
Added ShowAllFilterOption.
commit6240b0216d98930771ea3dc01b474009961fe85b authorPawel Stolowski <pawel.stolowski@canonical.com> dateMon 26 Aug 2013, 18:51 (13 years ago) parent7dd1fe0
5 files changed+126−4
plugins/Unity/CMakeLists.txt+1 plugins/Unity/genericoptionsmodel.cpp+16−3 plugins/Unity/genericoptionsmodel.h+2−1 plugins/Unity/showallfilteroption.cpp+58 plugins/Unity/showallfilteroption.h+49
plugins/Unity/CMakeLists.txt+1
@@ -43,6 +43,7 @@ set(QMLPLUGIN_SRC
4343 preview.cpp
4444 previewaction.cpp
4545 previewinfohint.cpp
46+ showallfilteroption.cpp
4647 signalslist.cpp
4748 socialpreview.cpp
4849 socialpreviewcomment.cpp
plugins/Unity/genericoptionsmodel.cpp+16−3
@@ -22,10 +22,18 @@
2222
2323// local
2424#include "abstractfilteroption.h"
25+#include "showallfilteroption.h"
2526
26−GenericOptionsModel::GenericOptionsModel(QObject *parent)
27+GenericOptionsModel::GenericOptionsModel(bool showAllOption, QObject *parent)
2728 : QAbstractListModel(parent)
2829{
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+ }
2937}
3038
3139GenericOptionsModel::~GenericOptionsModel()
@@ -52,7 +60,7 @@ QVariant GenericOptionsModel::data(const QModelIndex& index, int role) const
5260 return QVariant();
5361 }
5462
55− auto filterOption = m_options[index.row()];
63+ auto filterOption = (m_showAll != nullptr && index.row() == 0) ? m_showAll : m_options[index.row()];
5664 switch (role)
5765 {
5866 case GenericOptionsModel::RoleId:
@@ -73,7 +81,7 @@ QVariant GenericOptionsModel::data(const QModelIndex& index, int role) const
7381
7482int GenericOptionsModel::rowCount(const QModelIndex& /* parent */) const
7583{
76− return m_options.size ();
84+ return m_options.size;
7785}
7886
7987void GenericOptionsModel::setActive(int idx, bool value)
@@ -103,6 +111,11 @@ AbstractFilterOption* GenericOptionsModel::getRawOption(QVector<AbstractFilterOp
103111 return nullptr;
104112}
105113
114+void GenericOptionsModel::onShowAllClicked(bool active)
115+{
116+ ensureTheOnlyActive(m_options[0]);
117+}
118+
106119void GenericOptionsModel::ensureTheOnlyActive(AbstractFilterOption *activeOption)
107120{
108121 if (activeOption->active()) {
plugins/Unity/genericoptionsmodel.h+2−1
@@ -35,7 +35,7 @@ class Q_DECL_EXPORT GenericOptionsModel : public QAbstractListModel
3535 Q_ENUMS(Roles)
3636
3737public:
38− GenericOptionsModel(QObject *parent = nullptr);
38+ GenericOptionsModel(bool showAllOption = false, QObject *parent = nullptr);
3939 ~GenericOptionsModel();
4040
4141 enum Roles {
@@ -63,6 +63,7 @@ Q_SIGNALS:
6363protected Q_SLOTS:
6464 void onOptionChanged();
6565 void onActiveChanged();
66+ void onShowAllClicked(bool active);
6667
6768protected:
6869 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