[vlc-devel] [PATCH 10/16] qt: add ProxyColumnModel util class

Prince Gupta guptaprince8832 at gmail.com
Tue Feb 23 10:06:00 UTC 2021


---
 modules/gui/qt/Makefile.am               |  1 +
 modules/gui/qt/util/proxycolumnmodel.hpp | 70 ++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 modules/gui/qt/util/proxycolumnmodel.hpp

diff --git a/modules/gui/qt/Makefile.am b/modules/gui/qt/Makefile.am
index ef87fc8164..cb5595e8b2 100644
--- a/modules/gui/qt/Makefile.am
+++ b/modules/gui/qt/Makefile.am
@@ -213,6 +213,7 @@ libqt_plugin_la_SOURCES = \
 	gui/qt/util/qmleventfilter.hpp \
 	gui/qt/util/qt_dirs.cpp gui/qt/util/qt_dirs.hpp \
 	gui/qt/util/qvlcapp.hpp \
+	gui/qt/util/proxycolumnmodel.hpp \
 	gui/qt/util/registry.cpp gui/qt/util/registry.hpp \
 	gui/qt/util/renderer_manager.cpp gui/qt/util/renderer_manager.hpp \
 	gui/qt/util/selectable_list_model.cpp \
diff --git a/modules/gui/qt/util/proxycolumnmodel.hpp b/modules/gui/qt/util/proxycolumnmodel.hpp
new file mode 100644
index 0000000000..8d4fbdab3a
--- /dev/null
+++ b/modules/gui/qt/util/proxycolumnmodel.hpp
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (C) 2021 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * ( at your option ) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef PROXY_COLUMN_MODEL
+#define PROXY_COLUMN_MODEL
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "qt.hpp"
+#include <QAbstractItemModel>
+#include <type_traits>
+
+
+template <typename Model>
+class ProxyColumnModel : public Model
+{
+public:
+    ProxyColumnModel(const int extraColumns, const QHash<int, QString> &sectionDisplayData, QObject *parent = nullptr)
+        : Model {parent}
+        , m_extraColumns {extraColumns}
+        , m_sectionDisplayData {sectionDisplayData}
+    {
+    }
+
+    int columnCount(const QModelIndex &) const override
+    {
+        return 1 + m_extraColumns;
+    }
+
+    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
+    {
+        if (role == Qt::DisplayRole && m_sectionDisplayData.contains(section))
+            return m_sectionDisplayData.value(section);
+
+        return Model::headerData(section, orientation, role);
+    }
+
+    QVariant data(const QModelIndex &index, const int role) const override
+    {
+        if (index.column() != 0)
+            return {};
+
+        return Model::data(index, role);
+    }
+
+private:
+    const int m_extraColumns;
+    const QHash<int, QString> m_sectionDisplayData;
+
+    static_assert(std::is_base_of<QAbstractListModel, Model>::value, "must be a subclass of list model");
+};
+
+#endif // PROXY_COLUMN_MODEL
-- 
2.25.1



More information about the vlc-devel mailing list