OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
dialoguesubview.hpp
Go to the documentation of this file.
1 #ifndef CSV_WORLD_DIALOGUESUBVIEW_H
2 #define CSV_WORLD_DIALOGUESUBVIEW_H
3 
4 #include <set>
5 #include <map>
6 #include <memory>
7 
8 #include <QAbstractItemDelegate>
9 #include <QScrollArea>
10 
11 #include "../doc/subview.hpp"
12 
13 #include "../../model/world/columnbase.hpp"
14 #include "../../model/world/commanddispatcher.hpp"
15 #include "../../model/world/universalid.hpp"
16 
17 class QDataWidgetMapper;
18 class QSize;
19 class QEvent;
20 class QLabel;
21 class QVBoxLayout;
22 class QMenu;
23 
24 namespace CSMWorld
25 {
26  class IdTable;
27  class NestedTableProxyModel;
28 }
29 
30 namespace CSMPrefs
31 {
32  class Setting;
33 }
34 
35 namespace CSMDoc
36 {
37  class Document;
38 }
39 
40 namespace CSVWorld
41 {
42  class CommandDelegate;
43  class CreatorFactoryBase;
44  class TableBottomBox;
45 
47  {
49  public:
51  QObject * parent = 0);
52 
53  virtual void setEditorData (QWidget* editor, const QModelIndex& index) const;
54 
55  virtual void setModelData (QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
56 
57  virtual void paint (QPainter* painter,
58  const QStyleOptionViewItem& option,
59  const QModelIndex& index) const;
61 
62  virtual QSize sizeHint (const QStyleOptionViewItem& option,
63  const QModelIndex& index) const;
65 
66  virtual QWidget *createEditor (QWidget *parent,
67  const QStyleOptionViewItem& option,
68  const QModelIndex& index) const;
69  };
70 
71  //this can't be nested into the DialogueDelegateDispatcher, because it needs to emit signals
73  {
74  Q_OBJECT
75  class refWrapper
76  {
77  public:
78  refWrapper(const QModelIndex& index);
79 
80  const QModelIndex& mIndex;
81  };
82 
84 
86 
87  std::auto_ptr<refWrapper> mIndexWrapper;
88 
89  public:
92  QWidget* getEditor() const;
93 
94  public slots:
95  void editorDataCommited();
96  void setIndex(const QModelIndex& index);
97 
98  signals:
99  void editorDataCommited(QWidget* editor,
100  const QModelIndex& index,
102 
103  };
104 
106  {
107  Q_OBJECT
108  std::map<int, CommandDelegate*> mDelegates;
109 
111 
113 
116 
118 
119  std::vector<DialogueDelegateDispatcherProxy*> mProxys;
120  //once we move to the C++11 we should use unique_ptr
121 
122  public:
124  CSMWorld::IdTable* table,
125  CSMWorld::CommandDispatcher& commandDispatcher,
126  CSMDoc::Document& document,
127  QAbstractItemModel* model = 0);
128 
130 
132 
133  QWidget* makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex& index);
135  //same as for dispatcher itself
136 
137  virtual void setEditorData (QWidget* editor, const QModelIndex& index) const;
138 
139  virtual void setModelData (QWidget* editor, QAbstractItemModel* model,
140  const QModelIndex& index) const;
141 
142  virtual void setModelData (QWidget* editor,
143  QAbstractItemModel* model, const QModelIndex& index,
144  CSMWorld::ColumnBase::Display display) const;
145 
146  virtual void paint (QPainter* painter,
147  const QStyleOptionViewItem& option,
148  const QModelIndex& index) const;
150 
151  virtual QSize sizeHint (const QStyleOptionViewItem& option,
152  const QModelIndex& index) const;
154 
155  private slots:
156  void editorDataCommited(QWidget* editor, const QModelIndex& index,
158  };
159 
161  class IdContextMenu : public QObject
162  {
163  Q_OBJECT
164 
167  std::set<std::string> mExcludedIds;
169 
172 
173  QString getWidgetValue() const;
174  void addEditIdActionToMenu(const QString &text);
176 
177  public:
179 
180  void excludeId(const std::string &id);
181 
182  private slots:
183  void showContextMenu(const QPoint &pos);
184  void editIdRequest();
185 
186  signals:
187  void editIdRequest(const CSMWorld::UniversalId &id, const std::string &hint);
188  };
189 
190  class EditWidget : public QScrollArea
191  {
192  Q_OBJECT
193  QDataWidgetMapper *mWidgetMapper;
194  QDataWidgetMapper *mNestedTableMapper;
201  std::vector<CSMWorld::NestedTableProxyModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor
202 
203  void createEditorContextMenu(QWidget *editor,
205  int currentRow) const;
206  public:
207 
208  EditWidget (QWidget *parent, int row, CSMWorld::IdTable* table,
209  CSMWorld::CommandDispatcher& commandDispatcher,
210  CSMDoc::Document& document, bool createAndDelete = false);
211 
212  virtual ~EditWidget();
213 
214  void remake(int row);
215 
216  signals:
217  void editIdRequest(const CSMWorld::UniversalId &id, const std::string &hint);
218  };
219 
221  {
222  Q_OBJECT
223 
225  QVBoxLayout* mMainLayout;
227  bool mLocked;
230 
231  protected:
232 
233  QVBoxLayout& getMainLayout();
234 
236 
238 
240 
241  void updateCurrentId();
242 
243  bool isLocked() const;
244 
245  public:
246 
248 
249  virtual void setEditLock (bool locked);
250 
251  private slots:
252 
253  void dataChanged(const QModelIndex & index);
255 
256  void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
257  };
258 
259  class RecordButtonBar;
260 
262  {
263  Q_OBJECT
264 
267 
268  private:
269 
270  void addButtonBar();
271 
272  public:
273 
275  const CreatorFactoryBase& creatorFactory, bool sorting = false);
276 
277  virtual void setEditLock (bool locked);
278 
279  private slots:
280 
281  void settingChanged (const CSMPrefs::Setting *setting);
282 
283  void showPreview();
284 
285  void viewRecord();
286 
287  void switchToRow (int row);
288 
289  void requestFocus (const std::string& id);
290  };
291 }
292 
293 #endif
SimpleDialogueSubView(const CSMWorld::UniversalId &id, CSMDoc::Document &document)
Definition: dialoguesubview.cpp:733
EditWidget * mEditWidget
Definition: dialoguesubview.hpp:224
DialogueDelegateDispatcherProxy(QWidget *editor, CSMWorld::ColumnBase::Display display)
Definition: dialoguesubview.cpp:120
void createEditorContextMenu(QWidget *editor, CSMWorld::ColumnBase::Display display, int currentRow) const
Definition: dialoguesubview.cpp:435
static const struct @2 signals[]
Definition: dialoguesubview.hpp:46
void removeEditIdActionFromMenu()
Definition: dialoguesubview.cpp:389
QVBoxLayout * mMainLayout
Definition: dialoguesubview.hpp:225
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: dialoguesubview.cpp:217
Definition: idtable.hpp:15
std::vector< DialogueDelegateDispatcherProxy * > mProxys
Definition: dialoguesubview.hpp:119
QDataWidgetMapper * mNestedTableMapper
Definition: dialoguesubview.hpp:194
CSMWorld::ColumnBase::Display mDisplay
Definition: dialoguesubview.hpp:85
CSMWorld::UniversalId::Type mIdType
Definition: dialoguesubview.hpp:166
CSMWorld::CommandDispatcher & mCommandDispatcher
Definition: dialoguesubview.hpp:114
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
does nothing
Definition: dialoguesubview.cpp:239
void updateCurrentId()
Definition: dialoguesubview.cpp:843
QAbstractItemModel * mTable
Definition: dialoguesubview.hpp:112
Display
Definition: columnbase.hpp:39
void settingChanged(const CSMPrefs::Setting *setting)
Definition: dialoguesubview.cpp:896
Type
Definition: universalid.hpp:40
QVBoxLayout & getMainLayout()
Definition: dialoguesubview.cpp:708
EditWidget & getEditWidget()
Definition: dialoguesubview.cpp:723
const QModelIndex & mIndex
Definition: dialoguesubview.hpp:80
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: dialoguesubview.cpp:53
CSMWorld::IdTable * mTable
Definition: dialoguesubview.hpp:198
void editorDataCommited(QWidget *editor, const QModelIndex &index, CSMWorld::ColumnBase::Display display)
Definition: dialoguesubview.cpp:175
~DialogueDelegateDispatcher()
Definition: dialoguesubview.cpp:314
void addEditIdActionToMenu(const QString &text)
Definition: dialoguesubview.cpp:374
CSMWorld::IdTable & getTable()
Definition: dialoguesubview.cpp:713
CSVWorld::CommandDelegate * makeDelegate(CSMWorld::ColumnBase::Display display)
Definition: dialoguesubview.cpp:159
Button bar for use in dialogue-type subviews.
Definition: recordbuttonbar.hpp:36
const CSMWorld::IdTable * mTable
Definition: dialoguesubview.hpp:48
QWidget * mWidget
Definition: dialoguesubview.hpp:165
void switchToRow(int row)
Definition: dialoguesubview.cpp:941
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
does nothing
Definition: dialoguesubview.cpp:99
virtual void setEditLock(bool locked)
Definition: dialoguesubview.cpp:888
TableBottomBox * mBottom
Definition: dialoguesubview.hpp:265
DialogueSubView(const CSMWorld::UniversalId &id, CSMDoc::Document &document, const CreatorFactoryBase &creatorFactory, bool sorting=false)
Definition: dialoguesubview.cpp:870
virtual void setEditLock(bool locked)
Definition: dialoguesubview.cpp:768
CSMWorld::IdTable * mTable
Definition: dialoguesubview.hpp:226
void addButtonBar()
Definition: dialoguesubview.cpp:851
NotEditableSubDelegate mNotEditableDelegate
Definition: dialoguesubview.hpp:117
void viewRecord()
Definition: dialoguesubview.cpp:926
Definition: tablebottombox.hpp:23
CSMWorld::CommandDispatcher & getCommandDispatcher()
Definition: dialoguesubview.cpp:718
A context menu with "Edit 'ID'" action for editors in the dialogue subview.
Definition: dialoguesubview.hpp:161
bool isLocked() const
Definition: dialoguesubview.cpp:728
std::map< int, CommandDelegate * > mDelegates
Definition: dialoguesubview.hpp:108
void editIdRequest(const CSMWorld::UniversalId &id, const std::string &hint)
DialogueDelegateDispatcher * mNestedTableDispatcher
Definition: dialoguesubview.hpp:196
const CSMDoc::Document & mDocument
Definition: dialoguesubview.hpp:228
void setIndex(const QModelIndex &index)
Definition: dialoguesubview.cpp:135
RecordButtonBar * mButtons
Definition: dialoguesubview.hpp:266
void editorDataCommited()
Definition: dialoguesubview.cpp:127
void requestFocus(const std::string &id)
Definition: dialoguesubview.cpp:962
Definition: dialoguesubview.hpp:190
bool mLocked
Definition: dialoguesubview.hpp:227
std::vector< CSMWorld::NestedTableProxyModel * > mNestedModels
Definition: dialoguesubview.hpp:201
QObject * mParent
Definition: dialoguesubview.hpp:110
Definition: commanddispatcher.hpp:20
QAction * mEditIdAction
Definition: dialoguesubview.hpp:171
refWrapper(const QModelIndex &index)
Definition: dialoguesubview.cpp:116
Definition: util.hpp:99
Base class for Creator factory.
Definition: creator.hpp:54
Definition: subview.hpp:23
QDataWidgetMapper * mWidgetMapper
Definition: dialoguesubview.hpp:193
CSMWorld::CommandDispatcher & mCommandDispatcher
Definition: dialoguesubview.hpp:199
Definition: setting.hpp:22
Definition: dialoguesubview.hpp:105
Definition: dialoguesubview.hpp:220
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
does nothing
Definition: dialoguesubview.cpp:94
std::set< std::string > mExcludedIds
A list of IDs that should not have the Edit 'ID' action.
Definition: dialoguesubview.hpp:167
DialogueDelegateDispatcher(QObject *parent, CSMWorld::IdTable *table, CSMWorld::CommandDispatcher &commandDispatcher, CSMDoc::Document &document, QAbstractItemModel *model=0)
Definition: dialoguesubview.cpp:149
Definition: document.hpp:57
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: dialoguesubview.cpp:104
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
does nothing
Definition: dialoguesubview.cpp:233
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: dialoguesubview.cpp:181
DialogueDelegateDispatcher * mDispatcher
Definition: dialoguesubview.hpp:195
QMenu * mContextMenu
Definition: dialoguesubview.hpp:170
void showContextMenu(const QPoint &pos)
Definition: dialoguesubview.cpp:406
QWidget * mEditor
Definition: dialoguesubview.hpp:83
NotEditableSubDelegate(const CSMWorld::IdTable *table, QObject *parent=0)
Definition: dialoguesubview.cpp:48
CSMWorld::CommandDispatcher mCommandDispatcher
Definition: dialoguesubview.hpp:229
QWidget * makeEditor(CSMWorld::ColumnBase::Display display, const QModelIndex &index)
will return null if delegate is not present, parent of the widget is
Definition: dialoguesubview.cpp:245
Definition: dialoguesubview.hpp:261
QString getWidgetValue() const
Definition: dialoguesubview.cpp:357
std::auto_ptr< refWrapper > mIndexWrapper
Definition: dialoguesubview.hpp:87
CSMDoc::Document & mDocument
Definition: dialoguesubview.hpp:115
EditWidget(QWidget *parent, int row, CSMWorld::IdTable *table, CSMWorld::CommandDispatcher &commandDispatcher, CSMDoc::Document &document, bool createAndDelete=false)
Definition: dialoguesubview.cpp:469
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
we need to care for deleting currently edited record
Definition: dialoguesubview.cpp:822
QWidget * getEditor() const
Definition: dialoguesubview.cpp:140
void remake(int row)
Definition: dialoguesubview.cpp:485
IdContextMenu(QWidget *widget, CSMWorld::ColumnBase::Display display)
Definition: dialoguesubview.cpp:323
void dataChanged(const QModelIndex &index)
Definition: dialoguesubview.cpp:788
void excludeId(const std::string &id)
Definition: dialoguesubview.cpp:352
Definition: dialoguesubview.hpp:72
virtual ~EditWidget()
Definition: dialoguesubview.cpp:457
void showPreview()
Definition: dialoguesubview.cpp:913
CSMDoc::Document & mDocument
Definition: dialoguesubview.hpp:200
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: dialoguesubview.cpp:89
QWidget * mMainWidget
Definition: dialoguesubview.hpp:197
void editIdRequest()
Definition: dialoguesubview.cpp:425
Definition: universalid.hpp:12