mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-25 16:02:14 +08:00
cabana: hide/show columns using context menu (#28033)
This commit is contained in:
@@ -39,6 +39,10 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
|
||||
|
||||
view->header()->setSectionsMovable(true);
|
||||
|
||||
// Header context menu
|
||||
view->header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
QObject::connect(view->header(), &QHeaderView::customContextMenuRequested, view, &MessageView::headerContextMenuEvent);
|
||||
|
||||
main_layout->addWidget(view);
|
||||
|
||||
// suppress
|
||||
@@ -319,3 +323,34 @@ void MessageView::updateBytesSectionSize() {
|
||||
header()->resizeSection(5, width);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageView::headerContextMenuEvent(const QPoint &pos) {
|
||||
QMenu *menu = new QMenu(this);
|
||||
int cur_index = header()->logicalIndexAt(pos);
|
||||
|
||||
QString column_name;
|
||||
QAction *action;
|
||||
for (int visual_index = 0; visual_index < header()->count(); visual_index++) {
|
||||
int logical_index = header()->logicalIndex(visual_index);
|
||||
column_name = model()->headerData(logical_index, Qt::Horizontal).toString();
|
||||
|
||||
// Hide show action
|
||||
if (header()->isSectionHidden(logical_index)) {
|
||||
action = menu->addAction(tr(" %1").arg(column_name), [=]() { header()->showSection(logical_index); });
|
||||
} else {
|
||||
action = menu->addAction(tr("✓ %1").arg(column_name), [=]() { header()->hideSection(logical_index); });
|
||||
}
|
||||
|
||||
// Can't hide the name column
|
||||
action->setEnabled(logical_index > 0);
|
||||
|
||||
// Make current column bold
|
||||
if (logical_index == cur_index) {
|
||||
QFont font = action->font();
|
||||
font.setBold(true);
|
||||
action->setFont(font);
|
||||
}
|
||||
}
|
||||
|
||||
menu->popup(header()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QCheckBox>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QHeaderView>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QSet>
|
||||
#include <QTreeView>
|
||||
|
||||
@@ -43,6 +45,7 @@ public:
|
||||
void drawBranches(QPainter *painter, const QRect &rect, const QModelIndex &index) const override {}
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override;
|
||||
void updateBytesSectionSize();
|
||||
void headerContextMenuEvent(const QPoint &pos);
|
||||
};
|
||||
|
||||
class MessagesWidget : public QWidget {
|
||||
|
||||
Reference in New Issue
Block a user