From 4a8fe39b2c4e71f2d2108150552e7515bd097b82 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Sun, 7 Sep 2014 06:29:09 +1000 Subject: [PATCH 1/2] For bug #1710. Change the ID type of mime data for filterbox drop events to Referenceable rather than using the ID's native type. --- apps/opencs/model/world/tablemimedata.cpp | 21 ++++++++++++++++++++- apps/opencs/model/world/tablemimedata.hpp | 5 ++++- apps/opencs/view/filter/filterbox.cpp | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/apps/opencs/model/world/tablemimedata.cpp b/apps/opencs/model/world/tablemimedata.cpp index f3b0e37617..5988c4155c 100644 --- a/apps/opencs/model/world/tablemimedata.cpp +++ b/apps/opencs/model/world/tablemimedata.cpp @@ -68,6 +68,26 @@ 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 @@ -222,7 +242,6 @@ namespace { CSMWorld::UniversalId::Type_Race, CSMWorld::ColumnBase::Display_Race }, { CSMWorld::UniversalId::Type_Skill, CSMWorld::ColumnBase::Display_Skill }, { CSMWorld::UniversalId::Type_Class, CSMWorld::ColumnBase::Display_Class }, - { CSMWorld::UniversalId::Type_Class, CSMWorld::ColumnBase::Display_Class }, { CSMWorld::UniversalId::Type_Faction, CSMWorld::ColumnBase::Display_Faction }, { CSMWorld::UniversalId::Type_Sound, CSMWorld::ColumnBase::Display_Sound }, { CSMWorld::UniversalId::Type_Region, CSMWorld::ColumnBase::Display_Region }, diff --git a/apps/opencs/model/world/tablemimedata.hpp b/apps/opencs/model/world/tablemimedata.hpp index 85c243944c..48277a138f 100644 --- a/apps/opencs/model/world/tablemimedata.hpp +++ b/apps/opencs/model/world/tablemimedata.hpp @@ -43,6 +43,9 @@ 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; @@ -65,4 +68,4 @@ namespace CSMWorld }; } -#endif // TABLEMIMEDATA_H \ No newline at end of file +#endif // TABLEMIMEDATA_H diff --git a/apps/opencs/view/filter/filterbox.cpp b/apps/opencs/view/filter/filterbox.cpp index 7a42ef0a57..869e18d8dc 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->getData(); + std::vector data = mime->getRefTypeData(); emit recordDropped(data, event->proposedAction()); } From 724ed807c8d681bae2bbf796e8ce0423d5ffd092 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Mon, 8 Sep 2014 23:14:04 +1000 Subject: [PATCH 2/2] 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)); } }