2014-03-06 09:13:39 +00:00
|
|
|
|
|
|
|
#include "pagedworldspacewidget.hpp"
|
|
|
|
|
2014-04-01 08:04:14 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2014-04-30 12:27:11 +00:00
|
|
|
#include <qt4/QtGui/qevent.h>
|
|
|
|
|
|
|
|
#include <apps/opencs/model/world/tablemimedata.hpp>
|
|
|
|
|
2014-04-30 13:03:46 +00:00
|
|
|
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document)
|
2014-05-01 13:09:47 +00:00
|
|
|
: WorldspaceWidget (document, parent)
|
|
|
|
{}
|
2014-04-01 08:04:14 +00:00
|
|
|
|
|
|
|
void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
|
|
|
|
{
|
|
|
|
if (!hint.empty())
|
|
|
|
{
|
2014-04-07 12:16:02 +00:00
|
|
|
CSMWorld::CellSelection selection;
|
|
|
|
|
2014-04-01 08:04:14 +00:00
|
|
|
if (hint[0]=='c')
|
|
|
|
{
|
2014-04-07 13:23:14 +00:00
|
|
|
// syntax: c:#x1 y1; #x2 y2 (number of coordinate pairs can be 0 or larger)
|
|
|
|
char ignore;
|
2014-04-01 08:04:14 +00:00
|
|
|
|
|
|
|
std::istringstream stream (hint.c_str());
|
2014-04-07 13:23:14 +00:00
|
|
|
if (stream >> ignore)
|
2014-04-01 08:04:14 +00:00
|
|
|
{
|
2014-04-07 13:23:14 +00:00
|
|
|
char ignore1; // : or ;
|
|
|
|
char ignore2; // #
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
while (stream >> ignore1 >> ignore2 >> x >> y)
|
|
|
|
selection.add (CSMWorld::CellCoordinates (x, y));
|
2014-04-01 08:04:14 +00:00
|
|
|
|
|
|
|
/// \todo adjust camera position
|
|
|
|
}
|
|
|
|
}
|
2014-04-07 13:23:14 +00:00
|
|
|
else if (hint[0]=='r')
|
|
|
|
{
|
|
|
|
/// \todo implement 'r' type hints
|
|
|
|
}
|
2014-04-07 12:16:02 +00:00
|
|
|
|
|
|
|
setCellSelection (selection);
|
2014-04-01 08:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-07 12:16:02 +00:00
|
|
|
void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSelection& selection)
|
2014-04-01 08:04:14 +00:00
|
|
|
{
|
2014-04-07 12:16:02 +00:00
|
|
|
mSelection = selection;
|
|
|
|
emit cellSelectionChanged (mSelection);
|
2014-04-30 12:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVRender::PagedWorldspaceWidget::dropEvent (QDropEvent* event)
|
|
|
|
{
|
|
|
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
|
2014-05-01 13:09:47 +00:00
|
|
|
|
2014-04-30 13:03:46 +00:00
|
|
|
if (mime->fromDocument(mDocument))
|
2014-04-30 12:27:11 +00:00
|
|
|
{
|
2014-05-01 13:09:47 +00:00
|
|
|
const std::vector<CSMWorld::UniversalId> data(mime->getData());
|
|
|
|
CSVRender::WorldspaceWidget::dropType whatHappend = getDropType(data);
|
2014-04-30 13:03:46 +00:00
|
|
|
|
2014-05-01 13:09:47 +00:00
|
|
|
std::cout<<whatHappend<<std::endl;
|
|
|
|
switch (whatHappend)
|
2014-04-30 12:27:11 +00:00
|
|
|
{
|
2014-05-01 13:09:47 +00:00
|
|
|
case CSVRender::WorldspaceWidget::cellsExterior:
|
|
|
|
handleDrop(data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CSVRender::WorldspaceWidget::cellsInterior:
|
|
|
|
emit interiorCellsDropped(data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
//not interior or exterior = either mixed or not actually cells. We don't need to do anything in this case.
|
|
|
|
break;
|
2014-04-30 12:27:11 +00:00
|
|
|
}
|
2014-05-01 13:09:47 +00:00
|
|
|
} //not handling drops from different documents at the moment
|
2014-04-30 12:27:11 +00:00
|
|
|
}
|
2014-04-30 13:03:46 +00:00
|
|
|
|
|
|
|
std::pair< int, int > CSVRender::PagedWorldspaceWidget::getCoordinatesFromId (const std::string& record) const
|
|
|
|
{
|
2014-05-01 10:34:54 +00:00
|
|
|
std::istringstream stream (record.c_str());
|
|
|
|
char ignore;
|
|
|
|
int x, y;
|
2014-05-01 13:09:47 +00:00
|
|
|
stream >> ignore >> x >> y;
|
2014-04-30 13:03:46 +00:00
|
|
|
return std::make_pair(x, y);
|
|
|
|
}
|
|
|
|
|
2014-05-01 13:09:47 +00:00
|
|
|
void CSVRender::PagedWorldspaceWidget::handleDrop (const std::vector< CSMWorld::UniversalId >& data)
|
|
|
|
{
|
|
|
|
bool selectionChanged = false;
|
|
|
|
for (unsigned i = 0; i < data.size(); ++i)
|
|
|
|
{
|
|
|
|
std::pair<int, int> coordinates(getCoordinatesFromId(data[i].getId()));
|
|
|
|
if (mSelection.add(CSMWorld::CellCoordinates(coordinates.first, coordinates.second)))
|
|
|
|
{
|
|
|
|
selectionChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (selectionChanged)
|
|
|
|
{
|
|
|
|
emit cellSelectionChanged(mSelection);
|
|
|
|
}
|
|
|
|
}
|