2021-11-30 13:01:36 +00:00
|
|
|
/** @file
|
2017-11-22 15:54:32 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2017-11-22 15:54:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ASTRINGLIST_LIST_MODEL_H
|
|
|
|
#define ASTRINGLIST_LIST_MODEL_H
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2017-11-24 14:46:30 +00:00
|
|
|
#include <QAbstractTableModel>
|
2017-11-22 15:54:32 +00:00
|
|
|
#include <QModelIndex>
|
|
|
|
#include <QList>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QSortFilterProxyModel>
|
2017-11-24 14:46:30 +00:00
|
|
|
#include <QIdentityProxyModel>
|
2017-11-22 15:54:32 +00:00
|
|
|
|
2017-11-24 14:46:30 +00:00
|
|
|
class AStringListListModel : public QAbstractTableModel
|
2017-11-22 15:54:32 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AStringListListModel(QObject * parent = Q_NULLPTR);
|
|
|
|
virtual ~AStringListListModel();
|
|
|
|
|
|
|
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
|
|
|
PortsModel: don't populate it by doing a lot of weird string-pushing.
When enumerating port-to-name entries, the callback to
wmem_map_foreach() gets passed:
- a key, which is the port number for the entry;
- a value, which is a pointer to a structure containing pointers to port
names for various transport protocols;
- a user data pointer.
That's sufficient (if you work around some C++ annoyances) to append a
row to a PortsModel, if the user data pointer is a pointer to the
PortsModel.
The existing code, instead, appended to a QStringList of lines (in
effect, undoing the effort of the code that read the services file and
filled in the wmem_map, re-generating a set of lines) in the callback,
and then iterated over all the lines, splitting them with blanks and
appending rows.
Looking at that made my eyeballs bleed so badly that I decided not to
spend any time figuring out why it wasn't working.
So I just make the callback just append rows, avoiding all the
string-pushing.
Fixes #17395.
2021-05-18 08:03:04 +00:00
|
|
|
//
|
|
|
|
// This is not protected because we may need to invoke it from
|
|
|
|
// a wmem_map_foreach() callback implemented as an extern "C"
|
|
|
|
// static member function of a subclass. wmem_map_foreach() is
|
|
|
|
// passed, as the user data, a pointer to the class instance to
|
|
|
|
// which we want to append rows.
|
|
|
|
//
|
2018-01-29 22:40:45 +00:00
|
|
|
virtual void appendRow(const QStringList &, const QString & row_tooltip = QString(), const QModelIndex &parent = QModelIndex());
|
2017-11-22 15:54:32 +00:00
|
|
|
|
PortsModel: don't populate it by doing a lot of weird string-pushing.
When enumerating port-to-name entries, the callback to
wmem_map_foreach() gets passed:
- a key, which is the port number for the entry;
- a value, which is a pointer to a structure containing pointers to port
names for various transport protocols;
- a user data pointer.
That's sufficient (if you work around some C++ annoyances) to append a
row to a PortsModel, if the user data pointer is a pointer to the
PortsModel.
The existing code, instead, appended to a QStringList of lines (in
effect, undoing the effort of the code that read the services file and
filled in the wmem_map, re-generating a set of lines) in the callback,
and then iterated over all the lines, splitting them with blanks and
appending rows.
Looking at that made my eyeballs bleed so badly that I decided not to
spend any time figuring out why it wasn't working.
So I just make the callback just append rows, avoiding all the
string-pushing.
Fixes #17395.
2021-05-18 08:03:04 +00:00
|
|
|
protected:
|
2017-11-22 15:54:32 +00:00
|
|
|
virtual QStringList headerColumns() const = 0;
|
|
|
|
|
|
|
|
private:
|
2018-01-29 22:40:45 +00:00
|
|
|
QList<QStringList> display_data_;
|
|
|
|
QStringList tooltip_data_;
|
2017-11-22 15:54:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AStringListListSortFilterProxyModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum AStringListListFilterType
|
|
|
|
{
|
|
|
|
FilterByContains = 0,
|
2019-08-29 15:30:29 +00:00
|
|
|
FilterByStart,
|
|
|
|
FilterByEquivalent,
|
|
|
|
FilterNone
|
2017-11-22 15:54:32 +00:00
|
|
|
};
|
2019-08-29 15:30:29 +00:00
|
|
|
Q_ENUM(AStringListListFilterType)
|
2017-11-22 15:54:32 +00:00
|
|
|
|
|
|
|
explicit AStringListListSortFilterProxyModel(QObject * parent = Q_NULLPTR);
|
|
|
|
|
|
|
|
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
|
|
|
|
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
2019-08-29 15:30:29 +00:00
|
|
|
virtual bool filterAcceptsColumn(int column, const QModelIndex &sourceParent) const;
|
2017-11-22 15:54:32 +00:00
|
|
|
|
2019-08-29 15:30:29 +00:00
|
|
|
void setFilterType(AStringListListFilterType type, int column = -1);
|
2017-11-22 15:54:32 +00:00
|
|
|
|
|
|
|
void setColumnToFilter(int);
|
2022-05-16 15:04:49 +00:00
|
|
|
void setColumnsToFilter(QList<int>);
|
2017-11-22 15:54:32 +00:00
|
|
|
void clearColumnsToFilter();
|
|
|
|
|
2019-08-29 15:30:29 +00:00
|
|
|
void clearHiddenColumns();
|
|
|
|
void setColumnToHide(int col);
|
|
|
|
|
|
|
|
void clearNumericColumns();
|
|
|
|
void setColumnAsNumeric(int col);
|
|
|
|
|
2017-11-22 15:54:32 +00:00
|
|
|
public slots:
|
|
|
|
void setFilter(const QString&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString filter_;
|
2019-08-29 15:30:29 +00:00
|
|
|
QMap<int, AStringListListFilterType> types_;
|
2017-11-22 15:54:32 +00:00
|
|
|
QList<int> columnsToFilter_;
|
2019-08-29 15:30:29 +00:00
|
|
|
QList<int> hiddenColumns_;
|
|
|
|
QList<int> numericColumns_;
|
2017-11-22 15:54:32 +00:00
|
|
|
};
|
|
|
|
|
2017-11-24 14:46:30 +00:00
|
|
|
class AStringListListUrlProxyModel : public QIdentityProxyModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AStringListListUrlProxyModel(QObject * parent = Q_NULLPTR);
|
|
|
|
|
|
|
|
void setUrlColumn(int);
|
|
|
|
bool isUrlColumn(int) const;
|
2017-11-22 15:54:32 +00:00
|
|
|
|
2017-11-24 14:46:30 +00:00
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList<int> urls_;
|
|
|
|
};
|
2017-11-22 15:54:32 +00:00
|
|
|
|
|
|
|
#endif // ASTRINGLIST_LIST_MODEL_H
|