diff --git a/apps/opencs/model/world/tablemimedata.cpp b/apps/opencs/model/world/tablemimedata.cpp index b0cf0abcc..ee37dfce6 100644 --- a/apps/opencs/model/world/tablemimedata.cpp +++ b/apps/opencs/model/world/tablemimedata.cpp @@ -4,14 +4,15 @@ #include "universalid.hpp" #include "columnbase.hpp" -CSMWorld::TableMimeData::TableMimeData (UniversalId id) +CSMWorld::TableMimeData::TableMimeData (UniversalId id, const CSMDoc::Document& document) : +mDocument(document) { mUniversalId.push_back (id); mObjectsFormats << QString::fromStdString ("tabledata/" + id.getTypeName()); } -CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id) : - mUniversalId (id) +CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id, const CSMDoc::Document& document) : + mUniversalId (id), mDocument(document) { for (std::vector::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"); } +bool CSMWorld::TableMimeData::fromDocument (const CSMDoc::Document& document) const +{ + return &document == &mDocument; +} + CSMWorld::UniversalId::Type CSMWorld::TableMimeData::convertEnums (CSMWorld::ColumnBase::Display type) const { switch (type) diff --git a/apps/opencs/model/world/tablemimedata.hpp b/apps/opencs/model/world/tablemimedata.hpp index 51785714e..7c05386fb 100644 --- a/apps/opencs/model/world/tablemimedata.hpp +++ b/apps/opencs/model/world/tablemimedata.hpp @@ -10,6 +10,10 @@ #include "universalid.hpp" #include "columnbase.hpp" +namespace CSMDoc +{ + class Document; +} namespace CSMWorld { @@ -24,21 +28,33 @@ namespace CSMWorld class TableMimeData : public QMimeData { public: - TableMimeData(UniversalId id); - TableMimeData(std::vector& id); + TableMimeData(UniversalId id, const CSMDoc::Document& document); + + TableMimeData(std::vector& id, const CSMDoc::Document& document); + ~TableMimeData(); + virtual QStringList formats() const; + std::string getIcon() const; + std::vector getData() const; + bool holdsType(UniversalId::Type type) const; + bool holdsType(CSMWorld::ColumnBase::Display type) const; + + bool fromDocument(const CSMDoc::Document& document) const; + UniversalId returnMatching(UniversalId::Type type) const; + UniversalId returnMatching(CSMWorld::ColumnBase::Display type) const; private: std::vector mUniversalId; QStringList mObjectsFormats; + const CSMDoc::Document& mDocument; CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type) const; }; } diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 419935991..79700458d 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -455,7 +455,7 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event) if (selectedRows.size() == 1) { - mime = new CSMWorld::TableMimeData (getUniversalId (selectedRows.begin()->row())); + mime = new CSMWorld::TableMimeData (getUniversalId (selectedRows.begin()->row()), mDocument); } else { @@ -466,7 +466,7 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event) idToDrag.push_back (getUniversalId (it.row())); } - mime = new CSMWorld::TableMimeData (idToDrag); + mime = new CSMWorld::TableMimeData (idToDrag, mDocument); } drag->setMimeData (mime); @@ -485,21 +485,24 @@ void CSVWorld::Table::dropEvent(QDropEvent *event) { QModelIndex index = indexAt (event->pos()); - CSMWorld::ColumnBase::Display display = static_cast - (mModel->headerData(index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - - if (dynamic_cast(event->mimeData())->holdsType(display)) + if (dynamic_cast (event->mimeData())->fromDocument (mDocument)) { - const CSMWorld::TableMimeData* mime = dynamic_cast - (event->mimeData()); + CSMWorld::ColumnBase::Display display = static_cast + (mModel->headerData (index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); - CSMWorld::UniversalId record (mime->returnMatching (display)); + if (dynamic_cast (event->mimeData())->holdsType (display)) + { + const CSMWorld::TableMimeData* mime = dynamic_cast + (event->mimeData()); - std::auto_ptr command (new CSMWorld::ModifyCommand - (*mProxyModel, index, QVariant (QString::fromStdString (record.getId())))); + CSMWorld::UniversalId record (mime->returnMatching (display)); - mUndoStack.push (command.release()); - } + std::auto_ptr 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)