From cc18b30e17fe054b4c7b6bd41baafe3aeaa8799a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Wed, 12 Dec 2012 22:36:20 +0100 Subject: [PATCH] open sub view on double click in report view --- apps/opencs/model/tools/reportmodel.cpp | 5 +++++ apps/opencs/model/tools/reportmodel.hpp | 2 ++ apps/opencs/model/world/universalid.hpp | 4 ++++ apps/opencs/view/doc/subview.hpp | 4 ++++ apps/opencs/view/doc/view.cpp | 4 ++++ apps/opencs/view/doc/view.hpp | 6 ++++-- apps/opencs/view/tools/reportsubview.cpp | 11 +++++++++-- apps/opencs/view/tools/reportsubview.hpp | 13 +++++++++++++ 8 files changed, 45 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/tools/reportmodel.cpp b/apps/opencs/model/tools/reportmodel.cpp index f142d7669..b12531875 100644 --- a/apps/opencs/model/tools/reportmodel.cpp +++ b/apps/opencs/model/tools/reportmodel.cpp @@ -63,4 +63,9 @@ void CSMTools::ReportModel::add (const std::string& row) mRows.push_back (std::make_pair (row.substr (0, index), row.substr (index+1))); endInsertRows(); +} + +const CSMWorld::UniversalId& CSMTools::ReportModel::getUniversalId (int row) const +{ + return mRows.at (row).first; } \ No newline at end of file diff --git a/apps/opencs/model/tools/reportmodel.hpp b/apps/opencs/model/tools/reportmodel.hpp index 8814b6d49..55c25d907 100644 --- a/apps/opencs/model/tools/reportmodel.hpp +++ b/apps/opencs/model/tools/reportmodel.hpp @@ -29,6 +29,8 @@ namespace CSMTools virtual bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex()); void add (const std::string& row); + + const CSMWorld::UniversalId& getUniversalId (int row) const; }; } diff --git a/apps/opencs/model/world/universalid.hpp b/apps/opencs/model/world/universalid.hpp index 14c086510..8f43bf083 100644 --- a/apps/opencs/model/world/universalid.hpp +++ b/apps/opencs/model/world/universalid.hpp @@ -4,6 +4,8 @@ #include #include +#include + namespace CSMWorld { class UniversalId @@ -87,4 +89,6 @@ namespace CSMWorld std::ostream& operator< (std::ostream& stream, const UniversalId& universalId); } +Q_DECLARE_METATYPE (CSMWorld::UniversalId) + #endif diff --git a/apps/opencs/view/doc/subview.hpp b/apps/opencs/view/doc/subview.hpp index 50ec511ab..985c5eb3c 100644 --- a/apps/opencs/view/doc/subview.hpp +++ b/apps/opencs/view/doc/subview.hpp @@ -35,6 +35,10 @@ namespace CSVDoc CSMWorld::UniversalId getUniversalId() const; virtual void setEditLock (bool locked) = 0; + + signals: + + void focusId (const CSMWorld::UniversalId& universalId); }; } diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 4ffd9d749..13edb6e74 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -188,6 +188,10 @@ void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id) SubView *view = mSubViewFactory.makeSubView (id, *mDocument); addDockWidget (Qt::TopDockWidgetArea, view); + + connect (view, SIGNAL (focusId (const CSMWorld::UniversalId&)), this, + SLOT (addSubView (const CSMWorld::UniversalId&))); + view->show(); } diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index f7d4dd373..b1dedafe9 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -80,12 +80,14 @@ namespace CSVDoc void updateProgress (int current, int max, int type, int threads); - void addSubView (const CSMWorld::UniversalId& id); - signals: void newDocumentRequest(); + public slots: + + void addSubView (const CSMWorld::UniversalId& id); + private slots: void newView(); diff --git a/apps/opencs/view/tools/reportsubview.cpp b/apps/opencs/view/tools/reportsubview.cpp index 3c9283684..fe1be85d7 100644 --- a/apps/opencs/view/tools/reportsubview.cpp +++ b/apps/opencs/view/tools/reportsubview.cpp @@ -7,19 +7,26 @@ #include "../../model/tools/reportmodel.hpp" CSVTools::ReportSubView::ReportSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) -: CSVDoc::SubView (id) +: CSVDoc::SubView (id), mModel (document.getReport (id)) { setWidget (mTable = new QTableView (this)); - mTable->setModel (document.getReport (id)); + mTable->setModel (mModel); mTable->horizontalHeader()->setResizeMode (QHeaderView::Interactive); mTable->verticalHeader()->hide(); mTable->setSortingEnabled (true); mTable->setSelectionBehavior (QAbstractItemView::SelectRows); mTable->setSelectionMode (QAbstractItemView::ExtendedSelection); + + connect (mTable, SIGNAL (doubleClicked (const QModelIndex&)), this, SLOT (show (const QModelIndex&))); } void CSVTools::ReportSubView::setEditLock (bool locked) { // ignored. We don't change document state anyway. +} + +void CSVTools::ReportSubView::show (const QModelIndex& index) +{ + focusId (mModel->getUniversalId (index.row())); } \ No newline at end of file diff --git a/apps/opencs/view/tools/reportsubview.hpp b/apps/opencs/view/tools/reportsubview.hpp index f81f3c386..626ceb663 100644 --- a/apps/opencs/view/tools/reportsubview.hpp +++ b/apps/opencs/view/tools/reportsubview.hpp @@ -4,18 +4,27 @@ #include "../doc/subview.hpp" class QTableView; +class QModelIndex; namespace CSMDoc { class Document; } +namespace CSMTools +{ + class ReportModel; +} + namespace CSVTools { class Table; class ReportSubView : public CSVDoc::SubView { + Q_OBJECT + + CSMTools::ReportModel *mModel; QTableView *mTable; public: @@ -23,6 +32,10 @@ namespace CSVTools ReportSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document); virtual void setEditLock (bool locked); + + private slots: + + void show (const QModelIndex& index); }; }