2012-11-26 11:29:22 +00:00
|
|
|
#ifndef CSM_WOLRD_COLUMNS_H
|
|
|
|
#define CSM_WOLRD_COLUMNS_H
|
|
|
|
|
2013-03-24 13:51:48 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
2013-03-21 13:38:06 +00:00
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct DescriptionColumn : public Column<ESXRecordT>
|
|
|
|
{
|
|
|
|
DescriptionColumn() : Column<ESXRecordT> ("Description", ColumnBase::Display_String) {}
|
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return QString::fromUtf8 (record.get().mDescription.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
|
|
|
ESXRecordT record2 = record.get();
|
|
|
|
|
|
|
|
record2.mDescription = data.toString().toUtf8().constData();
|
|
|
|
|
|
|
|
record.setModified (record2);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2013-03-23 12:13:53 +00:00
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct SpecialisationColumn : public Column<ESXRecordT>
|
|
|
|
{
|
|
|
|
SpecialisationColumn() : Column<ESXRecordT> ("Specialisation", ColumnBase::Display_Specialisation) {}
|
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return record.get().mData.mSpecialization;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
|
|
|
ESXRecordT record2 = record.get();
|
|
|
|
|
|
|
|
record2.mData.mSpecialization = data.toInt();
|
|
|
|
|
|
|
|
record.setModified (record2);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2013-03-24 13:51:48 +00:00
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct UseValueColumn : public Column<ESXRecordT>
|
|
|
|
{
|
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
UseValueColumn (int index)
|
|
|
|
: Column<ESXRecordT> ("Use value #" + boost::lexical_cast<std::string> (index),
|
|
|
|
ColumnBase::Display_Float), mIndex (index)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return record.get().mData.mUseValue[mIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
|
|
|
ESXRecordT record2 = record.get();
|
|
|
|
|
|
|
|
record2.mData.mUseValue[mIndex] = data.toInt();
|
|
|
|
|
|
|
|
record.setModified (record2);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2013-03-24 14:50:29 +00:00
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct AttributeColumn : public Column<ESXRecordT>
|
|
|
|
{
|
|
|
|
AttributeColumn() : Column<ESXRecordT> ("Attribute", ColumnBase::Display_Attribute) {}
|
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return record.get().mData.mAttribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
|
|
|
ESXRecordT record2 = record.get();
|
|
|
|
|
|
|
|
record2.mData.mAttribute = data.toInt();
|
|
|
|
|
|
|
|
record.setModified (record2);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-25 13:31:46 +00:00
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct NameColumn : public Column<ESXRecordT>
|
|
|
|
{
|
|
|
|
NameColumn() : Column<ESXRecordT> ("Name", ColumnBase::Display_String) {}
|
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return QString::fromUtf8 (record.get().mName.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
|
|
|
ESXRecordT record2 = record.get();
|
|
|
|
|
|
|
|
record2.mName = data.toString().toUtf8().constData();
|
|
|
|
|
|
|
|
record.setModified (record2);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct AttributesColumn : public Column<ESXRecordT>
|
|
|
|
{
|
|
|
|
int mIndex;
|
|
|
|
|
|
|
|
AttributesColumn (int index)
|
|
|
|
: Column<ESXRecordT> ("Attribute #" + boost::lexical_cast<std::string> (index),
|
|
|
|
ColumnBase::Display_Attribute), mIndex (index) {}
|
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
|
|
|
return record.get().mData.mAttribute[mIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
|
|
|
ESXRecordT record2 = record.get();
|
|
|
|
|
|
|
|
record2.mData.mAttribute[mIndex] = data.toInt();
|
|
|
|
|
|
|
|
record.setModified (record2);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|