diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index a6bdb5180..c9308fbfb 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -50,32 +50,6 @@ void CSVRender::PagedWorldspaceWidget::setCellSelection (const CSMWorld::CellSel emit cellSelectionChanged (mSelection); } -void CSVRender::PagedWorldspaceWidget::dropEvent (QDropEvent* event) -{ - const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); - - if (mime->fromDocument(mDocument)) - { - const std::vector& data(mime->getData()); - CSVRender::WorldspaceWidget::dropType whatHappend = getDropType(data); - - switch (whatHappend) - { - 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()); @@ -101,3 +75,18 @@ void CSVRender::PagedWorldspaceWidget::handleDrop (const std::vector< CSMWorld:: emit cellSelectionChanged(mSelection); } } + +CSVRender::WorldspaceWidget::dropRequirments CSVRender::PagedWorldspaceWidget::getDropRequirements (CSVRender::WorldspaceWidget::dropType type) const +{ + switch (type) + { + case cellsExterior: + return canHandle; + + case cellsInterior: + return needUnpaged; + + default: + return ignored; + } +} \ No newline at end of file diff --git a/apps/opencs/view/render/pagedworldspacewidget.hpp b/apps/opencs/view/render/pagedworldspacewidget.hpp index bd5d1107c..0a73c791c 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.hpp +++ b/apps/opencs/view/render/pagedworldspacewidget.hpp @@ -15,8 +15,6 @@ namespace CSVRender private: - void dropEvent(QDropEvent* event); - std::pair getCoordinatesFromId(const std::string& record) const; public: @@ -32,11 +30,11 @@ namespace CSVRender virtual void handleDrop(const std::vector& data); + virtual dropRequirments getDropRequirements(dropType type) const; + signals: void cellSelectionChanged (const CSMWorld::CellSelection& selection); - - void interiorCellsDropped(const std::vector& data); }; } diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 1aee421ed..8a58b7d32 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -320,7 +320,7 @@ namespace CSVRender } - if (mUpdate) + if (mUpdate && mWindow) { mUpdate = false; mWindow->update(); diff --git a/apps/opencs/view/render/unpagedworldspacewidget.cpp b/apps/opencs/view/render/unpagedworldspacewidget.cpp index 929088789..de4dde9dd 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.cpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.cpp @@ -67,34 +67,24 @@ void CSVRender::UnpagedWorldspaceWidget::cellRowsAboutToBeRemoved (const QModelI emit closeRequest(); } -void CSVRender::UnpagedWorldspaceWidget::dropEvent (QDropEvent* event) +void CSVRender::UnpagedWorldspaceWidget::handleDrop (const std::vector< CSMWorld::UniversalId >& data) { - const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + mCellId = data.begin()->getId(); + update(); + emit cellChanged(*data.begin()); +} - if (mime->fromDocument (mDocument)) +CSVRender::WorldspaceWidget::dropRequirments CSVRender::UnpagedWorldspaceWidget::getDropRequirements (CSVRender::WorldspaceWidget::dropType type) const +{ + switch(type) { - const std::vector& data (mime->getData()); - CSVRender::WorldspaceWidget::dropType whatHappend = getDropType (data); - - switch (whatHappend) - { - case CSVRender::WorldspaceWidget::cellsExterior: - emit exteriorCellsDropped(data); - break; + case cellsInterior: + return canHandle; - case CSVRender::WorldspaceWidget::cellsInterior: - handleDrop(data); - break; + case cellsExterior: + return needPaged; - 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) -{ - mCellId = data.begin()->getId(); - update(); + default: + return ignored; + } } diff --git a/apps/opencs/view/render/unpagedworldspacewidget.hpp b/apps/opencs/view/render/unpagedworldspacewidget.hpp index ad1e22e39..bb5340845 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.hpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.hpp @@ -31,14 +31,11 @@ namespace CSVRender public: UnpagedWorldspaceWidget (const std::string& cellId, CSMDoc::Document& document, - QWidget *parent); + QWidget *parent); + virtual dropRequirments getDropRequirements(dropType type) const; - private: - - void handleDrop(const std::vector& data); - - void dropEvent(QDropEvent* event); + virtual void handleDrop(const std::vector& data); private slots: @@ -48,8 +45,7 @@ namespace CSVRender signals: - void exteriorCellsDropped(const std::vector& data); - + void cellChanged(const CSMWorld::UniversalId& id); }; } diff --git a/apps/opencs/view/render/worldspacewidget.cpp b/apps/opencs/view/render/worldspacewidget.cpp index 16ff0a403..c83a5a3e1 100644 --- a/apps/opencs/view/render/worldspacewidget.cpp +++ b/apps/opencs/view/render/worldspacewidget.cpp @@ -115,3 +115,14 @@ void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event) { event->accept(); } + + +void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event) +{ + const CSMWorld::TableMimeData* mime = dynamic_cast (event->mimeData()); + + if (mime->fromDocument (mDocument)) + { + emit dataDropped(mime->getData()); + } //not handling drops from different documents at the moment +} \ No newline at end of file diff --git a/apps/opencs/view/render/worldspacewidget.hpp b/apps/opencs/view/render/worldspacewidget.hpp index f9d4f9a06..a14e03915 100644 --- a/apps/opencs/view/render/worldspacewidget.hpp +++ b/apps/opencs/view/render/worldspacewidget.hpp @@ -7,6 +7,7 @@ #include "navigationfree.hpp" #include "navigationorbit.hpp" #include +#include namespace CSMWorld { @@ -30,13 +31,21 @@ namespace CSVRender public: - enum dropType - { - cellsMixed, - cellsInterior, - cellsExterior, - notCells - }; + enum dropType + { + cellsMixed, + cellsInterior, + cellsExterior, + notCells + }; + + enum dropRequirments + { + canHandle, + needPaged, + needUnpaged, + ignored //either mixed cells, or not cells + }; WorldspaceWidget (const CSMDoc::Document& document, QWidget *parent = 0); @@ -48,9 +57,13 @@ namespace CSVRender static dropType getDropType(const std::vector& data); + virtual dropRequirments getDropRequirements(dropType type) const = 0; + virtual void useViewHint (const std::string& hint); ///< Default-implementation: ignored. + virtual void handleDrop(const std::vector& data) = 0; + protected: const CSMDoc::Document& mDocument; //for checking if drop comes from same document @@ -58,6 +71,8 @@ namespace CSVRender void dragEnterEvent(QDragEnterEvent *event); + void dropEvent(QDropEvent* event); + void dragMoveEvent(QDragMoveEvent *event); private slots: @@ -67,6 +82,7 @@ namespace CSVRender signals: void closeRequest(); + void dataDropped(const std::vector& data); }; } diff --git a/apps/opencs/view/world/scenesubview.cpp b/apps/opencs/view/world/scenesubview.cpp index f3807e4e9..d411985b3 100644 --- a/apps/opencs/view/world/scenesubview.cpp +++ b/apps/opencs/view/world/scenesubview.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "../../model/doc/document.hpp" @@ -21,7 +22,7 @@ #include "scenetoolmode.hpp" CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document) -: SubView (id), mLayout(new QHBoxLayout), mDocument(document) +: SubView (id), mLayout(new QHBoxLayout), mDocument(document), mScene(NULL), mToolbar(NULL) { QVBoxLayout *layout = new QVBoxLayout; @@ -33,39 +34,26 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D mLayout->setContentsMargins (QMargins (0, 0, 0, 0)); - mToolbar = new SceneToolbar (48+6, this); + CSVRender::WorldspaceWidget* wordspaceWidget = NULL; if (id.getId()=="sys::default") { - CSVRender::PagedWorldspaceWidget *widget = new CSVRender::PagedWorldspaceWidget (this, document); + CSVRender::PagedWorldspaceWidget *newWidget = new CSVRender::PagedWorldspaceWidget (this, document); - mScene = widget; + wordspaceWidget = newWidget; - connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)), - this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&))); - - connect (widget, SIGNAL(interiorCellsDropped (const std::vector&)), - this, SLOT(changeToUnpaged (const std::vector&))); + makeConnections(newWidget); } else { - CSVRender::UnpagedWorldspaceWidget *widget = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this); + CSVRender::UnpagedWorldspaceWidget *newWidget = new CSVRender::UnpagedWorldspaceWidget (id.getId(), document, this); - mScene = widget; + wordspaceWidget = newWidget; - connect (widget, SIGNAL(exteriorCellsDropped(const std::vector&)), - this, SLOT(changeToUnpaged(const std::vector&))); + makeConnections(newWidget); } - SceneToolMode *navigationTool = mScene->makeNavigationSelector (mToolbar); - mToolbar->addTool (navigationTool); - - SceneToolMode *lightingTool = mScene->makeLightingSelector (mToolbar); - mToolbar->addTool (lightingTool); - - mLayout->addWidget (mToolbar, 0); - - mLayout->addWidget (mScene, 1); + replaceToolbarAndWorldspace(wordspaceWidget, makeToolbar(wordspaceWidget)); layout->insertLayout (0, mLayout, 1); @@ -78,10 +66,41 @@ CSVWorld::SceneSubView::SceneSubView (const CSMWorld::UniversalId& id, CSMDoc::D widget->setLayout (layout); setWidget (widget); +} - mScene->selectDefaultNavigationMode(); +void CSVWorld::SceneSubView::makeConnections (CSVRender::UnpagedWorldspaceWidget* widget) +{ + connect (widget, SIGNAL (closeRequest()), this, SLOT (closeRequest())); + + connect(widget, SIGNAL(dataDropped(const std::vector&)), + this, SLOT(handleDrop(const std::vector&))); - connect (mScene, SIGNAL (closeRequest()), this, SLOT (closeRequest())); + connect(widget, SIGNAL(cellChanged(const CSMWorld::UniversalId&)), + this, SLOT(cellSelectionChanged(const CSMWorld::UniversalId&))); +} + +void CSVWorld::SceneSubView::makeConnections (CSVRender::PagedWorldspaceWidget* widget) +{ + connect (widget, SIGNAL (closeRequest()), this, SLOT (closeRequest())); + + connect(widget, SIGNAL(dataDropped(const std::vector&)), + this, SLOT(handleDrop(const std::vector&))); + + connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)), + this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&))); +} + +CSVWorld::SceneToolbar* CSVWorld::SceneSubView::makeToolbar (CSVRender::WorldspaceWidget* widget) +{ + CSVWorld::SceneToolbar* toolbar = new SceneToolbar (48+6, this); + + SceneToolMode *navigationTool = widget->makeNavigationSelector (toolbar); + toolbar->addTool (navigationTool); + + SceneToolMode *lightingTool = widget->makeLightingSelector (toolbar); + toolbar->addTool (lightingTool); + + return toolbar; } void CSVWorld::SceneSubView::setEditLock (bool locked) @@ -111,8 +130,19 @@ void CSVWorld::SceneSubView::closeRequest() deleteLater(); } +void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::UniversalId& id) +{ + setUniversalId(id); + std::ostringstream stream; + stream << "Scene: " << getUniversalId().getId(); + + setWindowTitle (QString::fromUtf8 (stream.str().c_str())); +} + + void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::CellSelection& selection) { + setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Cell, "sys::default")); int size = selection.getSize(); std::ostringstream stream; @@ -137,70 +167,60 @@ void CSVWorld::SceneSubView::cellSelectionChanged (const CSMWorld::CellSelection setWindowTitle (QString::fromUtf8 (stream.str().c_str())); } -void CSVWorld::SceneSubView::changeToPaged (const std::vector< CSMWorld::UniversalId >& data) +void CSVWorld::SceneSubView::handleDrop (const std::vector< CSMWorld::UniversalId >& data) { - mLayout->removeWidget(mToolbar); - mLayout->removeWidget(mScene); - - delete mScene; - delete mToolbar; - - setUniversalId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Cell, "sys::default")); - mToolbar = new SceneToolbar (48+6, this); - - CSVRender::PagedWorldspaceWidget* widget = new CSVRender::PagedWorldspaceWidget (this, mDocument); - - mScene = widget; - - SceneToolMode* navigationTool = mScene->makeNavigationSelector (mToolbar); - mToolbar->addTool (navigationTool); - - SceneToolMode* lightingTool = mScene->makeLightingSelector (mToolbar); - mToolbar->addTool (lightingTool); - - connect (widget, SIGNAL (cellSelectionChanged (const CSMWorld::CellSelection&)), - this, SLOT (cellSelectionChanged (const CSMWorld::CellSelection&))); - - connect (widget, SIGNAL (interiorCellsDropped (const std::vector&)), - this, SLOT (changeToUnpaged (const std::vector&))); - - mLayout->addWidget (mToolbar, 0); - mLayout->addWidget (mScene, 1); - - mScene->selectDefaultNavigationMode(); - - connect (mScene, SIGNAL (closeRequest()), this, SLOT (closeRequest())); + CSVRender::PagedWorldspaceWidget* pagedNewWidget = NULL; + CSVRender::UnpagedWorldspaceWidget* unPagedNewWidget = NULL; + SceneToolbar* toolbar = NULL; - widget->handleDrop (data); + switch (mScene->getDropRequirements(CSVRender::WorldspaceWidget::getDropType(data))) + { + case CSVRender::WorldspaceWidget::canHandle: + mScene->handleDrop(data); + break; + + case CSVRender::WorldspaceWidget::needPaged: + pagedNewWidget = new CSVRender::PagedWorldspaceWidget(this, mDocument); + toolbar = makeToolbar(pagedNewWidget); + makeConnections(pagedNewWidget); + replaceToolbarAndWorldspace(pagedNewWidget, toolbar); + mScene->handleDrop(data); + break; + + case CSVRender::WorldspaceWidget::needUnpaged: + unPagedNewWidget = new CSVRender::UnpagedWorldspaceWidget(data.begin()->getId(), mDocument, this); + toolbar = makeToolbar(unPagedNewWidget); + makeConnections(unPagedNewWidget); + replaceToolbarAndWorldspace(unPagedNewWidget, toolbar); + cellSelectionChanged(*(data.begin())); + break; + + case CSVRender::WorldspaceWidget::ignored: + return; + } } -void CSVWorld::SceneSubView::changeToUnpaged (const std::vector< CSMWorld::UniversalId >& data) +void CSVWorld::SceneSubView::replaceToolbarAndWorldspace (CSVRender::WorldspaceWidget* widget, CSVWorld::SceneToolbar* toolbar) { - mLayout->removeWidget(mToolbar); - mLayout->removeWidget(mScene); + assert(mLayout); - delete mScene; - delete mToolbar; + if (mScene) + { + mLayout->removeWidget(mScene); + mScene->deleteLater(); + } - mToolbar = new SceneToolbar (48+6, this); - CSVRender::UnpagedWorldspaceWidget* widget = new CSVRender::UnpagedWorldspaceWidget (data.begin()->getId(), mDocument, this); - setUniversalId(*(data.begin())); + if (mToolbar) + { + mLayout->removeWidget(mToolbar); + mToolbar->deleteLater(); + } mScene = widget; - - SceneToolMode* navigationTool = mScene->makeNavigationSelector (mToolbar); - mToolbar->addTool (navigationTool); - - SceneToolMode* lightingTool = mScene->makeLightingSelector (mToolbar); - mToolbar->addTool (lightingTool); - - connect (widget, SIGNAL (exteriorCellsDropped (const std::vector&)), - this, SLOT (changeToPaged (const std::vector&))); + mToolbar = toolbar; mLayout->addWidget (mToolbar, 0); mLayout->addWidget (mScene, 1); mScene->selectDefaultNavigationMode(); - - connect (mScene, SIGNAL (closeRequest()), this, SLOT (closeRequest())); -} +} \ No newline at end of file diff --git a/apps/opencs/view/world/scenesubview.hpp b/apps/opencs/view/world/scenesubview.hpp index 9af76ef6a..251ddae1f 100644 --- a/apps/opencs/view/world/scenesubview.hpp +++ b/apps/opencs/view/world/scenesubview.hpp @@ -21,6 +21,8 @@ namespace CSMDoc namespace CSVRender { class WorldspaceWidget; + class PagedWorldspaceWidget; + class UnpagedWorldspaceWidget; } namespace CSVWorld @@ -51,15 +53,25 @@ namespace CSVWorld virtual void useHint (const std::string& hint); + private: + + void makeConnections(CSVRender::PagedWorldspaceWidget* widget); + + void makeConnections(CSVRender::UnpagedWorldspaceWidget* widget); + + void replaceToolbarAndWorldspace(CSVRender::WorldspaceWidget* widget, SceneToolbar* toolbar); + + SceneToolbar* makeToolbar(CSVRender::WorldspaceWidget* widget); + private slots: void closeRequest(); void cellSelectionChanged (const CSMWorld::CellSelection& selection); - void changeToPaged(const std::vector& data); + void cellSelectionChanged (const CSMWorld::UniversalId& id); - void changeToUnpaged(const std::vector& data); + void handleDrop(const std::vector& data); }; }