From 724ed807c8d681bae2bbf796e8ce0423d5ffd092 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Mon, 8 Sep 2014 23:14:04 +1000 Subject: [PATCH] Let the filterbox of the receiving side of the drag&drop to decide whether to add referenceable type. Only added if the table has "Referenceable ID" column AND the UniversalId type is referenceable. --- apps/opencs/model/world/tablemimedata.cpp | 22 +--------------------- apps/opencs/model/world/tablemimedata.hpp | 5 +---- apps/opencs/view/filter/filterbox.cpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 17 ++++++++++++----- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/apps/opencs/model/world/tablemimedata.cpp b/apps/opencs/model/world/tablemimedata.cpp index 5988c4155c..d40e0c217c 100644 --- a/apps/opencs/model/world/tablemimedata.cpp +++ b/apps/opencs/model/world/tablemimedata.cpp @@ -68,26 +68,6 @@ std::vector< CSMWorld::UniversalId > CSMWorld::TableMimeData::getData() const return mUniversalId; } -std::vector< CSMWorld::UniversalId > CSMWorld::TableMimeData::getRefTypeData() const -{ - std::vector ref_data; - - std::vector::const_iterator it = mUniversalId.begin(); - for(; it != mUniversalId.end(); ++it) - { - if(isReferencable(it->getType())) - { - // change the type - ref_data.push_back(CSMWorld::UniversalId( - CSMWorld::UniversalId::Type_Referenceable, it->getId())); - } - else - ref_data.push_back(*it); - } - - return ref_data; -} - bool CSMWorld::TableMimeData::isReferencable(CSMWorld::ColumnBase::Display type) const { return ( type == CSMWorld::ColumnBase::Display_Activator @@ -111,7 +91,7 @@ return ( type == CSMWorld::ColumnBase::Display_Activator || type == CSMWorld::ColumnBase::Display_Static || type == CSMWorld::ColumnBase::Display_Weapon); } -bool CSMWorld::TableMimeData::isReferencable(CSMWorld::UniversalId::Type type) const +bool CSMWorld::TableMimeData::isReferencable(CSMWorld::UniversalId::Type type) { return ( type == CSMWorld::UniversalId::Type_Activator || type == CSMWorld::UniversalId::Type_Potion diff --git a/apps/opencs/model/world/tablemimedata.hpp b/apps/opencs/model/world/tablemimedata.hpp index 48277a138f..06d252435f 100644 --- a/apps/opencs/model/world/tablemimedata.hpp +++ b/apps/opencs/model/world/tablemimedata.hpp @@ -43,9 +43,6 @@ namespace CSMWorld std::vector getData() const; - // change Id type to Type_Referenceable where possible - std::vector getRefTypeData() const; - bool holdsType(UniversalId::Type type) const; bool holdsType(CSMWorld::ColumnBase::Display type) const; @@ -62,8 +59,8 @@ namespace CSMWorld static CSMWorld::ColumnBase::Display convertEnums(CSMWorld::UniversalId::Type type); + static bool isReferencable(CSMWorld::UniversalId::Type type); private: - bool isReferencable(CSMWorld::UniversalId::Type type) const; bool isReferencable(CSMWorld::ColumnBase::Display type) const; }; diff --git a/apps/opencs/view/filter/filterbox.cpp b/apps/opencs/view/filter/filterbox.cpp index 869e18d8dc..7a42ef0a57 100644 --- a/apps/opencs/view/filter/filterbox.cpp +++ b/apps/opencs/view/filter/filterbox.cpp @@ -39,7 +39,7 @@ void CSVFilter::FilterBox::dropEvent (QDropEvent* event) if (!mime) // May happen when non-records (e.g. plain text) are dragged and dropped return; - std::vector data = mime->getRefTypeData(); + std::vector data = mime->getData(); emit recordDropped(data, event->proposedAction()); } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 327fb1c0e4..e2c8d5c1e3 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -111,14 +111,21 @@ void CSVWorld::TableSubView::createFilterRequest (std::vector< CSMWorld::Univers { std::vector > > filterSource; + std::vector refIdColumns = mTable->getColumnsWithDisplay(CSMWorld::TableMimeData::convertEnums(CSMWorld::UniversalId::Type_Referenceable)); + bool hasRefIdDisplay = !refIdColumns.empty(); + for (std::vector::iterator it(types.begin()); it != types.end(); ++it) { - std::pair > pair( //splited long line - std::make_pair(it->getId(), mTable->getColumnsWithDisplay(CSMWorld::TableMimeData::convertEnums(it->getType())))); - - if(!pair.second.empty()) + CSMWorld::UniversalId::Type type = it->getType(); + std::vector col = mTable->getColumnsWithDisplay(CSMWorld::TableMimeData::convertEnums(type)); + if(!col.empty()) { - filterSource.push_back(pair); + filterSource.push_back(std::make_pair(it->getId(), col)); + } + + if(hasRefIdDisplay && CSMWorld::TableMimeData::isReferencable(type)) + { + filterSource.push_back(std::make_pair(it->getId(), refIdColumns)); } }