mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 10:53:51 +00:00
replaced static adapter with a template
This commit is contained in:
parent
9426eda47a
commit
d715cf5431
4 changed files with 72 additions and 54 deletions
|
@ -1,49 +1,5 @@
|
||||||
|
|
||||||
#include "refidadapterimp.hpp"
|
#include "refidadapterimp.hpp"
|
||||||
|
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
#include <components/esm/loadstat.hpp>
|
|
||||||
|
|
||||||
#include "record.hpp"
|
|
||||||
#include "refiddata.hpp"
|
|
||||||
#include "universalid.hpp"
|
|
||||||
|
|
||||||
CSMWorld::StaticRefIdAdapter::StaticRefIdAdapter (const RefIdColumn *id, const RefIdColumn *modified)
|
|
||||||
: mId (id), mModified (modified)
|
|
||||||
{}
|
|
||||||
|
|
||||||
QVariant CSMWorld::StaticRefIdAdapter::getData (const RefIdColumn *column, const RefIdData& data,
|
|
||||||
int index) const
|
|
||||||
{
|
|
||||||
const Record<ESM::Static>& record = static_cast<const Record<ESM::Static>&> (
|
|
||||||
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Static)));
|
|
||||||
|
|
||||||
if (column==mId)
|
|
||||||
return QString::fromUtf8 (record.get().mId.c_str());
|
|
||||||
|
|
||||||
if (column==mModified)
|
|
||||||
{
|
|
||||||
if (record.mState==Record<ESM::Static>::State_Erased)
|
|
||||||
return static_cast<int> (Record<ESM::Static>::State_Deleted);
|
|
||||||
|
|
||||||
return static_cast<int> (record.mState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSMWorld::StaticRefIdAdapter::setData (const RefIdColumn *column, RefIdData& data, int index,
|
|
||||||
const QVariant& value) const
|
|
||||||
{
|
|
||||||
Record<ESM::Static>& record = static_cast<Record<ESM::Static>&> (
|
|
||||||
data.getRecord (RefIdData::LocalIndex (index, UniversalId::Type_Static)));
|
|
||||||
|
|
||||||
if (column==mModified)
|
|
||||||
record.mState = static_cast<RecordBase::State> (value.toInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string CSMWorld::StaticRefIdAdapter::getId (const RecordBase& record) const
|
|
||||||
{
|
|
||||||
return dynamic_cast<const Record<ESM::Static>&> (record).get().mId;
|
|
||||||
}
|
|
|
@ -1,28 +1,83 @@
|
||||||
#ifndef CSM_WOLRD_REFIDADAPTERIMP_H
|
#ifndef CSM_WOLRD_REFIDADAPTERIMP_H
|
||||||
#define CSM_WOLRD_REFIDADAPTERIMP_H
|
#define CSM_WOLRD_REFIDADAPTERIMP_H
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "record.hpp"
|
||||||
|
#include "refiddata.hpp"
|
||||||
|
#include "universalid.hpp"
|
||||||
#include "refidadapter.hpp"
|
#include "refidadapter.hpp"
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class StaticRefIdAdapter : public RefIdAdapter
|
struct BaseColumns
|
||||||
{
|
{
|
||||||
const RefIdColumn *mId;
|
const RefIdColumn *mId;
|
||||||
const RefIdColumn *mModified;
|
const RefIdColumn *mModified;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
class BaseRefIdAdapter : public RefIdAdapter
|
||||||
|
{
|
||||||
|
UniversalId::Type mType;
|
||||||
|
BaseColumns mBase;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
StaticRefIdAdapter (const RefIdColumn *id, const RefIdColumn *modified);
|
BaseRefIdAdapter (UniversalId::Type type, const BaseColumns& base);
|
||||||
|
|
||||||
virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int idnex)
|
virtual std::string getId (const RecordBase& record) const;
|
||||||
|
|
||||||
|
virtual QVariant getData (const RefIdColumn *column, const RefIdData& data, int index)
|
||||||
const;
|
const;
|
||||||
|
|
||||||
virtual void setData (const RefIdColumn *column, RefIdData& data, int index,
|
virtual void setData (const RefIdColumn *column, RefIdData& data, int index,
|
||||||
const QVariant& value) const;
|
const QVariant& value) const;
|
||||||
///< If the data type does not match an exception is thrown.
|
///< If the data type does not match an exception is thrown.
|
||||||
|
|
||||||
virtual std::string getId (const RecordBase& record) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
BaseRefIdAdapter<RecordT>::BaseRefIdAdapter (UniversalId::Type type, const BaseColumns& base)
|
||||||
|
: mType (type), mBase (base)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
std::string BaseRefIdAdapter<RecordT>::getId (const RecordBase& record) const
|
||||||
|
{
|
||||||
|
return dynamic_cast<const Record<RecordT>&> (record).get().mId;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
QVariant BaseRefIdAdapter<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, mType)));
|
||||||
|
|
||||||
|
if (column==mBase.mId)
|
||||||
|
return QString::fromUtf8 (record.get().mId.c_str());
|
||||||
|
|
||||||
|
if (column==mBase.mModified)
|
||||||
|
{
|
||||||
|
if (record.mState==Record<RecordT>::State_Erased)
|
||||||
|
return static_cast<int> (Record<RecordT>::State_Deleted);
|
||||||
|
|
||||||
|
return static_cast<int> (record.mState);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RecordT>
|
||||||
|
void BaseRefIdAdapter<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, mType)));
|
||||||
|
|
||||||
|
if (column==mBase.mModified)
|
||||||
|
record.mState = static_cast<RecordBase::State> (value.toInt());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,14 +34,20 @@ const CSMWorld::RefIdAdapter& CSMWorld::RefIdCollection::findAdaptor (UniversalI
|
||||||
|
|
||||||
CSMWorld::RefIdCollection::RefIdCollection()
|
CSMWorld::RefIdCollection::RefIdCollection()
|
||||||
{
|
{
|
||||||
|
BaseColumns baseColumns;
|
||||||
|
|
||||||
mColumns.push_back (RefIdColumn ("ID", ColumnBase::Display_String,
|
mColumns.push_back (RefIdColumn ("ID", ColumnBase::Display_String,
|
||||||
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
|
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
|
||||||
|
baseColumns.mId = &mColumns.back();
|
||||||
mColumns.push_back (RefIdColumn ("*", ColumnBase::Display_Integer,
|
mColumns.push_back (RefIdColumn ("*", ColumnBase::Display_Integer,
|
||||||
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
|
ColumnBase::Flag_Table | ColumnBase::Flag_Dialogue, false, false));
|
||||||
|
baseColumns.mModified = &mColumns.back();
|
||||||
// mColumns.push_back (RefIdColumn ("Name", ColumnBase::Display_String));
|
// mColumns.push_back (RefIdColumn ("Name", ColumnBase::Display_String));
|
||||||
|
|
||||||
mAdapters.insert (std::make_pair (UniversalId::Type_Static, new StaticRefIdAdapter (&mColumns[0],
|
|
||||||
&mColumns[1])));
|
|
||||||
|
mAdapters.insert (std::make_pair (UniversalId::Type_Static,
|
||||||
|
new BaseRefIdAdapter<ESM::Static> (UniversalId::Type_Static, baseColumns)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
#include "columnbase.hpp"
|
#include "columnbase.hpp"
|
||||||
#include "idcollection.hpp"
|
#include "idcollection.hpp"
|
||||||
|
@ -33,7 +34,7 @@ namespace CSMWorld
|
||||||
private:
|
private:
|
||||||
|
|
||||||
RefIdData mData;
|
RefIdData mData;
|
||||||
std::vector<RefIdColumn> mColumns;
|
std::deque<RefIdColumn> mColumns;
|
||||||
std::map<UniversalId::Type, RefIdAdapter *> mAdapters;
|
std::map<UniversalId::Type, RefIdAdapter *> mAdapters;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue