OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
columnbase.hpp
Go to the documentation of this file.
1 #ifndef CSM_WOLRD_COLUMNBASE_H
2 #define CSM_WOLRD_COLUMNBASE_H
3 
4 #include <string>
5 #include <vector>
6 #include <stdexcept>
7 
8 #include <Qt>
9 #include <QVariant>
10 
11 #include "record.hpp"
12 
13 namespace CSMWorld
14 {
15  struct ColumnBase
16  {
18  {
19  TableEdit_None, // no editing
20  TableEdit_Full, // edit cells and add/remove rows
21  TableEdit_FixedRows // edit cells only
22  };
23 
24  enum Roles
25  {
26  Role_Flags = Qt::UserRole,
27  Role_Display = Qt::UserRole+1,
28  Role_ColumnId = Qt::UserRole+2
29  };
30 
31  enum Flags
32  {
33  Flag_Table = 1, // column should be displayed in table view
34  Flag_Dialogue = 2, // column should be displayed in dialogue view
35  Flag_Dialogue_List = 4, // column should be diaplyed in dialogue view
36  Flag_Dialogue_Refresh = 8 // refresh dialogue view if this column is modified
37  };
38 
39  enum Display
40  {
41  Display_None, //Do not use
44 
45  //CONCRETE TYPES STARTS HERE (for drag and drop)
86  //CONCRETE TYPES ENDS HERE
87 
120  Display_ScriptLines, // console context
134 
135  Display_EffectSkill, // must display at least one, unlike Display_Skill
136  Display_EffectAttribute, // must display at least one, unlike Display_Attribute
137  Display_IngredEffectId, // display none allowed, unlike Display_EffectId
138 
139  //top level columns that nest other columns
141  };
142 
144  int mFlags;
146 
147  ColumnBase (int columnId, Display displayType, int flag);
148 
149  virtual ~ColumnBase();
150 
151  virtual bool isEditable() const = 0;
152 
153  virtual bool isUserEditable() const;
155 
156  virtual std::string getTitle() const;
157 
158  virtual int getId() const;
159 
160  static bool isId (Display display);
161 
162  static bool isText (Display display);
163 
164  static bool isScript (Display display);
165  };
166 
167  class NestableColumn : public ColumnBase
168  {
169  std::vector<NestableColumn *> mNestedColumns;
170 
171  public:
172 
173  NestableColumn(int columnId, Display displayType, int flag);
174 
175  ~NestableColumn();
176 
177  void addColumn(CSMWorld::NestableColumn *column);
178 
179  const ColumnBase& nestedColumn(int subColumn) const;
180 
181  bool hasChildren() const;
182  };
183 
184  template<typename ESXRecordT>
185  struct Column : public NestableColumn
186  {
187  Column (int columnId, Display displayType, int flags = Flag_Table | Flag_Dialogue)
188  : NestableColumn (columnId, displayType, flags) {}
189 
190  virtual QVariant get (const Record<ESXRecordT>& record) const = 0;
191 
192  virtual void set (Record<ESXRecordT>& record, const QVariant& data)
193  {
194  throw std::logic_error ("Column " + getTitle() + " is not editable");
195  }
196  };
197 
198  template<typename ESXRecordT>
199  struct NestedParentColumn : public Column<ESXRecordT>
200  {
201  NestedParentColumn (int id, int flags = ColumnBase::Flag_Dialogue, bool fixedRows = false)
202  : Column<ESXRecordT> (id, ColumnBase::Display_NestedHeader, flags), mFixedRows(fixedRows)
203  {}
204 
205  virtual void set (Record<ESXRecordT>& record, const QVariant& data)
206  {
207  // There is nothing to do here.
208  // This prevents exceptions from parent's implementation
209  }
210 
211  virtual QVariant get (const Record<ESXRecordT>& record) const
212  {
213  // by default editable; also see IdTree::hasChildren()
214  if (mFixedRows)
215  return QVariant::fromValue(ColumnBase::TableEdit_FixedRows);
216  else
217  return QVariant::fromValue(ColumnBase::TableEdit_Full);
218  }
219 
220  virtual bool isEditable() const
221  {
222  return true;
223  }
224 
225  private:
227  };
228 
230  {
231  NestedChildColumn (int id,
232  Display display, int flags = ColumnBase::Flag_Dialogue, bool isEditable = true);
233 
234  virtual bool isEditable() const;
235 
236  private:
238  };
239 }
240 
241 Q_DECLARE_METATYPE(CSMWorld::ColumnBase::TableEditModes)
242 
243 #endif
Definition: columnbase.hpp:73
Definition: columnbase.hpp:81
Flags
Definition: columnbase.hpp:31
Definition: columnbase.hpp:56
Definition: columnbase.hpp:112
Definition: columnbase.hpp:48
Definition: columnbase.hpp:229
Definition: columnbase.hpp:47
Definition: columnbase.hpp:61
int mFlags
Definition: columnbase.hpp:144
Definition: columnbase.hpp:114
Column(int columnId, Display displayType, int flags=Flag_Table|Flag_Dialogue)
Definition: columnbase.hpp:187
virtual bool isEditable() const
Definition: columnbase.cpp:150
Definition: columnbase.hpp:77
Definition: columnbase.hpp:136
Definition: columnbase.hpp:19
Definition: columnbase.hpp:109
virtual ~ColumnBase()
Definition: columnbase.cpp:9
Definition: columnbase.hpp:113
Definition: columnbase.hpp:104
Definition: columnbase.hpp:55
Definition: columnbase.hpp:80
const ColumnBase & nestedColumn(int subColumn) const
Definition: columnbase.cpp:119
Definition: columnbase.hpp:167
NestableColumn(int columnId, Display displayType, int flag)
Definition: columnbase.cpp:127
Definition: columnbase.hpp:42
Display
Definition: columnbase.hpp:39
Definition: columnbase.hpp:120
Definition: columnbase.hpp:117
Definition: columnbase.hpp:68
Definition: columnbase.hpp:107
Definition: columnbase.hpp:123
Definition: columnbase.hpp:95
Definition: columnbase.hpp:62
Definition: columnbase.hpp:91
Definition: columnbase.hpp:125
virtual int getId() const
Definition: columnbase.cpp:21
Definition: columnbase.hpp:72
Definition: columnbase.hpp:99
Definition: columnbase.hpp:33
Definition: columnbase.hpp:102
Definition: columnbase.hpp:49
Definition: columnbase.hpp:36
TableEditModes
Definition: columnbase.hpp:17
static bool isScript(Display display)
Definition: columnbase.cpp:109
virtual bool isUserEditable() const
Can this column be edited directly by the user?
Definition: columnbase.cpp:11
Definition: columnbase.hpp:131
Definition: columnbase.hpp:64
Definition: columnbase.hpp:124
Definition: columnbase.hpp:108
Definition: columnbase.hpp:20
Definition: columnbase.hpp:130
int mColumnId
Definition: columnbase.hpp:143
Definition: columnbase.hpp:78
virtual bool isEditable() const =0
Definition: columnbase.hpp:93
Definition: columnbase.hpp:101
Definition: columnbase.hpp:79
Definition: columnbase.hpp:74
Definition: columnbase.hpp:129
Definition: columnbase.hpp:69
bool mFixedRows
Definition: columnbase.hpp:226
Definition: columnbase.hpp:27
Definition: nestedcolumnadapter.hpp:11
NestedParentColumn(int id, int flags=ColumnBase::Flag_Dialogue, bool fixedRows=false)
Definition: columnbase.hpp:201
Definition: columnbase.hpp:185
Definition: columnbase.hpp:85
Definition: columnbase.hpp:135
Definition: columnbase.hpp:71
Definition: columnbase.hpp:46
Display mDisplayType
Definition: columnbase.hpp:145
Definition: columnbase.hpp:76
Definition: columnbase.hpp:63
Definition: columnbase.hpp:57
Definition: columnbase.hpp:105
Definition: columnbase.hpp:82
Definition: columnbase.hpp:100
ColumnBase(int columnId, Display displayType, int flag)
Definition: columnbase.cpp:5
Definition: columnbase.hpp:199
Definition: columnbase.hpp:110
Definition: columnbase.hpp:70
virtual void set(Record< ESXRecordT > &record, const QVariant &data)
Definition: columnbase.hpp:205
Definition: columnbase.hpp:128
Definition: columnbase.hpp:115
Definition: columnbase.hpp:21
Definition: columnbase.hpp:58
Definition: columnbase.hpp:54
Definition: columnbase.hpp:133
Definition: columnbase.hpp:126
Definition: columnbase.hpp:122
Definition: columnbase.hpp:111
static bool isText(Display display)
Definition: columnbase.cpp:103
Definition: columnbase.hpp:41
Definition: columnbase.hpp:84
Definition: columnbase.hpp:89
Definition: columnbase.hpp:35
Definition: columnbase.hpp:98
virtual std::string getTitle() const
Definition: columnbase.cpp:16
Definition: columnbase.hpp:140
NestedChildColumn(int id, Display display, int flags=ColumnBase::Flag_Dialogue, bool isEditable=true)
Definition: columnbase.cpp:145
Definition: columnbase.hpp:15
Definition: columnbase.hpp:26
void addColumn(CSMWorld::NestableColumn *column)
Definition: columnbase.cpp:114
std::vector< NestableColumn * > mNestedColumns
Definition: columnbase.hpp:169
Definition: columnbase.hpp:116
Definition: columnbase.hpp:75
static bool isId(Display display)
Definition: columnbase.cpp:26
Definition: columnbase.hpp:59
bool hasChildren() const
Definition: columnbase.cpp:140
Definition: columnbase.hpp:43
Definition: columnbase.hpp:106
Definition: columnbase.hpp:119
Definition: columnbase.hpp:97
Definition: columnbase.hpp:60
Definition: columnbase.hpp:51
virtual void set(Record< ESXRecordT > &record, const QVariant &data)
Definition: columnbase.hpp:192
~NestableColumn()
Definition: columnbase.cpp:132
Definition: columnbase.hpp:127
Definition: columnbase.hpp:96
Definition: columnbase.hpp:34
Roles
Definition: columnbase.hpp:24
bool mIsEditable
Definition: columnbase.hpp:237
Definition: columnbase.hpp:28
Definition: columnbase.hpp:92
Definition: columnbase.hpp:90
Definition: columnbase.hpp:132
Definition: columnbase.hpp:65
Definition: columnbase.hpp:52
Definition: columnbase.hpp:103
Definition: columnbase.hpp:137
Definition: columnbase.hpp:50
Definition: columnbase.hpp:53
Definition: columnbase.hpp:118
virtual bool isEditable() const
Definition: columnbase.hpp:220