From 6aaa15b2e86f5ddc69e6e4250bccf2a7b65f0831 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Wed, 30 Apr 2014 15:03:46 +0200 Subject: [PATCH] paged worldspace drop --- .../view/render/pagedworldspacewidget.cpp | 40 ++++++++++++------- .../view/render/pagedworldspacewidget.hpp | 6 ++- apps/opencs/view/world/scenesubview.cpp | 2 +- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index 3f40712d2..d916e33e9 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -9,8 +9,9 @@ #include -CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent) -: WorldspaceWidget (parent) +CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document) +: WorldspaceWidget (parent), +mDocument(document) { setAcceptDrops(true); } @@ -66,24 +67,33 @@ void CSVRender::PagedWorldspaceWidget::dragMoveEvent (QDragMoveEvent* event) void CSVRender::PagedWorldspaceWidget::dropEvent (QDropEvent* event) { - /* const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); - if (true) + if (mime->fromDocument(mDocument)) { - if (mime->holdsType(CSMWorld::UniversalId::Type_Cell)) + std::vector data(mime->getData()); + + for (unsigned i = 0; i < data.size(); ++i) { - CSMWorld::UniversalId record(mime->returnMatching (CSMWorld::UniversalId::Type_Cell)); - QString id(QString::fromUtf8(record.getId().c_str())); - if (*id.begin() == '#') + if (data[i].getType() == CSMWorld::UniversalId::Type_Cell || + data[i].getType() == CSMWorld::UniversalId::Type_Cell_Missing) { - id.remove(0,1); - QStringList splited(id.split(' ')); - int x = splited.begin()->toInt(); - int y = (splited.begin()+1)->toInt(); - mSelection.add(CSMWorld::CellCoordinates(x, y)); + if (*(data[i].getId().begin()) == '#') + { + std::pair coordinate(getCoordinatesFromId(data[i].getId())); + mSelection.add(CSMWorld::CellCoordinates(coordinate.first, coordinate.second)); + } } } } - */ - //TODO! } + +std::pair< int, int > CSVRender::PagedWorldspaceWidget::getCoordinatesFromId (const std::string& record) const +{ + QString id(QString::fromUtf8(record.c_str())); + id.remove(0,1); + QStringList splited(id.split(' ')); //Well, this is the simplest approach + int x = splited.begin()->toInt(); + int y = (splited.begin()+1)->toInt(); + return std::make_pair(x, y); +} + diff --git a/apps/opencs/view/render/pagedworldspacewidget.hpp b/apps/opencs/view/render/pagedworldspacewidget.hpp index c6fdbf3be..bfcb25e66 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.hpp +++ b/apps/opencs/view/render/pagedworldspacewidget.hpp @@ -2,6 +2,7 @@ #define OPENCS_VIEW_PAGEDWORLDSPACEWIDGET_H #include "../../model/world/cellselection.hpp" +#include #include "worldspacewidget.hpp" @@ -12,6 +13,7 @@ namespace CSVRender Q_OBJECT CSMWorld::CellSelection mSelection; + const CSMDoc::Document& mDocument; //for checking if drop comes from same document private: @@ -21,9 +23,11 @@ namespace CSVRender void dragMoveEvent(QDragMoveEvent *event); + std::pair getCoordinatesFromId(const std::string& record) const; + public: - PagedWorldspaceWidget (QWidget *parent); + PagedWorldspaceWidget (QWidget *parent, const CSMDoc::Document& document); ///< \note Sets the cell area selection to an invalid value to indicate that currently /// no cells are displayed. The cells to be displayed will be specified later through /// hint system. diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index 0bb11ce8c..506a0288d 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -40,7 +40,7 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D if (id.getId()=="sys::default") { - CSVRender::PagedWorldspaceWidget *widget = new CSVRender::PagedWorldspaceWidget (this); + CSVRender::PagedWorldspaceWidget *widget = new CSVRender::PagedWorldspaceWidget (this, document); mScene = widget; connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)), this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&)));