OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
util.hpp
Go to the documentation of this file.
1 #ifndef CSV_WORLD_UTIL_H
2 #define CSV_WORLD_UTIL_H
3 
4 #include <map>
5 
6 #include <QAbstractTableModel>
7 #include <QStyledItemDelegate>
8 
9 #include "../../model/world/columnbase.hpp"
10 #include "../../model/doc/document.hpp"
11 
12 class QUndoStack;
13 
14 namespace CSMWorld
15 {
16  class TableMimeData;
17  class UniversalId;
18  class CommandDispatcher;
19 }
20 
21 namespace CSMPrefs
22 {
23  class Setting;
24 }
25 
26 namespace CSVWorld
27 {
32  {
34  QVariant mData;
35 
36  public:
37 
39 
40  int rowCount (const QModelIndex & parent = QModelIndex()) const;
41 
42  int columnCount (const QModelIndex & parent = QModelIndex()) const;
43 
44  QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const;
45 
46  bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
47 
48  QVariant getData() const;
49  };
50 
51  class CommandDelegate;
52 
54  {
55  public:
56 
57  virtual ~CommandDelegateFactory();
58 
60  CSMDoc::Document& document, QObject *parent)
61  const = 0;
63  };
64 
66  {
68  std::map<CSMWorld::ColumnBase::Display, CommandDelegateFactory *> mFactories;
69 
70  private:
71 
72  // not implemented
75 
76  public:
77 
79 
81 
86 
88  CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document,
89  QObject *parent) const;
93 
94  static const CommandDelegateFactoryCollection& get();
95 
96  };
97 
100  {
101  Q_OBJECT
102 
103  bool mEditLock;
106 
107  protected:
108 
109  QUndoStack& getUndoStack() const;
110 
111  CSMDoc::Document& getDocument() const;
112 
113  CSMWorld::ColumnBase::Display getDisplayTypeFromIndex(const QModelIndex &index) const;
114 
115  virtual void setModelDataImp (QWidget *editor, QAbstractItemModel *model,
116  const QModelIndex& index) const;
117 
118  public:
119 
122  CommandDelegate (CSMWorld::CommandDispatcher *commandDispatcher, CSMDoc::Document& document, QObject *parent);
123 
124  virtual void setModelData (QWidget *editor, QAbstractItemModel *model,
125  const QModelIndex& index) const;
126 
127  virtual QWidget *createEditor (QWidget *parent,
128  const QStyleOptionViewItem& option,
129  const QModelIndex& index) const;
130 
131  virtual QWidget *createEditor (QWidget *parent,
132  const QStyleOptionViewItem& option,
133  const QModelIndex& index,
134  CSMWorld::ColumnBase::Display display) const;
135 
136  void setEditLock (bool locked);
137 
138  bool isEditLocked() const;
139 
141 
142  virtual void setEditorData (QWidget *editor, const QModelIndex& index) const;
143 
144  virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const;
145 
148  virtual void settingChanged (const CSMPrefs::Setting *setting);
149  };
150 }
151 
152 #endif
CommandDelegate(CSMWorld::CommandDispatcher *commandDispatcher, CSMDoc::Document &document, QObject *parent)
Definition: util.cpp:148
CSMDoc::Document & getDocument() const
Definition: util.cpp:113
QVariant getData() const
Definition: util.cpp:52
void setEditLock(bool locked)
Definition: util.cpp:277
CommandDelegateFactoryCollection()
Definition: util.cpp:63
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: util.cpp:287
std::map< CSMWorld::ColumnBase::Display, CommandDelegateFactory * > mFactories
Definition: util.hpp:68
NastyTableModelHack(QAbstractItemModel &model)
Definition: util.cpp:27
QUndoStack & getUndoStack() const
Definition: util.cpp:108
Display
Definition: columnbase.hpp:39
CSMWorld::CommandDispatcher * mCommandDispatcher
Definition: util.hpp:104
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: util.cpp:36
virtual ~CommandDelegateFactory()
Definition: util.cpp:58
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Definition: util.cpp:46
bool mEditLock
Definition: util.hpp:103
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: util.cpp:41
virtual void settingChanged(const CSMPrefs::Setting *setting)
Definition: util.cpp:340
~CommandDelegateFactoryCollection()
Definition: util.cpp:71
Getting the data out of an editor widget.
Definition: util.hpp:31
CSMDoc::Document & mDocument
Definition: util.hpp:105
bool isEditLocked() const
Definition: util.cpp:282
CSMWorld::ColumnBase::Display getDisplayTypeFromIndex(const QModelIndex &index) const
Definition: util.cpp:118
virtual CommandDelegate * makeDelegate(CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document &document, QObject *parent) const =0
The ownership of the returned CommandDelegate is transferred to the caller.
QAbstractItemModel & mModel
Definition: util.hpp:33
Use commands instead of manipulating the model directly.
Definition: util.hpp:65
CommandDelegateFactoryCollection & operator=(const CommandDelegateFactoryCollection &)
QVariant mData
Definition: util.hpp:34
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: util.cpp:165
Definition: commanddispatcher.hpp:20
Definition: util.hpp:99
Definition: setting.hpp:22
static CommandDelegateFactoryCollection * sThis
Definition: util.hpp:67
Definition: document.hpp:57
void add(CSMWorld::ColumnBase::Display display, CommandDelegateFactory *factory)
Definition: util.cpp:81
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: util.cpp:154
CommandDelegate * makeDelegate(CSMWorld::ColumnBase::Display display, CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document &document, QObject *parent) const
Definition: util.cpp:87
virtual void setModelDataImp(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: util.cpp:124
Definition: util.hpp:53
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: util.cpp:31