mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-28 17:56:37 +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, const std::string& string); | ||||
|         ///< Non-string type that can also be interpreted as a string.
 | ||||
| 
 | ||||
|         Token (const std::string& string); | ||||
| 
 | ||||
|         Token (double number); | ||||
| 
 | ||||
|         operator bool() const; | ||||
| 
 | ||||
|         bool isString() const; | ||||
|     }; | ||||
| 
 | ||||
|     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 (double number) : mType (Type_Number), mNumber (number) {} | ||||
| 
 | ||||
|     bool Token::isString() const | ||||
|     { | ||||
|         return mType==Type_String || mType>=Type_Keyword_True; | ||||
|     } | ||||
| 
 | ||||
|     Token::operator bool() const | ||||
|     { | ||||
|         return mType!=Type_None; | ||||
|  | @ -120,7 +132,7 @@ CSMFilter::Token CSMFilter::Parser::getStringToken() | |||
|         } | ||||
| 
 | ||||
|         if (string[0]=='"') | ||||
|             string = string.substr (1, string.size()-2); | ||||
|             return string.substr (1, string.size()-2); | ||||
|     } | ||||
| 
 | ||||
|     return checkKeywords (string); | ||||
|  | @ -182,7 +194,7 @@ CSMFilter::Token CSMFilter::Parser::checkKeywords (const Token& token) | |||
| 
 | ||||
|     for (int i=0; sKeywords[i]; ++i) | ||||
|         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; | ||||
| } | ||||
|  | @ -351,7 +363,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseText() | |||
|         if (static_cast<int> (token.mNumber)==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); | ||||
|     } | ||||
|  | @ -373,7 +385,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseText() | |||
|     // parse text pattern
 | ||||
|     token = getNextToken(); | ||||
| 
 | ||||
|     if (token.mType!=Token::Type_String) | ||||
|     if (!token.isString()) | ||||
|     { | ||||
|         error(); | ||||
|         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) | ||||
|             columnId = static_cast<int> (token.mNumber); | ||||
|     } | ||||
|     else if (token.mType==Token::Type_String) | ||||
|     else if (token.isString()) | ||||
|     { | ||||
|         columnId = CSMWorld::Columns::getId (token.mString); | ||||
|     } | ||||
|  | @ -437,22 +449,22 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | |||
|     // parse value
 | ||||
|     double lower = 0; | ||||
|     double upper = 0; | ||||
|     bool min = false; | ||||
|     bool max = false; | ||||
|     ValueNode::Type lowerType = ValueNode::Type_Open; | ||||
|     ValueNode::Type upperType = ValueNode::Type_Open; | ||||
| 
 | ||||
|     token = getNextToken(); | ||||
| 
 | ||||
|     if (token.mType==Token::Type_Number) | ||||
|     { | ||||
|         // single value
 | ||||
|         min = max = true; | ||||
|         lower = upper = token.mNumber; | ||||
|         lowerType = upperType = ValueNode::Type_Closed; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         // interval
 | ||||
|         if (token.mType==Token::Type_OpenSquare) | ||||
|             min = true; | ||||
|             lowerType = ValueNode::Type_Closed; | ||||
|         else if (token.mType!=Token::Type_CloseSquare && token.mType!=Token::Type_Open) | ||||
|         { | ||||
|             error(); | ||||
|  | @ -461,17 +473,23 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | |||
| 
 | ||||
|         token = getNextToken(); | ||||
| 
 | ||||
|         if (token.mType!=Token::Type_Number) | ||||
|         if (token.mType==Token::Type_Number) | ||||
|         { | ||||
|             error(); | ||||
|             return boost::shared_ptr<Node>(); | ||||
|             lower = token.mNumber; | ||||
| 
 | ||||
|             token = getNextToken(); | ||||
| 
 | ||||
|             if (token.mType!=Token::Type_Comma) | ||||
|             { | ||||
|                 error(); | ||||
|                 return boost::shared_ptr<Node>(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         lower = token.mNumber; | ||||
| 
 | ||||
|         token = getNextToken(); | ||||
| 
 | ||||
|         if (token.mType!=Token::Type_Comma) | ||||
|         else if (token.mType==Token::Type_Comma) | ||||
|         { | ||||
|             lowerType = ValueNode::Type_Infinite; | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             error(); | ||||
|             return boost::shared_ptr<Node>(); | ||||
|  | @ -479,18 +497,20 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | |||
| 
 | ||||
|         token = getNextToken(); | ||||
| 
 | ||||
|         if (token.mType!=Token::Type_Number) | ||||
|         if (token.mType==Token::Type_Number) | ||||
|         { | ||||
|             error(); | ||||
|             return boost::shared_ptr<Node>(); | ||||
|             upper = token.mNumber; | ||||
| 
 | ||||
|             token = getNextToken(); | ||||
|         } | ||||
| 
 | ||||
|         upper = token.mNumber; | ||||
| 
 | ||||
|         token = getNextToken(); | ||||
|         else | ||||
|             upperType = ValueNode::Type_Infinite; | ||||
| 
 | ||||
|         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) | ||||
|         { | ||||
|             error(); | ||||
|  | @ -506,7 +526,7 @@ boost::shared_ptr<CSMFilter::Node> CSMFilter::Parser::parseValue() | |||
|         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() | ||||
|  | @ -553,6 +573,8 @@ bool CSMFilter::Parser::parse (const std::string& filter, bool allowPredefined) | |||
| 
 | ||||
|         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) | ||||
|     { | ||||
|         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); | ||||
| 
 | ||||
|     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; | ||||
| 
 | ||||
|     /// \todo make pattern syntax configurable
 | ||||
|     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 | ||||
|  |  | |||
|  | @ -7,10 +7,9 @@ | |||
| #include "../world/columns.hpp" | ||||
| #include "../world/idtable.hpp" | ||||
| 
 | ||||
| CSMFilter::ValueNode::ValueNode (int columnId, | ||||
|     double lower, double upper, bool min, bool max) | ||||
| : mColumnId (columnId), mLower (lower), mUpper (upper), mMin (min), mMax (max) | ||||
| {} | ||||
| CSMFilter::ValueNode::ValueNode (int columnId, Type lowerType, Type upperType, | ||||
|     double lower, double upper) | ||||
| : mColumnId (columnId), mLowerType (lowerType), mUpperType (upperType), mLower (lower), mUpper (upper){} | ||||
| 
 | ||||
| bool CSMFilter::ValueNode::test (const CSMWorld::IdTable& table, int row, | ||||
|     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(); | ||||
| 
 | ||||
|     if (mLower==mUpper && mMin && mMax) | ||||
|         return value==mLower; | ||||
|     switch (mLowerType) | ||||
|     { | ||||
|         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 | ||||
|  | @ -60,10 +70,26 @@ std::string CSMFilter::ValueNode::toString (bool numericColumns) const | |||
| 
 | ||||
|     stream << ", \""; | ||||
| 
 | ||||
|     if (mLower==mUpper && mMin && mMax) | ||||
|     if (mLower==mUpper && mLowerType!=Type_Infinite && mUpperType!=Type_Infinite) | ||||
|         stream << mLower; | ||||
|     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 << ")"; | ||||
| 
 | ||||
|  |  | |||
|  | @ -7,16 +7,25 @@ namespace CSMFilter | |||
| { | ||||
|     class ValueNode : public LeafNode | ||||
|     { | ||||
|         public: | ||||
| 
 | ||||
|             enum Type | ||||
|             { | ||||
|                 Type_Closed, Type_Open, Type_Infinite | ||||
|             }; | ||||
| 
 | ||||
|         private: | ||||
| 
 | ||||
|             int mColumnId; | ||||
|             std::string mText; | ||||
|             double mLower; | ||||
|             double mUpper; | ||||
|             bool mMin; | ||||
|             bool mMax; | ||||
|             Type mLowerType; | ||||
|             Type mUpperType; | ||||
| 
 | ||||
|         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, | ||||
|                 const std::map<int, int>& columns) const; | ||||
|  |  | |||
|  | @ -3,6 +3,8 @@ | |||
| 
 | ||||
| #include <components/misc/stringops.hpp> | ||||
| 
 | ||||
| #include "universalid.hpp" | ||||
| 
 | ||||
| namespace CSMWorld | ||||
| { | ||||
|     namespace Columns | ||||
|  | @ -197,3 +199,103 @@ int CSMWorld::Columns::getId (const std::string& name) | |||
| 
 | ||||
|     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 | ||||
| 
 | ||||
| #include <string> | ||||
| #include <vector> | ||||
| 
 | ||||
| namespace CSMWorld | ||||
| { | ||||
|  | @ -180,6 +181,11 @@ namespace CSMWorld | |||
| 
 | ||||
|         int getId (const std::string& 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_Weapon, "Weapon", ":./weapon.png" }, | ||||
|         { 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
 | ||||
|     }; | ||||
| 
 | ||||
|  | @ -90,8 +90,6 @@ namespace | |||
| 
 | ||||
|         { 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) | ||||
|  | @ -151,6 +149,22 @@ CSMWorld::UniversalId::UniversalId (Type type) : mArgumentType (ArgumentType_Non | |||
|             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"); | ||||
| } | ||||
| 
 | ||||
|  | @ -293,25 +307,6 @@ std::vector<CSMWorld::UniversalId::Type> CSMWorld::UniversalId::listReferenceabl | |||
|     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) | ||||
| { | ||||
|     return left.isEqual (right); | ||||
|  |  | |||
|  | @ -34,7 +34,7 @@ namespace CSMWorld | |||
| 
 | ||||
|             enum Type | ||||
|             { | ||||
|                 Type_None, | ||||
|                 Type_None = 0, | ||||
|                 Type_Globals, | ||||
|                 Type_Global, | ||||
|                 Type_VerificationResults, | ||||
|  | @ -89,6 +89,8 @@ namespace CSMWorld | |||
|                 Type_Filters | ||||
|             }; | ||||
| 
 | ||||
|             enum { NumberOfTypes = Type_Filters+1 }; | ||||
| 
 | ||||
|         private: | ||||
| 
 | ||||
|             Class mClass; | ||||
|  | @ -102,7 +104,6 @@ namespace CSMWorld | |||
|             UniversalId (const std::string& universalId); | ||||
| 
 | ||||
|             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); | ||||
|             ///< 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.
 | ||||
| 
 | ||||
|             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); | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ | |||
| 
 | ||||
| #include "../../model/doc/documentmanager.hpp" | ||||
| #include "../../model/doc/document.hpp" | ||||
| #include "../../model/world/columns.hpp" | ||||
| 
 | ||||
| #include "../world/util.hpp" | ||||
| #include "../world/enumdelegate.hpp" | ||||
|  | @ -43,51 +44,6 @@ void CSVDoc::ViewManager::updateIndices() | |||
| CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) | ||||
|     : 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->add (CSMWorld::ColumnBase::Display_GmstVarType, | ||||
|  | @ -96,38 +52,37 @@ CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) | |||
|     mDelegateFactories->add (CSMWorld::ColumnBase::Display_GlobalVarType, | ||||
|         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, | ||||
|         new CSVWorld::RecordStatusDelegateFactory() ); | ||||
|         new CSVWorld::RecordStatusDelegateFactory()); | ||||
| 
 | ||||
|     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 &)), | ||||
|              this, SLOT (slotUpdateEditorSetting (const QString &, const QString &))); | ||||
|         this, SLOT (slotUpdateEditorSetting (const QString &, const QString &))); | ||||
| } | ||||
| 
 | ||||
| CSVDoc::ViewManager::~ViewManager() | ||||
|  |  | |||
|  | @ -109,6 +109,18 @@ CSVWorld::EnumDelegateFactory::EnumDelegateFactory (const char **names, bool all | |||
|         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, | ||||
|     QObject *parent) const | ||||
| { | ||||
|  |  | |||
|  | @ -54,6 +54,9 @@ namespace CSVWorld | |||
|             ///< \param names Array of char pointer with a 0-pointer as end mark
 | ||||
|             /// \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; | ||||
|             ///< The ownership of the returned CommandDelegate is transferred to the caller.
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,8 +1,11 @@ | |||
| #include "recordstatusdelegate.hpp" | ||||
| 
 | ||||
| #include <QPainter> | ||||
| #include <QApplication> | ||||
| #include <QUndoStack> | ||||
| 
 | ||||
| #include "../../model/settings/usersettings.hpp" | ||||
| #include "../../model/world/columns.hpp" | ||||
| 
 | ||||
| CSVWorld::RecordStatusDelegate::RecordStatusDelegate(const ValueList& values, | ||||
|                                                      const IconList & icons, | ||||
|  | @ -37,9 +40,14 @@ bool CSVWorld::RecordStatusDelegate::updateEditorSetting (const QString &setting | |||
| 
 | ||||
| CSVWorld::RecordStatusDelegateFactory::RecordStatusDelegateFactory() | ||||
| { | ||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_BaseOnly,     "Base",     ":./base.png"); | ||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Deleted,      "Deleted",  ":./removed.png"); | ||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Erased,       "Deleted",  ":./removed.png"); | ||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_Modified,     "Modified", ":./modified.png"); | ||||
|     DataDisplayDelegateFactory::add ( CSMWorld::RecordBase::State_ModifiedOnly, "Added",    ":./added.png"); | ||||
|     std::vector<std::string> enums = | ||||
|         CSMWorld::Columns::getEnums (CSMWorld::Columns::ColumnId_Modification); | ||||
| 
 | ||||
|     static const char *sIcons[] = | ||||
|     { | ||||
|         ":./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 "../../model/world/universalid.hpp" | ||||
| 
 | ||||
| CSVWorld::RefIdTypeDelegate::RefIdTypeDelegate | ||||
|  | @ -6,6 +7,26 @@ CSVWorld::RefIdTypeDelegate::RefIdTypeDelegate | |||
|     : 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() | ||||
| { | ||||
|     UidTypeList uIdList = buildUidTypeList(); | ||||
|  | @ -39,22 +60,3 @@ CSVWorld::RefIdTypeDelegateFactory::UidTypeList CSVWorld::RefIdTypeDelegateFacto | |||
| 
 | ||||
|     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 "../../model/world/commands.hpp" | ||||
| #include "../../model/world/columns.hpp" | ||||
| 
 | ||||
| void CSVWorld::VarTypeDelegate::addCommands (QAbstractItemModel *model, const QModelIndex& index, int type) | ||||
|     const | ||||
|  | @ -75,29 +76,11 @@ CSVWorld::CommandDelegate *CSVWorld::VarTypeDelegateFactory::makeDelegate (QUndo | |||
| 
 | ||||
| void CSVWorld::VarTypeDelegateFactory::add (ESM::VarType type) | ||||
| { | ||||
|     struct Name | ||||
|     { | ||||
|         ESM::VarType mType; | ||||
|         const char *mName; | ||||
|     }; | ||||
|     std::vector<std::string> enums = | ||||
|         CSMWorld::Columns::getEnums (CSMWorld::Columns::ColumnId_ValueType); | ||||
| 
 | ||||
|     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
 | ||||
|     }; | ||||
|     if (type<0 && type>=enums.size()) | ||||
|         throw std::logic_error ("Unsupported variable type"); | ||||
| 
 | ||||
|     for (int i=0; sNames[i].mName; ++i) | ||||
|         if (sNames[i].mType==type) | ||||
|         { | ||||
|             mValues.push_back (std::make_pair (type, sNames[i].mName)); | ||||
|             return; | ||||
|         } | ||||
| 
 | ||||
|     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 | ||||
|     { | ||||
|         VT_Unknown, | ||||
|         VT_Unknown = 0, | ||||
|         VT_None, | ||||
|         VT_Short, // stored as a float, kinda
 | ||||
|         VT_Int, | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue