2012-11-26 11:29:22 +00:00
|
|
|
#ifndef CSM_WOLRD_COLUMNS_H
|
|
|
|
#define CSM_WOLRD_COLUMNS_H
|
|
|
|
|
2012-12-30 13:01:52 +00:00
|
|
|
#include "columnbase.hpp"
|
2012-11-26 11:29:22 +00:00
|
|
|
|
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct FloatValueColumn : public Column<ESXRecordT>
|
|
|
|
{
|
2013-01-03 10:20:25 +00:00
|
|
|
FloatValueColumn() : Column<ESXRecordT> ("Value", ColumnBase::Display_Float) {}
|
2012-11-26 11:29:22 +00:00
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
2013-03-04 13:32:59 +00:00
|
|
|
return record.get().mValue.getFloat();
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
2012-11-29 13:45:34 +00:00
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
2013-02-09 14:25:50 +00:00
|
|
|
ESXRecordT record2 = record.get();
|
2013-03-04 13:32:59 +00:00
|
|
|
record2.mValue.setFloat (data.toFloat());
|
2013-02-09 14:25:50 +00:00
|
|
|
record.setModified (record2);
|
2012-11-29 13:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-26 11:29:22 +00:00
|
|
|
};
|
|
|
|
|
2012-11-29 17:56:28 +00:00
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct StringIdColumn : public Column<ESXRecordT>
|
|
|
|
{
|
2013-01-03 10:20:25 +00:00
|
|
|
StringIdColumn() : Column<ESXRecordT> ("ID", ColumnBase::Display_String) {}
|
2012-11-29 17:56:28 +00:00
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
2013-03-21 11:47:22 +00:00
|
|
|
return QString::fromUtf8 (record.get().mId.c_str());
|
2012-11-29 17:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-12-01 12:42:12 +00:00
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct RecordStateColumn : public Column<ESXRecordT>
|
|
|
|
{
|
2013-01-03 10:20:25 +00:00
|
|
|
RecordStateColumn() : Column<ESXRecordT> ("*", ColumnBase::Display_Integer) {}
|
2012-12-01 12:42:12 +00:00
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
2012-12-03 12:56:02 +00:00
|
|
|
if (record.mState==Record<ESXRecordT>::State_Erased)
|
|
|
|
return static_cast<int> (Record<ESXRecordT>::State_Deleted);
|
|
|
|
|
2012-12-01 12:42:12 +00:00
|
|
|
return static_cast<int> (record.mState);
|
|
|
|
}
|
|
|
|
|
2012-12-06 13:56:04 +00:00
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
|
|
|
record.mState = static_cast<RecordBase::State> (data.toInt());
|
|
|
|
}
|
|
|
|
|
2012-12-01 12:42:12 +00:00
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
2012-12-06 13:56:04 +00:00
|
|
|
return true;
|
2012-12-01 12:42:12 +00:00
|
|
|
}
|
2012-12-13 12:52:26 +00:00
|
|
|
|
|
|
|
virtual bool isUserEditable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-01 12:42:12 +00:00
|
|
|
};
|
2012-12-13 12:35:08 +00:00
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct FixedRecordTypeColumn : public Column<ESXRecordT>
|
|
|
|
{
|
|
|
|
int mType;
|
|
|
|
|
2013-01-03 10:20:25 +00:00
|
|
|
FixedRecordTypeColumn (int type)
|
2013-02-17 16:27:25 +00:00
|
|
|
: Column<ESXRecordT> ("Record Type", ColumnBase::Display_Integer, 0), mType (type) {}
|
2012-12-13 12:35:08 +00:00
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2013-02-08 11:20:03 +00:00
|
|
|
|
2013-02-17 16:27:25 +00:00
|
|
|
/// \attention A var type column must be immediately followed by a suitable value column.
|
2013-02-08 11:20:03 +00:00
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct VarTypeColumn : public Column<ESXRecordT>
|
|
|
|
{
|
2013-03-05 10:37:13 +00:00
|
|
|
VarTypeColumn (ColumnBase::Display display) : Column<ESXRecordT> ("Type", display) {}
|
2013-02-08 11:20:03 +00:00
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
2013-03-05 07:02:27 +00:00
|
|
|
return static_cast<int> (record.get().mValue.getType());
|
2013-02-08 11:20:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
2013-02-09 14:25:50 +00:00
|
|
|
ESXRecordT record2 = record.get();
|
2013-03-05 07:02:27 +00:00
|
|
|
record2.mValue.setType (static_cast<ESM::VarType> (data.toInt()));
|
2013-02-09 14:25:50 +00:00
|
|
|
record.setModified (record2);
|
2013-02-08 11:20:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2013-02-08 13:48:38 +00:00
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct VarValueColumn : public Column<ESXRecordT>
|
|
|
|
{
|
|
|
|
VarValueColumn() : Column<ESXRecordT> ("Value", ColumnBase::Display_Var) {}
|
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
2013-03-05 07:02:27 +00:00
|
|
|
switch (record.get().mValue.getType())
|
2013-02-08 13:48:38 +00:00
|
|
|
{
|
2013-03-05 10:37:13 +00:00
|
|
|
case ESM::VT_String:
|
|
|
|
|
2013-03-21 11:47:22 +00:00
|
|
|
return QString::fromUtf8 (record.get().mValue.getString().c_str());
|
2013-03-05 10:37:13 +00:00
|
|
|
|
|
|
|
case ESM::VT_Int:
|
|
|
|
case ESM::VT_Short:
|
|
|
|
case ESM::VT_Long:
|
|
|
|
|
2013-03-21 11:47:22 +00:00
|
|
|
return record.get().mValue.getInteger();
|
2013-03-05 10:37:13 +00:00
|
|
|
|
|
|
|
case ESM::VT_Float:
|
|
|
|
|
2013-03-21 11:47:22 +00:00
|
|
|
return record.get().mValue.getFloat();
|
2013-02-08 13:48:38 +00:00
|
|
|
|
|
|
|
default: return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
2013-02-09 14:25:50 +00:00
|
|
|
ESXRecordT record2 = record.get();
|
2013-02-08 13:48:38 +00:00
|
|
|
|
2013-03-05 07:02:27 +00:00
|
|
|
switch (record2.mValue.getType())
|
2013-02-08 13:48:38 +00:00
|
|
|
{
|
2013-03-05 07:02:27 +00:00
|
|
|
case ESM::VT_String:
|
|
|
|
|
|
|
|
record2.mValue.setString (data.toString().toUtf8().constData());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESM::VT_Int:
|
2013-03-05 10:37:13 +00:00
|
|
|
case ESM::VT_Short:
|
|
|
|
case ESM::VT_Long:
|
2013-03-05 07:02:27 +00:00
|
|
|
|
|
|
|
record2.mValue.setInteger (data.toInt());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESM::VT_Float:
|
|
|
|
|
|
|
|
record2.mValue.setFloat (data.toFloat());
|
|
|
|
break;
|
2013-02-08 13:48:38 +00:00
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2013-02-09 14:25:50 +00:00
|
|
|
record.setModified (record2);
|
2013-02-08 13:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|