From f2fc6933250d4cfa6b4a1459463657a349e00f76 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 6 Dec 2014 14:17:56 +0100 Subject: [PATCH] added context menu to report table --- apps/opencs/view/tools/reporttable.cpp | 28 ++++++++++++++++++++++++++ apps/opencs/view/tools/reporttable.hpp | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/apps/opencs/view/tools/reporttable.cpp b/apps/opencs/view/tools/reporttable.cpp index 5bf38f020..ec2ba74d2 100644 --- a/apps/opencs/view/tools/reporttable.cpp +++ b/apps/opencs/view/tools/reporttable.cpp @@ -2,11 +2,26 @@ #include "reporttable.hpp" #include +#include +#include #include "../../model/tools/reportmodel.hpp" #include "../../view/world/idtypedelegate.hpp" +void CSVTools::ReportTable::contextMenuEvent (QContextMenuEvent *event) +{ + QModelIndexList selectedRows = selectionModel()->selectedRows(); + + // create context menu + QMenu menu (this); + + if (!selectedRows.empty()) + menu.addAction (mShowAction); + + menu.exec (event->globalPos()); +} + void CSVTools::ReportTable::mouseMoveEvent (QMouseEvent *event) { if (event->buttons() & Qt::LeftButton) @@ -31,6 +46,10 @@ CSVTools::ReportTable::ReportTable (CSMDoc::Document& document, setItemDelegateForColumn (0, mIdTypeDelegate); + mShowAction = new QAction (tr ("Show"), this); + connect (mShowAction, SIGNAL (triggered()), this, SLOT (showSelection())); + addAction (mShowAction); + connect (this, SIGNAL (doubleClicked (const QModelIndex&)), this, SLOT (show (const QModelIndex&))); } @@ -57,4 +76,13 @@ void CSVTools::ReportTable::updateUserSetting (const QString& name, const QStrin void CSVTools::ReportTable::show (const QModelIndex& index) { emit editRequest (mModel->getUniversalId (index.row()), mModel->getHint (index.row())); +} + +void CSVTools::ReportTable::showSelection() +{ + QModelIndexList selectedRows = selectionModel()->selectedRows(); + + for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); + ++iter) + show (*iter); } \ No newline at end of file diff --git a/apps/opencs/view/tools/reporttable.hpp b/apps/opencs/view/tools/reporttable.hpp index acd1ed3cc..75b6e8553 100644 --- a/apps/opencs/view/tools/reporttable.hpp +++ b/apps/opencs/view/tools/reporttable.hpp @@ -3,6 +3,8 @@ #include "../world/dragrecordtable.hpp" +class QAction; + namespace CSMTools { class ReportModel; @@ -21,9 +23,12 @@ namespace CSVTools CSMTools::ReportModel *mModel; CSVWorld::CommandDelegate *mIdTypeDelegate; + QAction *mShowAction; private: + void contextMenuEvent (QContextMenuEvent *event); + void mouseMoveEvent (QMouseEvent *event); public: @@ -39,6 +44,8 @@ namespace CSVTools void show (const QModelIndex& index); + void showSelection(); + signals: void editRequest (const CSMWorld::UniversalId& id, const std::string& hint);