2012-12-16 11:52:23 +00:00
|
|
|
#ifndef CSM_WOLRD_COLUMNBASE_H
|
|
|
|
#define CSM_WOLRD_COLUMNBASE_H
|
|
|
|
|
|
|
|
#include <string>
|
2014-06-19 16:46:09 +00:00
|
|
|
#include <vector>
|
2015-04-02 09:19:15 +00:00
|
|
|
#include <stdexcept>
|
2012-12-16 11:52:23 +00:00
|
|
|
|
|
|
|
#include <Qt>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include "record.hpp"
|
|
|
|
|
|
|
|
namespace CSMWorld
|
|
|
|
{
|
|
|
|
struct ColumnBase
|
|
|
|
{
|
2015-10-28 12:33:24 +00:00
|
|
|
enum TableEditModes
|
|
|
|
{
|
|
|
|
TableEdit_None, // no editing
|
|
|
|
TableEdit_Full, // edit cells and add/remove rows
|
|
|
|
TableEdit_FixedRows // edit cells only
|
|
|
|
};
|
|
|
|
|
2012-12-16 11:52:23 +00:00
|
|
|
enum Roles
|
|
|
|
{
|
2013-01-03 10:20:25 +00:00
|
|
|
Role_Flags = Qt::UserRole,
|
2015-01-16 10:27:17 +00:00
|
|
|
Role_Display = Qt::UserRole+1,
|
2015-04-24 23:39:37 +00:00
|
|
|
Role_ColumnId = Qt::UserRole+2
|
2012-12-16 11:52:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Flags
|
|
|
|
{
|
|
|
|
Flag_Table = 1, // column should be displayed in table view
|
2015-04-16 15:27:36 +00:00
|
|
|
Flag_Dialogue = 2, // column should be displayed in dialogue view
|
2015-05-26 03:35:10 +00:00
|
|
|
Flag_Dialogue_List = 4, // column should be diaplyed in dialogue view
|
|
|
|
Flag_Dialogue_Refresh = 8 // refresh dialogue view if this column is modified
|
2012-12-16 11:52:23 +00:00
|
|
|
};
|
|
|
|
|
2013-01-03 10:20:25 +00:00
|
|
|
enum Display
|
|
|
|
{
|
2014-02-20 18:27:51 +00:00
|
|
|
Display_None, //Do not use
|
2013-01-03 10:20:25 +00:00
|
|
|
Display_String,
|
2014-03-10 13:11:49 +00:00
|
|
|
Display_LongString,
|
2014-02-12 08:04:52 +00:00
|
|
|
|
2014-06-20 11:40:54 +00:00
|
|
|
//CONCRETE TYPES STARTS HERE (for drag and drop)
|
2014-02-12 08:04:52 +00:00
|
|
|
Display_Skill,
|
|
|
|
Display_Class,
|
|
|
|
Display_Faction,
|
|
|
|
Display_Race,
|
|
|
|
Display_Sound,
|
|
|
|
Display_Region,
|
|
|
|
Display_Birthsign,
|
|
|
|
Display_Spell,
|
|
|
|
Display_Cell,
|
|
|
|
Display_Referenceable,
|
|
|
|
Display_Activator,
|
|
|
|
Display_Potion,
|
|
|
|
Display_Apparatus,
|
|
|
|
Display_Armor,
|
|
|
|
Display_Book,
|
|
|
|
Display_Clothing,
|
|
|
|
Display_Container,
|
|
|
|
Display_Creature,
|
|
|
|
Display_Door,
|
|
|
|
Display_Ingredient,
|
|
|
|
Display_CreatureLevelledList,
|
|
|
|
Display_ItemLevelledList,
|
|
|
|
Display_Light,
|
|
|
|
Display_Lockpick,
|
|
|
|
Display_Miscellaneous,
|
|
|
|
Display_Npc,
|
|
|
|
Display_Probe,
|
|
|
|
Display_Repair,
|
|
|
|
Display_Static,
|
|
|
|
Display_Weapon,
|
|
|
|
Display_Reference,
|
|
|
|
Display_Filter,
|
|
|
|
Display_Topic,
|
|
|
|
Display_Journal,
|
|
|
|
Display_TopicInfo,
|
|
|
|
Display_JournalInfo,
|
|
|
|
Display_Scene,
|
2014-08-30 08:13:34 +00:00
|
|
|
Display_GlobalVariable,
|
2015-06-02 21:02:53 +00:00
|
|
|
Display_BodyPart,
|
|
|
|
Display_Enchantment,
|
2014-02-12 08:04:52 +00:00
|
|
|
//CONCRETE TYPES ENDS HERE
|
|
|
|
|
2016-04-06 06:18:19 +00:00
|
|
|
Display_UnsignedInteger8,
|
2013-01-03 10:20:25 +00:00
|
|
|
Display_Integer,
|
2013-02-08 13:48:38 +00:00
|
|
|
Display_Float,
|
2013-02-17 16:27:25 +00:00
|
|
|
Display_Var,
|
2013-03-05 10:37:13 +00:00
|
|
|
Display_GmstVarType,
|
2013-03-23 12:13:53 +00:00
|
|
|
Display_GlobalVarType,
|
2013-03-24 14:50:29 +00:00
|
|
|
Display_Specialisation,
|
2013-03-26 08:51:39 +00:00
|
|
|
Display_Attribute,
|
2013-04-09 09:53:47 +00:00
|
|
|
Display_Boolean,
|
2013-04-10 18:14:10 +00:00
|
|
|
Display_SpellType,
|
2013-05-13 10:51:27 +00:00
|
|
|
Display_Script,
|
2013-05-14 12:21:30 +00:00
|
|
|
Display_ApparatusType,
|
2013-05-15 09:37:46 +00:00
|
|
|
Display_ArmorType,
|
2013-05-16 14:27:33 +00:00
|
|
|
Display_ClothingType,
|
2013-05-19 12:44:41 +00:00
|
|
|
Display_CreatureType,
|
2013-05-29 11:38:35 +00:00
|
|
|
Display_WeaponType,
|
2013-06-29 13:11:09 +00:00
|
|
|
Display_RecordState,
|
2013-10-20 15:26:09 +00:00
|
|
|
Display_RefRecordType,
|
2013-10-31 11:54:55 +00:00
|
|
|
Display_DialogueType,
|
2013-11-05 10:41:48 +00:00
|
|
|
Display_QuestStatusType,
|
2014-07-01 07:42:56 +00:00
|
|
|
Display_EnchantmentType,
|
2014-07-01 12:28:12 +00:00
|
|
|
Display_BodyPartType,
|
|
|
|
Display_MeshType,
|
2014-07-08 07:08:01 +00:00
|
|
|
Display_Gender,
|
2014-07-08 07:51:17 +00:00
|
|
|
Display_Mesh,
|
|
|
|
Display_Icon,
|
|
|
|
Display_Music,
|
|
|
|
Display_SoundRes,
|
|
|
|
Display_Texture,
|
|
|
|
Display_Video,
|
2014-08-24 11:15:18 +00:00
|
|
|
Display_Colour,
|
2015-04-04 17:55:53 +00:00
|
|
|
Display_ScriptFile,
|
2014-09-25 09:40:45 +00:00
|
|
|
Display_ScriptLines, // console context
|
2014-09-30 10:33:48 +00:00
|
|
|
Display_SoundGeneratorType,
|
2015-03-28 13:48:06 +00:00
|
|
|
Display_School,
|
2015-04-17 03:45:45 +00:00
|
|
|
Display_Id,
|
2015-10-08 01:35:09 +00:00
|
|
|
Display_SkillId,
|
2015-04-17 22:09:14 +00:00
|
|
|
Display_EffectRange,
|
|
|
|
Display_EffectId,
|
2015-04-17 22:31:08 +00:00
|
|
|
Display_PartRefType,
|
2015-04-17 23:37:19 +00:00
|
|
|
Display_AiPackageType,
|
2015-05-09 11:21:16 +00:00
|
|
|
Display_InfoCondFunc,
|
|
|
|
Display_InfoCondVar,
|
|
|
|
Display_InfoCondComp,
|
2015-06-26 16:19:00 +00:00
|
|
|
Display_String32,
|
|
|
|
Display_LongString256,
|
2015-04-17 03:45:45 +00:00
|
|
|
|
2015-10-28 00:49:24 +00:00
|
|
|
Display_EffectSkill, // must display at least one, unlike Display_Skill
|
|
|
|
Display_EffectAttribute, // must display at least one, unlike Display_Attribute
|
|
|
|
Display_IngredEffectId, // display none allowed, unlike Display_EffectId
|
|
|
|
|
2015-04-17 03:45:45 +00:00
|
|
|
//top level columns that nest other columns
|
|
|
|
Display_NestedHeader
|
2013-01-03 10:20:25 +00:00
|
|
|
};
|
|
|
|
|
2013-08-07 07:36:05 +00:00
|
|
|
int mColumnId;
|
2012-12-16 11:52:23 +00:00
|
|
|
int mFlags;
|
2013-01-03 10:20:25 +00:00
|
|
|
Display mDisplayType;
|
2012-12-16 11:52:23 +00:00
|
|
|
|
2013-08-07 07:36:05 +00:00
|
|
|
ColumnBase (int columnId, Display displayType, int flag);
|
2012-12-16 11:52:23 +00:00
|
|
|
|
|
|
|
virtual ~ColumnBase();
|
|
|
|
|
|
|
|
virtual bool isEditable() const = 0;
|
|
|
|
|
|
|
|
virtual bool isUserEditable() const;
|
|
|
|
///< Can this column be edited directly by the user?
|
2013-01-03 10:20:25 +00:00
|
|
|
|
2013-08-07 07:36:05 +00:00
|
|
|
virtual std::string getTitle() const;
|
2014-03-08 14:27:43 +00:00
|
|
|
|
|
|
|
virtual int getId() const;
|
2015-03-25 10:56:14 +00:00
|
|
|
|
|
|
|
static bool isId (Display display);
|
|
|
|
|
|
|
|
static bool isText (Display display);
|
|
|
|
|
|
|
|
static bool isScript (Display display);
|
2015-04-09 09:11:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class NestableColumn : public ColumnBase
|
|
|
|
{
|
|
|
|
std::vector<NestableColumn *> mNestedColumns;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
NestableColumn(int columnId, Display displayType, int flag);
|
|
|
|
|
|
|
|
~NestableColumn();
|
|
|
|
|
|
|
|
void addColumn(CSMWorld::NestableColumn *column);
|
|
|
|
|
|
|
|
const ColumnBase& nestedColumn(int subColumn) const;
|
|
|
|
|
|
|
|
bool hasChildren() const;
|
2012-12-16 11:52:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
2015-04-09 09:11:19 +00:00
|
|
|
struct Column : public NestableColumn
|
2012-12-16 11:52:23 +00:00
|
|
|
{
|
2013-08-07 07:36:05 +00:00
|
|
|
Column (int columnId, Display displayType, int flags = Flag_Table | Flag_Dialogue)
|
2015-04-09 09:11:19 +00:00
|
|
|
: NestableColumn (columnId, displayType, flags) {}
|
2012-12-16 11:52:23 +00:00
|
|
|
|
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const = 0;
|
|
|
|
|
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
2013-08-07 07:36:05 +00:00
|
|
|
throw std::logic_error ("Column " + getTitle() + " is not editable");
|
2012-12-16 11:52:23 +00:00
|
|
|
}
|
|
|
|
};
|
2015-04-11 22:52:09 +00:00
|
|
|
|
|
|
|
template<typename ESXRecordT>
|
|
|
|
struct NestedParentColumn : public Column<ESXRecordT>
|
|
|
|
{
|
2015-10-28 09:30:30 +00:00
|
|
|
NestedParentColumn (int id, int flags = ColumnBase::Flag_Dialogue, bool fixedRows = false)
|
|
|
|
: Column<ESXRecordT> (id, ColumnBase::Display_NestedHeader, flags), mFixedRows(fixedRows)
|
2015-04-11 22:52:09 +00:00
|
|
|
{}
|
|
|
|
|
2015-08-02 14:16:06 +00:00
|
|
|
virtual void set (Record<ESXRecordT>& record, const QVariant& data)
|
|
|
|
{
|
|
|
|
// There is nothing to do here.
|
|
|
|
// This prevents exceptions from parent's implementation
|
|
|
|
}
|
|
|
|
|
2015-04-11 22:52:09 +00:00
|
|
|
virtual QVariant get (const Record<ESXRecordT>& record) const
|
|
|
|
{
|
2015-10-28 09:30:30 +00:00
|
|
|
// by default editable; also see IdTree::hasChildren()
|
|
|
|
if (mFixedRows)
|
2015-10-28 12:33:24 +00:00
|
|
|
return QVariant::fromValue(ColumnBase::TableEdit_FixedRows);
|
2015-10-28 09:30:30 +00:00
|
|
|
else
|
2015-10-28 12:33:24 +00:00
|
|
|
return QVariant::fromValue(ColumnBase::TableEdit_Full);
|
2015-04-11 22:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isEditable() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-28 09:30:30 +00:00
|
|
|
|
2015-10-28 09:52:07 +00:00
|
|
|
private:
|
2015-10-28 09:30:30 +00:00
|
|
|
bool mFixedRows;
|
2015-04-11 22:52:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct NestedChildColumn : public NestableColumn
|
|
|
|
{
|
2015-05-26 03:35:10 +00:00
|
|
|
NestedChildColumn (int id,
|
2015-05-26 03:58:58 +00:00
|
|
|
Display display, int flags = ColumnBase::Flag_Dialogue, bool isEditable = true);
|
2015-04-11 22:52:09 +00:00
|
|
|
|
|
|
|
virtual bool isEditable() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mIsEditable;
|
|
|
|
};
|
2012-12-16 11:52:23 +00:00
|
|
|
}
|
|
|
|
|
2015-10-28 12:33:24 +00:00
|
|
|
Q_DECLARE_METATYPE(CSMWorld::ColumnBase::TableEditModes)
|
2015-10-28 09:30:30 +00:00
|
|
|
|
2012-12-16 11:52:23 +00:00
|
|
|
#endif
|