From 0d352cb8832863445b7ad464610f8351c2588323 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 7 Apr 2014 14:16:02 +0200 Subject: [PATCH] replaced rectangular cell selection with a CellSelection object --- .../view/render/pagedworldspacewidget.cpp | 21 ++++++------ .../view/render/pagedworldspacewidget.hpp | 9 +++--- apps/opencs/view/world/scenesubview.cpp | 32 +++++++++++++------ apps/opencs/view/world/scenesubview.hpp | 7 +++- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 96d44543e..ab02d63ee 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -4,36 +4,37 @@ #include CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent) -: WorldspaceWidget (parent), mMin (std::make_pair (0, 0)), mMax (std::make_pair (-1, -1)) +: WorldspaceWidget (parent) {} void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint) { if (!hint.empty()) { + CSMWorld::CellSelection selection; + if (hint[0]=='c') { char ignore1, ignore2, ignore3; - std::pair cellIndex; + int x, y; std::istringstream stream (hint.c_str()); - if (stream >> ignore1 >> ignore2 >> ignore3 >> cellIndex.first >> cellIndex.second) + if (stream >> ignore1 >> ignore2 >> ignore3 >> x >> y) { - setCellIndex (cellIndex, cellIndex); + selection.add (CSMWorld::CellCoordinates (x, y)); /// \todo adjust camera position } } /// \todo implement 'r' type hints + + setCellSelection (selection); } } -void CSVRender::PagedWorldspaceWidget::setCellIndex (const std::pair& min, - const std::pair& max) +void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSelection& selection) { - mMin = min; - mMax = max; - - emit cellIndexChanged (mMin, mMax); + mSelection = selection; + emit cellSelectionChanged (mSelection); } \ No newline at end of file diff --git a/apps/opencs/view/render/pagedworldspacewidget.hpp b/apps/opencs/view/render/pagedworldspacewidget.hpp index 9a4b79c3a..f6ff32dc1 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.hpp +++ b/apps/opencs/view/render/pagedworldspacewidget.hpp @@ -1,6 +1,8 @@ #ifndef OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H #define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H +#include "../../model/world/cellselection.hpp" + #include "worldspacewidget.hpp" namespace CSVRender @@ -9,8 +11,7 @@ namespace CSVRender { Q_OBJECT - std::pair mMin; - std::pair mMax; + CSMWorld::CellSelection mSelection; public: @@ -21,11 +22,11 @@ namespace CSVRender virtual void useViewHint (const std::string& hint); - void setCellIndex (const std::pair& min, const std::pair& max); + void setCellSelection (const CSMWorld::CellSelection& selection); signals: - void cellIndexChanged (const std::pair& min, const std::pair& max); + void cellSelectionChanged (const CSMWorld::CellSelection& selection); }; } diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index 4ebaa9352..0bb11ce8c 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -9,6 +9,8 @@ #include "../../model/doc/document.hpp" +#include "../../model/world/cellselection.hpp" + #include "../filter/filterbox.hpp" #include "../render/pagedworldspacewidget.hpp" @@ -40,10 +42,8 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D { CSVRender::PagedWorldspaceWidget *widget = new CSVRender::PagedWorldspaceWidget (this); mScene = widget; - connect (widget, - SIGNAL (cellIndexChanged (const std::pair&, const std::pair&)), - this, - SLOT (cellIndexChanged (const std::pair&, const std::pair&))); + connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)), + this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&))); } else mScene = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this); @@ -102,16 +102,28 @@ void CSVWorld::SceneSubView::closeRequest() deleteLater(); } -void CSVWorld::SceneSubView::cellIndexChanged (const std::pair& min, - const std::pair& max) +void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::CellSelection& selection) { + int size = selection.getSize(); + std::ostringstream stream; - stream << "Scene: " << getUniversalId().getId() << " (" << min.first << ", " << min.second; + stream << "Scene: " << getUniversalId().getId(); - if (min!=max) - stream << " to " << max.first << ", " << max.second; + if (size==0) + stream << " (empty)"; + else if (size==1) + { + stream << " (" << *selection.begin() << ")"; + } + else + { + stream << " (" << selection.getCentre() << " and " << size-1 << " more "; - stream << ")"; + if (size>1) + stream << "cells around it)"; + else + stream << "cell around it)"; + } setWindowTitle (QString::fromUtf8 (stream.str().c_str())); } \ No newline at end of file diff --git a/apps/opencs/view/world/scenesubview.hpp b/apps/opencs/view/world/scenesubview.hpp index ee5b7b41f..0b15ea541 100644 --- a/apps/opencs/view/world/scenesubview.hpp +++ b/apps/opencs/view/world/scenesubview.hpp @@ -5,6 +5,11 @@ class QModelIndex; +namespace CSMWorld +{ + class CellSelection; +} + namespace CSMDoc { class Document; @@ -44,7 +49,7 @@ namespace CSVWorld void closeRequest(); - void cellIndexChanged (const std::pair& min, const std::pair& max); + void cellSelectionChanged (const CSMWorld::CellSelection& selection); }; }