1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-30 11:06:43 +00:00

replaced rectangular cell selection with a CellSelection object

This commit is contained in:
Marc Zinnschlag 2014-04-07 14:16:02 +02:00
parent 67965ec10c
commit 0d352cb883
4 changed files with 44 additions and 25 deletions

View file

@ -4,36 +4,37 @@
#include <sstream> #include <sstream>
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent) 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) void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
{ {
if (!hint.empty()) if (!hint.empty())
{ {
CSMWorld::CellSelection selection;
if (hint[0]=='c') if (hint[0]=='c')
{ {
char ignore1, ignore2, ignore3; char ignore1, ignore2, ignore3;
std::pair<int, int> cellIndex; int x, y;
std::istringstream stream (hint.c_str()); 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 adjust camera position
} }
} }
/// \todo implement 'r' type hints /// \todo implement 'r' type hints
setCellSelection (selection);
} }
} }
void CSVRender::PagedWorldspaceWidget::setCellIndex (const std::pair<int, int>& min, void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSelection& selection)
const std::pair<int, int>& max)
{ {
mMin = min; mSelection = selection;
mMax = max; emit cellSelectionChanged (mSelection);
emit cellIndexChanged (mMin, mMax);
} }

View file

@ -1,6 +1,8 @@
#ifndef OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H #ifndef OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H
#define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H #define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H
#include "../../model/world/cellselection.hpp"
#include "worldspacewidget.hpp" #include "worldspacewidget.hpp"
namespace CSVRender namespace CSVRender
@ -9,8 +11,7 @@ namespace CSVRender
{ {
Q_OBJECT Q_OBJECT
std::pair<int, int> mMin; CSMWorld::CellSelection mSelection;
std::pair<int, int> mMax;
public: public:
@ -21,11 +22,11 @@ namespace CSVRender
virtual void useViewHint (const std::string& hint); virtual void useViewHint (const std::string& hint);
void setCellIndex (const std::pair<int, int>& min, const std::pair<int, int>& max); void setCellSelection (const CSMWorld::CellSelection& selection);
signals: signals:
void cellIndexChanged (const std::pair<int, int>& min, const std::pair<int, int>& max); void cellSelectionChanged (const CSMWorld::CellSelection& selection);
}; };
} }

View file

@ -9,6 +9,8 @@
#include "../../model/doc/document.hpp" #include "../../model/doc/document.hpp"
#include "../../model/world/cellselection.hpp"
#include "../filter/filterbox.hpp" #include "../filter/filterbox.hpp"
#include "../render/pagedworldspacewidget.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); CSVRender::PagedWorldspaceWidget *widget = new CSVRender::PagedWorldspaceWidget (this);
mScene = widget; mScene = widget;
connect (widget, connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)),
SIGNAL (cellIndexChanged (const std::pair<int, int>&, const std::pair<int, int>&)), this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&)));
this,
SLOT (cellIndexChanged (const std::pair<int, int>&, const std::pair<int, int>&)));
} }
else else
mScene = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this); mScene = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this);
@ -102,16 +102,28 @@ void CSVWorld::SceneSubView::closeRequest()
deleteLater(); deleteLater();
} }
void CSVWorld::SceneSubView::cellIndexChanged (const std::pair<int, int>& min, void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::CellSelection& selection)
const std::pair<int, int>& max)
{ {
int size = selection.getSize();
std::ostringstream stream; std::ostringstream stream;
stream << "Scene: " << getUniversalId().getId() << " (" << min.first << ", " << min.second; stream << "Scene: " << getUniversalId().getId();
if (min!=max) if (size==0)
stream << " to " << max.first << ", " << max.second; 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())); setWindowTitle (QString::fromUtf8 (stream.str().c_str()));
} }

View file

@ -5,6 +5,11 @@
class QModelIndex; class QModelIndex;
namespace CSMWorld
{
class CellSelection;
}
namespace CSMDoc namespace CSMDoc
{ {
class Document; class Document;
@ -44,7 +49,7 @@ namespace CSVWorld
void closeRequest(); void closeRequest();
void cellIndexChanged (const std::pair<int, int>& min, const std::pair<int, int>& max); void cellSelectionChanged (const CSMWorld::CellSelection& selection);
}; };
} }