From 5f3f867a10cde649afd4d749680e12aba180da83 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Thu, 13 Feb 2014 10:21:49 +0100 Subject: [PATCH] Implemented convertEnums function --- apps/opencs/model/world/columnbase.hpp | 22 -- apps/opencs/model/world/columnimp.hpp | 2 +- apps/opencs/model/world/tablemimedata.cpp | 234 +++++++++++++++++++++- apps/opencs/model/world/tablemimedata.hpp | 9 +- apps/opencs/view/world/table.cpp | 6 - 5 files changed, 234 insertions(+), 39 deletions(-) diff --git a/apps/opencs/model/world/columnbase.hpp b/apps/opencs/model/world/columnbase.hpp index d0419289f..e689c6a3f 100644 --- a/apps/opencs/model/world/columnbase.hpp +++ b/apps/opencs/model/world/columnbase.hpp @@ -29,30 +29,15 @@ namespace CSMWorld Display_String, //CONCRETE TYPES STARTS HERE - Display_Globals, - Display_Global, - Display_VerificationResults, - Display_Gmsts, - Display_Gmst, - Display_Skills, Display_Skill, - Display_Classes, Display_Class, - Display_Factions, Display_Faction, - Display_Races, Display_Race, - Display_Sounds, Display_Sound, - Display_Regions, Display_Region, - Display_Birthsigns, Display_Birthsign, - Display_Spells, Display_Spell, - Display_Cells, Display_Cell, - Display_Referenceables, Display_Referenceable, Display_Activator, Display_Potion, @@ -74,18 +59,11 @@ namespace CSMWorld Display_Repair, Display_Static, Display_Weapon, - Display_References, Display_Reference, - Display_RegionMap, Display_Filter, - Display_Filters, - Display_Topics, Display_Topic, - Display_Journals, Display_Journal, - Display_TopicInfos, Display_TopicInfo, - Display_JournalInfos, Display_JournalInfo, Display_Scene, //CONCRETE TYPES ENDS HERE diff --git a/apps/opencs/model/world/columnimp.hpp b/apps/opencs/model/world/columnimp.hpp index 049042109..9e9bedcf8 100644 --- a/apps/opencs/model/world/columnimp.hpp +++ b/apps/opencs/model/world/columnimp.hpp @@ -373,7 +373,7 @@ namespace CSMWorld SkillsColumn (int index, bool typePrefix = false, bool major = false) : Column ((typePrefix ? ( major ? Columns::ColumnId_MajorSkill1 : Columns::ColumnId_MinorSkill1) : - Columns::ColumnId_Skill1) + index, ColumnBase::Display_Skills), + Columns::ColumnId_Skill1) + index, ColumnBase::Display_Skill), mIndex (index), mMajor (major) {} diff --git a/apps/opencs/model/world/tablemimedata.cpp b/apps/opencs/model/world/tablemimedata.cpp index 0cdcdba3a..45305431e 100644 --- a/apps/opencs/model/world/tablemimedata.cpp +++ b/apps/opencs/model/world/tablemimedata.cpp @@ -1,19 +1,21 @@ #include "tablemimedata.hpp" -#include "universalid.hpp" #include +#include "universalid.hpp" +#include "columnbase.hpp" + CSMWorld::TableMimeData::TableMimeData (UniversalId id) { - mUniversalId.push_back(id); - mObjectsFormats << QString::fromStdString("tabledata/" + id.getTypeName()); + mUniversalId.push_back (id); + mObjectsFormats << QString::fromStdString ("tabledata/" + id.getTypeName()); } -CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id) +CSMWorld::TableMimeData::TableMimeData (std::vector< CSMWorld::UniversalId >& id) : + mUniversalId (id) { - mUniversalId = id; - for (std::vector::iterator it(mUniversalId.begin()); it != mUniversalId.end(); ++it) + for (std::vector::iterator it (mUniversalId.begin()); it != mUniversalId.end(); ++it) { - mObjectsFormats << QString::fromStdString("tabledata/" + it->getTypeName()); + mObjectsFormats << QString::fromStdString ("tabledata/" + it->getTypeName()); } } @@ -30,11 +32,12 @@ std::string CSMWorld::TableMimeData::getIcon() const { if (mUniversalId.empty()) { - throw("TableMimeData holds no UniversalId"); + throw ("TableMimeData holds no UniversalId"); } std::string tmpIcon; bool firstIteration = true; + for (unsigned i = 0; i < mUniversalId.size(); ++i) { if (firstIteration) @@ -51,10 +54,223 @@ std::string CSMWorld::TableMimeData::getIcon() const tmpIcon = mUniversalId[i].getIcon(); } + return mUniversalId.begin()->getIcon(); //All objects are of the same type; } std::vector< CSMWorld::UniversalId > CSMWorld::TableMimeData::getData() const { return mUniversalId; -} \ No newline at end of file +} + +bool CSMWorld::TableMimeData::holdsType (CSMWorld::UniversalId::Type type) const +{ + for (std::vector::const_iterator it = mUniversalId.begin(); it != mUniversalId.end(); ++it) + { + if (it->getType() == type) + { + return true; + } + } + + return false; +} + +bool CSMWorld::TableMimeData::holdsType (CSMWorld::ColumnBase::Display type) +{ + for (std::vector::const_iterator it = mUniversalId.begin(); it != mUniversalId.end(); ++it) + { + if (it->getType() == convertEnums (type)) + { + return true; + } + } + + return false; +} + +CSMWorld::UniversalId CSMWorld::TableMimeData::returnMatching (CSMWorld::UniversalId::Type type) const +{ + for (std::vector::const_iterator it = mUniversalId.begin(); it != mUniversalId.end(); ++it) + { + if (it->getType() == type) + { + return *it; + } + } + + throw ("TableMimeData object does not hold object of the seeked type"); +} + +CSMWorld::UniversalId CSMWorld::TableMimeData::returnMatching (CSMWorld::ColumnBase::Display type) +{ + for (std::vector::const_iterator it = mUniversalId.begin(); it != mUniversalId.end(); ++it) + { + if (it->getType() == convertEnums (type)) + { + return *it; + } + } + + throw ("TableMimeData object does not hold object of the seeked type"); +} + +CSMWorld::UniversalId::Type CSMWorld::TableMimeData::convertEnums (CSMWorld::ColumnBase::Display type) +{ + switch (type) + { + default: + throw ("This type is not handled"); + return CSMWorld::UniversalId::Type_None; + break; + + case CSMWorld::ColumnBase::Display_Race: + return CSMWorld::UniversalId::Type_Race; + break; + + case CSMWorld::ColumnBase::Display_Skill: + return CSMWorld::UniversalId::Type_Skill; + break; + + case CSMWorld::ColumnBase::Display_Class: + return CSMWorld::UniversalId::Type_Class; + break; + + case CSMWorld::ColumnBase::Display_Faction: + return CSMWorld::UniversalId::Type_Faction; + break; + + case CSMWorld::ColumnBase::Display_Sound: + return CSMWorld::UniversalId::Type_Sound; + break; + + case CSMWorld::ColumnBase::Display_Region: + return CSMWorld::UniversalId::Type_Region; + break; + + case CSMWorld::ColumnBase::Display_Birthsign: + return CSMWorld::UniversalId::Type_Birthsign; + break; + + case CSMWorld::ColumnBase::Display_Spell: + return CSMWorld::UniversalId::Type_Spell; + break; + + case CSMWorld::ColumnBase::Display_Cell: + return CSMWorld::UniversalId::Type_Cell; + break; + + case CSMWorld::ColumnBase::Display_Referenceable: + return CSMWorld::UniversalId::Type_Referenceable; + break; + + case CSMWorld::ColumnBase::Display_Activator: + return CSMWorld::UniversalId::Type_Activator; + break; + + case CSMWorld::ColumnBase::Display_Potion: + return CSMWorld::UniversalId::Type_Potion; + break; + + case CSMWorld::ColumnBase::Display_Apparatus: + return CSMWorld::UniversalId::Type_Apparatus; + break; + + case CSMWorld::ColumnBase::Display_Armor: + return CSMWorld::UniversalId::Type_Armor; + break; + + case CSMWorld::ColumnBase::Display_Book: + return CSMWorld::UniversalId::Type_Book; + break; + + case CSMWorld::ColumnBase::Display_Clothing: + return CSMWorld::UniversalId::Type_Clothing; + break; + + case CSMWorld::ColumnBase::Display_Container: + return CSMWorld::UniversalId::Type_Container; + break; + + case CSMWorld::ColumnBase::Display_Creature: + return CSMWorld::UniversalId::Type_Creature; + break; + + case CSMWorld::ColumnBase::Display_Door: + return CSMWorld::UniversalId::Type_Door; + break; + + case CSMWorld::ColumnBase::Display_Ingredient: + return CSMWorld::UniversalId::Type_Ingredient; + break; + + case CSMWorld::ColumnBase::Display_CreatureLevelledList: + return CSMWorld::UniversalId::Type_CreatureLevelledList; + break; + + case CSMWorld::ColumnBase::Display_ItemLevelledList: + return CSMWorld::UniversalId::Type_ItemLevelledList; + break; + + case CSMWorld::ColumnBase::Display_Light: + return CSMWorld::UniversalId::Type_Light; + break; + + case CSMWorld::ColumnBase::Display_Lockpick: + return CSMWorld::UniversalId::Type_Lockpick; + break; + + case CSMWorld::ColumnBase::Display_Miscellaneous: + return CSMWorld::UniversalId::Type_Miscellaneous; + break; + + case CSMWorld::ColumnBase::Display_Npc: + return CSMWorld::UniversalId::Type_Npc; + break; + + case CSMWorld::ColumnBase::Display_Probe: + return CSMWorld::UniversalId::Type_Probe; + break; + + case CSMWorld::ColumnBase::Display_Repair: + return CSMWorld::UniversalId::Type_Repair; + break; + + case CSMWorld::ColumnBase::Display_Static: + return CSMWorld::UniversalId::Type_Static; + break; + + case CSMWorld::ColumnBase::Display_Weapon: + return CSMWorld::UniversalId::Type_Weapon; + break; + + case CSMWorld::ColumnBase::Display_Reference: + return CSMWorld::UniversalId::Type_Reference; + break; + + case CSMWorld::ColumnBase::Display_Filter: + return CSMWorld::UniversalId::Type_Filter; + break; + + case CSMWorld::ColumnBase::Display_Topic: + return CSMWorld::UniversalId::Type_Topic; + break; + + case CSMWorld::ColumnBase::Display_Journal: + return CSMWorld::UniversalId::Type_Journal; + break; + + case CSMWorld::ColumnBase::Display_TopicInfo: + return CSMWorld::UniversalId::Type_TopicInfo; + break; + + case CSMWorld::ColumnBase::Display_JournalInfo: + return CSMWorld::UniversalId::Type_JournalInfo; + break; + + case CSMWorld::ColumnBase::Display_Scene: + return CSMWorld::UniversalId::Type_Scene; + break; + } +} +// kate: indent-mode cstyle; indent-width 4; replace-tabs on; diff --git a/apps/opencs/model/world/tablemimedata.hpp b/apps/opencs/model/world/tablemimedata.hpp index 7509bd905..d2e5d3ecb 100644 --- a/apps/opencs/model/world/tablemimedata.hpp +++ b/apps/opencs/model/world/tablemimedata.hpp @@ -10,6 +10,7 @@ #include #include "universalid.hpp" +#include "columnbase.hpp" namespace CSMWorld @@ -23,10 +24,16 @@ namespace CSMWorld virtual QStringList formats() const; std::string getIcon() const; std::vector getData() const; + bool holdsType(UniversalId::Type type) const; + bool holdsType(CSMWorld::ColumnBase::Display type); + UniversalId returnMatching(UniversalId::Type type) const; + UniversalId returnMatching(CSMWorld::ColumnBase::Display type); private: std::vector mUniversalId; QStringList mObjectsFormats; + + CSMWorld::UniversalId::Type convertEnums(CSMWorld::ColumnBase::Display type); }; } -#endif // TABLEMIMEDATA_H \ No newline at end of file +#endif // TABLEMIMEDATA_H diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 7ac5946c8..c39ed3469 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -469,25 +469,19 @@ void CSVWorld::Table::mouseMoveEvent (QMouseEvent* event) drag->setMimeData (mime); drag->setPixmap (QString::fromStdString (mime->getIcon())); drag->exec(); - std::cout << "startdrag\n"; } } void CSVWorld::Table::dragEnterEvent(QDragEnterEvent *event) { - //if (event->mimeData()->hasFormat("text/plain")) - std::cout << "accept drag event\n"; event->acceptProposedAction(); - } void CSVWorld::Table::dropEvent(QDropEvent *event) { - std::cout << "drop\n"; event->acceptProposedAction(); QModelIndex index = indexAt(event->pos()); - std::cout << index.row(); } void CSVWorld::Table::dragMoveEvent(QDragMoveEvent *event)