Qt: Minor changes to TrafficTrees

Move the corner button to a QToolButton and put it in a widget
to better handle size constraints. Also fix some fallthroughs
and remove unneeded code
This commit is contained in:
Roland Knall 2022-06-02 11:03:32 +02:00
parent 335795ab16
commit f725bbef5e
3 changed files with 18 additions and 37 deletions

View File

@ -330,41 +330,6 @@ QVariant EndpointDataModel::headerData(int section, Qt::Orientation orientation,
if (section == ENDP_COLUMN_ADDR)
return Qt::AlignLeft;
return Qt::AlignRight;
#if 0
} else if (role == Qt::SizeHintRole) {
QFontMetrics fm = mainApp->mainWindow()->fontMetrics();
QSize size = QAbstractListModel::headerData(section, orientation, role).toSize();
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
#define FONT_WIDTH_FUNC horizontalAdvance
#else
#define FONT_WIDTH_FUNC width
#endif
switch (column) {
case ENDP_COLUMN_ADDR:
size.setWidth(fm.FONT_WIDTH_FUNC("000.000.000.000"));
return size;
break;
case ENDP_COLUMN_PORT:
size.setWidth(fm.FONT_WIDTH_FUNC("000000"));
return size;
break;
case ENDP_COLUMN_PACKETS:
case ENDP_COLUMN_PKT_AB:
case ENDP_COLUMN_PKT_BA:
size.setWidth(fm.FONT_WIDTH_FUNC("00,000"));
return size;
break;
case ENDP_COLUMN_BYTES:
case ENDP_COLUMN_BYTES_AB:
case ENDP_COLUMN_BYTES_BA:
size.setWidth(fm.FONT_WIDTH_FUNC("000,000"));
return size;
break;
default:
size.setWidth(fm.FONT_WIDTH_FUNC("000000000000000")); // Geolocation
return size;
}
#endif
}
return QVariant();
@ -436,18 +401,22 @@ QVariant EndpointDataModel::data(const QModelIndex &idx, int role) const
if (mmdb_lookup && mmdb_lookup->found && mmdb_lookup->country) {
return QVariant(mmdb_lookup->country);
}
return QVariant();
case ENDP_COLUMN_GEO_CITY:
if (mmdb_lookup && mmdb_lookup->found && mmdb_lookup->city) {
return QVariant(mmdb_lookup->city);
}
return QVariant();
case ENDP_COLUMN_GEO_AS_NUM:
if (mmdb_lookup && mmdb_lookup->found && mmdb_lookup->as_number) {
return QVariant(mmdb_lookup->as_number);
}
return QVariant();
case ENDP_COLUMN_GEO_AS_ORG:
if (mmdb_lookup && mmdb_lookup->found && mmdb_lookup->as_org) {
return QVariant(mmdb_lookup->as_org);
}
return QVariant();
default:
return QVariant();
}

View File

@ -142,7 +142,7 @@ public:
/**
* @brief Use nanosecond timestamps if requested
*
* @param useNSTime use nanosecond timestamps if required and requested
* @param nanoseconds use nanosecond timestamps if required and requested
*/
void useNanosecondTimestamps(bool nanoseconds);

View File

@ -42,6 +42,7 @@
#include <QMessageBox>
#include <QUrl>
#include <QTemporaryFile>
#include <QHBoxLayout>
TabData::TabData() :
_name(QString()),
@ -118,7 +119,16 @@ void TrafficTab::setProtocolInfo(QString tableName, GList ** recentList, ATapMod
_protocols << proto_get_id_by_filter_name(name.toStdString().c_str());
}
QWidget * container = new QWidget(this);
container->setFixedHeight(tabBar()->height());
container->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
QHBoxLayout * layout = new QHBoxLayout(container);
layout->setContentsMargins(1, 0, 1, 0);
QPushButton * cornerButton = new QPushButton(tr("%1 Types").arg(tableName));
cornerButton->setFixedHeight(tabBar()->height());
cornerButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
QMenu * cornerMenu = new QMenu();
conversation_table_iterate_tables(iterateProtocols, &_allTaps);
foreach (int protoId, _allTaps.keys())
@ -131,7 +141,9 @@ void TrafficTab::setProtocolInfo(QString tableName, GList ** recentList, ATapMod
cornerMenu->addAction(endPoint);
}
cornerButton->setMenu(cornerMenu);
setCornerWidget(cornerButton);
layout->addWidget(cornerButton);
setCornerWidget(container, Qt::TopRightCorner);
updateTabs();
}