aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt
diff options
context:
space:
mode:
authorRoland Knall <roland.knall@br-automation.com>2018-01-12 13:15:20 +0100
committerRoland Knall <rknall@gmail.com>2018-01-12 12:49:14 +0000
commitac9c89de65f29411c435a3ed38abf333fd7b1b09 (patch)
tree718f337a4237e398157aff68abcfb62159c36aa1 /ui/qt
parentc1301a486217f0027e11ae90816006f723bf4b9e (diff)
Qt: Add InfoProxyModel
Add an identity model, which can be used to display non-selectable information at the end of any list Change-Id: Iaca436f34cb8e5b251eb0dc00ea2c0ce1bd9e0e2 Reviewed-on: https://code.wireshark.org/review/25280 Petri-Dish: Roland Knall <rknall@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Roland Knall <rknall@gmail.com>
Diffstat (limited to 'ui/qt')
-rw-r--r--ui/qt/CMakeLists.txt2
-rw-r--r--ui/qt/Makefile.am2
-rw-r--r--ui/qt/models/info_proxy_model.cpp107
-rw-r--r--ui/qt/models/info_proxy_model.h58
4 files changed, 169 insertions, 0 deletions
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt
index ad09591e56..3e6eda79a0 100644
--- a/ui/qt/CMakeLists.txt
+++ b/ui/qt/CMakeLists.txt
@@ -83,6 +83,7 @@ set(WIRESHARK_MODEL_HEADERS
models/export_objects_model.h
models/fileset_entry_model.h
models/html_text_delegate.h
+ models/info_proxy_model.h
models/interface_sort_filter_model.h
models/interface_tree_cache_model.h
models/interface_tree_model.h
@@ -306,6 +307,7 @@ set(WIRESHARK_MODEL_SRCS
models/export_objects_model.cpp
models/fileset_entry_model.cpp
models/html_text_delegate.cpp
+ models/info_proxy_model.cpp
models/interface_sort_filter_model.cpp
models/interface_tree_cache_model.cpp
models/interface_tree_model.cpp
diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am
index 419700ded5..78fdded367 100644
--- a/ui/qt/Makefile.am
+++ b/ui/qt/Makefile.am
@@ -215,6 +215,7 @@ MOC_MODELS_HDRS = \
models/export_objects_model.h \
models/fileset_entry_model.h \
models/html_text_delegate.h \
+ models/info_proxy_model.h \
models/interface_sort_filter_model.h \
models/interface_tree_cache_model.h \
models/interface_tree_model.h \
@@ -563,6 +564,7 @@ WIRESHARK_QT_MODELS_SRCS = \
models/export_objects_model.cpp \
models/fileset_entry_model.cpp \
models/html_text_delegate.cpp \
+ models/info_proxy_model.cpp \
models/interface_sort_filter_model.cpp \
models/interface_tree_cache_model.cpp \
models/interface_tree_model.cpp \
diff --git a/ui/qt/models/info_proxy_model.cpp b/ui/qt/models/info_proxy_model.cpp
new file mode 100644
index 0000000000..1bc22678e4
--- /dev/null
+++ b/ui/qt/models/info_proxy_model.cpp
@@ -0,0 +1,107 @@
+/* info_proxy_model.cpp
+ * Proxy model for displaying an info text at the end of any QAbstractListModel
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <config.h>
+
+#include <ui/qt/models/info_proxy_model.h>
+
+#include <QFont>
+
+InfoProxyModel::InfoProxyModel(int column, QObject * parent) : QIdentityProxyModel (parent)
+{
+ column_ = column;
+}
+
+InfoProxyModel::~InfoProxyModel()
+{
+ infos_.clear();
+}
+
+void InfoProxyModel::appendInfo(QString info)
+{
+ if ( ! infos_.contains(info) )
+ infos_ << info;
+}
+
+int InfoProxyModel::rowCount(const QModelIndex &parent) const
+{
+ return sourceModel()->rowCount(parent) + infos_.count();
+}
+
+QVariant InfoProxyModel::data (const QModelIndex &index, int role) const
+{
+ if ( ! index.isValid() )
+ return QVariant();
+
+ if ( index.row() < sourceModel()->rowCount() )
+ return sourceModel()->data(mapToSource(index), role);
+
+ int ifIdx = index.row() - sourceModel()->rowCount();
+ if ( index.column() != column_ || ifIdx < 0 || ifIdx >= infos_.count() )
+ return QVariant();
+
+ switch ( role )
+ {
+ case Qt::DisplayRole:
+ return infos_.at(ifIdx);
+ break;
+ case Qt::FontRole:
+ QFont font = QIdentityProxyModel::data(index, Qt::FontRole).value<QFont>();
+ font.setItalic(true);
+ return font;
+ }
+
+ return QIdentityProxyModel::data(index, role);
+}
+
+Qt::ItemFlags InfoProxyModel::flags(const QModelIndex &index) const
+{
+ if ( index.row() < sourceModel()->rowCount() )
+ return sourceModel()->flags(mapToSource(index));
+
+ return 0;
+}
+
+QModelIndex InfoProxyModel::index(int row, int column, const QModelIndex &parent) const
+{
+ if ( row >= sourceModel()->rowCount() && row < rowCount() )
+ return createIndex(row, column);
+
+ return QIdentityProxyModel::index(row, column, parent);
+}
+
+QModelIndex InfoProxyModel::mapToSource(const QModelIndex &proxyIndex) const
+{
+ if ( ! proxyIndex.isValid() )
+ return QModelIndex();
+
+ if ( proxyIndex.row() >= sourceModel()->rowCount() )
+ return QModelIndex();
+
+ return QIdentityProxyModel::mapToSource(proxyIndex);
+}
+
+QModelIndex InfoProxyModel::mapFromSource(const QModelIndex &fromIndex) const
+{
+ return QIdentityProxyModel::mapFromSource(fromIndex);
+}
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */
diff --git a/ui/qt/models/info_proxy_model.h b/ui/qt/models/info_proxy_model.h
new file mode 100644
index 0000000000..470b11a0c3
--- /dev/null
+++ b/ui/qt/models/info_proxy_model.h
@@ -0,0 +1,58 @@
+/* info_proxy_model.h
+ * Proxy model for displaying an info text at the end of any QAbstractListModel
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef INFO_PROXY_MODEL_H
+#define INFO_PROXY_MODEL_H
+
+#include <config.h>
+
+#include <QStringList>
+#include <QIdentityProxyModel>
+
+class InfoProxyModel : public QIdentityProxyModel
+{
+ Q_OBJECT
+
+public:
+ explicit InfoProxyModel(int column, QObject * parent);
+ ~InfoProxyModel();
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const;
+
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+
+ virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
+ virtual QModelIndex mapFromSource(const QModelIndex &fromIndex) const;
+
+ void appendInfo(QString info);
+
+private:
+
+ int column_;
+
+ QStringList infos_;
+};
+
+#endif // INFO_PROXY_MODEL_H
+
+/*
+ * Editor modelines
+ *
+ * Local Variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * ex: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */