From 74366d1c6b07bd91dd2d3428400fc5f7e219547f Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Tue, 20 Sep 2022 17:49:04 -0500 Subject: [PATCH] context menu in place for node rebase/duplicate need to add menu for rebase options and code for both actions --- dbc/dbcmaineditor.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ dbc/dbcmaineditor.h | 5 ++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index 54a046b..d10fcc3 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -21,11 +21,14 @@ DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) dbcHandler = DBCHandler::getReference(); referenceFrames = frames; + ui->treeDBC->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->btnSearch, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearch); connect(ui->lineSearch, &QLineEdit::returnPressed, this, &DBCMainEditor::handleSearch); connect(ui->btnSearchNext, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearchForward); connect(ui->btnSearchPrev, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearchBackward); connect(ui->treeDBC, &QTreeWidget::doubleClicked, this, &DBCMainEditor::onTreeDoubleClicked); + connect(ui->treeDBC, &QTreeWidget::customContextMenuRequested, this, &DBCMainEditor::onTreeContextMenu); connect(ui->treeDBC, &QTreeWidget::currentItemChanged, this, &DBCMainEditor::currentItemChanged); connect(ui->btnDelete, &QAbstractButton::clicked, this, &DBCMainEditor::deleteCurrentTreeItem); connect(ui->btnNewNode, &QAbstractButton::clicked, this, &DBCMainEditor::newNode); @@ -298,6 +301,51 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index) } } +void DBCMainEditor::onTreeContextMenu(const QPoint & pos) +{ + QTreeWidgetItem* firstCol = ui->treeDBC->currentItem(); + bool ret = false; + DBC_MESSAGE *msg; + DBC_SIGNAL *sig; + DBC_NODE *node; + uint32_t msgID; + QString idString; + + qDebug() << firstCol->data(0, Qt::UserRole) << " - " << firstCol->text(0); + + switch (firstCol->data(0, Qt::UserRole).toInt()) + { + case 1: //a node + idString = firstCol->text(0).split(" ")[0]; + node = dbcFile->findNodeByName(idString); + + QAction *actionRebase = new QAction(QIcon(":/Resource/warning32.ico"), tr("Rebase all messages"), this); + actionRebase->setStatusTip(tr("Rebase all messages in node")); + connect(actionRebase, SIGNAL(triggered()), this, SLOT(onRebaseMessages())); + + QAction *actionDupe = new QAction(QIcon(":/Resource/warning32.ico"), tr("Duplicate node"), this); + actionDupe->setStatusTip(tr("Duplicate node and messages")); + connect(actionDupe, SIGNAL(triggered()), this, SLOT(onDuplicateNode())); + + QMenu menu(this); + menu.addAction(actionRebase); + menu.addAction(actionDupe); + + QPoint pt(pos); + menu.exec( ui->treeDBC->mapToGlobal(pos) ); + break; + } +} + +void DBCMainEditor::onRebaseMessages() +{ + qDebug() << "rebase!!"; +} + +void DBCMainEditor::onDuplicateNode() +{ + qDebug() << "dupe!!"; +} /* * Recreate the whole tree with pretty icons and custom user roles that give the rest of code an easy way to figure out whether a given tree node diff --git a/dbc/dbcmaineditor.h b/dbc/dbcmaineditor.h index bfc3acd..dc8ea7c 100644 --- a/dbc/dbcmaineditor.h +++ b/dbc/dbcmaineditor.h @@ -32,6 +32,7 @@ public slots: private slots: void onTreeDoubleClicked(const QModelIndex &index); + void onTreeContextMenu(const QPoint & pos); void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *prev); void onCustomMenuTree(QPoint); void deleteCurrentTreeItem(); @@ -43,7 +44,9 @@ private slots: void handleSearchBackward(); void newNode(); void newMessage(); - void newSignal(); + void newSignal(); + void onRebaseMessages(); + void onDuplicateNode(); private: Ui::DBCMainEditor *ui;