Bayeux  3.4.1
Core Foundation library for SuperNEMO
parameter_item_delegate.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2014-10-06
4  * Last modified : 2016-11-15
5  *
6  * Copyright (C) 2014-2016 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * Qt-based parameter item delegate for a tree view of a variant registry.
26  *
27  */
28 
29 // http://qt-project.org/doc/qt-4.8/model-view-programming.html#delegate-classes
30 // http://qt-project.org/doc/qt-4.8/qstyleoptionviewitem.html
31 
32 #ifndef DATATOOLS_CONFIGURATION_UI_PARAMETER_ITEM_DELEGATE_H
33 #define DATATOOLS_CONFIGURATION_UI_PARAMETER_ITEM_DELEGATE_H
34 
35 // Third party:
36 // - Qt:
37 #include <QObject>
38 #include <QItemDelegate>
39 #include <QStyledItemDelegate>
40 #include <QPushButton>
41 #include <QFileDialog>
42 #include <QInputDialog>
43 
44 // Forward declaration
45 class QWidget;
46 class QModelIndex;
47 class QAbstractItemModel;
48 class QComboBox;
49 
50 // This project:
51 #include <datatools/logger.h>
52 
53 namespace datatools {
54 
55  namespace configuration {
56 
57  // Forward declaration:
58  class parameter_model;
59  class variant_record;
60  class variant_repository;
61 
62  namespace ui {
63 
65  class RealDialogLauncherButton : public QPushButton
66  {
67  Q_OBJECT
68 
69  public:
70 
72  RealDialogLauncherButton(const QModelIndex & index_,
73  const QString & button_text_ = "Set value",
74  QWidget * parent_ = 0 );
76  virtual ~RealDialogLauncherButton();
77 
79  double get_unit_value() const;
80 
82  double get_value() const;
83 
85  const std::string & get_unit_symbol() const;
86 
87  public slots:
88 
90 
91  void slot_set_value();
92 
93  signals:
94 
95  void signal_launch_real_dialog(const QModelIndex & index_);
96 
97  public:
98 
100 
101  private:
102 
103  const QModelIndex * _index_ = nullptr;
104  QInputDialog * _real_dialog_ = nullptr;
105  const variant_record * _real_record_ = nullptr;
106  const parameter_model * _param_model_ = nullptr;
107  std::string _unit_label_;
108  std::string _unit_symbol_;
109  double _unit_value_;
110  double _value_;
111 
112  };
113 
115  class FileDialogLauncherButton : public QPushButton
116  {
117  Q_OBJECT
118 
119  public:
120 
122  FileDialogLauncherButton(const QModelIndex & index_,
123  const QString & button_text_ = "Choose file path",
124  QWidget * parent_ = 0 );
126  virtual ~FileDialogLauncherButton();
127 
128  bool is_open() const;
129 
130  bool is_save() const;
131 
132  const QString & get_path() const;
133 
134  public slots:
135 
137 
138  void slot_set_path();
139 
140  signals:
141 
142  void signal_launch_file_dialog(const QModelIndex & index_);
143 
144  public:
145 
147 
148  private:
149 
150  QFileDialog::AcceptMode _accept_mode_;
151  const QModelIndex * _index_ = nullptr;
152  QFileDialog * _path_dialog_ = nullptr;
153  const variant_record * _path_record_ = nullptr;
154  const parameter_model * _param_model_ = nullptr;
155  QString _path_;
156 
157  };
158 
160  class parameter_item_delegate : public QStyledItemDelegate
161  {
162 
163  Q_OBJECT
164 
165  public:
166 
168  parameter_item_delegate(QObject * parent_ = 0);
169 
171  virtual ~parameter_item_delegate();
172 
174  bool has_parent_repository() const;
175 
178 
181 
184 
186  virtual QWidget *createEditor(QWidget * parent_,
187  const QStyleOptionViewItem & option_,
188  const QModelIndex & index_) const;
189 
191  virtual void setEditorData(QWidget * editor_,
192  const QModelIndex & index_) const;
193 
195  void setEditorData2(QWidget * editor_,
196  const QModelIndex & index_) const;
197 
198  // Set the model data
199  virtual void setModelData(QWidget * editor_,
200  QAbstractItemModel * model_,
201  const QModelIndex & index_) const;
202 
203 
204  virtual void updateEditorGeometry(QWidget * editor_,
205  const QStyleOptionViewItem & option_,
206  const QModelIndex & index_) const;
207 
208  // QSize sizeHint(const QStyleOptionViewItem & option_,
209  // const QModelIndex & index_) const;
210 
211  // void paint(QPainter * painter_,
212  // const QStyleOptionViewItem & option_,
213  // const QModelIndex & index_) const;
214 
217 
220 
221  private slots:
222 
223  QWidget * _create_boolean_editor(QWidget * parent_,
224  const QStyleOptionViewItem & option_,
225  const QModelIndex & index_,
226  const variant_record & var_rec_) const;
227 
228  QWidget * _create_integer_editor(QWidget * parent_,
229  const QStyleOptionViewItem & option_,
230  const QModelIndex & index_,
231  const variant_record & var_rec_) const;
232 
233  QWidget * _create_real_editor(QWidget * parent_,
234  const QStyleOptionViewItem & option_,
235  const QModelIndex & index_,
236  const variant_record & var_rec_) const;
237 
238  QWidget * _create_string_editor(QWidget * parent_,
239  const QStyleOptionViewItem & option_,
240  const QModelIndex & index_,
241  const variant_record & var_rec_) const;
242 
243  bool _set_boolean_editor_data(QWidget * editor_,
244  const QModelIndex & index_,
245  const variant_record & var_rec_) const;
246 
247  bool _set_integer_editor_data(QWidget * editor_,
248  const QModelIndex & index_,
249  const variant_record & var_rec_) const;
250 
251  bool _set_real_editor_data(QWidget * editor_,
252  const QModelIndex & index_,
253  const variant_record & var_rec_) const;
254 
255  bool _set_string_editor_data(QWidget * editor_,
256  const QModelIndex & index_,
257  const variant_record & var_rec_) const;
258 
259  // void _slot_path_edit_(const QModelIndex & index_);
260 
261  private:
262 
264  const variant_repository * _parent_repository_ = nullptr;
265 
266  };
267 
268  } // end of namespace ui
269 
270  } // end of namespace configuration
271 
272 } // end of namespace datatools
273 
274 #endif // DATATOOLS_CONFIGURATION_UI_PARAMETER_ITEM_DELEGATE_H
275 
276 // Local Variables: --
277 // mode: c++ --
278 // c-file-style: "gnu" --
279 // tab-width: 2 --
280 // End: --
Button to launch a real dialog widget.
Definition: parameter_item_delegate.h:65
datatools::logger::priority logging
Logging priority.
Definition: parameter_item_delegate.h:99
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
bool allowed_dynamically_enabled_values() const
Check if dynamically enabled values is allowed.
RealDialogLauncherButton(const QModelIndex &index_, const QString &button_text_="Set value", QWidget *parent_=0)
Constructor.
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
Button to launch a file dialog widget.
Definition: parameter_item_delegate.h:115
FileDialogLauncherButton(const QModelIndex &index_, const QString &button_text_="Choose file path", QWidget *parent_=0)
Constructor.
void setEditorData2(QWidget *editor_, const QModelIndex &index_) const
Set the initial value in the editor at given index.
virtual void updateEditorGeometry(QWidget *editor_, const QStyleOptionViewItem &option_, const QModelIndex &index_) const
virtual QWidget * createEditor(QWidget *parent_, const QStyleOptionViewItem &option_, const QModelIndex &index_) const
Create editor widget.
double get_unit_value() const
Return the unit value.
const datatools::configuration::variant_repository & get_parent_repository() const
Return the parent repository.
void signal_launch_file_dialog(const QModelIndex &index_)
void set_logging(datatools::logger::priority p_)
Set the logging priority.
Item delegate for parameter value.
Definition: parameter_item_delegate.h:160
datatools::logger::priority get_logging() const
Return the logging priority.
const std::string & get_unit_symbol() const
Return the unit symbol.
bool has_parent_repository() const
Check if the parent repository is set.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
Utilities for logging information.
void signal_launch_real_dialog(const QModelIndex &index_)
virtual void setModelData(QWidget *editor_, QAbstractItemModel *model_, const QModelIndex &index_) const
virtual void setEditorData(QWidget *editor_, const QModelIndex &index_) const
Set the initial value in the editor at given index.
datatools::logger::priority logging
Logging priority.
Definition: parameter_item_delegate.h:146
parameter_item_delegate(QObject *parent_=0)
Default constructor.
Variant registry record node.
Definition: variant_record.h:52
double get_value() const
Return the selected value.
void set_parent_repository(const datatools::configuration::variant_repository &)
Set the parent repository.
Variant repository.
Definition: variant_repository.h:57
Description/model of a configuration parameter.
Definition: parameter_model.h:60