mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-29 03:26:38 +00:00 
			
		
		
		
	Merge branch 'filter'
This commit is contained in:
		
						commit
						dc345dd43d
					
				
					 17 changed files with 330 additions and 271 deletions
				
			
		|  | @ -49,19 +49,31 @@ namespace CSMFilter | ||||||
| 
 | 
 | ||||||
|         Token (Type type = Type_None); |         Token (Type type = Type_None); | ||||||
| 
 | 
 | ||||||
|  |         Token (Type type, const std::string& string); | ||||||
|  |         ///< Non-string type that can also be interpreted as a string.
 | ||||||
|  | 
 | ||||||
|         Token (const std::string& string); |         Token (const std::string& string); | ||||||
| 
 | 
 | ||||||
|         Token (double number); |         Token (double number); | ||||||
| 
 | 
 | ||||||
|         operator bool() const; |         operator bool() const; | ||||||
|  | 
 | ||||||
|  |         bool isString() const; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     Token::Token (Type type) : mType (type) {} |     Token::Token (Type type) : mType (type) {} | ||||||
| 
 | 
 | ||||||
|  |     Token::Token (Type type, const std::string& string) : mType (type), mString (string) {} | ||||||
|  | 
 | ||||||
|     Token::Token (const std::string& string) : mType (Type_String), mString (string) {} |     Token::Token (const std::string& string) : mType (Type_String), mString (string) {} | ||||||
| 
 | 
 | ||||||
|     Token::Token (double number) : mType (Type_Number), mNumber (number) {} |     Token::Token (double number) : mType (Type_Number), mNumber (number) {} | ||||||
| 
 | 
 | ||||||
|  |     bool Token::isString() const | ||||||
|  |     { | ||||||
|  |         return mType==Type_String || mType>=Type_Keyword_True; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     Token::operator bool() const |     Token::operator bool() const | ||||||
|     { |     { | ||||||
|         return mType!=Type_None; |         return mType!=Type_None; | ||||||
|  | @ -120,7 +132,7 @@ CSMFilter::Token CSMFilter::Parser::getStringToken() | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (string[0]=='"') |         if (string[0]=='"') | ||||||
|             string = string.substr (1, string.size()-2); |             return string.substr (1, string.size()-2); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return checkKeywords (string); |     return checkKeywords (string); | ||||||
|  | @ -182,7 +194,7 @@ CSMFilter::Token CSMFilter::Parser::checkKeywords (const Token& token) | ||||||
| 
 | 
 | ||||||
|     for (int i=0; sKeywords[i]; ++i) |     for (int i=0; sKeywords[i]; ++i) | ||||||
|         if (sKeywords[i]==string || (string.size()==1 && sKeywords[i][0]==string[0])) |         if (sKeywords[i]==string || (string.size()==1 && sKeywords[i][0]==string[0])) | ||||||
|             return Token (static_cast<Token::Type> (i+Token::Type_Keyword_True)); |             return Token (static_cast<Token::Type> (i+Token::Type_Keyword_True), token.mString); | ||||||
| 
 | 
 | ||||||
|     return token; |     return token; | ||||||
| } | } | ||||||
|  | @ -351,7 +363,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseText() | ||||||
|         if (static_cast<int> (token.mNumber)==token.mNumber) |         if (static_cast<int> (token.mNumber)==token.mNumber) | ||||||
|             columnId = static_cast<int> (token.mNumber); |             columnId = static_cast<int> (token.mNumber); | ||||||
|     } |     } | ||||||
|     else if (token.mType==Token::Type_String) |     else if (token.isString()) | ||||||
|     { |     { | ||||||
|         columnId = CSMWorld::Columns::getId (token.mString); |         columnId = CSMWorld::Columns::getId (token.mString); | ||||||
|     } |     } | ||||||
|  | @ -373,7 +385,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseText() | ||||||
|     // parse text pattern
 |     // parse text pattern
 | ||||||
|     token = getNextToken(); |     token = getNextToken(); | ||||||
| 
 | 
 | ||||||
|     if (token.mType!=Token::Type_String) |     if (!token.isString()) | ||||||
|     { |     { | ||||||
|         error(); |         error(); | ||||||
|         return boost::shared_ptr<Node>(); |         return boost::shared_ptr<Node>(); | ||||||
|  | @ -415,7 +427,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | ||||||
|         if (static_cast<int> (token.mNumber)==token.mNumber) |         if (static_cast<int> (token.mNumber)==token.mNumber) | ||||||
|             columnId = static_cast<int> (token.mNumber); |             columnId = static_cast<int> (token.mNumber); | ||||||
|     } |     } | ||||||
|     else if (token.mType==Token::Type_String) |     else if (token.isString()) | ||||||
|     { |     { | ||||||
|         columnId = CSMWorld::Columns::getId (token.mString); |         columnId = CSMWorld::Columns::getId (token.mString); | ||||||
|     } |     } | ||||||
|  | @ -437,22 +449,22 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | ||||||
|     // parse value
 |     // parse value
 | ||||||
|     double lower = 0; |     double lower = 0; | ||||||
|     double upper = 0; |     double upper = 0; | ||||||
|     bool min = false; |     ValueNode::Type lowerType = ValueNode::Type_Open; | ||||||
|     bool max = false; |     ValueNode::Type upperType = ValueNode::Type_Open; | ||||||
| 
 | 
 | ||||||
|     token = getNextToken(); |     token = getNextToken(); | ||||||
| 
 | 
 | ||||||
|     if (token.mType==Token::Type_Number) |     if (token.mType==Token::Type_Number) | ||||||
|     { |     { | ||||||
|         // single value
 |         // single value
 | ||||||
|         min = max = true; |  | ||||||
|         lower = upper = token.mNumber; |         lower = upper = token.mNumber; | ||||||
|  |         lowerType = upperType = ValueNode::Type_Closed; | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|         // interval
 |         // interval
 | ||||||
|         if (token.mType==Token::Type_OpenSquare) |         if (token.mType==Token::Type_OpenSquare) | ||||||
|             min = true; |             lowerType = ValueNode::Type_Closed; | ||||||
|         else if (token.mType!=Token::Type_CloseSquare && token.mType!=Token::Type_Open) |         else if (token.mType!=Token::Type_CloseSquare && token.mType!=Token::Type_Open) | ||||||
|         { |         { | ||||||
|             error(); |             error(); | ||||||
|  | @ -461,12 +473,8 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | ||||||
| 
 | 
 | ||||||
|         token = getNextToken(); |         token = getNextToken(); | ||||||
| 
 | 
 | ||||||
|         if (token.mType!=Token::Type_Number) |         if (token.mType==Token::Type_Number) | ||||||
|         { |         { | ||||||
|             error(); |  | ||||||
|             return boost::shared_ptr<Node>(); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|             lower = token.mNumber; |             lower = token.mNumber; | ||||||
| 
 | 
 | ||||||
|             token = getNextToken(); |             token = getNextToken(); | ||||||
|  | @ -476,21 +484,33 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | ||||||
|                 error(); |                 error(); | ||||||
|                 return boost::shared_ptr<Node>(); |                 return boost::shared_ptr<Node>(); | ||||||
|             } |             } | ||||||
| 
 |         } | ||||||
|         token = getNextToken(); |         else if (token.mType==Token::Type_Comma) | ||||||
| 
 |         { | ||||||
|         if (token.mType!=Token::Type_Number) |             lowerType = ValueNode::Type_Infinite; | ||||||
|  |         } | ||||||
|  |         else | ||||||
|         { |         { | ||||||
|             error(); |             error(); | ||||||
|             return boost::shared_ptr<Node>(); |             return boost::shared_ptr<Node>(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         token = getNextToken(); | ||||||
|  | 
 | ||||||
|  |         if (token.mType==Token::Type_Number) | ||||||
|  |         { | ||||||
|             upper = token.mNumber; |             upper = token.mNumber; | ||||||
| 
 | 
 | ||||||
|             token = getNextToken(); |             token = getNextToken(); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |             upperType = ValueNode::Type_Infinite; | ||||||
| 
 | 
 | ||||||
|         if (token.mType==Token::Type_CloseSquare) |         if (token.mType==Token::Type_CloseSquare) | ||||||
|             max = true; |         { | ||||||
|  |             if (upperType!=ValueNode::Type_Infinite) | ||||||
|  |                 upperType = ValueNode::Type_Closed; | ||||||
|  |         } | ||||||
|         else if (token.mType!=Token::Type_OpenSquare && token.mType!=Token::Type_Close) |         else if (token.mType!=Token::Type_OpenSquare && token.mType!=Token::Type_Close) | ||||||
|         { |         { | ||||||
|             error(); |             error(); | ||||||
|  | @ -506,7 +526,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | ||||||
|         return boost::shared_ptr<Node>(); |         return boost::shared_ptr<Node>(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return boost::shared_ptr<Node> (new ValueNode (columnId, lower, upper, min, max)); |     return boost::shared_ptr<Node> (new ValueNode (columnId, lowerType, upperType, lower, upper)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CSMFilter::Parser::error() | void CSMFilter::Parser::error() | ||||||
|  | @ -553,6 +573,8 @@ bool CSMFilter::Parser::parse (const std::string& filter, bool allowPredefined) | ||||||
| 
 | 
 | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |     // We do not use isString() here, because there could be a pre-defined filter with an ID that is
 | ||||||
|  |     // equal a filter keyword.
 | ||||||
|     else if (token.mType==Token::Type_String && allowPredefined) |     else if (token.mType==Token::Type_String && allowPredefined) | ||||||
|     { |     { | ||||||
|         if (getNextToken()!=Token (Token::Type_EOS)) |         if (getNextToken()!=Token (Token::Type_EOS)) | ||||||
|  |  | ||||||
|  | @ -28,13 +28,34 @@ bool CSMFilter::TextNode::test (const CSMWorld::IdTable& table, int row, | ||||||
| 
 | 
 | ||||||
|     QVariant data = table.data (index); |     QVariant data = table.data (index); | ||||||
| 
 | 
 | ||||||
|     if (data.type()!=QVariant::String) |     QString string; | ||||||
|  | 
 | ||||||
|  |     if (data.type()==QVariant::String) | ||||||
|  |     { | ||||||
|  |         string = data.toString(); | ||||||
|  |     } | ||||||
|  |     else if (data.type()==QVariant::Int || data.type()==QVariant::UInt || | ||||||
|  |         CSMWorld::Columns::hasEnums (static_cast<CSMWorld::Columns::ColumnId> (mColumnId))) | ||||||
|  |     { | ||||||
|  |         int value = data.toInt(); | ||||||
|  | 
 | ||||||
|  |         std::vector<std::string> enums = | ||||||
|  |             CSMWorld::Columns::getEnums (static_cast<CSMWorld::Columns::ColumnId> (mColumnId)); | ||||||
|  | 
 | ||||||
|  |         if (value>=0 && value<static_cast<int> (enums.size())) | ||||||
|  |             string = QString::fromUtf8 (enums[value].c_str()); | ||||||
|  |     } | ||||||
|  |     else if (data.type()==QVariant::Bool) | ||||||
|  |     { | ||||||
|  |         string = data.toBool() ? "true" : " false"; | ||||||
|  |     } | ||||||
|  |     else | ||||||
|         return false; |         return false; | ||||||
| 
 | 
 | ||||||
|     /// \todo make pattern syntax configurable
 |     /// \todo make pattern syntax configurable
 | ||||||
|     QRegExp regExp (QString::fromUtf8 (mText.c_str()), Qt::CaseInsensitive); |     QRegExp regExp (QString::fromUtf8 (mText.c_str()), Qt::CaseInsensitive); | ||||||
| 
 | 
 | ||||||
|     return regExp.exactMatch (data.toString()); |     return regExp.exactMatch (string); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::vector<int> CSMFilter::TextNode::getReferencedColumns() const | std::vector<int> CSMFilter::TextNode::getReferencedColumns() const | ||||||
|  |  | ||||||
|  | @ -7,10 +7,9 @@ | ||||||
| #include "../world/columns.hpp" | #include "../world/columns.hpp" | ||||||
| #include "../world/idtable.hpp" | #include "../world/idtable.hpp" | ||||||
| 
 | 
 | ||||||
| CSMFilter::ValueNode::ValueNode (int columnId, | CSMFilter::ValueNode::ValueNode (int columnId, Type lowerType, Type upperType, | ||||||
|     double lower, double upper, bool min, bool max) |     double lower, double upper) | ||||||
| : mColumnId (columnId), mLower (lower), mUpper (upper), mMin (min), mMax (max) | : mColumnId (columnId), mLowerType (lowerType), mUpperType (upperType), mLower (lower), mUpper (upper){} | ||||||
| {} |  | ||||||
| 
 | 
 | ||||||
| bool CSMFilter::ValueNode::test (const CSMWorld::IdTable& table, int row, | bool CSMFilter::ValueNode::test (const CSMWorld::IdTable& table, int row, | ||||||
|     const std::map<int, int>& columns) const |     const std::map<int, int>& columns) const | ||||||
|  | @ -33,10 +32,21 @@ bool CSMFilter::ValueNode::test (const CSMWorld::IdTable& table, int row, | ||||||
| 
 | 
 | ||||||
|     double value = data.toDouble(); |     double value = data.toDouble(); | ||||||
| 
 | 
 | ||||||
|     if (mLower==mUpper && mMin && mMax) |     switch (mLowerType) | ||||||
|         return value==mLower; |     { | ||||||
|  |         case Type_Closed: if (value<mLower) return false; break; | ||||||
|  |         case Type_Open: if (value<=mLower) return false; break; | ||||||
|  |         case Type_Infinite: break; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return (mMin ? value>=mLower : value>mLower) && (mMax ? value<=mUpper : value<mUpper); |     switch (mUpperType) | ||||||
|  |     { | ||||||
|  |         case Type_Closed: if (value>mUpper) return false; break; | ||||||
|  |         case Type_Open: if (value>=mUpper) return false; break; | ||||||
|  |         case Type_Infinite: break; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::vector<int> CSMFilter::ValueNode::getReferencedColumns() const | std::vector<int> CSMFilter::ValueNode::getReferencedColumns() const | ||||||
|  | @ -60,10 +70,26 @@ std::string CSMFilter::ValueNode::toString (bool numericColumns) const | ||||||
| 
 | 
 | ||||||
|     stream << ", \""; |     stream << ", \""; | ||||||
| 
 | 
 | ||||||
|     if (mLower==mUpper && mMin && mMax) |     if (mLower==mUpper && mLowerType!=Type_Infinite && mUpperType!=Type_Infinite) | ||||||
|         stream << mLower; |         stream << mLower; | ||||||
|     else |     else | ||||||
|         stream << (mMin ? "[" : "(") << mLower << ", " << mUpper << (mMax ? "]" : ")"); |     { | ||||||
|  |         switch (mLowerType) | ||||||
|  |         { | ||||||
|  |             case Type_Closed: stream << "[" << mLower; break; | ||||||
|  |             case Type_Open: stream << "(" << mLower; break; | ||||||
|  |             case Type_Infinite: stream << "("; break; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         stream << ", "; | ||||||
|  | 
 | ||||||
|  |         switch (mUpperType) | ||||||
|  |         { | ||||||
|  |             case Type_Closed: stream << mUpper << "]"; break; | ||||||
|  |             case Type_Open: stream << mUpper << ")"; break; | ||||||
|  |             case Type_Infinite: stream << ")"; break; | ||||||
|  |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     stream << ")"; |     stream << ")"; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,16 +7,25 @@ namespace CSMFilter | ||||||
| { | { | ||||||
|     class ValueNode : public LeafNode |     class ValueNode : public LeafNode | ||||||
|     { |     { | ||||||
|  |         public: | ||||||
|  | 
 | ||||||
|  |             enum Type | ||||||
|  |             { | ||||||
|  |                 Type_Closed, Type_Open, Type_Infinite | ||||||
|  |             }; | ||||||
|  | 
 | ||||||
|  |         private: | ||||||
|  | 
 | ||||||
|             int mColumnId; |             int mColumnId; | ||||||
|             std::string mText; |             std::string mText; | ||||||
|             double mLower; |             double mLower; | ||||||
|             double mUpper; |             double mUpper; | ||||||
|             bool mMin; |             Type mLowerType; | ||||||
|             bool mMax; |             Type mUpperType; | ||||||
| 
 | 
 | ||||||
|         public: |         public: | ||||||
| 
 | 
 | ||||||
|             ValueNode (int columnId, double lower, double upper, bool min, bool max); |             ValueNode (int columnId, Type lowerType, Type upperType, double lower, double upper); | ||||||
| 
 | 
 | ||||||
|             virtual bool test (const CSMWorld::IdTable& table, int row, |             virtual bool test (const CSMWorld::IdTable& table, int row, | ||||||
|                 const std::map<int, int>& columns) const; |                 const std::map<int, int>& columns) const; | ||||||
|  |  | ||||||
|  | @ -3,6 +3,8 @@ | ||||||
| 
 | 
 | ||||||
| #include <components/misc/stringops.hpp> | #include <components/misc/stringops.hpp> | ||||||
| 
 | 
 | ||||||
|  | #include "universalid.hpp" | ||||||
|  | 
 | ||||||
| namespace CSMWorld | namespace CSMWorld | ||||||
| { | { | ||||||
|     namespace Columns |     namespace Columns | ||||||
|  | @ -197,3 +199,103 @@ int CSMWorld::Columns::getId (const std::string& name) | ||||||
| 
 | 
 | ||||||
|     return -1; |     return -1; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | namespace | ||||||
|  | { | ||||||
|  |     static const char *sSpecialisations[] = | ||||||
|  |     { | ||||||
|  |         "Combat", "Magic", "Stealth", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sAttributes[] = | ||||||
|  |     { | ||||||
|  |         "Strength", "Intelligence", "Willpower", "Agility", "Speed", "Endurance", "Personality", | ||||||
|  |         "Luck", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sSpellTypes[] = | ||||||
|  |     { | ||||||
|  |         "Spell", "Ability", "Blight", "Disease", "Curse", "Power", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sApparatusTypes[] = | ||||||
|  |     { | ||||||
|  |         "Mortar & Pestle", "Albemic", "Calcinator", "Retort", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sArmorTypes[] = | ||||||
|  |     { | ||||||
|  |         "Helmet", "Cuirass", "Left Pauldron", "Right Pauldron", "Greaves", "Boots", "Left Gauntlet", | ||||||
|  |         "Right Gauntlet", "Shield", "Left Bracer", "Right Bracer", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sClothingTypes[] = | ||||||
|  |     { | ||||||
|  |         "Pants", "Shoes", "Shirt", "Belt", "Robe", "Right Glove", "Left Glove", "Skirt", "Ring", | ||||||
|  |         "Amulet", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sCreatureTypes[] = | ||||||
|  |     { | ||||||
|  |         "Creature", "Deadra", "Undead", "Humanoid", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sWeaponTypes[] = | ||||||
|  |     { | ||||||
|  |         "Short Blade 1H", "Long Blade 1H", "Long Blade 2H", "Blunt 1H", "Blunt 2H Close", | ||||||
|  |         "Blunt 2H Wide", "Spear 2H", "Axe 1H", "Axe 2H", "Bow", "Crossbow", "Thrown", "Arrow", | ||||||
|  |         "Bolt", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sModificationEnums[] = | ||||||
|  |     { | ||||||
|  |         "Base", "Modified", "Added", "Deleted", "Deleted", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const char *sVarTypeEnums[] = | ||||||
|  |     { | ||||||
|  |         "unknown", "none", "short", "integer", "long", "float", "string", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     const char **getEnumNames (CSMWorld::Columns::ColumnId column) | ||||||
|  |     { | ||||||
|  |         switch (column) | ||||||
|  |         { | ||||||
|  |             case CSMWorld::Columns::ColumnId_Specialisation: return sSpecialisations; | ||||||
|  |             case CSMWorld::Columns::ColumnId_Attribute: return sAttributes; | ||||||
|  |             case CSMWorld::Columns::ColumnId_SpellType: return sSpellTypes; | ||||||
|  |             case CSMWorld::Columns::ColumnId_ApparatusType: return sApparatusTypes; | ||||||
|  |             case CSMWorld::Columns::ColumnId_ArmorType: return sArmorTypes; | ||||||
|  |             case CSMWorld::Columns::ColumnId_ClothingType: return sClothingTypes; | ||||||
|  |             case CSMWorld::Columns::ColumnId_CreatureType: return sCreatureTypes; | ||||||
|  |             case CSMWorld::Columns::ColumnId_WeaponType: return sWeaponTypes; | ||||||
|  |             case CSMWorld::Columns::ColumnId_Modification: return sModificationEnums; | ||||||
|  |             case CSMWorld::Columns::ColumnId_ValueType: return sVarTypeEnums; | ||||||
|  | 
 | ||||||
|  |             default: return 0; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | bool CSMWorld::Columns::hasEnums (ColumnId column) | ||||||
|  | { | ||||||
|  |     return getEnumNames (column)!=0 || column==ColumnId_RecordType; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | std::vector<std::string> CSMWorld::Columns::getEnums (ColumnId column) | ||||||
|  | { | ||||||
|  |     std::vector<std::string> enums; | ||||||
|  | 
 | ||||||
|  |     if (const char **table = getEnumNames (column)) | ||||||
|  |         for (int i=0; table[i]; ++i) | ||||||
|  |             enums.push_back (table[i]); | ||||||
|  |     else if (column==ColumnId_RecordType) | ||||||
|  |     { | ||||||
|  |         enums.push_back (""); // none
 | ||||||
|  | 
 | ||||||
|  |         for (int i=UniversalId::Type_None+1; i<UniversalId::NumberOfTypes; ++i) | ||||||
|  |             enums.push_back (UniversalId (static_cast<UniversalId::Type> (i)).getTypeName()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return enums; | ||||||
|  | } | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| #define CSM_WOLRD_COLUMNS_H | #define CSM_WOLRD_COLUMNS_H | ||||||
| 
 | 
 | ||||||
| #include <string> | #include <string> | ||||||
|  | #include <vector> | ||||||
| 
 | 
 | ||||||
| namespace CSMWorld | namespace CSMWorld | ||||||
| { | { | ||||||
|  | @ -180,6 +181,11 @@ namespace CSMWorld | ||||||
| 
 | 
 | ||||||
|         int getId (const std::string& name); |         int getId (const std::string& name); | ||||||
|         ///< Will return -1 for an invalid name.
 |         ///< Will return -1 for an invalid name.
 | ||||||
|  | 
 | ||||||
|  |         bool hasEnums (ColumnId column); | ||||||
|  | 
 | ||||||
|  |         std::vector<std::string> getEnums (ColumnId column); | ||||||
|  |         ///< Returns an empty vector, if \æ column isn't an enum type column.
 | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -80,7 +80,7 @@ namespace | ||||||
|         { CSMWorld::UniversalId::Class_RefRecord, CSMWorld::UniversalId::Type_Static, "Static", ":./static.png" }, |         { CSMWorld::UniversalId::Class_RefRecord, CSMWorld::UniversalId::Type_Static, "Static", ":./static.png" }, | ||||||
|         { CSMWorld::UniversalId::Class_RefRecord, CSMWorld::UniversalId::Type_Weapon, "Weapon", ":./weapon.png" }, |         { CSMWorld::UniversalId::Class_RefRecord, CSMWorld::UniversalId::Type_Weapon, "Weapon", ":./weapon.png" }, | ||||||
|         { CSMWorld::UniversalId::Class_SubRecord, CSMWorld::UniversalId::Type_Reference, "Reference", 0 }, |         { CSMWorld::UniversalId::Class_SubRecord, CSMWorld::UniversalId::Type_Reference, "Reference", 0 }, | ||||||
| 
 |         { CSMWorld::UniversalId::Class_SubRecord, CSMWorld::UniversalId::Type_Filter, "Filter", 0 }, | ||||||
|         { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0, 0 } // end marker
 |         { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0, 0 } // end marker
 | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | @ -90,8 +90,6 @@ namespace | ||||||
| 
 | 
 | ||||||
|         { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0, 0 } // end marker
 |         { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0, 0 } // end marker
 | ||||||
|     }; |     }; | ||||||
| 
 |  | ||||||
|     static const unsigned int IDARG_SIZE = sizeof (sIdArg) / sizeof (TypeData); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| CSMWorld::UniversalId::UniversalId (const std::string& universalId) | CSMWorld::UniversalId::UniversalId (const std::string& universalId) | ||||||
|  | @ -151,6 +149,22 @@ CSMWorld::UniversalId::UniversalId (Type type) : mArgumentType (ArgumentType_Non | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |     for (int i=0; sIdArg[i].mName; ++i) | ||||||
|  |         if (type==sIdArg[i].mType) | ||||||
|  |         { | ||||||
|  |             mArgumentType = ArgumentType_Id; | ||||||
|  |             mClass = sIdArg[i].mClass; | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     for (int i=0; sIndexArg[i].mName; ++i) | ||||||
|  |         if (type==sIndexArg[i].mType) | ||||||
|  |         { | ||||||
|  |             mArgumentType = ArgumentType_Index; | ||||||
|  |             mClass = sIndexArg[i].mClass; | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|     throw std::logic_error ("invalid argument-less UniversalId type"); |     throw std::logic_error ("invalid argument-less UniversalId type"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -293,25 +307,6 @@ std::vector<CSMWorld::UniversalId::Type> CSMWorld::UniversalId::listReferenceabl | ||||||
|     return list; |     return list; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::pair<int, const char *> CSMWorld::UniversalId::getIdArgPair (unsigned int index) |  | ||||||
| { |  | ||||||
|     std::pair<int, const char *> retPair; |  | ||||||
| 
 |  | ||||||
|     if ( index < IDARG_SIZE ) |  | ||||||
|     { |  | ||||||
|         retPair.first = sIdArg[index].mType; |  | ||||||
|         retPair.second = sIdArg[index].mName; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return retPair; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| unsigned int CSMWorld::UniversalId::getIdArgSize() |  | ||||||
| { |  | ||||||
|    return IDARG_SIZE; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| bool CSMWorld::operator== (const CSMWorld::UniversalId& left, const CSMWorld::UniversalId& right) | bool CSMWorld::operator== (const CSMWorld::UniversalId& left, const CSMWorld::UniversalId& right) | ||||||
| { | { | ||||||
|     return left.isEqual (right); |     return left.isEqual (right); | ||||||
|  |  | ||||||
|  | @ -34,7 +34,7 @@ namespace CSMWorld | ||||||
| 
 | 
 | ||||||
|             enum Type |             enum Type | ||||||
|             { |             { | ||||||
|                 Type_None, |                 Type_None = 0, | ||||||
|                 Type_Globals, |                 Type_Globals, | ||||||
|                 Type_Global, |                 Type_Global, | ||||||
|                 Type_VerificationResults, |                 Type_VerificationResults, | ||||||
|  | @ -89,6 +89,8 @@ namespace CSMWorld | ||||||
|                 Type_Filters |                 Type_Filters | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|  |             enum { NumberOfTypes = Type_Filters+1 }; | ||||||
|  | 
 | ||||||
|         private: |         private: | ||||||
| 
 | 
 | ||||||
|             Class mClass; |             Class mClass; | ||||||
|  | @ -102,7 +104,6 @@ namespace CSMWorld | ||||||
|             UniversalId (const std::string& universalId); |             UniversalId (const std::string& universalId); | ||||||
| 
 | 
 | ||||||
|             UniversalId (Type type = Type_None); |             UniversalId (Type type = Type_None); | ||||||
|             ///< Using a type for a non-argument-less UniversalId will throw an exception.
 |  | ||||||
| 
 | 
 | ||||||
|             UniversalId (Type type, const std::string& id); |             UniversalId (Type type, const std::string& id); | ||||||
|             ///< Using a type for a non-ID-argument UniversalId will throw an exception.
 |             ///< Using a type for a non-ID-argument UniversalId will throw an exception.
 | ||||||
|  | @ -134,9 +135,6 @@ namespace CSMWorld | ||||||
|             ///< Will return an empty string, if no icon is available.
 |             ///< Will return an empty string, if no icon is available.
 | ||||||
| 
 | 
 | ||||||
|             static std::vector<Type> listReferenceableTypes(); |             static std::vector<Type> listReferenceableTypes(); | ||||||
| 
 |  | ||||||
|             static std::pair<int, const char *> getIdArgPair (unsigned int index); |  | ||||||
|             static unsigned int getIdArgSize (); |  | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     bool operator== (const UniversalId& left, const UniversalId& right); |     bool operator== (const UniversalId& left, const UniversalId& right); | ||||||
|  |  | ||||||
|  | @ -8,6 +8,7 @@ | ||||||
| 
 | 
 | ||||||
| #include "../../model/doc/documentmanager.hpp" | #include "../../model/doc/documentmanager.hpp" | ||||||
| #include "../../model/doc/document.hpp" | #include "../../model/doc/document.hpp" | ||||||
|  | #include "../../model/world/columns.hpp" | ||||||
| 
 | 
 | ||||||
| #include "../world/util.hpp" | #include "../world/util.hpp" | ||||||
| #include "../world/enumdelegate.hpp" | #include "../world/enumdelegate.hpp" | ||||||
|  | @ -43,51 +44,6 @@ void CSVDoc::ViewManager::updateIndices() | ||||||
| CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) | CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) | ||||||
|     : mDocumentManager (documentManager), mExitOnSaveStateChange(false), mUserWarned(false) |     : mDocumentManager (documentManager), mExitOnSaveStateChange(false), mUserWarned(false) | ||||||
| { | { | ||||||
|     static const char *sSpecialisations[] = |  | ||||||
|     { |  | ||||||
|         "Combat", "Magic", "Stealth", 0 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     static const char *sAttributes[] = |  | ||||||
|     { |  | ||||||
|         "Strength", "Intelligence", "Willpower", "Agility", "Speed", "Endurance", "Personality", |  | ||||||
|         "Luck", 0 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     static const char *sSpellTypes[] = |  | ||||||
|     { |  | ||||||
|         "Spell", "Ability", "Blight", "Disease", "Curse", "Power", 0 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     static const char *sApparatusTypes[] = |  | ||||||
|     { |  | ||||||
|         "Mortar & Pestle", "Albemic", "Calcinator", "Retort", 0 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     static const char *sArmorTypes[] = |  | ||||||
|     { |  | ||||||
|         "Helmet", "Cuirass", "Left Pauldron", "Right Pauldron", "Greaves", "Boots", "Left Gauntlet", |  | ||||||
|         "Right Gauntlet", "Shield", "Left Bracer", "Right Bracer", 0 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     static const char *sClothingTypes[] = |  | ||||||
|     { |  | ||||||
|         "Pants", "Shoes", "Shirt", "Belt", "Robe", "Right Glove", "Left Glove", "Skirt", "Ring", |  | ||||||
|         "Amulet", 0 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     static const char *sCreatureTypes[] = |  | ||||||
|     { |  | ||||||
|         "Creature", "Deadra", "Undead", "Humanoid", 0 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     static const char *sWeaponTypes[] = |  | ||||||
|     { |  | ||||||
|         "Short Blade 1H", "Long Blade 1H", "Long Blade 2H", "Blunt 1H", "Blunt 2H Close", |  | ||||||
|         "Blunt 2H Wide", "Spear 2H", "Axe 1H", "Axe 2H", "Bow", "Crossbow", "Thrown", "Arrow", |  | ||||||
|         "Bolt", 0 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories = new CSVWorld::CommandDelegateFactoryCollection; |     mDelegateFactories = new CSVWorld::CommandDelegateFactoryCollection; | ||||||
| 
 | 
 | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_GmstVarType, |     mDelegateFactories->add (CSMWorld::ColumnBase::Display_GmstVarType, | ||||||
|  | @ -96,36 +52,35 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_GlobalVarType, |     mDelegateFactories->add (CSMWorld::ColumnBase::Display_GlobalVarType, | ||||||
|         new CSVWorld::VarTypeDelegateFactory (ESM::VT_Short, ESM::VT_Long, ESM::VT_Float)); |         new CSVWorld::VarTypeDelegateFactory (ESM::VT_Short, ESM::VT_Long, ESM::VT_Float)); | ||||||
| 
 | 
 | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_Specialisation, |  | ||||||
|         new CSVWorld::EnumDelegateFactory (sSpecialisations)); |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_Attribute, |  | ||||||
|         new CSVWorld::EnumDelegateFactory (sAttributes, true)); |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_SpellType, |  | ||||||
|         new CSVWorld::EnumDelegateFactory (sSpellTypes)); |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_ApparatusType, |  | ||||||
|         new CSVWorld::EnumDelegateFactory (sApparatusTypes)); |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_ArmorType, |  | ||||||
|         new CSVWorld::EnumDelegateFactory (sArmorTypes)); |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_ClothingType, |  | ||||||
|         new CSVWorld::EnumDelegateFactory (sClothingTypes)); |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_CreatureType, |  | ||||||
|         new CSVWorld::EnumDelegateFactory (sCreatureTypes)); |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_WeaponType, |  | ||||||
|         new CSVWorld::EnumDelegateFactory (sWeaponTypes)); |  | ||||||
| 
 |  | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_RecordState, |     mDelegateFactories->add (CSMWorld::ColumnBase::Display_RecordState, | ||||||
|         new CSVWorld::RecordStatusDelegateFactory()); |         new CSVWorld::RecordStatusDelegateFactory()); | ||||||
| 
 | 
 | ||||||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_RefRecordType, |     mDelegateFactories->add (CSMWorld::ColumnBase::Display_RefRecordType, | ||||||
|         new CSVWorld::RefIdTypeDelegateFactory()); |         new CSVWorld::RefIdTypeDelegateFactory()); | ||||||
| 
 | 
 | ||||||
|  |     struct Mapping | ||||||
|  |     { | ||||||
|  |         CSMWorld::ColumnBase::Display mDisplay; | ||||||
|  |         CSMWorld::Columns::ColumnId mColumnId; | ||||||
|  |         bool mAllowNone; | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     static const Mapping sMapping[] = | ||||||
|  |     { | ||||||
|  |         { CSMWorld::ColumnBase::Display_Specialisation, CSMWorld::Columns::ColumnId_Specialisation, false }, | ||||||
|  |         { CSMWorld::ColumnBase::Display_Attribute, CSMWorld::Columns::ColumnId_Attribute, true }, | ||||||
|  |         { CSMWorld::ColumnBase::Display_SpellType, CSMWorld::Columns::ColumnId_SpellType, false }, | ||||||
|  |         { CSMWorld::ColumnBase::Display_ApparatusType, CSMWorld::Columns::ColumnId_ApparatusType, false }, | ||||||
|  |         { CSMWorld::ColumnBase::Display_ArmorType, CSMWorld::Columns::ColumnId_ArmorType, false }, | ||||||
|  |         { CSMWorld::ColumnBase::Display_ClothingType, CSMWorld::Columns::ColumnId_ClothingType, false }, | ||||||
|  |         { CSMWorld::ColumnBase::Display_CreatureType, CSMWorld::Columns::ColumnId_CreatureType, false }, | ||||||
|  |         { CSMWorld::ColumnBase::Display_WeaponType, CSMWorld::Columns::ColumnId_WeaponType, false } | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     for (std::size_t i=0; i<sizeof (sMapping)/sizeof (Mapping); ++i) | ||||||
|  |         mDelegateFactories->add (sMapping[i].mDisplay, new CSVWorld::EnumDelegateFactory ( | ||||||
|  |             CSMWorld::Columns::getEnums (sMapping[i].mColumnId), sMapping[i].mAllowNone)); | ||||||
|  | 
 | ||||||
|     connect (&CSMSettings::UserSettings::instance(), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), |     connect (&CSMSettings::UserSettings::instance(), SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)), | ||||||
|         this, SLOT (slotUpdateEditorSetting (const QString &, const QString &))); |         this, SLOT (slotUpdateEditorSetting (const QString &, const QString &))); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -109,6 +109,18 @@ CSVWorld::EnumDelegateFactory::EnumDelegateFactory (const char **names, bool all | ||||||
|         add (i, names[i]); |         add (i, names[i]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | CSVWorld::EnumDelegateFactory::EnumDelegateFactory (const std::vector<std::string>& names, | ||||||
|  |     bool allowNone) | ||||||
|  | { | ||||||
|  |     if (allowNone) | ||||||
|  |         add (-1, ""); | ||||||
|  | 
 | ||||||
|  |     int size = static_cast<int> (names.size()); | ||||||
|  | 
 | ||||||
|  |     for (int i=0; i<size; ++i) | ||||||
|  |         add (i, names[i].c_str()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| CSVWorld::CommandDelegate *CSVWorld::EnumDelegateFactory::makeDelegate (QUndoStack& undoStack, | CSVWorld::CommandDelegate *CSVWorld::EnumDelegateFactory::makeDelegate (QUndoStack& undoStack, | ||||||
|     QObject *parent) const |     QObject *parent) const | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -54,6 +54,9 @@ namespace CSVWorld | ||||||
|             ///< \param names Array of char pointer with a 0-pointer as end mark
 |             ///< \param names Array of char pointer with a 0-pointer as end mark
 | ||||||
|             /// \param allowNone Use value of -1 for "none selected" (empty string)
 |             /// \param allowNone Use value of -1 for "none selected" (empty string)
 | ||||||
| 
 | 
 | ||||||
|  |             EnumDelegateFactory (const std::vector<std::string>& names, bool allowNone = false); | ||||||
|  |             /// \param allowNone Use value of -1 for "none selected" (empty string)
 | ||||||
|  | 
 | ||||||
|             virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; |             virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; | ||||||
|             ///< The ownership of the returned CommandDelegate is transferred to the caller.
 |             ///< The ownership of the returned CommandDelegate is transferred to the caller.
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,8 +1,11 @@ | ||||||
| #include "recordstatusdelegate.hpp" | #include "recordstatusdelegate.hpp" | ||||||
|  | 
 | ||||||
| #include <QPainter> | #include <QPainter> | ||||||
| #include <QApplication> | #include <QApplication> | ||||||
| #include <QUndoStack> | #include <QUndoStack> | ||||||
|  | 
 | ||||||
| #include "../../model/settings/usersettings.hpp" | #include "../../model/settings/usersettings.hpp" | ||||||
|  | #include "../../model/world/columns.hpp" | ||||||
| 
 | 
 | ||||||
| CSVWorld::RecordStatusDelegate::RecordStatusDelegate(const ValueList& values, | CSVWorld::RecordStatusDelegate::RecordStatusDelegate(const ValueList& values, | ||||||
|                                                      const IconList & icons, |                                                      const IconList & icons, | ||||||
|  | @ -37,9 +40,14 @@ bool CSVWorld::RecordStatusDelegate::updateEditorSetting (const QString &setting | ||||||
| 
 | 
 | ||||||
| CSVWorld::RecordStatusDelegateFactory::RecordStatusDelegateFactory() | CSVWorld::RecordStatusDelegateFactory::RecordStatusDelegateFactory() | ||||||
| { | { | ||||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_BaseOnly,     "Base",     ":./base.png"); |     std::vector<std::string> enums = | ||||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Deleted,      "Deleted",  ":./removed.png"); |         CSMWorld::Columns::getEnums (CSMWorld::Columns::ColumnId_Modification); | ||||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Erased,       "Deleted",  ":./removed.png"); | 
 | ||||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Modified,     "Modified", ":./modified.png"); |     static const char *sIcons[] = | ||||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_ModifiedOnly, "Added",    ":./added.png"); |     { | ||||||
|  |         ":./base.png", ":./modified.png", ":./added.png", ":./removed.png", ":./removed.png", 0 | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     for (int i=0; sIcons[i]; ++i) | ||||||
|  |         add (i, enums.at (i).c_str(), sIcons[i]); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| #include "refidtypedelegate.hpp" | #include "refidtypedelegate.hpp" | ||||||
|  | 
 | ||||||
| #include "../../model/world/universalid.hpp" | #include "../../model/world/universalid.hpp" | ||||||
| 
 | 
 | ||||||
| CSVWorld::RefIdTypeDelegate::RefIdTypeDelegate | CSVWorld::RefIdTypeDelegate::RefIdTypeDelegate | ||||||
|  | @ -6,6 +7,26 @@ CSVWorld::RefIdTypeDelegate::RefIdTypeDelegate | ||||||
|     : DataDisplayDelegate (values, icons, undoStack, parent) |     : DataDisplayDelegate (values, icons, undoStack, parent) | ||||||
| {} | {} | ||||||
| 
 | 
 | ||||||
|  | bool CSVWorld::RefIdTypeDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue) | ||||||
|  | { | ||||||
|  |     if (settingName == "Referenceable ID Type Display") | ||||||
|  |     { | ||||||
|  |         if (settingValue == "Icon and Text") | ||||||
|  |             mDisplayMode = Mode_IconAndText; | ||||||
|  | 
 | ||||||
|  |         else if (settingValue == "Icon Only") | ||||||
|  |             mDisplayMode = Mode_IconOnly; | ||||||
|  | 
 | ||||||
|  |         else if (settingValue == "Text Only") | ||||||
|  |             mDisplayMode = Mode_TextOnly; | ||||||
|  | 
 | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return false; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| CSVWorld::RefIdTypeDelegateFactory::RefIdTypeDelegateFactory() | CSVWorld::RefIdTypeDelegateFactory::RefIdTypeDelegateFactory() | ||||||
| { | { | ||||||
|     UidTypeList uIdList = buildUidTypeList(); |     UidTypeList uIdList = buildUidTypeList(); | ||||||
|  | @ -39,22 +60,3 @@ CSVWorld::RefIdTypeDelegateFactory::UidTypeList CSVWorld::RefIdTypeDelegateFacto | ||||||
| 
 | 
 | ||||||
|     return list; |     return list; | ||||||
| } | } | ||||||
| 
 |  | ||||||
| bool CSVWorld::RefIdTypeDelegate::updateEditorSetting (const QString &settingName, const QString &settingValue) |  | ||||||
| { |  | ||||||
|     if (settingName == "Referenceable ID Type Display") |  | ||||||
|     { |  | ||||||
|         if (settingValue == "Icon and Text") |  | ||||||
|             mDisplayMode = Mode_IconAndText; |  | ||||||
| 
 |  | ||||||
|         else if (settingValue == "Icon Only") |  | ||||||
|             mDisplayMode = Mode_IconOnly; |  | ||||||
| 
 |  | ||||||
|         else if (settingValue == "Text Only") |  | ||||||
|             mDisplayMode = Mode_TextOnly; |  | ||||||
| 
 |  | ||||||
|         return true; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     return false; |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  | @ -1,25 +0,0 @@ | ||||||
| #include "refrecordtypedelegate.hpp" |  | ||||||
| #include "../../model/world/universalid.hpp" |  | ||||||
| 
 |  | ||||||
| CSVWorld::RefRecordTypeDelegate::RefRecordTypeDelegate |  | ||||||
|     (const std::vector<std::pair<int, QString> > &values, QUndoStack& undoStack, QObject *parent) |  | ||||||
|         : EnumDelegate (values, undoStack, parent) |  | ||||||
| {} |  | ||||||
| 
 |  | ||||||
| CSVWorld::RefRecordTypeDelegateFactory::RefRecordTypeDelegateFactory() |  | ||||||
| { |  | ||||||
|     unsigned int argSize = CSMWorld::UniversalId::getIdArgSize(); |  | ||||||
| 
 |  | ||||||
|     for (unsigned int i = 0; i < argSize; i++) |  | ||||||
|     { |  | ||||||
|         std::pair<int, const char *> idPair = CSMWorld::UniversalId::getIdArgPair(i); |  | ||||||
| 
 |  | ||||||
|         mValues.push_back (std::pair<int, QString>(idPair.first, QString::fromUtf8(idPair.second))); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| CSVWorld::CommandDelegate *CSVWorld::RefRecordTypeDelegateFactory::makeDelegate (QUndoStack& undoStack, |  | ||||||
|     QObject *parent) const |  | ||||||
| { |  | ||||||
|     return new RefRecordTypeDelegate (mValues, undoStack, parent); |  | ||||||
| } |  | ||||||
|  | @ -1,58 +0,0 @@ | ||||||
| #ifndef REFRECORDTYPEDELEGATE_HPP |  | ||||||
| #define REFRECORDTYPEDELEGATE_HPP |  | ||||||
| 
 |  | ||||||
| #include "enumdelegate.hpp" |  | ||||||
| #include "util.hpp" |  | ||||||
| 
 |  | ||||||
| namespace CSVWorld |  | ||||||
| { |  | ||||||
|     class RefRecordTypeDelegate : public EnumDelegate |  | ||||||
|     { |  | ||||||
|         public: |  | ||||||
|             RefRecordTypeDelegate (const std::vector<std::pair<int, QString> > &mValues, QUndoStack& undoStack, QObject *parent); |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     class RefRecordTypeDelegateFactory : public CommandDelegateFactory |  | ||||||
|     { |  | ||||||
| 
 |  | ||||||
|         std::vector<std::pair<int, QString> > mValues; |  | ||||||
| 
 |  | ||||||
|         public: |  | ||||||
|             RefRecordTypeDelegateFactory(); |  | ||||||
| 
 |  | ||||||
|             virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; |  | ||||||
|             ///< The ownership of the returned CommandDelegate is transferred to the caller.
 |  | ||||||
|     }; |  | ||||||
| } |  | ||||||
| /*
 |  | ||||||
|     class VarTypeDelegate : public EnumDelegate |  | ||||||
|     { |  | ||||||
|         private: |  | ||||||
| 
 |  | ||||||
|             virtual void addCommands (QAbstractItemModel *model, |  | ||||||
|                 const QModelIndex& index, int type) const; |  | ||||||
| 
 |  | ||||||
|         public: |  | ||||||
| 
 |  | ||||||
|             VarTypeDelegate (const std::vector<std::pair<int, QString> >& values, |  | ||||||
|                 QUndoStack& undoStack, QObject *parent); |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     class VarTypeDelegateFactory : public CommandDelegateFactory |  | ||||||
|     { |  | ||||||
|             std::vector<std::pair<int, QString> > mValues; |  | ||||||
| 
 |  | ||||||
|         public: |  | ||||||
| 
 |  | ||||||
|             VarTypeDelegateFactory (ESM::VarType type0 = ESM::VT_Unknown, |  | ||||||
|                 ESM::VarType type1 = ESM::VT_Unknown, ESM::VarType type2 = ESM::VT_Unknown, |  | ||||||
|                 ESM::VarType type3 = ESM::VT_Unknown); |  | ||||||
| 
 |  | ||||||
|             virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const; |  | ||||||
|             ///< The ownership of the returned CommandDelegate is transferred to the caller.
 |  | ||||||
| 
 |  | ||||||
|             void add (ESM::VarType type); |  | ||||||
|     }; |  | ||||||
| */ |  | ||||||
| 
 |  | ||||||
| #endif // REFRECORDTYPEDELEGATE_HPP
 |  | ||||||
|  | @ -4,6 +4,7 @@ | ||||||
| #include <QUndoStack> | #include <QUndoStack> | ||||||
| 
 | 
 | ||||||
| #include "../../model/world/commands.hpp" | #include "../../model/world/commands.hpp" | ||||||
|  | #include "../../model/world/columns.hpp" | ||||||
| 
 | 
 | ||||||
| void CSVWorld::VarTypeDelegate::addCommands (QAbstractItemModel *model, const QModelIndex& index, int type) | void CSVWorld::VarTypeDelegate::addCommands (QAbstractItemModel *model, const QModelIndex& index, int type) | ||||||
|     const |     const | ||||||
|  | @ -75,29 +76,11 @@ CSVWorld::CommandDelegate *CSVWorld::VarTypeDelegateFactory::makeDelegate (QUndo | ||||||
| 
 | 
 | ||||||
| void CSVWorld::VarTypeDelegateFactory::add (ESM::VarType type) | void CSVWorld::VarTypeDelegateFactory::add (ESM::VarType type) | ||||||
| { | { | ||||||
|     struct Name |     std::vector<std::string> enums = | ||||||
|     { |         CSMWorld::Columns::getEnums (CSMWorld::Columns::ColumnId_ValueType); | ||||||
|         ESM::VarType mType; |  | ||||||
|         const char *mName; |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     static const Name sNames[] = |  | ||||||
|     { |  | ||||||
|         { ESM::VT_None, "empty" }, |  | ||||||
|         { ESM::VT_Short, "short" }, |  | ||||||
|         { ESM::VT_Int, "integer" }, |  | ||||||
|         { ESM::VT_Long, "long" }, |  | ||||||
|         { ESM::VT_Float, "float" }, |  | ||||||
|         { ESM::VT_String, "string" }, |  | ||||||
|         { ESM::VT_Unknown, 0 } // end marker
 |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     for (int i=0; sNames[i].mName; ++i) |  | ||||||
|         if (sNames[i].mType==type) |  | ||||||
|         { |  | ||||||
|             mValues.push_back (std::make_pair (type, sNames[i].mName)); |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|  |     if (type<0 && type>=enums.size()) | ||||||
|         throw std::logic_error ("Unsupported variable type"); |         throw std::logic_error ("Unsupported variable type"); | ||||||
|  | 
 | ||||||
|  |     mValues.push_back (std::make_pair (type, QString::fromUtf8 (enums[type].c_str()))); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -11,7 +11,7 @@ namespace ESM | ||||||
| 
 | 
 | ||||||
|     enum VarType |     enum VarType | ||||||
|     { |     { | ||||||
|         VT_Unknown, |         VT_Unknown = 0, | ||||||
|         VT_None, |         VT_None, | ||||||
|         VT_Short, // stored as a float, kinda
 |         VT_Short, // stored as a float, kinda
 | ||||||
|         VT_Int, |         VT_Int, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue