OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
enumdelegate.hpp
Go to the documentation of this file.
1 #ifndef CSV_WORLD_ENUMDELEGATE_H
2 #define CSV_WORLD_ENUMDELEGATE_H
3 
4 #include <vector>
5 
6 #include <QString>
7 #include <QStyledItemDelegate>
8 
10 
11 #include "util.hpp"
12 
13 namespace CSVWorld
14 {
17  {
18  protected:
19 
20  std::vector<std::pair<int, QString> > mValues;
21 
22  int getValueIndex(const QModelIndex &index, int role = Qt::DisplayRole) const;
23 
24  private:
25 
26  virtual void setModelDataImp (QWidget *editor, QAbstractItemModel *model,
27  const QModelIndex& index) const;
28 
29  virtual void addCommands (QAbstractItemModel *model,
30  const QModelIndex& index, int type) const;
31 
32  public:
33 
34  EnumDelegate (const std::vector<std::pair<int, QString> >& values,
35  CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent);
36 
37  virtual QWidget *createEditor(QWidget *parent,
38  const QStyleOptionViewItem& option,
39  const QModelIndex& index) const;
40 
41  virtual QWidget *createEditor(QWidget *parent,
42  const QStyleOptionViewItem& option,
43  const QModelIndex& index,
45 
46  virtual void setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay = false) const;
47 
48  virtual void paint (QPainter *painter, const QStyleOptionViewItem& option,
49  const QModelIndex& index) const;
50 
51  virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
52 
53  };
54 
56  {
57  protected:
58  std::vector<std::pair<int, QString> > mValues;
59 
60  public:
61 
63 
64  EnumDelegateFactory (const char **names, bool allowNone = false);
67 
68  EnumDelegateFactory (const std::vector<std::string>& names, bool allowNone = false);
70 
71  virtual CommandDelegate *makeDelegate (CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document& document, QObject *parent) const;
73 
74  void add (int value, const QString& name);
75  };
76 
77 
78 }
79 
80 #endif
virtual void setEditorData(QWidget *editor, const QModelIndex &index, bool tryDisplay=false) const
Definition: enumdelegate.cpp:85
int getValueIndex(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: enumdelegate.cpp:12
Display
Definition: columnbase.hpp:39
EnumDelegateFactory()
Definition: enumdelegate.cpp:141
Definition: enumdelegate.hpp:55
std::vector< std::pair< int, QString > > mValues
Definition: enumdelegate.hpp:20
virtual void addCommands(QAbstractItemModel *model, const QModelIndex &index, int type) const
Definition: enumdelegate.cpp:49
virtual void setModelDataImp(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: enumdelegate.cpp:30
void add(int value, const QString &name)
Definition: enumdelegate.cpp:172
std::vector< std::pair< int, QString > > mValues
Definition: enumdelegate.hpp:58
Definition: commanddispatcher.hpp:20
Definition: util.hpp:99
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: enumdelegate.cpp:107
virtual CommandDelegate * makeDelegate(CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document &document, QObject *parent) const
The ownership of the returned CommandDelegate is transferred to the caller.
Definition: enumdelegate.cpp:166
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: enumdelegate.cpp:63
Definition: columnbase.hpp:41
Definition: document.hpp:57
EnumDelegate(const std::vector< std::pair< int, QString > > &values, CSMWorld::CommandDispatcher *dispatcher, CSMDoc::Document &document, QObject *parent)
Definition: enumdelegate.cpp:56
Integer value that represents an enum and is interacted with via a combobox.
Definition: enumdelegate.hpp:16
Definition: util.hpp:53
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: enumdelegate.cpp:119
const char * name
Definition: crashcatcher.cpp:59