forked from mirror/openmw-tes3mp
Checking if the drop comes from same document.
This commit is contained in:
parent
d6820b977e
commit
b1f63947e8
3 changed files with 43 additions and 18 deletions
|
@ -4,14 +4,15 @@
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
#include "columnbase.hpp"
|
#include "columnbase.hpp"
|
||||||
|
|
||||||
CSMWorld::TableMimeData::TableMimeData (UniversalId id)
|
CSMWorld::TableMimeData::TableMimeData (UniversalId id, const CSMDoc::Document& document) :
|
||||||
|
mDocument(document)
|
||||||
{
|
{
|
||||||
mUniversalId.push_back (id);
|
mUniversalId.push_back (id);
|
||||||
mObjectsFormats << QString::fromStdString ("tabledata/" + id.getTypeName());
|
mObjectsFormats << QString::fromStdString ("tabledata/" + id.getTypeName());
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id) :
|
CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id, const CSMDoc::Document& document) :
|
||||||
mUniversalId (id)
|
mUniversalId (id), mDocument(document)
|
||||||
{
|
{
|
||||||
for (std::vector<UniversalId>::iterator it (mUniversalId.begin()); it != mUniversalId.end(); ++it)
|
for (std::vector<UniversalId>::iterator it (mUniversalId.begin()); it != mUniversalId.end(); ++it)
|
||||||
{
|
{
|
||||||
|
@ -115,6 +116,11 @@ CSMWorld::UniversalId CSMWorld::TableMimeData::returnMatching (CSMWorld::ColumnB
|
||||||
throw ("TableMimeData object does not hold object of the seeked type");
|
throw ("TableMimeData object does not hold object of the seeked type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSMWorld::TableMimeData::fromDocument (const CSMDoc::Document& document) const
|
||||||
|
{
|
||||||
|
return &document == &mDocument;
|
||||||
|
}
|
||||||
|
|
||||||
CSMWorld::UniversalId::Type CSMWorld::TableMimeData::convertEnums (CSMWorld::ColumnBase::Display type) const
|
CSMWorld::UniversalId::Type CSMWorld::TableMimeData::convertEnums (CSMWorld::ColumnBase::Display type) const
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
#include "columnbase.hpp"
|
#include "columnbase.hpp"
|
||||||
|
|
||||||
|
namespace CSMDoc
|
||||||
|
{
|
||||||
|
class Document;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
|
@ -24,21 +28,33 @@ namespace CSMWorld
|
||||||
class TableMimeData : public QMimeData
|
class TableMimeData : public QMimeData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TableMimeData(UniversalId id);
|
TableMimeData(UniversalId id, const CSMDoc::Document& document);
|
||||||
TableMimeData(std::vector<UniversalId>& id);
|
|
||||||
|
TableMimeData(std::vector<UniversalId>& id, const CSMDoc::Document& document);
|
||||||
|
|
||||||
~TableMimeData();
|
~TableMimeData();
|
||||||
|
|
||||||
virtual QStringList formats() const;
|
virtual QStringList formats() const;
|
||||||
|
|
||||||
std::string getIcon() const;
|
std::string getIcon() const;
|
||||||
|
|
||||||
std::vector<UniversalId> getData() const;
|
std::vector<UniversalId> getData() const;
|
||||||
|
|
||||||
bool holdsType(UniversalId::Type type) const;
|
bool holdsType(UniversalId::Type type) const;
|
||||||
|
|
||||||
bool holdsType(CSMWorld::ColumnBase::Display type) const;
|
bool holdsType(CSMWorld::ColumnBase::Display type) const;
|
||||||
|
|
||||||
|
bool fromDocument(const CSMDoc::Document& document) const;
|
||||||
|
|
||||||
UniversalId returnMatching(UniversalId::Type type) const;
|
UniversalId returnMatching(UniversalId::Type type) const;
|
||||||
|
|
||||||
UniversalId returnMatching(CSMWorld::ColumnBase::Display type) const;
|
UniversalId returnMatching(CSMWorld::ColumnBase::Display type) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<UniversalId> mUniversalId;
|
std::vector<UniversalId> mUniversalId;
|
||||||
QStringList mObjectsFormats;
|
QStringList mObjectsFormats;
|
||||||
|
|
||||||
|
const CSMDoc::Document& mDocument;
|
||||||
CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type) const;
|
CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,7 +455,7 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event)
|
||||||
|
|
||||||
if (selectedRows.size() == 1)
|
if (selectedRows.size() == 1)
|
||||||
{
|
{
|
||||||
mime = new CSMWorld::TableMimeData (getUniversalId (selectedRows.begin()->row()));
|
mime = new CSMWorld::TableMimeData (getUniversalId (selectedRows.begin()->row()), mDocument);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -466,7 +466,7 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event)
|
||||||
idToDrag.push_back (getUniversalId (it.row()));
|
idToDrag.push_back (getUniversalId (it.row()));
|
||||||
}
|
}
|
||||||
|
|
||||||
mime = new CSMWorld::TableMimeData (idToDrag);
|
mime = new CSMWorld::TableMimeData (idToDrag, mDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
drag->setMimeData (mime);
|
drag->setMimeData (mime);
|
||||||
|
@ -485,21 +485,24 @@ void CSVWorld::Table::dropEvent(QDropEvent *event)
|
||||||
{
|
{
|
||||||
QModelIndex index = indexAt (event->pos());
|
QModelIndex index = indexAt (event->pos());
|
||||||
|
|
||||||
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
|
if (dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData())->fromDocument (mDocument))
|
||||||
(mModel->headerData(index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
|
||||||
|
|
||||||
if (dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData())->holdsType(display))
|
|
||||||
{
|
{
|
||||||
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*>
|
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
|
||||||
(event->mimeData());
|
(mModel->headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
||||||
|
|
||||||
CSMWorld::UniversalId record (mime->returnMatching (display));
|
if (dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData())->holdsType (display))
|
||||||
|
{
|
||||||
|
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*>
|
||||||
|
(event->mimeData());
|
||||||
|
|
||||||
std::auto_ptr<CSMWorld::ModifyCommand> command (new CSMWorld::ModifyCommand
|
CSMWorld::UniversalId record (mime->returnMatching (display));
|
||||||
(*mProxyModel, index, QVariant (QString::fromStdString (record.getId()))));
|
|
||||||
|
|
||||||
mUndoStack.push (command.release());
|
std::auto_ptr<CSMWorld::ModifyCommand> command (new CSMWorld::ModifyCommand
|
||||||
}
|
(*mProxyModel, index, QVariant (QString::fromStdString (record.getId()))));
|
||||||
|
|
||||||
|
mUndoStack.push (command.release());
|
||||||
|
}
|
||||||
|
} //TODO handle drops from different document
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::Table::dragMoveEvent(QDragMoveEvent *event)
|
void CSVWorld::Table::dragMoveEvent(QDragMoveEvent *event)
|
||||||
|
|
Loading…
Reference in a new issue