OpenMW
apps/opencs/model/world/columnbase.hpp
Go to the documentation of this file.
00001 #ifndef CSM_WOLRD_COLUMNBASE_H
00002 #define CSM_WOLRD_COLUMNBASE_H
00003 
00004 #include <string>
00005 
00006 #include <Qt>
00007 #include <QVariant>
00008 
00009 #include "record.hpp"
00010 
00011 namespace CSMWorld
00012 {
00013     struct ColumnBase
00014     {
00015         enum Roles
00016         {
00017             Role_Flags = Qt::UserRole,
00018             Role_Display = Qt::UserRole+1
00019         };
00020 
00021         enum Flags
00022         {
00023             Flag_Table = 1, // column should be displayed in table view
00024             Flag_Dialogue = 2 // column should be displayed in dialogue view
00025         };
00026 
00027         enum Display
00028         {
00029             Display_String,
00030             Display_Integer,
00031             Display_Float,
00032             Display_Var,
00033             Display_GmstVarType,
00034             Display_GlobalVarType,
00035             Display_Specialisation,
00036             Display_Attribute,
00037             Display_Boolean,
00038             Display_SpellType,
00039             Display_Script,
00040             Display_ApparatusType,
00041             Display_ArmorType,
00042             Display_ClothingType,
00043             Display_CreatureType,
00044             Display_WeaponType,
00045             Display_RecordState,
00046             Display_RefRecordType,
00047             Display_DialogueType,
00048             Display_QuestStatusType,
00049             Display_Gender
00050         };
00051 
00052         int mColumnId;
00053         int mFlags;
00054         Display mDisplayType;
00055 
00056         ColumnBase (int columnId, Display displayType, int flag);
00057 
00058         virtual ~ColumnBase();
00059 
00060         virtual bool isEditable() const = 0;
00061 
00062         virtual bool isUserEditable() const;
00064 
00065         virtual std::string getTitle() const;
00066     };
00067 
00068     template<typename ESXRecordT>
00069     struct Column : public ColumnBase
00070     {
00071         int mFlags;
00072 
00073         Column (int columnId, Display displayType, int flags = Flag_Table | Flag_Dialogue)
00074         : ColumnBase (columnId, displayType, flags) {}
00075 
00076         virtual QVariant get (const Record<ESXRecordT>& record) const = 0;
00077 
00078         virtual void set (Record<ESXRecordT>& record, const QVariant& data)
00079         {
00080             throw std::logic_error ("Column " + getTitle() + " is not editable");
00081         }
00082     };
00083 }
00084 
00085 #endif