working on worldspace drops

openmw-30
Marek Kochanowicz 11 years ago
parent 57131332f4
commit d00dbf47d5

@ -8,11 +8,8 @@
#include <apps/opencs/model/world/tablemimedata.hpp>
CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document)
: WorldspaceWidget (parent),
mDocument(document)
{
setAcceptDrops(true);
}
: WorldspaceWidget (document, parent)
{}
void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
{
@ -53,48 +50,55 @@ void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSel
emit cellSelectionChanged (mSelection);
}
void CSVRender::PagedWorldspaceWidget::dragEnterEvent (QDragEnterEvent* event)
{
event->accept();
}
void CSVRender::PagedWorldspaceWidget::dragMoveEvent (QDragMoveEvent* event)
{
event->accept();
}
void CSVRender::PagedWorldspaceWidget::dropEvent (QDropEvent* event)
{
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
if (mime->fromDocument(mDocument))
{
std::vector<CSMWorld::UniversalId> data(mime->getData());
const std::vector<CSMWorld::UniversalId> data(mime->getData());
CSVRender::WorldspaceWidget::dropType whatHappend = getDropType(data);
for (unsigned i = 0; i < data.size(); ++i)
std::cout<<whatHappend<<std::endl;
switch (whatHappend)
{
if (data[i].getType() == CSMWorld::UniversalId::Type_Cell ||
data[i].getType() == CSMWorld::UniversalId::Type_Cell_Missing)
{
if (*(data[i].getId().begin()) == '#')
{
std::pair<int, int> coordinate(getCoordinatesFromId(data[i].getId()));
mSelection.add(CSMWorld::CellCoordinates(coordinate.first, coordinate.second));
}
}
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;
}
}
} //not handling drops from different documents at the moment
}
std::pair< int, int > CSVRender::PagedWorldspaceWidget::getCoordinatesFromId (const std::string& record) const
{
std::istringstream stream (record.c_str());
char ignore;
stream >> ignore;
char ignore1; // : or ;
char ignore2; // #
int x, y;
stream >> ignore1 >> ignore2 >> x >> y;
stream >> ignore >> x >> y;
return std::make_pair(x, y);
}
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);
}
}

@ -2,7 +2,6 @@
#define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H
#include "../../model/world/cellselection.hpp"
#include <apps/opencs/model/doc/document.hpp>
#include "worldspacewidget.hpp"
@ -13,18 +12,15 @@ namespace CSVRender
Q_OBJECT
CSMWorld::CellSelection mSelection;
const CSMDoc::Document& mDocument; //for checking if drop comes from same document
private:
void dropEvent(QDropEvent* event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
std::pair<int, int> getCoordinatesFromId(const std::string& record) const;
void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
public:
PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document);
@ -39,6 +35,8 @@ namespace CSVRender
signals:
void cellSelectionChanged (const CSMWorld::CellSelection& selection);
void interiorCellsDropped(const std::vector<CSMWorld::UniversalId>& data);
};
}

@ -3,10 +3,13 @@
#include <OgreColourValue.h>
#include <qt4/QtGui/qevent.h>
#include "../../model/doc/document.hpp"
#include "../../model/world/data.hpp"
#include "../../model/world/idtable.hpp"
#include "../../model/world/tablemimedata.hpp"
void CSVRender::UnpagedWorldspaceWidget::update()
{
@ -22,7 +25,7 @@ void CSVRender::UnpagedWorldspaceWidget::update()
CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget (const std::string& cellId,
CSMDoc::Document& document, QWidget *parent)
: WorldspaceWidget (parent), mCellId (cellId)
: WorldspaceWidget (document, parent), mCellId (cellId)
{
mCellsModel = &dynamic_cast<CSMWorld::IdTable&> (
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Cells));
@ -63,4 +66,35 @@ void CSVRender::UnpagedWorldspaceWidget::cellRowsAboutToBeRemoved (const QModelI
if (cellIndex.row()>=start && cellIndex.row()<=end)
emit closeRequest();
}
}
void CSVRender::UnpagedWorldspaceWidget::dropEvent (QDropEvent* event)
{
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
if (mime->fromDocument (mDocument))
{
const std::vector<CSMWorld::UniversalId> data (mime->getData());
CSVRender::WorldspaceWidget::dropType whatHappend = getDropType (data);
switch (whatHappend)
{
case CSVRender::WorldspaceWidget::cellsExterior:
emit exteriorCellsDropped(data);
break;
case CSVRender::WorldspaceWidget::cellsInterior:
handleDrop(data);
break;
default:
//not interior or exterior = either mixed or not actually cells. We don't need to do anything in this case.
break;
}
} //not handling drops from different documents at the moment
}
void CSVRender::UnpagedWorldspaceWidget::handleDrop (const std::vector< CSMWorld::UniversalId >& data)
{
}

@ -33,11 +33,22 @@ namespace CSVRender
UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document,
QWidget *parent);
private:
void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
void dropEvent(QDropEvent* event);
private slots:
void cellDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
void cellRowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
signals:
void exteriorCellsDropped(const std::vector<CSMWorld::UniversalId>& data);
};
}

@ -5,15 +5,20 @@
#include <OgreSceneManager.h>
#include <OgreEntity.h>
#include <qt4/QtGui/qevent.h>
#include "../world/scenetoolmode.hpp"
#include <apps/opencs/model/world/universalid.hpp>
CSVRender::WorldspaceWidget::WorldspaceWidget (QWidget *parent)
: SceneWidget (parent)
CSVRender::WorldspaceWidget::WorldspaceWidget (const CSMDoc::Document& document, QWidget* parent)
: SceneWidget (parent), mDocument(document)
{
Ogre::Entity* ent = getSceneManager()->createEntity("cube", Ogre::SceneManager::PT_CUBE);
ent->setMaterialName("BaseWhite");
getSceneManager()->getRootSceneNode()->attachObject(ent);
setAcceptDrops(true);
}
void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode)
@ -46,4 +51,67 @@ CSVWorld::SceneToolMode *CSVRender::WorldspaceWidget::makeNavigationSelector (
this, SLOT (selectNavigationMode (const std::string&)));
return tool;
}
}
CSVRender::WorldspaceWidget::dropType CSVRender::WorldspaceWidget::getDropType (
const std::vector< CSMWorld::UniversalId >& data) const
{
dropType output = notCells;
bool firstIteration = true;
for (unsigned i = 0; i < data.size(); ++i)
{
if (data[i].getType() == CSMWorld::UniversalId::Type_Cell ||
data[i].getType() == CSMWorld::UniversalId::Type_Cell_Missing)
{
if (*(data[i].getId().begin()) == '#') //exterior
{
if (firstIteration)
{
output = cellsExterior;
firstIteration = false;
continue;
}
if (output == cellsInterior)
{
output = cellsMixed;
break;
} else {
output = cellsInterior;
}
} else //interior
{
if (firstIteration)
{
output = cellsInterior;
firstIteration = false;
continue;
}
if (output == cellsExterior)
{
output = cellsMixed;
break;
} else {
output = cellsInterior;
}
}
} else {
output = notCells;
break;
}
}
return output;
}
void CSVRender::WorldspaceWidget::dragEnterEvent (QDragEnterEvent* event)
{
event->accept();
}
void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event)
{
event->accept();
}

@ -6,7 +6,12 @@
#include "navigation1st.hpp"
#include "navigationfree.hpp"
#include "navigationorbit.hpp"
#include <apps/opencs/model/doc/document.hpp>
namespace CSMWorld
{
class UniversalId;
}
namespace CSVWorld
{
class SceneToolMode;
@ -25,7 +30,7 @@ namespace CSVRender
public:
WorldspaceWidget (QWidget *parent = 0);
WorldspaceWidget (const CSMDoc::Document& document, QWidget *parent = 0);
CSVWorld::SceneToolMode *makeNavigationSelector (CSVWorld::SceneToolbar *parent);
///< \attention The created tool is not added to the toolbar (via addTool). Doing that
@ -36,6 +41,25 @@ namespace CSVRender
virtual void useViewHint (const std::string& hint);
///< Default-implementation: ignored.
protected:
const CSMDoc::Document& mDocument; //for checking if drop comes from same document
enum dropType
{
cellsMixed,
cellsInterior,
cellsExterior,
notCells
};
dropType getDropType(const std::vector<CSMWorld::UniversalId>& data) const;
private:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
private slots:
void selectNavigationMode (const std::string& mode);

Loading…
Cancel
Save