on xenial help sign in
add a custom proxy model for the quicklist
c5236e2Michael Zanetti
plugins/Utils/CMakeLists.txt+1
@@ -36,6 +36,7 @@ set(QMLPLUGIN_SRC
36 URLDispatcher.cpp
36 URLDispatcher.cpp
37 tabfocusfence.cpp
37 tabfocusfence.cpp
38 expressionfiltermodel.cpp
38 expressionfiltermodel.cpp
39+ quicklistproxymodel.cpp
39 plugin.cpp
40 plugin.cpp
40 )
41 )
41
42
plugins/Utils/plugin.cpp+2
@@ -42,6 +42,7 @@
42#include "appdrawerproxymodel.h"
42#include "appdrawerproxymodel.h"
43#include "tabfocusfence.h"
43#include "tabfocusfence.h"
44#include "expressionfiltermodel.h"
44#include "expressionfiltermodel.h"
45+#include "quicklistproxymodel.h"
45
46
46static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
47static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
47{
48{
@@ -88,4 +89,5 @@ void UtilsPlugin::registerTypes(const char *uri)
88 qmlRegisterType<AppDrawerProxyModel>(uri, 0, 1, "AppDrawerProxyModel");
89 qmlRegisterType<AppDrawerProxyModel>(uri, 0, 1, "AppDrawerProxyModel");
89 qmlRegisterType<TabFocusFenceItem>(uri, 0, 1, "TabFocusFence");
90 qmlRegisterType<TabFocusFenceItem>(uri, 0, 1, "TabFocusFence");
90 qmlRegisterType<ExpressionFilterModel>(uri, 0, 1, "ExpressionFilterModel");
91 qmlRegisterType<ExpressionFilterModel>(uri, 0, 1, "ExpressionFilterModel");
92+ qmlRegisterType<QuickListProxyModel>(uri, 0, 1, "QuickListProxyModel");
91}
93}
plugins/Utils/quicklistproxymodel.cppnew file+72
@@ -0,0 +1,72 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU 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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "quicklistproxymodel.h"
18+
19+#include <QDebug>
20+
21+QuickListProxyModel::QuickListProxyModel(QObject *parent):
22+ QSortFilterProxyModel(parent)
23+{
24+ connect(this, &QAbstractListModel::rowsInserted, this, &QuickListProxyModel::countChanged);
25+ connect(this, &QAbstractListModel::rowsRemoved, this, &QuickListProxyModel::countChanged);
26+ connect(this, &QAbstractListModel::layoutChanged, this, &QuickListProxyModel::countChanged);
27+}
28+
29+QAbstractItemModel *QuickListProxyModel::source() const
30+{
31+ return m_source;
32+}
33+
34+bool QuickListProxyModel::privateMode() const
35+{
36+ return m_privateMode;
37+}
38+
39+void QuickListProxyModel::setPrivateMode(bool privateMode)
40+{
41+ if (m_privateMode != privateMode) {
42+ m_privateMode = privateMode;
43+ invalidateFilter();
44+ Q_EMIT privateModeChanged();
45+ }
46+}
47+
48+void QuickListProxyModel::setSource(QAbstractItemModel *source)
49+{
50+ if (m_source != source) {
51+ m_source = source;
52+ setSourceModel(m_source);
53+ connect(m_source, &QAbstractItemModel::rowsRemoved, this, &QuickListProxyModel::invalidate);
54+ connect(m_source, &QAbstractItemModel::rowsInserted, this, &QuickListProxyModel::invalidate);
55+ Q_EMIT sourceChanged();
56+ }
57+}
58+
59+int QuickListProxyModel::count() const
60+{
61+ return rowCount();
62+}
63+
64+bool QuickListProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
65+{
66+ Q_UNUSED(source_parent)
67+
68+ if (m_privateMode) {
69+ return !m_source->data(m_source->index(source_row, 0), QuickListModelInterface::RoleIsPrivate).toBool();
70+ }
71+ return true;
72+}
plugins/Utils/quicklistproxymodel.hnew file+52
@@ -0,0 +1,52 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU 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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include <QSortFilterProxyModel>
18+
19+#include <unity/shell/launcher/QuickListModelInterface.h>
20+
21+using namespace unity::shell::launcher;
22+
23+class QuickListProxyModel: public QSortFilterProxyModel
24+{
25+ Q_OBJECT
26+ Q_PROPERTY(QAbstractItemModel* source READ source WRITE setSource NOTIFY sourceChanged)
27+ Q_PROPERTY(bool privateMode READ privateMode WRITE setPrivateMode NOTIFY privateModeChanged)
28+ Q_PROPERTY(int count READ count NOTIFY countChanged)
29+
30+public:
31+ QuickListProxyModel(QObject* parent = nullptr);
32+
33+ QAbstractItemModel* source() const;
34+ void setSource(QAbstractItemModel* source);
35+
36+ bool privateMode() const;
37+ void setPrivateMode(bool privateMode);
38+
39+ int count() const;
40+
41+protected:
42+ bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
43+
44+Q_SIGNALS:
45+ void sourceChanged();
46+ void privateModeChanged();
47+ void countChanged();
48+
49+private:
50+ QAbstractItemModel* m_source = nullptr;
51+ bool m_privateMode;
52+};
qml/Launcher/LauncherPanel.qml+3−4
@@ -814,10 +814,9 @@ Rectangle {
814 Repeater {
814 Repeater {
815 id: popoverRepeater
815 id: popoverRepeater
816 objectName: "popoverRepeater"
816 objectName: "popoverRepeater"
817− model: UnitySortFilterProxyModel {
817+ model: QuickListProxyModel {
818− model: quickList.model
818+ source: quickList.model
819− filterRole: QuickListModelInterface.RoleIsPrivate
820− filterRegExp: root.privateMode ? RegExp(false) : RegExp()
819+ privateMode: root.privateMode
821 }
820 }
822
821
823 ListItem {
822 ListItem {
tests/mocks/Utils/CMakeLists.txt+2
@@ -27,6 +27,7 @@ set(QMLPLUGIN_SRC
27 ${CMAKE_SOURCE_DIR}/plugins/Utils/appdrawerproxymodel.cpp
27 ${CMAKE_SOURCE_DIR}/plugins/Utils/appdrawerproxymodel.cpp
28 ${CMAKE_SOURCE_DIR}/plugins/Utils/tabfocusfence.cpp
28 ${CMAKE_SOURCE_DIR}/plugins/Utils/tabfocusfence.cpp
29 ${CMAKE_SOURCE_DIR}/plugins/Utils/expressionfiltermodel.cpp
29 ${CMAKE_SOURCE_DIR}/plugins/Utils/expressionfiltermodel.cpp
30+ ${CMAKE_SOURCE_DIR}/plugins/Utils/quicklistproxymodel.cpp
30 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
31 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
31 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
32 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
32 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
33 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/MirSurfaceInterface.h
@@ -35,6 +36,7 @@ set(QMLPLUGIN_SRC
35 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/AppDrawerModelInterface.h
36 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/AppDrawerModelInterface.h
36 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
37 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherModelInterface.h
37 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
38 ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/LauncherItemInterface.h
39+ ${LAUNCHER_API_INCLUDEDIR}/unity/shell/launcher/QuickListModelInterface.h
38 constants.cpp
40 constants.cpp
39 plugin.cpp
41 plugin.cpp
40 windowstatestorage.cpp
42 windowstatestorage.cpp
tests/mocks/Utils/plugin.cpp+2
@@ -43,6 +43,7 @@
43#include <appdrawerproxymodel.h>
43#include <appdrawerproxymodel.h>
44#include <tabfocusfence.h>
44#include <tabfocusfence.h>
45#include <expressionfiltermodel.h>
45#include <expressionfiltermodel.h>
46+#include <quicklistproxymodel.h>
46
47
47static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
48static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
48{
49{
@@ -88,4 +89,5 @@ void FakeUtilsPlugin::registerTypes(const char *uri)
88 qmlRegisterType<AppDrawerProxyModel>(uri, 0, 1, "AppDrawerProxyModel");
89 qmlRegisterType<AppDrawerProxyModel>(uri, 0, 1, "AppDrawerProxyModel");
89 qmlRegisterType<TabFocusFenceItem>(uri, 0, 1, "TabFocusFence");
90 qmlRegisterType<TabFocusFenceItem>(uri, 0, 1, "TabFocusFence");
90 qmlRegisterType<ExpressionFilterModel>(uri, 0, 1, "ExpressionFilterModel");
91 qmlRegisterType<ExpressionFilterModel>(uri, 0, 1, "ExpressionFilterModel");
92+ qmlRegisterType<QuickListProxyModel>(uri, 0, 1, "QuickListProxyModel");
91}
93}