forked from mirror/openmw-tes3mp
added name column
This commit is contained in:
parent
318ebe0cb6
commit
e24ecfd5d2
2 changed files with 78 additions and 18 deletions
|
@ -148,6 +148,62 @@ namespace CSMWorld
|
|||
else
|
||||
BaseRefIdAdapter<RecordT>::setData (column, data, index, value);
|
||||
}
|
||||
|
||||
struct NameColumns : public ModelColumns
|
||||
{
|
||||
const RefIdColumn *mName;
|
||||
|
||||
NameColumns (const ModelColumns& base) : ModelColumns (base) {}
|
||||
};
|
||||
|
||||
/// \brief Adapter for IDs with names (all but levelled lists and statics)
|
||||
template<typename RecordT>
|
||||
class NameRefIdAdapter : public ModelRefIdAdapter<RecordT>
|
||||
{
|
||||
NameColumns mName;
|
||||
|
||||
public:
|
||||
|
||||
NameRefIdAdapter (UniversalId::Type type, const NameColumns& columns);
|
||||
|
||||
virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int index)
|
||||
const;
|
||||
|
||||
virtual void setData (const RefIdColumn *column, RefIdData& data, int index,
|
||||
const QVariant& value) const;
|
||||
///< If the data type does not match an exception is thrown.
|
||||
};
|
||||
|
||||
template<typename RecordT>
|
||||
NameRefIdAdapter<RecordT>::NameRefIdAdapter (UniversalId::Type type, const NameColumns& columns)
|
||||
: ModelRefIdAdapter<RecordT> (type, columns), mName (columns)
|
||||
{}
|
||||
|
||||
template<typename RecordT>
|
||||
QVariant NameRefIdAdapter<RecordT>::getData (const RefIdColumn *column, const RefIdData& data,
|
||||
int index) const
|
||||
{
|
||||
const Record<RecordT>& record = static_cast<const Record<RecordT>&> (
|
||||
data.getRecord (RefIdData::LocalIndex (index, BaseRefIdAdapter<RecordT>::getType())));
|
||||
|
||||
if (column==mName.mName)
|
||||
return QString::fromUtf8 (record.get().mName.c_str());
|
||||
|
||||
return ModelRefIdAdapter<RecordT>::getData (column, data, index);
|
||||
}
|
||||
|
||||
template<typename RecordT>
|
||||
void NameRefIdAdapter<RecordT>::setData (const RefIdColumn *column, RefIdData& data, int index,
|
||||
const QVariant& value) const
|
||||
{
|
||||
Record<RecordT>& record = static_cast<Record<RecordT>&> (
|
||||
data.getRecord (RefIdData::LocalIndex (index, BaseRefIdAdapter<RecordT>::getType())));
|
||||
|
||||
if (column==mName.mName)
|
||||
record.get().mName = value.toString().toUtf8().constData();
|
||||
else
|
||||
ModelRefIdAdapter<RecordT>::setData (column, data, index, value);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -45,54 +45,58 @@ CSMWorld::RefIdCollection::RefIdCollection()
|
|||
mColumns.push_back (RefIdColumn ("Type", ColumnBase::Display_Integer,
|
||||
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
|
||||
baseColumns.mType = &mColumns.back();
|
||||
// mColumns.push_back (RefIdColumn ("Name", ColumnBase::Display_String));
|
||||
|
||||
ModelColumns modelColumns (baseColumns);
|
||||
|
||||
mColumns.push_back (RefIdColumn ("Model", ColumnBase::Display_String));
|
||||
modelColumns.mModel = &mColumns.back();
|
||||
|
||||
NameColumns nameColumns (modelColumns);
|
||||
|
||||
mColumns.push_back (RefIdColumn ("Name", ColumnBase::Display_String));
|
||||
nameColumns.mName = &mColumns.back();
|
||||
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Activator,
|
||||
new ModelRefIdAdapter<ESM::Activator> (UniversalId::Type_Activator, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Activator> (UniversalId::Type_Activator, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Potion,
|
||||
new ModelRefIdAdapter<ESM::Potion> (UniversalId::Type_Potion, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Potion> (UniversalId::Type_Potion, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Apparatus,
|
||||
new ModelRefIdAdapter<ESM::Apparatus> (UniversalId::Type_Apparatus, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Apparatus> (UniversalId::Type_Apparatus, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Armor,
|
||||
new ModelRefIdAdapter<ESM::Armor> (UniversalId::Type_Armor, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Armor> (UniversalId::Type_Armor, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Book,
|
||||
new ModelRefIdAdapter<ESM::Book> (UniversalId::Type_Book, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Book> (UniversalId::Type_Book, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Clothing,
|
||||
new ModelRefIdAdapter<ESM::Clothing> (UniversalId::Type_Clothing, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Clothing> (UniversalId::Type_Clothing, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Container,
|
||||
new ModelRefIdAdapter<ESM::Container> (UniversalId::Type_Container, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Container> (UniversalId::Type_Container, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Creature,
|
||||
new ModelRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Creature> (UniversalId::Type_Creature, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Door,
|
||||
new ModelRefIdAdapter<ESM::Door> (UniversalId::Type_Door, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Door> (UniversalId::Type_Door, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Ingredient,
|
||||
new ModelRefIdAdapter<ESM::Ingredient> (UniversalId::Type_Ingredient, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Ingredient> (UniversalId::Type_Ingredient, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_CreatureLevelledList,
|
||||
new BaseRefIdAdapter<ESM::CreatureLevList> (
|
||||
UniversalId::Type_CreatureLevelledList, baseColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_ItemLevelledList,
|
||||
new BaseRefIdAdapter<ESM::ItemLevList> (UniversalId::Type_ItemLevelledList, baseColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Light,
|
||||
new ModelRefIdAdapter<ESM::Light> (UniversalId::Type_Light, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Light> (UniversalId::Type_Light, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Lockpick,
|
||||
new ModelRefIdAdapter<ESM::Lockpick> (UniversalId::Type_Lockpick, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Lockpick> (UniversalId::Type_Lockpick, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Miscellaneous,
|
||||
new ModelRefIdAdapter<ESM::Miscellaneous> (UniversalId::Type_Miscellaneous, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Miscellaneous> (UniversalId::Type_Miscellaneous, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Npc,
|
||||
new ModelRefIdAdapter<ESM::NPC> (UniversalId::Type_Npc, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::NPC> (UniversalId::Type_Npc, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Probe,
|
||||
new ModelRefIdAdapter<ESM::Probe> (UniversalId::Type_Probe, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Probe> (UniversalId::Type_Probe, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Repair,
|
||||
new ModelRefIdAdapter<ESM::Repair> (UniversalId::Type_Repair, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Repair> (UniversalId::Type_Repair, nameColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Static,
|
||||
new ModelRefIdAdapter<ESM::Static> (UniversalId::Type_Static, modelColumns)));
|
||||
mAdapters.insert (std::make_pair (UniversalId::Type_Weapon,
|
||||
new ModelRefIdAdapter<ESM::Weapon> (UniversalId::Type_Weapon, modelColumns)));
|
||||
new NameRefIdAdapter<ESM::Weapon> (UniversalId::Type_Weapon, nameColumns)));
|
||||
}
|
||||
|
||||
CSMWorld::RefIdCollection::~RefIdCollection()
|
||||
|
|
Loading…
Reference in a new issue