mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
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
|
else
|
||||||
BaseRefIdAdapter<RecordT>::setData (column, data, index, value);
|
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
|
#endif
|
||||||
|
|
|
@ -45,54 +45,58 @@ CSMWorld::RefIdCollection::RefIdCollection()
|
||||||
mColumns.push_back (RefIdColumn ("Type", ColumnBase::Display_Integer,
|
mColumns.push_back (RefIdColumn ("Type", ColumnBase::Display_Integer,
|
||||||
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
|
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
|
||||||
baseColumns.mType = &mColumns.back();
|
baseColumns.mType = &mColumns.back();
|
||||||
// mColumns.push_back (RefIdColumn ("Name", ColumnBase::Display_String));
|
|
||||||
|
|
||||||
ModelColumns modelColumns (baseColumns);
|
ModelColumns modelColumns (baseColumns);
|
||||||
|
|
||||||
mColumns.push_back (RefIdColumn ("Model", ColumnBase::Display_String));
|
mColumns.push_back (RefIdColumn ("Model", ColumnBase::Display_String));
|
||||||
modelColumns.mModel = &mColumns.back();
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
mAdapters.insert (std::make_pair (UniversalId::Type_CreatureLevelledList,
|
||||||
new BaseRefIdAdapter<ESM::CreatureLevList> (
|
new BaseRefIdAdapter<ESM::CreatureLevList> (
|
||||||
UniversalId::Type_CreatureLevelledList, baseColumns)));
|
UniversalId::Type_CreatureLevelledList, baseColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_ItemLevelledList,
|
mAdapters.insert (std::make_pair (UniversalId::Type_ItemLevelledList,
|
||||||
new BaseRefIdAdapter<ESM::ItemLevList> (UniversalId::Type_ItemLevelledList, baseColumns)));
|
new BaseRefIdAdapter<ESM::ItemLevList> (UniversalId::Type_ItemLevelledList, baseColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Light,
|
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,
|
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,
|
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,
|
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,
|
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,
|
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,
|
mAdapters.insert (std::make_pair (UniversalId::Type_Static,
|
||||||
new ModelRefIdAdapter<ESM::Static> (UniversalId::Type_Static, modelColumns)));
|
new ModelRefIdAdapter<ESM::Static> (UniversalId::Type_Static, modelColumns)));
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Weapon,
|
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()
|
CSMWorld::RefIdCollection::~RefIdCollection()
|
||||||
|
|
Loading…
Reference in a new issue