Drag and drop works.

openmw-30
Marek Kochanowicz 11 years ago
parent 7f1df878f6
commit 5e99381019

@ -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<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:
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;
}
}

@ -15,8 +15,6 @@ namespace CSVRender
private:
void dropEvent(QDropEvent* event);
std::pair<int, int> getCoordinatesFromId(const std::string& record) const;
public:
@ -32,11 +30,11 @@ namespace CSVRender
virtual void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
virtual dropRequirments getDropRequirements(dropType type) const;
signals:
void cellSelectionChanged (const CSMWorld::CellSelection& selection);
void interiorCellsDropped(const std::vector<CSMWorld::UniversalId>& data);
};
}

@ -320,7 +320,7 @@ namespace CSVRender
}
if (mUpdate)
if (mUpdate && mWindow)
{
mUpdate = false;
mWindow->update();

@ -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<const CSMWorld::TableMimeData*> (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<CSMWorld::UniversalId>& 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;
}
}

@ -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<CSMWorld::UniversalId>& data);
void dropEvent(QDropEvent* event);
virtual void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
private slots:
@ -48,8 +45,7 @@ namespace CSVRender
signals:
void exteriorCellsDropped(const std::vector<CSMWorld::UniversalId>& data);
void cellChanged(const CSMWorld::UniversalId& id);
};
}

@ -115,3 +115,14 @@ void CSVRender::WorldspaceWidget::dragMoveEvent(QDragMoveEvent *event)
{
event->accept();
}
void CSVRender::WorldspaceWidget::dropEvent (QDropEvent* event)
{
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
if (mime->fromDocument (mDocument))
{
emit dataDropped(mime->getData());
} //not handling drops from different documents at the moment
}

@ -7,6 +7,7 @@
#include "navigationfree.hpp"
#include "navigationorbit.hpp"
#include <apps/opencs/model/doc/document.hpp>
#include <apps/opencs/model/world/tablemimedata.hpp>
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<CSMWorld::UniversalId>& data);
virtual dropRequirments getDropRequirements(dropType type) const = 0;
virtual void useViewHint (const std::string& hint);
///< Default-implementation: ignored.
virtual void handleDrop(const std::vector<CSMWorld::UniversalId>& 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<CSMWorld::UniversalId>& data);
};
}

@ -6,6 +6,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <cassert>
#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<CSMWorld::UniversalId>&)),
this, SLOT(changeToUnpaged (const std::vector<CSMWorld::UniversalId>&)));
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<CSMWorld::UniversalId>&)),
this, SLOT(changeToUnpaged(const std::vector<CSMWorld::UniversalId>&)));
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<CSMWorld::UniversalId>&)),
this, SLOT(handleDrop(const std::vector<CSMWorld::UniversalId>&)));
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<CSMWorld::UniversalId>&)),
this, SLOT(handleDrop(const std::vector<CSMWorld::UniversalId>&)));
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<CSMWorld::UniversalId>&)),
this, SLOT (changeToUnpaged (const std::vector<CSMWorld::UniversalId>&)));
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<CSMWorld::UniversalId>&)),
this, SLOT (changeToPaged (const std::vector<CSMWorld::UniversalId>&)));
mToolbar = toolbar;
mLayout->addWidget (mToolbar, 0);
mLayout->addWidget (mScene, 1);
mScene->selectDefaultNavigationMode();
connect (mScene, SIGNAL (closeRequest()), this, SLOT (closeRequest()));
}
}

@ -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<CSMWorld::UniversalId>& data);
void cellSelectionChanged (const CSMWorld::UniversalId& id);
void changeToUnpaged(const std::vector<CSMWorld::UniversalId>& data);
void handleDrop(const std::vector<CSMWorld::UniversalId>& data);
};
}

Loading…
Cancel
Save