diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 6da863b97..f7b7daee4 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -24,11 +24,11 @@ opencs_units (model/world opencs_units_noqt (model/world universalid data record commands columnbase scriptcontext cell refidcollection - refidadapter refiddata refidadapterimp ref collectionbase refcollection + refidadapter refiddata refidadapterimp ref collectionbase refcollection columns ) opencs_hdrs_noqt (model/world - columns idcollection collection + columnimp idcollection collection ) @@ -107,6 +107,10 @@ opencs_units_noqt (model/settings settingsitem ) +opencs_hdrs_noqt (model/filter + filter + ) + set (OPENCS_US ) diff --git a/apps/opencs/model/filter/filter.hpp b/apps/opencs/model/filter/filter.hpp new file mode 100644 index 000000000..bddc9cc2d --- /dev/null +++ b/apps/opencs/model/filter/filter.hpp @@ -0,0 +1,26 @@ +#ifndef CSM_FILTER_FILTER_H +#define CSM_FILTER_FILTER_H + +#include +#include + +#include + +namespace CSMFilter +{ + /// \brief Wrapper for Filter record + struct Filter : public ESM::Filter + { + enum scope + { + Global = 0, + Local = 1, + Session = 2, + Content = 3 + }; + + scope mScope; + }; +} + +#endif \ No newline at end of file diff --git a/apps/opencs/model/world/columnbase.cpp b/apps/opencs/model/world/columnbase.cpp index 134c582c4..34bad20cc 100644 --- a/apps/opencs/model/world/columnbase.cpp +++ b/apps/opencs/model/world/columnbase.cpp @@ -1,8 +1,10 @@ #include "columnbase.hpp" -CSMWorld::ColumnBase::ColumnBase (const std::string& title, Display displayType, int flags) -: mTitle (title), mDisplayType (displayType), mFlags (flags) +#include "columns.hpp" + +CSMWorld::ColumnBase::ColumnBase (int columnId, Display displayType, int flags) +: mColumnId (columnId), mDisplayType (displayType), mFlags (flags) {} CSMWorld::ColumnBase::~ColumnBase() {} @@ -10,4 +12,9 @@ CSMWorld::ColumnBase::~ColumnBase() {} bool CSMWorld::ColumnBase::isUserEditable() const { return isEditable(); +} + +std::string CSMWorld::ColumnBase::getTitle() const +{ + return Columns::getName (static_cast (mColumnId)); } \ No newline at end of file diff --git a/apps/opencs/model/world/columnbase.hpp b/apps/opencs/model/world/columnbase.hpp index 280341216..c1b423c94 100644 --- a/apps/opencs/model/world/columnbase.hpp +++ b/apps/opencs/model/world/columnbase.hpp @@ -46,11 +46,11 @@ namespace CSMWorld Display_RefRecordType }; - std::string mTitle; + int mColumnId; int mFlags; Display mDisplayType; - ColumnBase (const std::string& title, Display displayType, int flag); + ColumnBase (int columnId, Display displayType, int flag); virtual ~ColumnBase(); @@ -59,22 +59,22 @@ namespace CSMWorld virtual bool isUserEditable() const; ///< Can this column be edited directly by the user? + virtual std::string getTitle() const; }; template struct Column : public ColumnBase { - std::string mTitle; int mFlags; - Column (const std::string& title, Display displayType, int flags = Flag_Table | Flag_Dialogue) - : ColumnBase (title, displayType, flags) {} + Column (int columnId, Display displayType, int flags = Flag_Table | Flag_Dialogue) + : ColumnBase (columnId, displayType, flags) {} virtual QVariant get (const Record& record) const = 0; virtual void set (Record& record, const QVariant& data) { - throw std::logic_error ("Column " + mTitle + " is not editable"); + throw std::logic_error ("Column " + getTitle() + " is not editable"); } }; } diff --git a/apps/opencs/model/world/columnimp.hpp b/apps/opencs/model/world/columnimp.hpp new file mode 100644 index 000000000..8a1595a30 --- /dev/null +++ b/apps/opencs/model/world/columnimp.hpp @@ -0,0 +1,1196 @@ +#ifndef CSM_WOLRD_COLUMNIMP_H +#define CSM_WOLRD_COLUMNIMP_H + +#include + +#include + +#include + +#include "columnbase.hpp" +#include "columns.hpp" + +namespace CSMWorld +{ + /// \note Shares ID with VarValueColumn. A table can not have both. + template + struct FloatValueColumn : public Column + { + FloatValueColumn() : Column (Columns::ColumnId_Value, ColumnBase::Display_Float) {} + + virtual QVariant get (const Record& record) const + { + return record.get().mValue.getFloat(); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mValue.setFloat (data.toFloat()); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + /// \note Shares ID with IdColumn. A table can not have both. + template + struct StringIdColumn : public Column + { + StringIdColumn (bool hidden = false) + : Column (Columns::ColumnId_Id, ColumnBase::Display_String, + hidden ? 0 : ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue) + {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mId.c_str()); + } + + virtual bool isEditable() const + { + return false; + } + }; + + template + struct RecordStateColumn : public Column + { + RecordStateColumn() + : Column (Columns::ColumnId_Modification, ColumnBase::Display_RecordState) + {} + + virtual QVariant get (const Record& record) const + { + if (record.mState==Record::State_Erased) + return static_cast (Record::State_Deleted); + + return static_cast (record.mState); + } + + virtual void set (Record& record, const QVariant& data) + { + record.mState = static_cast (data.toInt()); + } + + virtual bool isEditable() const + { + return true; + } + + virtual bool isUserEditable() const + { + return false; + } + }; + + template + struct FixedRecordTypeColumn : public Column + { + int mType; + + FixedRecordTypeColumn (int type) + : Column (Columns::ColumnId_RecordType, ColumnBase::Display_Integer, 0), + mType (type) + {} + + virtual QVariant get (const Record& record) const + { + return mType; + } + + virtual bool isEditable() const + { + return false; + } + }; + + /// \attention A var type column must be immediately followed by a suitable value column. + template + struct VarTypeColumn : public Column + { + VarTypeColumn (ColumnBase::Display display) + : Column (Columns::ColumnId_ValueType, display) + {} + + virtual QVariant get (const Record& record) const + { + return static_cast (record.get().mValue.getType()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mValue.setType (static_cast (data.toInt())); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + /// \note Shares ID with FloatValueColumn. A table can not have both. + template + struct VarValueColumn : public Column + { + VarValueColumn() : Column (Columns::ColumnId_Value, ColumnBase::Display_Var) {} + + virtual QVariant get (const Record& record) const + { + switch (record.get().mValue.getType()) + { + case ESM::VT_String: + + return QString::fromUtf8 (record.get().mValue.getString().c_str()); + + case ESM::VT_Int: + case ESM::VT_Short: + case ESM::VT_Long: + + return record.get().mValue.getInteger(); + + case ESM::VT_Float: + + return record.get().mValue.getFloat(); + + default: return QVariant(); + } + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + switch (record2.mValue.getType()) + { + case ESM::VT_String: + + record2.mValue.setString (data.toString().toUtf8().constData()); + break; + + case ESM::VT_Int: + case ESM::VT_Short: + case ESM::VT_Long: + + record2.mValue.setInteger (data.toInt()); + break; + + case ESM::VT_Float: + + record2.mValue.setFloat (data.toFloat()); + break; + + default: break; + } + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct DescriptionColumn : public Column + { + DescriptionColumn() + : Column (Columns::ColumnId_Description, ColumnBase::Display_String) + {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mDescription.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mDescription = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct SpecialisationColumn : public Column + { + SpecialisationColumn() + : Column (Columns::ColumnId_Specialisation, ColumnBase::Display_Specialisation) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mData.mSpecialization; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mData.mSpecialization = data.toInt(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct UseValueColumn : public Column + { + int mIndex; + + UseValueColumn (int index) + : Column (Columns::ColumnId_UseValue1 + index - 1, ColumnBase::Display_Float), + mIndex (index) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mData.mUseValue[mIndex]; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mData.mUseValue[mIndex] = data.toInt(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct AttributeColumn : public Column + { + AttributeColumn() + : Column (Columns::ColumnId_Attribute, ColumnBase::Display_Attribute) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mData.mAttribute; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mData.mAttribute = data.toInt(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct NameColumn : public Column + { + NameColumn() : Column (Columns::ColumnId_Name, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mName.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mName = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct AttributesColumn : public Column + { + int mIndex; + + AttributesColumn (int index) + : Column (Columns::ColumnId_Attribute1 + index - 1, ColumnBase::Display_Attribute), + mIndex (index) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mData.mAttribute[mIndex]; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mData.mAttribute[mIndex] = data.toInt(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct SkillsColumn : public Column + { + int mIndex; + bool mMajor; + + SkillsColumn (int index, bool typePrefix = false, bool major = false) + : Column ((typePrefix ? ( + major ? Columns::ColumnId_MajorSkill1 : Columns::ColumnId_MinorSkill1) : + Columns::ColumnId_Skill1) + index - 1, ColumnBase::Display_String), + mIndex (index), mMajor (major) + {} + + virtual QVariant get (const Record& record) const + { + int skill = record.get().mData.getSkill (mIndex, mMajor); + + return QString::fromUtf8 (ESM::Skill::indexToId (skill).c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + std::istringstream stream (data.toString().toUtf8().constData()); + + int index = -1; + char c; + + stream >> c >> index; + + if (index!=-1) + { + ESXRecordT record2 = record.get(); + + record2.mData.getSkill (mIndex, mMajor) = index; + + record.setModified (record2); + } + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct PlayableColumn : public Column + { + PlayableColumn() : Column (Columns::ColumnId_Playable, ColumnBase::Display_Boolean) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mData.mIsPlayable!=0; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mData.mIsPlayable = data.toInt(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct HiddenColumn : public Column + { + HiddenColumn() : Column (Columns::ColumnId_Hidden, ColumnBase::Display_Boolean) {} + + virtual QVariant get (const Record& record) const + { + return record.get().mData.mIsHidden!=0; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mData.mIsHidden = data.toInt(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct FlagColumn : public Column + { + int mMask; + + FlagColumn (int columnId, int mask) + : Column (columnId, ColumnBase::Display_Boolean), mMask (mask) + {} + + virtual QVariant get (const Record& record) const + { + return (record.get().mData.mFlags & mMask)!=0; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + int flags = record2.mData.mFlags & ~mMask; + + if (data.toInt()) + flags |= mMask; + + record2.mData.mFlags = flags; + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct WeightHeightColumn : public Column + { + bool mMale; + bool mWeight; + + WeightHeightColumn (bool male, bool weight) + : Column (male ? + (weight ? Columns::ColumnId_MaleWeight : Columns::ColumnId_MaleHeight) : + (weight ? Columns::ColumnId_FemaleWeight : Columns::ColumnId_FemaleHeight), + ColumnBase::Display_Float), + mMale (male), mWeight (weight) + {} + + virtual QVariant get (const Record& record) const + { + const ESM::Race::MaleFemaleF& value = + mWeight ? record.get().mData.mWeight : record.get().mData.mHeight; + + return mMale ? value.mMale : value.mFemale; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + ESM::Race::MaleFemaleF& value = + mWeight ? record2.mData.mWeight : record2.mData.mHeight; + + (mMale ? value.mMale : value.mFemale) = data.toFloat(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct SoundParamColumn : public Column + { + enum Type + { + Type_Volume, + Type_MinRange, + Type_MaxRange + }; + + Type mType; + + SoundParamColumn (Type type) + : Column (type==Type_Volume ? Columns::ColumnId_Volume : + (type==Type_MinRange ? Columns::ColumnId_MinRange : Columns::ColumnId_MaxRange), + ColumnBase::Display_Integer), + mType (type) + {} + + virtual QVariant get (const Record& record) const + { + int value = 0; + + switch (mType) + { + case Type_Volume: value = record.get().mData.mVolume; break; + case Type_MinRange: value = record.get().mData.mMinRange; break; + case Type_MaxRange: value = record.get().mData.mMaxRange; break; + } + + return value; + } + + virtual void set (Record& record, const QVariant& data) + { + int value = data.toInt(); + + if (value<0) + value = 0; + else if (value>255) + value = 255; + + ESXRecordT record2 = record.get(); + + switch (mType) + { + case Type_Volume: record2.mData.mVolume = static_cast (value); break; + case Type_MinRange: record2.mData.mMinRange = static_cast (value); break; + case Type_MaxRange: record2.mData.mMaxRange = static_cast (value); break; + } + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct SoundFileColumn : public Column + { + SoundFileColumn() + : Column (Columns::ColumnId_SoundFile, ColumnBase::Display_String) + {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mSound.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mSound = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + /// \todo QColor is a GUI class and should not be in model. Need to think of an alternative + /// solution. + template + struct MapColourColumn : public Column + { + /// \todo Replace Display_Integer with something that displays the colour value more directly. + MapColourColumn() + : Column (Columns::ColumnId_MapColour, ColumnBase::Display_Integer) + {} + + virtual QVariant get (const Record& record) const + { + int colour = record.get().mMapColor; + + return QColor (colour & 0xff, (colour>>8) & 0xff, (colour>>16) & 0xff); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + QColor colour = data.value(); + + record2.mMapColor = colour.rgb() & 0xffffff; + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct SleepListColumn : public Column + { + SleepListColumn() + : Column (Columns::ColumnId_SleepEncounter, ColumnBase::Display_String) + {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mSleepList.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mSleepList = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct TextureColumn : public Column + { + TextureColumn() : Column (Columns::ColumnId_Texture, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mTexture.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mTexture = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct SpellTypeColumn : public Column + { + SpellTypeColumn() + : Column (Columns::ColumnId_SpellType, ColumnBase::Display_SpellType) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mData.mType; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mData.mType = data.toInt(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct CostColumn : public Column + { + CostColumn() : Column (Columns::ColumnId_Cost, ColumnBase::Display_Integer) {} + + virtual QVariant get (const Record& record) const + { + return record.get().mData.mCost; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mData.mCost = data.toInt(); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct ScriptColumn : public Column + { + ScriptColumn() + : Column (Columns::ColumnId_ScriptText, ColumnBase::Display_Script, 0) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mScriptText.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mScriptText = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct RegionColumn : public Column + { + RegionColumn() : Column (Columns::ColumnId_Region, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mRegion.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mRegion = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct CellColumn : public Column + { + CellColumn() : Column (Columns::ColumnId_Cell, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mCellId.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mCellId = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + + virtual bool isUserEditable() const + { + return false; + } + }; + + /// \note Shares ID with StringIdColumn. A table can not have both. + template + struct IdColumn : public Column + { + IdColumn() : Column (Columns::ColumnId_Id, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mRefID.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mRefID = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct ScaleColumn : public Column + { + ScaleColumn() : Column (Columns::ColumnId_Scale, ColumnBase::Display_Float) {} + + virtual QVariant get (const Record& record) const + { + return record.get().mScale; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mScale = data.toFloat(); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct OwnerColumn : public Column + { + OwnerColumn() : Column (Columns::ColumnId_Owner, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mOwner.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mOwner = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct SoulColumn : public Column + { + SoulColumn() : Column (Columns::ColumnId_Soul, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mSoul.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mSoul = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct FactionColumn : public Column + { + FactionColumn() : Column (Columns::ColumnId_Faction, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mFaction.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mFaction = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct FactionIndexColumn : public Column + { + FactionIndexColumn() + : Column (Columns::ColumnId_FactionIndex, ColumnBase::Display_Integer) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mFactIndex; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mFactIndex = data.toInt(); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct ChargesColumn : public Column + { + ChargesColumn() : Column (Columns::ColumnId_Charges, ColumnBase::Display_Integer) {} + + virtual QVariant get (const Record& record) const + { + return record.get().mCharge; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mCharge = data.toInt(); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct EnchantmentChargesColumn : public Column + { + EnchantmentChargesColumn() + : Column (Columns::ColumnId_Enchantment, ColumnBase::Display_Float) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mEnchantmentCharge; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mEnchantmentCharge = data.toFloat(); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct GoldValueColumn : public Column + { + GoldValueColumn() + : Column (Columns::ColumnId_CoinValue, ColumnBase::Display_Integer) {} + + virtual QVariant get (const Record& record) const + { + return record.get().mGoldValue; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mGoldValue = data.toInt(); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct TeleportColumn : public Column + { + TeleportColumn() + : Column (Columns::ColumnId_Teleport, ColumnBase::Display_Boolean) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mTeleport; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mTeleport = data.toInt(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct TeleportCellColumn : public Column + { + TeleportCellColumn() + : Column (Columns::ColumnId_TeleportCell, ColumnBase::Display_String) + {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mDestCell.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mDestCell = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + + virtual bool isUserEditable() const + { + return false; + } + }; + + template + struct LockLevelColumn : public Column + { + LockLevelColumn() + : Column (Columns::ColumnId_LockLevel, ColumnBase::Display_Integer) + {} + + virtual QVariant get (const Record& record) const + { + return record.get().mLockLevel; + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + record2.mLockLevel = data.toInt(); + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct KeyColumn : public Column + { + KeyColumn() : Column (Columns::ColumnId_Key, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mKey.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mKey = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; + + template + struct TrapColumn : public Column + { + TrapColumn() : Column (Columns::ColumnId_Trap, ColumnBase::Display_String) {} + + virtual QVariant get (const Record& record) const + { + return QString::fromUtf8 (record.get().mTrap.c_str()); + } + + virtual void set (Record& record, const QVariant& data) + { + ESXRecordT record2 = record.get(); + + record2.mTrap = data.toString().toUtf8().constData(); + + record.setModified (record2); + } + + virtual bool isEditable() const + { + return true; + } + }; +} + +#endif diff --git a/apps/opencs/model/world/columns.cpp b/apps/opencs/model/world/columns.cpp new file mode 100644 index 000000000..2198d1b0c --- /dev/null +++ b/apps/opencs/model/world/columns.cpp @@ -0,0 +1,197 @@ + +#include "columns.hpp" + +#include + +namespace CSMWorld +{ + namespace Columns + { + struct ColumnDesc + { + int mId; + const char *mName; + }; + + const ColumnDesc sNames[] = + { + { ColumnId_Value, "Value" }, + { ColumnId_Id, "ID" }, + { ColumnId_Modification, "Modified" }, + { ColumnId_RecordType, "Record Type" }, + { ColumnId_ValueType, "Value Type" }, + { ColumnId_Description, "Description" }, + { ColumnId_Specialisation, "Specialisation" }, + { ColumnId_Attribute, "Attribute" }, + { ColumnId_Name, "Name" }, + { ColumnId_Playable, "Playable" }, + { ColumnId_Hidden, "Hidden" }, + { ColumnId_MaleWeight, "Male Weight" }, + { ColumnId_FemaleWeight, "Female Weight" }, + { ColumnId_MaleHeight, "Male Height" }, + { ColumnId_FemaleHeight, "Female Height" }, + { ColumnId_Volume, "Volume" }, + { ColumnId_MinRange, "Min Range" }, + { ColumnId_MaxRange, "Max Range" }, + { ColumnId_SoundFile, "Sound File" }, + { ColumnId_MapColour, "Map Colour" }, + { ColumnId_SleepEncounter, "Sleep Encounter" }, + { ColumnId_Texture, "Texture" }, + { ColumnId_SpellType, "Spell Type" }, + { ColumnId_Cost, "Cost" }, + { ColumnId_ScriptText, "Script Text" }, + { ColumnId_Region, "Region" }, + { ColumnId_Cell, "Cell" }, + { ColumnId_Scale, "Scale" }, + { ColumnId_Owner, "Owner" }, + { ColumnId_Soul, "Soul" }, + { ColumnId_Faction, "Faction" }, + { ColumnId_FactionIndex, "Faction Index" }, + { ColumnId_Charges, "Charges" }, + { ColumnId_Enchantment, "Enchantment" }, + { ColumnId_Value, "Coin Value" }, + { ColumnId_Teleport, "Teleport" }, + { ColumnId_TeleportCell, "Teleport Cell" }, + { ColumnId_LockLevel, "Lock Level" }, + { ColumnId_Key, "Key" }, + { ColumnId_Trap, "Trap" }, + { ColumnId_BeastRace, "Beast Race" }, + { ColumnId_AutoCalc, "Auto Calc" }, + { ColumnId_StarterSpell, "Starter Spell" }, + { ColumnId_AlwaysSucceeds, "Always Succeeds" }, + { ColumnId_SleepForbidden, "Sleep Forbidden" }, + { ColumnId_InteriorWater, "Interior Water" }, + { ColumnId_InteriorSky, "Interior Sky" }, + { ColumnId_Model, "Model" }, + { ColumnId_Script, "Script" }, + { ColumnId_Icon, "Icon" }, + { ColumnId_Weight, "Weight" }, + { ColumnId_EnchantmentPoints, "Enchantment Points" }, + { ColumnId_Quality, "Quality" }, + { ColumnId_Ai, "AI" }, + { ColumnId_AiHello, "AI Hello" }, + { ColumnId_AiFlee, "AI Flee" }, + { ColumnId_AiFight, "AI Fight" }, + { ColumnId_AiAlarm, "AI Alarm" }, + { ColumnId_BuysWeapons, "Buys Weapons" }, + { ColumnId_BuysArmor, "Buys Armor" }, + { ColumnId_BuysClothing, "Buys Clothing" }, + { ColumnId_BuysBooks, "Buys Books" }, + { ColumnId_BuysIngredients, "Buys Ingredients" }, + { ColumnId_BuysLockpicks, "Buys Lockpicks" }, + { ColumnId_BuysProbes, "Buys Probes" }, + { ColumnId_BuysLights, "Buys Lights" }, + { ColumnId_BuysApparati, "Buys Apparati" }, + { ColumnId_BuysRepairItems, "Buys Repair Items" }, + { ColumnId_BuysMiscItems, "Buys Misc Items" }, + { ColumnId_BuysPotions, "Buys Potions" }, + { ColumnId_BuysMagicItems, "Buys Magic Items" }, + { ColumnId_SellsSpells, "Sells Spells" }, + { ColumnId_Trainer, "Trainer" }, + { ColumnId_Spellmaking, "Spellmaking" }, + { ColumnId_EnchantingService, "Enchanting Service" }, + { ColumnId_RepairService, "Repair Serivce" }, + { ColumnId_ApparatusType, "Apparatus Type" }, + { ColumnId_ArmorType, "Armor Type" }, + { ColumnId_Health, "Health" }, + { ColumnId_ArmorValue, "Armor Value" }, + { ColumnId_Scroll, "Scroll" }, + { ColumnId_ClothingType, "Clothing Type" }, + { ColumnId_WeightCapacity, "Weight Capacity" }, + { ColumnId_OrganicContainer, "Organic Container" }, + { ColumnId_Respawn, "Respawn" }, + { ColumnId_CreatureType, "Creature Type" }, + { ColumnId_SoulPoints, "Soul Points" }, + { ColumnId_OriginalCreature, "Original Creature" }, + { ColumnId_Biped, "Biped" }, + { ColumnId_HasWeapon, "Has Weapon" }, + { ColumnId_NoMovement, "No Movement" }, + { ColumnId_Swims, "Swims" }, + { ColumnId_Flies, "Flies" }, + { ColumnId_Walks, "Walks" }, + { ColumnId_Essential, "Essential" }, + { ColumnId_SkeletonBlood, "Skeleton Blood" }, + { ColumnId_MetalBlood, "Metal Blood" }, + { ColumnId_OpenSound, "Open Sound" }, + { ColumnId_CloseSound, "Close Sound" }, + { ColumnId_Duration, "Duration" }, + { ColumnId_Radius, "Radius" }, + { ColumnId_Colour, "Colour" }, + { ColumnId_Sound, "Sound" }, + { ColumnId_Dynamic, "Dynamic" }, + { ColumnId_Portable, "Portable" }, + { ColumnId_NegativeLight, "Negative Light" }, + { ColumnId_Flickering, "Flickering" }, + { ColumnId_SlowFlickering, "Slow Flickering" }, + { ColumnId_Pulsing, "Pulsing" }, + { ColumnId_SlowPulsing, "Slow Pulsing" }, + { ColumnId_Fire, "Fire" }, + { ColumnId_OffByDefault, "Off by default" }, + { ColumnId_IsKey, "Is Key" }, + { ColumnId_Race, "Race" }, + { ColumnId_Class, "Class" }, + { Columnid_Hair, "Hair" }, + { ColumnId_Head, "Head" }, + { ColumnId_Female, "Female" }, + { ColumnId_WeaponType, "Weapon Type" }, + { ColumnId_WeaponSpeed, "Weapon Speed" }, + { ColumnId_WeaponReach, "Weapon Reach" }, + { ColumnId_MinChop, "Min Chop" }, + { ColumnId_MaxChip, "Max Chop" }, + { Columnid_MinSlash, "Min Slash" }, + { ColumnId_MaxSlash, "Max Slash" }, + { ColumnId_MinThrust, "Min Thrust" }, + { ColumnId_MaxThrust, "Max Thrust" }, + { ColumnId_Magical, "Magical" }, + { ColumnId_Silver, "Silver" }, + + { ColumnId_UseValue1, "Use value 1" }, + { ColumnId_UseValue2, "Use value 2" }, + { ColumnId_UseValue3, "Use value 3" }, + { ColumnId_UseValue4, "Use value 4" }, + + { ColumnId_Attribute1, "Attribute 1" }, + { ColumnId_Attribute2, "Attribute 2" }, + + { ColumnId_MajorSkill1, "Major Skill 1" }, + { ColumnId_MajorSkill2, "Major Skill 2" }, + { ColumnId_MajorSkill3, "Major Skill 3" }, + { ColumnId_MajorSkill4, "Major Skill 4" }, + { ColumnId_MajorSkill5, "Major Skill 5" }, + + { ColumnId_MinorSkill1, "Minor Skill 1" }, + { ColumnId_MinorSkill2, "Minor Skill 2" }, + { ColumnId_MinorSkill3, "Minor Skill 3" }, + { ColumnId_MinorSkill4, "Minor Skill 4" }, + { ColumnId_MinorSkill5, "Minor Skill 5" }, + + { ColumnId_Skill1, "Skill 1" }, + { ColumnId_Skill1, "Skill 2" }, + { ColumnId_Skill1, "Skill 3" }, + { ColumnId_Skill1, "Skill 4" }, + { ColumnId_Skill1, "Skill 5" }, + + { -1, 0 } // end marker + }; + } +} + +std::string CSMWorld::Columns::getName (ColumnId column) +{ + for (int i=0; sNames[i].mName; ++i) + if (column==sNames[i].mId) + return sNames[i].mName; + + return ""; +} + +int CSMWorld::Columns::getId (const std::string& name) +{ + std::string name2 = Misc::StringUtils::lowerCase (name); + + for (int i=0; sNames[i].mName; ++i) + if (name2==Misc::StringUtils::lowerCase (sNames[i].mName)) + return sNames[i].mId; + + return -1; +} \ No newline at end of file diff --git a/apps/opencs/model/world/columns.hpp b/apps/opencs/model/world/columns.hpp index 23837959d..adde80dc9 100644 --- a/apps/opencs/model/world/columns.hpp +++ b/apps/opencs/model/world/columns.hpp @@ -1,1154 +1,184 @@ #ifndef CSM_WOLRD_COLUMNS_H #define CSM_WOLRD_COLUMNS_H -#include - -#include - -#include - -#include "columnbase.hpp" +#include namespace CSMWorld { - template - struct FloatValueColumn : public Column - { - FloatValueColumn() : Column ("Value", ColumnBase::Display_Float) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mValue.getFloat(); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mValue.setFloat (data.toFloat()); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct StringIdColumn : public Column - { - StringIdColumn (bool hidden = false) - : Column ("ID", ColumnBase::Display_String, - hidden ? 0 : ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue) - {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mId.c_str()); - } - - virtual bool isEditable() const - { - return false; - } - }; - - template - struct RecordStateColumn : public Column - { - RecordStateColumn() : Column ("*", ColumnBase::Display_RecordState) {} - - virtual QVariant get (const Record& record) const - { - if (record.mState==Record::State_Erased) - return static_cast (Record::State_Deleted); - - return static_cast (record.mState); - } - - virtual void set (Record& record, const QVariant& data) - { - record.mState = static_cast (data.toInt()); - } - - virtual bool isEditable() const - { - return true; - } - - virtual bool isUserEditable() const - { - return false; - } - }; - - template - struct FixedRecordTypeColumn : public Column - { - int mType; - - FixedRecordTypeColumn (int type) - : Column ("Record Type", ColumnBase::Display_Integer, 0), mType (type) {} - - virtual QVariant get (const Record& record) const - { - return mType; - } - - virtual bool isEditable() const - { - return false; - } - }; - - /// \attention A var type column must be immediately followed by a suitable value column. - template - struct VarTypeColumn : public Column - { - VarTypeColumn (ColumnBase::Display display) : Column ("Type", display) {} - - virtual QVariant get (const Record& record) const - { - return static_cast (record.get().mValue.getType()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mValue.setType (static_cast (data.toInt())); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct VarValueColumn : public Column - { - VarValueColumn() : Column ("Value", ColumnBase::Display_Var) {} - - virtual QVariant get (const Record& record) const - { - switch (record.get().mValue.getType()) - { - case ESM::VT_String: - - return QString::fromUtf8 (record.get().mValue.getString().c_str()); - - case ESM::VT_Int: - case ESM::VT_Short: - case ESM::VT_Long: - - return record.get().mValue.getInteger(); - - case ESM::VT_Float: - - return record.get().mValue.getFloat(); - - default: return QVariant(); - } - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - switch (record2.mValue.getType()) - { - case ESM::VT_String: - - record2.mValue.setString (data.toString().toUtf8().constData()); - break; - - case ESM::VT_Int: - case ESM::VT_Short: - case ESM::VT_Long: - - record2.mValue.setInteger (data.toInt()); - break; - - case ESM::VT_Float: - - record2.mValue.setFloat (data.toFloat()); - break; - - default: break; - } - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct DescriptionColumn : public Column - { - DescriptionColumn() : Column ("Description", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mDescription.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mDescription = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct SpecialisationColumn : public Column - { - SpecialisationColumn() : Column ("Specialisation", ColumnBase::Display_Specialisation) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mData.mSpecialization; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mData.mSpecialization = data.toInt(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct UseValueColumn : public Column - { - int mIndex; - - UseValueColumn (int index) - : Column ("Use value #" + boost::lexical_cast (index), - ColumnBase::Display_Float), mIndex (index) - {} - - virtual QVariant get (const Record& record) const - { - return record.get().mData.mUseValue[mIndex]; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mData.mUseValue[mIndex] = data.toInt(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct AttributeColumn : public Column - { - AttributeColumn() : Column ("Attribute", ColumnBase::Display_Attribute) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mData.mAttribute; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mData.mAttribute = data.toInt(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct NameColumn : public Column - { - NameColumn() : Column ("Name", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mName.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mName = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct AttributesColumn : public Column - { - int mIndex; - - AttributesColumn (int index) - : Column ("Attribute #" + boost::lexical_cast (index), - ColumnBase::Display_Attribute), mIndex (index) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mData.mAttribute[mIndex]; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mData.mAttribute[mIndex] = data.toInt(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct SkillsColumn : public Column - { - int mIndex; - bool mMajor; - - SkillsColumn (int index, bool typePrefix = false, bool major = false) - : Column ((typePrefix ? (major ? "Major Skill #" : "Minor Skill #") : "Skill #")+ - boost::lexical_cast (index), ColumnBase::Display_String), - mIndex (index), mMajor (major) - {} - - virtual QVariant get (const Record& record) const - { - int skill = record.get().mData.getSkill (mIndex, mMajor); - - return QString::fromUtf8 (ESM::Skill::indexToId (skill).c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - std::istringstream stream (data.toString().toUtf8().constData()); - - int index = -1; - char c; - - stream >> c >> index; - - if (index!=-1) - { - ESXRecordT record2 = record.get(); - - record2.mData.getSkill (mIndex, mMajor) = index; - - record.setModified (record2); - } - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct PlayableColumn : public Column - { - PlayableColumn() : Column ("Playable", ColumnBase::Display_Boolean) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mData.mIsPlayable!=0; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mData.mIsPlayable = data.toInt(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct HiddenColumn : public Column - { - HiddenColumn() : Column ("Hidden", ColumnBase::Display_Boolean) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mData.mIsHidden!=0; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mData.mIsHidden = data.toInt(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct FlagColumn : public Column - { - int mMask; - - FlagColumn (const std::string& name, int mask) - : Column (name, ColumnBase::Display_Boolean), mMask (mask) - {} - - virtual QVariant get (const Record& record) const - { - return (record.get().mData.mFlags & mMask)!=0; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - int flags = record2.mData.mFlags & ~mMask; - - if (data.toInt()) - flags |= mMask; - - record2.mData.mFlags = flags; - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct WeightHeightColumn : public Column - { - bool mMale; - bool mWeight; - - WeightHeightColumn (bool male, bool weight) - : Column (male ? (weight ? "Male Weight" : "Male Height") : - (weight ? "Female Weight" : "Female Height"), ColumnBase::Display_Float), - mMale (male), mWeight (weight) - {} - - virtual QVariant get (const Record& record) const - { - const ESM::Race::MaleFemaleF& value = - mWeight ? record.get().mData.mWeight : record.get().mData.mHeight; - - return mMale ? value.mMale : value.mFemale; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - ESM::Race::MaleFemaleF& value = - mWeight ? record2.mData.mWeight : record2.mData.mHeight; - - (mMale ? value.mMale : value.mFemale) = data.toFloat(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct SoundParamColumn : public Column - { - enum Type - { - Type_Volume, - Type_MinRange, - Type_MaxRange + namespace Columns + { + enum ColumnId + { + ColumnId_Value = 0, + ColumnId_Id = 1, + ColumnId_Modification = 2, + ColumnId_RecordType = 3, + ColumnId_ValueType = 4, + ColumnId_Description = 5, + ColumnId_Specialisation = 6, + ColumnId_Attribute = 7, + ColumnId_Name = 8, + ColumnId_Playable = 9, + ColumnId_Hidden = 10, + ColumnId_MaleWeight = 11, + ColumnId_FemaleWeight = 12, + ColumnId_MaleHeight = 13, + ColumnId_FemaleHeight = 14, + ColumnId_Volume = 15, + ColumnId_MinRange = 16, + ColumnId_MaxRange = 17, + ColumnId_SoundFile = 18, + ColumnId_MapColour = 19, + ColumnId_SleepEncounter = 20, + ColumnId_Texture = 21, + ColumnId_SpellType = 22, + ColumnId_Cost = 23, + ColumnId_ScriptText = 24, + ColumnId_Region = 25, + ColumnId_Cell = 26, + ColumnId_Scale = 27, + ColumnId_Owner = 28, + ColumnId_Soul = 29, + ColumnId_Faction = 30, + ColumnId_FactionIndex = 31, + ColumnId_Charges = 32, + ColumnId_Enchantment = 33, + ColumnId_CoinValue = 34, + ColumnId_Teleport = 25, + ColumnId_TeleportCell = 26, + ColumnId_LockLevel = 27, + ColumnId_Key = 28, + ColumnId_Trap = 29, + ColumnId_BeastRace = 30, + ColumnId_AutoCalc = 31, + ColumnId_StarterSpell = 32, + ColumnId_AlwaysSucceeds = 33, + ColumnId_SleepForbidden = 34, + ColumnId_InteriorWater = 35, + ColumnId_InteriorSky = 36, + ColumnId_Model = 37, + ColumnId_Script = 38, + ColumnId_Icon = 39, + ColumnId_Weight = 40, + ColumnId_EnchantmentPoints = 31, + ColumnId_Quality = 32, + ColumnId_Ai = 33, + ColumnId_AiHello = 34, + ColumnId_AiFlee = 35, + ColumnId_AiFight = 36, + ColumnId_AiAlarm = 37, + ColumnId_BuysWeapons = 38, + ColumnId_BuysArmor = 39, + ColumnId_BuysClothing = 40, + ColumnId_BuysBooks = 41, + ColumnId_BuysIngredients = 42, + ColumnId_BuysLockpicks = 43, + ColumnId_BuysProbes = 44, + ColumnId_BuysLights = 45, + ColumnId_BuysApparati = 46, + ColumnId_BuysRepairItems = 47, + ColumnId_BuysMiscItems = 48, + ColumnId_BuysPotions = 49, + ColumnId_BuysMagicItems = 50, + ColumnId_SellsSpells = 51, + ColumnId_Trainer = 52, + ColumnId_Spellmaking = 53, + ColumnId_EnchantingService = 54, + ColumnId_RepairService = 55, + ColumnId_ApparatusType = 56, + ColumnId_ArmorType = 57, + ColumnId_Health = 58, + ColumnId_ArmorValue = 59, + ColumnId_Scroll = 60, + ColumnId_ClothingType = 61, + ColumnId_WeightCapacity = 62, + ColumnId_OrganicContainer = 63, + ColumnId_Respawn = 64, + ColumnId_CreatureType = 65, + ColumnId_SoulPoints = 66, + ColumnId_OriginalCreature = 67, + ColumnId_Biped = 68, + ColumnId_HasWeapon = 69, + ColumnId_NoMovement = 70, + ColumnId_Swims = 71, + ColumnId_Flies = 72, + ColumnId_Walks = 73, + ColumnId_Essential = 74, + ColumnId_SkeletonBlood = 75, + ColumnId_MetalBlood = 76, + ColumnId_OpenSound = 77, + ColumnId_CloseSound = 78, + ColumnId_Duration = 79, + ColumnId_Radius = 80, + ColumnId_Colour = 81, + ColumnId_Sound = 82, + ColumnId_Dynamic = 83, + ColumnId_Portable = 84, + ColumnId_NegativeLight = 85, + ColumnId_Flickering = 86, + ColumnId_SlowFlickering = 87, + ColumnId_Pulsing = 88, + ColumnId_SlowPulsing = 89, + ColumnId_Fire = 90, + ColumnId_OffByDefault = 91, + ColumnId_IsKey = 92, + ColumnId_Race = 93, + ColumnId_Class = 94, + Columnid_Hair = 95, + ColumnId_Head = 96, + ColumnId_Female = 97, + ColumnId_WeaponType = 98, + ColumnId_WeaponSpeed = 99, + ColumnId_WeaponReach = 100, + ColumnId_MinChop = 101, + ColumnId_MaxChip = 102, + Columnid_MinSlash = 103, + ColumnId_MaxSlash = 104, + ColumnId_MinThrust = 105, + ColumnId_MaxThrust = 106, + ColumnId_Magical = 107, + ColumnId_Silver = 108, + + // Allocated to a separate value range, so we don't get a collision should we ever need + // to extend the number of use values. + ColumnId_UseValue1 = 0x10000, + ColumnId_UseValue2 = 0x10001, + ColumnId_UseValue3 = 0x10002, + ColumnId_UseValue4 = 0x10003, + + // Allocated to a separate value range, so we don't get a collision should we ever need + // to extend the number of attributes. Note that this is not the number of different + // attributes, but the number of attributes that can be references from a record. + ColumnId_Attribute1 = 0x20000, + ColumnId_Attribute2 = 0x20001, + + // Allocated to a separate value range, so we don't get a collision should we ever need + // to extend the number of skills. Note that this is not the number of different + // skills, but the number of skills that can be references from a record. + ColumnId_MajorSkill1 = 0x30000, + ColumnId_MajorSkill2 = 0x30001, + ColumnId_MajorSkill3 = 0x30002, + ColumnId_MajorSkill4 = 0x30003, + ColumnId_MajorSkill5 = 0x30004, + + ColumnId_MinorSkill1 = 0x40000, + ColumnId_MinorSkill2 = 0x40001, + ColumnId_MinorSkill3 = 0x40002, + ColumnId_MinorSkill4 = 0x40003, + ColumnId_MinorSkill5 = 0x40004, + + ColumnId_Skill1 = 0x50000, + ColumnId_Skill2 = 0x50001, + ColumnId_Skill3 = 0x50002, + ColumnId_Skill4 = 0x50003, + ColumnId_Skill5 = 0x50004 }; - Type mType; - - SoundParamColumn (Type type) - : Column ( - type==Type_Volume ? "Volume" : (type==Type_MinRange ? "Min Range" : "Max Range"), - ColumnBase::Display_Integer), - mType (type) - {} - - virtual QVariant get (const Record& record) const - { - int value = 0; - - switch (mType) - { - case Type_Volume: value = record.get().mData.mVolume; break; - case Type_MinRange: value = record.get().mData.mMinRange; break; - case Type_MaxRange: value = record.get().mData.mMaxRange; break; - } - - return value; - } - - virtual void set (Record& record, const QVariant& data) - { - int value = data.toInt(); - - if (value<0) - value = 0; - else if (value>255) - value = 255; - - ESXRecordT record2 = record.get(); - - switch (mType) - { - case Type_Volume: record2.mData.mVolume = static_cast (value); break; - case Type_MinRange: record2.mData.mMinRange = static_cast (value); break; - case Type_MaxRange: record2.mData.mMaxRange = static_cast (value); break; - } - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct SoundFileColumn : public Column - { - SoundFileColumn() : Column ("Sound File", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mSound.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mSound = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - /// \todo QColor is a GUI class and should not be in model. Need to think of an alternative - /// solution. - template - struct MapColourColumn : public Column - { - /// \todo Replace Display_Integer with something that displays the colour value more directly. - MapColourColumn() : Column ("Map Colour", ColumnBase::Display_Integer) {} - - virtual QVariant get (const Record& record) const - { - int colour = record.get().mMapColor; - - return QColor (colour & 0xff, (colour>>8) & 0xff, (colour>>16) & 0xff); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - QColor colour = data.value(); - - record2.mMapColor = colour.rgb() & 0xffffff; - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct SleepListColumn : public Column - { - SleepListColumn() : Column ("Sleep Encounter", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mSleepList.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mSleepList = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct TextureColumn : public Column - { - TextureColumn() : Column ("Texture", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mTexture.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mTexture = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct SpellTypeColumn : public Column - { - SpellTypeColumn() : Column ("Type", ColumnBase::Display_SpellType) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mData.mType; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mData.mType = data.toInt(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct CostColumn : public Column - { - CostColumn() : Column ("Cost", ColumnBase::Display_Integer) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mData.mCost; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mData.mCost = data.toInt(); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct ScriptColumn : public Column - { - ScriptColumn() : Column ("Script", ColumnBase::Display_Script, 0) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mScriptText.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mScriptText = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct RegionColumn : public Column - { - RegionColumn() : Column ("Region", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mRegion.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mRegion = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct CellColumn : public Column - { - CellColumn() : Column ("Cell", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mCellId.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mCellId = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - - virtual bool isUserEditable() const - { - return false; - } - }; - - template - struct IdColumn : public Column - { - IdColumn() : Column ("ID", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mRefID.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mRefID = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct ScaleColumn : public Column - { - ScaleColumn() : Column ("Scale", ColumnBase::Display_Float) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mScale; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mScale = data.toFloat(); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct OwnerColumn : public Column - { - OwnerColumn() : Column ("Owner", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mOwner.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mOwner = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct SoulColumn : public Column - { - SoulColumn() : Column ("Soul", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mSoul.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mSoul = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct FactionColumn : public Column - { - FactionColumn() : Column ("Faction", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mFaction.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mFaction = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct FactionIndexColumn : public Column - { - FactionIndexColumn() : Column ("Faction Index", ColumnBase::Display_Integer) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mFactIndex; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mFactIndex = data.toInt(); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct ChargesColumn : public Column - { - ChargesColumn() : Column ("Charges", ColumnBase::Display_Integer) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mCharge; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mCharge = data.toInt(); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct EnchantmentChargesColumn : public Column - { - EnchantmentChargesColumn() : Column ("Entchantment", ColumnBase::Display_Float) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mEnchantmentCharge; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mEnchantmentCharge = data.toFloat(); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct GoldValueColumn : public Column - { - GoldValueColumn() : Column ("Value", ColumnBase::Display_Integer) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mGoldValue; - } + std::string getName (ColumnId column); - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mGoldValue = data.toInt(); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct TeleportColumn : public Column - { - TeleportColumn() : Column ("Teleport", ColumnBase::Display_Boolean) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mTeleport; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mTeleport = data.toInt(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct TeleportCellColumn : public Column - { - TeleportCellColumn() : Column ("Teleport Cell", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mDestCell.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mDestCell = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - - virtual bool isUserEditable() const - { - return false; - } - }; - - template - struct LockLevelColumn : public Column - { - LockLevelColumn() : Column ("Lock Level", ColumnBase::Display_Integer) {} - - virtual QVariant get (const Record& record) const - { - return record.get().mLockLevel; - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - record2.mLockLevel = data.toInt(); - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct KeyColumn : public Column - { - KeyColumn() : Column ("Key", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mKey.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mKey = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; - - template - struct TrapColumn : public Column - { - TrapColumn() : Column ("Trap", ColumnBase::Display_String) {} - - virtual QVariant get (const Record& record) const - { - return QString::fromUtf8 (record.get().mTrap.c_str()); - } - - virtual void set (Record& record, const QVariant& data) - { - ESXRecordT record2 = record.get(); - - record2.mTrap = data.toString().toUtf8().constData(); - - record.setModified (record2); - } - - virtual bool isEditable() const - { - return true; - } - }; + int getId (const std::string& name); + ///< Will return -1 for an invalid name. + } } #endif diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 594bc19c2..9c5e13562 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -10,8 +10,9 @@ #include #include "idtable.hpp" -#include "columns.hpp" +#include "columnimp.hpp" #include "regionmap.hpp" +#include "columns.hpp" void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type1, UniversalId::Type type2) @@ -76,8 +77,8 @@ CSMWorld::Data::Data() : mRefs (mCells) mRaces.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Race)); mRaces.addColumn (new NameColumn); mRaces.addColumn (new DescriptionColumn); - mRaces.addColumn (new FlagColumn ("Playable", 0x1)); - mRaces.addColumn (new FlagColumn ("Beast Race", 0x2)); + mRaces.addColumn (new FlagColumn (Columns::ColumnId_Playable, 0x1)); + mRaces.addColumn (new FlagColumn (Columns::ColumnId_BeastRace, 0x2)); mRaces.addColumn (new WeightHeightColumn (true, true)); mRaces.addColumn (new WeightHeightColumn (true, false)); mRaces.addColumn (new WeightHeightColumn (false, true)); @@ -116,17 +117,17 @@ CSMWorld::Data::Data() : mRefs (mCells) mSpells.addColumn (new NameColumn); mSpells.addColumn (new SpellTypeColumn); mSpells.addColumn (new CostColumn); - mSpells.addColumn (new FlagColumn ("Autocalc", 0x1)); - mSpells.addColumn (new FlagColumn ("Starter Spell", 0x2)); - mSpells.addColumn (new FlagColumn ("Always Succeeds", 0x4)); + mSpells.addColumn (new FlagColumn (Columns::ColumnId_AutoCalc, 0x1)); + mSpells.addColumn (new FlagColumn (Columns::ColumnId_StarterSpell, 0x2)); + mSpells.addColumn (new FlagColumn (Columns::ColumnId_AlwaysSucceeds, 0x4)); mCells.addColumn (new StringIdColumn); mCells.addColumn (new RecordStateColumn); mCells.addColumn (new FixedRecordTypeColumn (UniversalId::Type_Cell)); mCells.addColumn (new NameColumn); - mCells.addColumn (new FlagColumn ("Sleep forbidden", ESM::Cell::NoSleep)); - mCells.addColumn (new FlagColumn ("Interior Water", ESM::Cell::HasWater)); - mCells.addColumn (new FlagColumn ("Interior Sky", ESM::Cell::QuasiEx)); + mCells.addColumn (new FlagColumn (Columns::ColumnId_SleepForbidden, ESM::Cell::NoSleep)); + mCells.addColumn (new FlagColumn (Columns::ColumnId_InteriorWater, ESM::Cell::HasWater)); + mCells.addColumn (new FlagColumn (Columns::ColumnId_InteriorSky, ESM::Cell::QuasiEx)); mCells.addColumn (new RegionColumn); mRefs.addColumn (new StringIdColumn (true)); @@ -147,6 +148,9 @@ CSMWorld::Data::Data() : mRefs (mCells) mRefs.addColumn (new KeyColumn); mRefs.addColumn (new TrapColumn); + mFilters.addColumn (new StringIdColumn); + mFilters.addColumn (new RecordStateColumn); + addModel (new IdTable (&mGlobals), UniversalId::Type_Globals, UniversalId::Type_Global); addModel (new IdTable (&mGmsts), UniversalId::Type_Gmsts, UniversalId::Type_Gmst); addModel (new IdTable (&mSkills), UniversalId::Type_Skills, UniversalId::Type_Skill); @@ -162,6 +166,7 @@ CSMWorld::Data::Data() : mRefs (mCells) addModel (new IdTable (&mReferenceables), UniversalId::Type_Referenceables, UniversalId::Type_Referenceable); addModel (new IdTable (&mRefs), UniversalId::Type_References, UniversalId::Type_Reference); + addModel (new IdTable (&mFilters), UniversalId::Type_Filters, UniversalId::Type_Filter); } CSMWorld::Data::~Data() diff --git a/apps/opencs/model/world/data.hpp b/apps/opencs/model/world/data.hpp index 8b2403db3..aebdd6ecd 100644 --- a/apps/opencs/model/world/data.hpp +++ b/apps/opencs/model/world/data.hpp @@ -18,6 +18,8 @@ #include #include +#include "../filter/filter.hpp" + #include "idcollection.hpp" #include "universalid.hpp" #include "cell.hpp" @@ -44,6 +46,7 @@ namespace CSMWorld IdCollection mCells; RefIdCollection mReferenceables; RefCollection mRefs; + IdCollection mFilters; std::vector mModels; std::map mModelIndex; diff --git a/apps/opencs/model/world/idtable.cpp b/apps/opencs/model/world/idtable.cpp index 3d36b5503..baaf75289 100644 --- a/apps/opencs/model/world/idtable.cpp +++ b/apps/opencs/model/world/idtable.cpp @@ -47,7 +47,7 @@ QVariant CSMWorld::IdTable::headerData (int section, Qt::Orientation orientation return QVariant(); if (role==Qt::DisplayRole) - return tr (mIdCollection->getColumn (section).mTitle.c_str()); + return tr (mIdCollection->getColumn (section).getTitle().c_str()); if (role==ColumnBase::Role_Flags) return mIdCollection->getColumn (section).mFlags; @@ -157,4 +157,25 @@ void CSMWorld::IdTable::setRecord (const std::string& id, const RecordBase& reco const CSMWorld::RecordBase& CSMWorld::IdTable::getRecord (const std::string& id) const { return mIdCollection->getRecord (id); +} + +int CSMWorld::IdTable::searchColumnIndex (Columns::ColumnId id) const +{ + int columns = mIdCollection->getColumns(); + + for (int i=0; igetColumn (i).mColumnId==id) + return i; + + return -1; +} + +int CSMWorld::IdTable::findColumnIndex (Columns::ColumnId id) const +{ + int index = searchColumnIndex (id); + + if (index==-1) + throw std::logic_error ("invalid column index"); + + return index; } \ No newline at end of file diff --git a/apps/opencs/model/world/idtable.hpp b/apps/opencs/model/world/idtable.hpp index 556d7f0ba..00c577236 100644 --- a/apps/opencs/model/world/idtable.hpp +++ b/apps/opencs/model/world/idtable.hpp @@ -4,6 +4,7 @@ #include #include "universalid.hpp" +#include "columns.hpp" namespace CSMWorld { @@ -55,6 +56,13 @@ namespace CSMWorld ///< Add record or overwrite existing recrod. const RecordBase& getRecord (const std::string& id) const; + + int searchColumnIndex (Columns::ColumnId id) const; + ///< Return index of column with the given \a id. If no such column exists, -1 is returned. + + int findColumnIndex (Columns::ColumnId id) const; + ///< Return index of column with the given \a id. If no such column exists, an exception is + /// thrown. }; } diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index a51f2f00c..343cbe302 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -7,10 +7,11 @@ #include "refidadapter.hpp" #include "refidadapterimp.hpp" +#include "columns.hpp" -CSMWorld::RefIdColumn::RefIdColumn (const std::string& title, Display displayType, int flag, +CSMWorld::RefIdColumn::RefIdColumn (int columnId, Display displayType, int flag, bool editable, bool userEditable) -: ColumnBase (title, displayType, flag), mEditable (editable), mUserEditable (userEditable) +: ColumnBase (columnId, displayType, flag), mEditable (editable), mUserEditable (userEditable) {} bool CSMWorld::RefIdColumn::isEditable() const @@ -38,157 +39,158 @@ CSMWorld::RefIdCollection::RefIdCollection() { BaseColumns baseColumns; - mColumns.push_back (RefIdColumn ("ID", ColumnBase::Display_String, + mColumns.push_back (RefIdColumn (Columns::ColumnId_Id, ColumnBase::Display_String, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false)); baseColumns.mId = &mColumns.back(); - mColumns.push_back (RefIdColumn ("*", ColumnBase::Display_RecordState, + mColumns.push_back (RefIdColumn (Columns::ColumnId_Modification, ColumnBase::Display_RecordState, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false)); baseColumns.mModified = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Type", ColumnBase::Display_RefRecordType, + mColumns.push_back (RefIdColumn (Columns::ColumnId_RecordType, ColumnBase::Display_RefRecordType, ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false)); baseColumns.mType = &mColumns.back(); ModelColumns modelColumns (baseColumns); - mColumns.push_back (RefIdColumn ("Model", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Model, ColumnBase::Display_String)); modelColumns.mModel = &mColumns.back(); NameColumns nameColumns (modelColumns); - mColumns.push_back (RefIdColumn ("Name", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Name, ColumnBase::Display_String)); nameColumns.mName = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Script", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Script, ColumnBase::Display_String)); nameColumns.mScript = &mColumns.back(); InventoryColumns inventoryColumns (nameColumns); - mColumns.push_back (RefIdColumn ("Icon", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Icon, ColumnBase::Display_String)); inventoryColumns.mIcon = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Weight", ColumnBase::Display_Float)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Weight, ColumnBase::Display_Float)); inventoryColumns.mWeight = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Value", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_CoinValue, ColumnBase::Display_Integer)); inventoryColumns.mValue = &mColumns.back(); EnchantableColumns enchantableColumns (inventoryColumns); - mColumns.push_back (RefIdColumn ("Enchantment", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Enchantment, ColumnBase::Display_String)); enchantableColumns.mEnchantment = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Enchantment Points", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_EnchantmentPoints, ColumnBase::Display_Integer)); enchantableColumns.mEnchantmentPoints = &mColumns.back(); ToolColumns toolsColumns (inventoryColumns); - mColumns.push_back (RefIdColumn ("Quality", ColumnBase::Display_Float)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Quality, ColumnBase::Display_Float)); toolsColumns.mQuality = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Uses", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Charges, ColumnBase::Display_Integer)); toolsColumns.mUses = &mColumns.back(); ActorColumns actorsColumns (nameColumns); - mColumns.push_back (RefIdColumn ("AI", ColumnBase::Display_Boolean)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Ai, ColumnBase::Display_Boolean)); actorsColumns.mHasAi = &mColumns.back(); - mColumns.push_back (RefIdColumn ("AI Hello", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AiHello, ColumnBase::Display_Integer)); actorsColumns.mHello = &mColumns.back(); - mColumns.push_back (RefIdColumn ("AI Flee", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AiFlee, ColumnBase::Display_Integer)); actorsColumns.mFlee = &mColumns.back(); - mColumns.push_back (RefIdColumn ("AI Fight", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AiFight, ColumnBase::Display_Integer)); actorsColumns.mFight = &mColumns.back(); - mColumns.push_back (RefIdColumn ("AI Alarm", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AiAlarm, ColumnBase::Display_Integer)); actorsColumns.mAlarm = &mColumns.back(); static const struct { - const char *mName; + int mName; unsigned int mFlag; } sServiceTable[] = { - { "Buys Weapons", ESM::NPC::Weapon}, - { "Buys Armor", ESM::NPC::Armor}, - { "Buys Clothing", ESM::NPC::Clothing}, - { "Buys Books", ESM::NPC::Books}, - { "Buys Ingredients", ESM::NPC::Ingredients}, - { "Buys Lockpicks", ESM::NPC::Picks}, - { "Buys Probes", ESM::NPC::Probes}, - { "Buys Lights", ESM::NPC::Lights}, - { "Buys Apparati", ESM::NPC::Apparatus}, - { "Buys Repair Items", ESM::NPC::RepairItem}, - { "Buys Misc Items", ESM::NPC::Misc}, - { "Buys Potions", ESM::NPC::Potions}, - { "Buys Magic Items", ESM::NPC::MagicItems}, - { "Sells Spells", ESM::NPC::Spells}, - { "Trainer", ESM::NPC::Training}, - { "Spellmaking", ESM::NPC::Spellmaking}, - { "Enchanting Service", ESM::NPC::Enchanting}, - { "Repair Serivce", ESM::NPC::Repair}, - { 0, 0 } + { Columns::ColumnId_BuysWeapons, ESM::NPC::Weapon}, + { Columns::ColumnId_BuysArmor, ESM::NPC::Armor}, + { Columns::ColumnId_BuysClothing, ESM::NPC::Clothing}, + { Columns::ColumnId_BuysBooks, ESM::NPC::Books}, + { Columns::ColumnId_BuysIngredients, ESM::NPC::Ingredients}, + { Columns::ColumnId_BuysLockpicks, ESM::NPC::Picks}, + { Columns::ColumnId_BuysProbes, ESM::NPC::Probes}, + { Columns::ColumnId_BuysLights, ESM::NPC::Lights}, + { Columns::ColumnId_BuysApparati, ESM::NPC::Apparatus}, + { Columns::ColumnId_BuysRepairItems, ESM::NPC::RepairItem}, + { Columns::ColumnId_BuysMiscItems, ESM::NPC::Misc}, + { Columns::ColumnId_BuysPotions, ESM::NPC::Potions}, + { Columns::ColumnId_BuysMagicItems, ESM::NPC::MagicItems}, + { Columns::ColumnId_SellsSpells, ESM::NPC::Spells}, + { Columns::ColumnId_Trainer, ESM::NPC::Training}, + { Columns::ColumnId_Spellmaking, ESM::NPC::Spellmaking}, + { Columns::ColumnId_EnchantingService, ESM::NPC::Enchanting}, + { Columns::ColumnId_RepairService, ESM::NPC::Repair}, + { -1, 0 } }; - for (int i=0; sServiceTable[i].mName; ++i) + for (int i=0; sServiceTable[i].mName!=-1; ++i) { mColumns.push_back (RefIdColumn (sServiceTable[i].mName, ColumnBase::Display_Boolean)); actorsColumns.mServices.insert (std::make_pair (&mColumns.back(), sServiceTable[i].mFlag)); } - mColumns.push_back (RefIdColumn ("Auto Calc", ColumnBase::Display_Boolean)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_AutoCalc, ColumnBase::Display_Boolean)); const RefIdColumn *autoCalc = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Apparatus Type", ColumnBase::Display_ApparatusType)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_ApparatusType, + ColumnBase::Display_ApparatusType)); const RefIdColumn *apparatusType = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Armor Type", ColumnBase::Display_ArmorType)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_ArmorType, ColumnBase::Display_ArmorType)); const RefIdColumn *armorType = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Health", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Health, ColumnBase::Display_Integer)); const RefIdColumn *health = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Armor Value", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_ArmorValue, ColumnBase::Display_Integer)); const RefIdColumn *armor = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Scroll", ColumnBase::Display_Boolean)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Scroll, ColumnBase::Display_Boolean)); const RefIdColumn *scroll = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Attribute", ColumnBase::Display_Attribute)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Attribute, ColumnBase::Display_Attribute)); const RefIdColumn *attribute = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Clothing Type", ColumnBase::Display_ClothingType)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_ClothingType, ColumnBase::Display_ClothingType)); const RefIdColumn *clothingType = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Weight Capacity", ColumnBase::Display_Float)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_WeightCapacity, ColumnBase::Display_Float)); const RefIdColumn *weightCapacity = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Organic Container", ColumnBase::Display_Boolean)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_OrganicContainer, ColumnBase::Display_Boolean)); const RefIdColumn *organic = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Respawn", ColumnBase::Display_Boolean)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Respawn, ColumnBase::Display_Boolean)); const RefIdColumn *respawn = &mColumns.back(); CreatureColumns creatureColumns (actorsColumns); - mColumns.push_back (RefIdColumn ("Creature Type", ColumnBase::Display_CreatureType)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_CreatureType, ColumnBase::Display_CreatureType)); creatureColumns.mType = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Soul Points", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_SoulPoints, ColumnBase::Display_Integer)); creatureColumns.mSoul = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Scale", ColumnBase::Display_Float)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Scale, ColumnBase::Display_Float)); creatureColumns.mScale = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Original Creature", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_OriginalCreature, ColumnBase::Display_String)); creatureColumns.mOriginal = &mColumns.back(); static const struct { - const char *mName; + int mName; unsigned int mFlag; } sCreatureFlagTable[] = { - { "Biped", ESM::Creature::Biped }, - { "Has Weapon", ESM::Creature::Weapon }, - { "No Movement", ESM::Creature::None }, - { "Swims", ESM::Creature::Swims }, - { "Flies", ESM::Creature::Flies }, - { "Walks", ESM::Creature::Walks }, - { "Essential", ESM::Creature::Essential }, - { "Skeleton Blood", ESM::Creature::Skeleton }, - { "Metal Blood", ESM::Creature::Metal }, - { 0, 0 } + { Columns::ColumnId_Biped, ESM::Creature::Biped }, + { Columns::ColumnId_HasWeapon, ESM::Creature::Weapon }, + { Columns::ColumnId_NoMovement, ESM::Creature::None }, + { Columns::ColumnId_Swims, ESM::Creature::Swims }, + { Columns::ColumnId_Flies, ESM::Creature::Flies }, + { Columns::ColumnId_Walks, ESM::Creature::Walks }, + { Columns::ColumnId_Essential, ESM::Creature::Essential }, + { Columns::ColumnId_SkeletonBlood, ESM::Creature::Skeleton }, + { Columns::ColumnId_MetalBlood, ESM::Creature::Metal }, + { -1, 0 } }; // for re-use in NPC records @@ -196,7 +198,7 @@ CSMWorld::RefIdCollection::RefIdCollection() const RefIdColumn *skeletonBlood = 0; const RefIdColumn *metalBlood = 0; - for (int i=0; sCreatureFlagTable[i].mName; ++i) + for (int i=0; sCreatureFlagTable[i].mName!=-1; ++i) { mColumns.push_back (RefIdColumn (sCreatureFlagTable[i].mName, ColumnBase::Display_Boolean)); creatureColumns.mFlags.insert (std::make_pair (&mColumns.back(), sCreatureFlagTable[i].mFlag)); @@ -211,71 +213,71 @@ CSMWorld::RefIdCollection::RefIdCollection() creatureColumns.mFlags.insert (std::make_pair (respawn, ESM::Creature::Respawn)); - mColumns.push_back (RefIdColumn ("Open Sound", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_OpenSound, ColumnBase::Display_String)); const RefIdColumn *openSound = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Close Sound", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_CloseSound, ColumnBase::Display_String)); const RefIdColumn *closeSound = &mColumns.back(); LightColumns lightColumns (inventoryColumns); - mColumns.push_back (RefIdColumn ("Duration", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Duration, ColumnBase::Display_Integer)); lightColumns.mTime = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Radius", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Radius, ColumnBase::Display_Integer)); lightColumns.mRadius = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Colour", ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Colour, ColumnBase::Display_Integer)); lightColumns.mColor = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Sound", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Sound, ColumnBase::Display_String)); lightColumns.mSound = &mColumns.back(); static const struct { - const char *mName; + int mName; unsigned int mFlag; } sLightFlagTable[] = { - { "Dynamic", ESM::Light::Dynamic }, - { "Portable", ESM::Light::Carry }, - { "Negative Light", ESM::Light::Negative }, - { "Flickering", ESM::Light::Flicker }, - { "Slow Flickering", ESM::Light::Flicker }, - { "Pulsing", ESM::Light::Pulse }, - { "Slow Pulsing", ESM::Light::PulseSlow }, - { "Fire", ESM::Light::Fire }, - { "Off by default", ESM::Light::OffDefault }, - { 0, 0 } + { Columns::ColumnId_Dynamic, ESM::Light::Dynamic }, + { Columns::ColumnId_Portable, ESM::Light::Carry }, + { Columns::ColumnId_NegativeLight, ESM::Light::Negative }, + { Columns::ColumnId_Flickering, ESM::Light::Flicker }, + { Columns::ColumnId_SlowFlickering, ESM::Light::Flicker }, + { Columns::ColumnId_Pulsing, ESM::Light::Pulse }, + { Columns::ColumnId_SlowPulsing, ESM::Light::PulseSlow }, + { Columns::ColumnId_Fire, ESM::Light::Fire }, + { Columns::ColumnId_OffByDefault, ESM::Light::OffDefault }, + { -1, 0 } }; - for (int i=0; sLightFlagTable[i].mName; ++i) + for (int i=0; sLightFlagTable[i].mName!=-1; ++i) { mColumns.push_back (RefIdColumn (sLightFlagTable[i].mName, ColumnBase::Display_Boolean)); lightColumns.mFlags.insert (std::make_pair (&mColumns.back(), sLightFlagTable[i].mFlag)); } - mColumns.push_back (RefIdColumn ("Key", ColumnBase::Display_Boolean)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_IsKey, ColumnBase::Display_Boolean)); const RefIdColumn *key = &mColumns.back(); NpcColumns npcColumns (actorsColumns); - mColumns.push_back (RefIdColumn ("Race", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Race, ColumnBase::Display_String)); npcColumns.mRace = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Class", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Class, ColumnBase::Display_String)); npcColumns.mClass = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Faction", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Faction, ColumnBase::Display_String)); npcColumns.mFaction = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Hair", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::Columnid_Hair, ColumnBase::Display_String)); npcColumns.mHair = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Head", ColumnBase::Display_String)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Head, ColumnBase::Display_String)); npcColumns.mHead = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Female", ColumnBase::Display_Boolean)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_Female, ColumnBase::Display_Boolean)); npcColumns.mFlags.insert (std::make_pair (&mColumns.back(), ESM::NPC::Female)); npcColumns.mFlags.insert (std::make_pair (essential, ESM::NPC::Essential)); @@ -290,43 +292,35 @@ CSMWorld::RefIdCollection::RefIdCollection() WeaponColumns weaponColumns (enchantableColumns); - mColumns.push_back (RefIdColumn ("Weapon Type", ColumnBase::Display_WeaponType)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_WeaponType, ColumnBase::Display_WeaponType)); weaponColumns.mType = &mColumns.back(); weaponColumns.mHealth = health; - mColumns.push_back (RefIdColumn ("Weapon Speed", ColumnBase::Display_Float)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_WeaponSpeed, ColumnBase::Display_Float)); weaponColumns.mSpeed = &mColumns.back(); - mColumns.push_back (RefIdColumn ("Weapon Reach", ColumnBase::Display_Float)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_WeaponReach, ColumnBase::Display_Float)); weaponColumns.mReach = &mColumns.back(); - for (int i=0; i<2; ++i) + for (int i=0; i<6; ++i) { - std::string suffix = i==0 ? "Min " : "Max "; - - mColumns.push_back (RefIdColumn ("Chop" + suffix, ColumnBase::Display_Integer)); + mColumns.push_back (RefIdColumn (Columns::ColumnId_MinChop + i, ColumnBase::Display_Integer)); weaponColumns.mChop[i] = &mColumns.back(); - - mColumns.push_back (RefIdColumn ("Slash" + suffix, ColumnBase::Display_Integer)); - weaponColumns.mSlash[i] = &mColumns.back(); - - mColumns.push_back (RefIdColumn ("Thrust" + suffix, ColumnBase::Display_Integer)); - weaponColumns.mThrust[i] = &mColumns.back(); } static const struct { - const char *mName; + int mName; unsigned int mFlag; } sWeaponFlagTable[] = { - { "Magical", ESM::Weapon::Magical }, - { "Silver", ESM::Weapon::Silver }, - { 0, 0 } + { Columns::ColumnId_Magical, ESM::Weapon::Magical }, + { Columns::ColumnId_Silver, ESM::Weapon::Silver }, + { -1, 0 } }; - for (int i=0; sWeaponFlagTable[i].mName; ++i) + for (int i=0; sWeaponFlagTable[i].mName!=-1; ++i) { mColumns.push_back (RefIdColumn (sWeaponFlagTable[i].mName, ColumnBase::Display_Boolean)); weaponColumns.mFlags.insert (std::make_pair (&mColumns.back(), sWeaponFlagTable[i].mFlag)); diff --git a/apps/opencs/model/world/refidcollection.hpp b/apps/opencs/model/world/refidcollection.hpp index 7aaf55626..c10d1d2d0 100644 --- a/apps/opencs/model/world/refidcollection.hpp +++ b/apps/opencs/model/world/refidcollection.hpp @@ -20,7 +20,7 @@ namespace CSMWorld public: - RefIdColumn (const std::string& title, Display displayType, + RefIdColumn (int columnId, Display displayType, int flag = Flag_Table | Flag_Dialogue, bool editable = true, bool userEditable = true); diff --git a/apps/opencs/model/world/universalid.cpp b/apps/opencs/model/world/universalid.cpp index 4674f23f1..42ebd1f80 100644 --- a/apps/opencs/model/world/universalid.cpp +++ b/apps/opencs/model/world/universalid.cpp @@ -36,6 +36,7 @@ namespace "References", 0 }, { CSMWorld::UniversalId::Class_NonRecord, CSMWorld::UniversalId::Type_RegionMap, "Region Map", 0 }, + { CSMWorld::UniversalId::Class_RecordList, CSMWorld::UniversalId::Type_Filters, "Filters", 0 }, { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0, 0 } // end marker }; diff --git a/apps/opencs/model/world/universalid.hpp b/apps/opencs/model/world/universalid.hpp index 7dc4c851a..8042c3dfd 100644 --- a/apps/opencs/model/world/universalid.hpp +++ b/apps/opencs/model/world/universalid.hpp @@ -84,7 +84,9 @@ namespace CSMWorld Type_Weapon, Type_References, Type_Reference, - Type_RegionMap + Type_RegionMap, + Type_Filter, + Type_Filters }; private: diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index b3374c4a5..6801ea20d 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -83,6 +83,10 @@ void CSVDoc::View::setupViewMenu() mShowStatusBar->setCheckable (true); connect (mShowStatusBar, SIGNAL (toggled (bool)), this, SLOT (toggleShowStatusBar (bool))); view->addAction (mShowStatusBar); + + QAction *filters = new QAction (tr ("Filters"), this); + connect (filters, SIGNAL (triggered()), this, SLOT (addFiltersSubView())); + view->addAction (filters); } void CSVDoc::View::setupWorldMenu() @@ -390,6 +394,11 @@ void CSVDoc::View::addRegionMapSubView() addSubView (CSMWorld::UniversalId::Type_RegionMap); } +void CSVDoc::View::addFiltersSubView() +{ + addSubView (CSMWorld::UniversalId::Type_Filters); +} + void CSVDoc::View::abortOperation (int type) { mDocument->abortOperation (type); diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index c0163ce61..56c0b3edd 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -158,6 +158,8 @@ namespace CSVDoc void addRegionMapSubView(); + void addFiltersSubView(); + void showUserSettings(); void toggleShowStatusBar (bool show); diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 7502b6555..df43d6c5f 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -46,14 +46,14 @@ std::string CSVWorld::GenericCreator::getId() const void CSVWorld::GenericCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const {} -const CSMWorld::Data& CSVWorld::GenericCreator::getData() const +CSMWorld::Data& CSVWorld::GenericCreator::getData() const { return mData; } -CSMWorld::Data& CSVWorld::GenericCreator::getData() +const CSMWorld::UniversalId& CSVWorld::GenericCreator::getCollectionId() const { - return mData; + return mListId; } CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack, diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 5409f0839..6752d8591 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -44,9 +44,9 @@ namespace CSVWorld virtual void configureCreateCommand (CSMWorld::CreateCommand& command) const; - const CSMWorld::Data& getData() const; + CSMWorld::Data& getData() const; - CSMWorld::Data& getData(); + const CSMWorld::UniversalId& getCollectionId() const; public: diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 48a168a35..aef25a81d 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -6,6 +6,8 @@ #include "../../model/world/data.hpp" #include "../../model/world/commands.hpp" +#include "../../model/world/columns.hpp" +#include "../../model/world/idtable.hpp" std::string CSVWorld::ReferenceCreator::getId() const { @@ -14,8 +16,11 @@ std::string CSVWorld::ReferenceCreator::getId() const void CSVWorld::ReferenceCreator::configureCreateCommand (CSMWorld::CreateCommand& command) const { - /// \todo avoid using hard-coded column numbers - command.addValue (2, mCell->text()); + int index = + dynamic_cast (*getData().getTableModel (getCollectionId())). + findColumnIndex (CSMWorld::Columns::ColumnId_Cell); + + command.addValue (index, mCell->text()); } CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& undoStack, diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index 8990e2c72..2ca711a59 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -33,6 +33,7 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) CSMWorld::UniversalId::Type_Regions, CSMWorld::UniversalId::Type_Birthsigns, CSMWorld::UniversalId::Type_Spells, + CSMWorld::UniversalId::Type_Filters, CSMWorld::UniversalId::Type_None // end marker }; diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index fdbf67e42..4ae25d10b 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -44,7 +44,6 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) std::vector CSVWorld::Table::listRevertableSelectedIds() const { - /// \todo Do not use hardcoded column numbers std::vector revertableIds; if (mProxyModel->columnCount()>0) @@ -62,7 +61,9 @@ std::vector CSVWorld::Table::listRevertableSelectedIds() const if (state!=CSMWorld::RecordBase::State_BaseOnly) { - std::string id = mModel->data (mModel->index (index.row(), 0)). + int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id); + + std::string id = mModel->data (mModel->index (index.row(), columnIndex)). toString().toUtf8().constData(); revertableIds.push_back (id); @@ -75,7 +76,6 @@ std::vector CSVWorld::Table::listRevertableSelectedIds() const std::vector CSVWorld::Table::listDeletableSelectedIds() const { - /// \todo Do not use hardcoded column numbers std::vector deletableIds; if (mProxyModel->columnCount()>0) @@ -93,7 +93,9 @@ std::vector CSVWorld::Table::listDeletableSelectedIds() const if (state!=CSMWorld::RecordBase::State_Deleted) { - std::string id = mModel->data (mModel->index (index.row(), 0)). + int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id); + + std::string id = mModel->data (mModel->index (index.row(), columnIndex)). toString().toUtf8().constData(); deletableIds.push_back (id); @@ -263,8 +265,8 @@ void CSVWorld::Table::tableSizeUpdate() { QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (i, 0)); - /// \todo Do not use hardcoded column numbers - int state = mModel->data (mModel->index (index.row(), 1)).toInt(); + int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Modification); + int state = mModel->data (mModel->index (index.row(), columnIndex)).toInt(); switch (state) { diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 44e67674d..529891b4c 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -39,7 +39,7 @@ add_component_dir (esm loadclas loadclot loadcont loadcrea loadcrec loaddial loaddoor loadench loadfact loadglob loadgmst loadinfo loadingr loadland loadlevlist loadligh loadlock loadprob loadrepa loadltex loadmgef loadmisc loadnpcc loadnpc loadpgrd loadrace loadregn loadscpt loadskil loadsndg loadsoun loadspel loadsscr loadstat - loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref + loadweap records aipackage effectlist spelllist variant variantimp loadtes3 cellref filter ) add_component_dir (misc diff --git a/components/esm/filter.cpp b/components/esm/filter.cpp new file mode 100644 index 000000000..205332f6b --- /dev/null +++ b/components/esm/filter.cpp @@ -0,0 +1,20 @@ + +#include "filter.hpp" + +#include "esmreader.hpp" +#include "esmwriter.hpp" + +void ESM::Filter::load (ESMReader& esm) +{ + mFilter = esm.getHNString ("FILT"); +} + +void ESM::Filter::save (ESMWriter& esm) +{ + esm.writeHNCString ("FILT", mFilter); +} + +void ESM::Filter::blank() +{ + mFilter.clear(); +} diff --git a/components/esm/filter.hpp b/components/esm/filter.hpp new file mode 100644 index 000000000..2dde92fb0 --- /dev/null +++ b/components/esm/filter.hpp @@ -0,0 +1,25 @@ +#ifndef COMPONENTS_ESM_FILTER_H +#define COMPONENTS_ESM_FILTER_H + +#include + +namespace ESM +{ + class ESMReader; + class ESMWriter; + + struct Filter + { + std::string mId; + + std::string mFilter; + + void load (ESMReader& esm); + void save (ESMWriter& esm); + + void blank(); + ///< Set record to default state (does not touch the ID). + }; +} + +#endif