Version: 8.3.0
ValueDelegate.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef _VALUEDELEGATE_HXX
21 #define _VALUEDELEGATE_HXX
22 
23 #include "CaseSwitch.hxx"
24 
25 #include <QItemDelegate>
26 #include <QModelIndex>
27 #include <QObject>
28 #include <QLineEdit>
29 #include <QSpinBox>
30 #include <QVariant>
31 #include <set>
32 
33 namespace YACS
34 {
35  namespace HMI
36  {
37  class Subject;
38  class ValueDelegate;
39 
41  {
42  public:
43  GenericEditor();
44  virtual ~GenericEditor();
45  virtual void setSubject(Subject* subject);
46  virtual void setColumn(int column);
47  virtual void setDelegate(const ValueDelegate* delegate);
48  virtual QString GetStrValue();
49  virtual Subject* getSubject();
50  virtual int getColumnInSubject();
51  virtual void setData(QVariant val);
52  virtual bool firstSetData();
53  protected:
55  int _column;
57  bool _first;
58  };
59 
60  class GeneralEditor: public QLineEdit, public GenericEditor
61  {
62  Q_OBJECT
63 
64  public:
65  GeneralEditor(Subject* subject,
66  const ValueDelegate* delegate,
67  int column = 0,
68  QWidget* parent = 0);
69  virtual ~GeneralEditor();
70  virtual QString GetStrValue();
71  virtual void setData(QVariant val);
72  };
73 
74  class NameEditor: public QLineEdit, public GenericEditor
75  {
76  Q_OBJECT
77 
78  public:
79  NameEditor(Subject* subject,
80  const ValueDelegate* delegate,
81  int column = 0,
82  QWidget* parent = 0);
83  virtual ~NameEditor();
84  virtual QString GetStrValue();
85  virtual void setData(QVariant val);
86  };
87 
88  class IntEditor: public QSpinBox, public GenericEditor
89  {
90  Q_OBJECT
91 
92  public:
93  IntEditor(Subject* subject,
94  const ValueDelegate* delegate,
95  int column = 0,
96  QWidget* parent = 0);
97  virtual ~IntEditor();
98  virtual QString GetStrValue();
99  virtual void setData(QVariant val);
100  };
101 
103  {
104  Q_OBJECT
105 
106  public:
107  CaseSwitchEditor(Subject* subject,
108  const ValueDelegate* delegate,
109  int column = 0,
110  QWidget* parent = 0);
111  virtual ~CaseSwitchEditor();
112  virtual QString GetStrValue();
113  virtual void setData(QVariant val);
114  };
115 
117  {
118  Q_OBJECT
119 
120  public:
121  ValueDelegate(QObject *parent = 0);
122  virtual ~ValueDelegate();
123 
124  virtual QWidget *createEditor(QWidget *parent,
125  const QStyleOptionViewItem &option,
126  const QModelIndex &index) const;
127 
128  virtual void setEditorData(QWidget *editor,
129  const QModelIndex &index) const;
130  virtual void setModelData(QWidget *editor,
131  QAbstractItemModel *model,
132  const QModelIndex &index) const;
133 
134  virtual void updateEditorGeometry(QWidget *editor,
135  const QStyleOptionViewItem &option,
136  const QModelIndex &index) const;
137  virtual void setResultEditing(QWidget *editor, bool isOk);
138 
139  protected:
140  mutable std::map<Subject*, std::string> _errorMap;
141 
142  };
143  }
144 }
145 #endif