Developer Documentation
configValue.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 //== INCLUDES =================================================================
51 #include <QVBoxLayout>
52 #include <QFrame>
53 
54 #include "../scene/elementInput.hh"
55 #include "../parser/type.hh"
56 #include "../parser/element.hh"
57 #include "../parser/context.hh"
58 
59 #include "configValue.hh"
60 
61 //== NAMESPACES ===============================================================
62 namespace VSI {
63 
64 //=============================================================================
65 //
66 // CLASS VSI::ConfigValue - IMPLEMENTATION
67 //
68 //=============================================================================
69 
72  input_ (_input),
73  main_ (0),
74  constant_ (0),
75  optional_ (0),
76  forceAskUser_ (0),
77  buttonGroup_ (0)
78 {
79  group_ = new QGroupBox (_input->inOut ()->shortDescription ());
80  group_->setCheckable (false);
81 
82  Type *t = _input->inOut ()->element ()->context ()->getType (_input->inOut ()->typeString ());
83  if (!t)
84  return;
85 
86  QVBoxLayout *vL = new QVBoxLayout;
87  QHBoxLayout *hL = new QHBoxLayout;
88 
89  if (_input->state () & Input::Optional || !(_input->state () & Input::NoExternalInput) ||
90  !(_input->state () & Input::NoRuntimeUserInput))
91  {
92  QHBoxLayout *bL = new QHBoxLayout;
93  QString dI = (_input->state () & Input::NoExternalInput) ? "" : "Direct Input / ";
94 
95  buttonGroup_ = new QButtonGroup (this);
96 
97  constant_ = new QRadioButton ("Constant value");
98  if (_input->state () & Input::Optional)
99  {
100  optional_ = new QRadioButton (dI + "Optional");
101  if (!(_input->state () & Input::NoRuntimeUserInput))
102  {
103  forceAskUser_ = new QRadioButton ("Ask during execution");
104  buttonGroup_->addButton (forceAskUser_, 2);
105  }
106  }
107  else
108  optional_ = new QRadioButton (dI + "Ask during execution");
109  buttonGroup_->addButton (optional_, 0);
110  buttonGroup_->addButton (constant_, 1);
111 
112  bL->addWidget (optional_);
113  bL->addWidget (constant_);
114  if (forceAskUser_)
115  {
116  bL->addWidget (forceAskUser_);
117  buttonGroup_->addButton (forceAskUser_, 2);
118  }
119 
120  vL->addLayout (bL);
121 
122  QFrame *f = new QFrame ();
123 
124  f->setFrameStyle (QFrame::HLine | QFrame::Plain);
125  vL->addWidget (f);
126 
127  connect (buttonGroup_, SIGNAL (buttonClicked (int)),
128  this, SLOT (selectionChange()));
129  }
130 
131 
132  main_ = t->widget (_input->inOut ()->hints (), _input->inOut ()->typeString ());
133 
134  hL->addWidget (main_);
135  hL->setStretchFactor (main_, 2);
136 
137  QFrame *f = new QFrame ();
138 
139  f->setFrameStyle (QFrame::VLine | QFrame::Plain);
140  hL->addWidget (f);
141 
142  default_ = new QPushButton ("Default");
143  hL->addWidget (default_);
144 
145  vL->addLayout (hL);
146  vL->addStretch(1);
147  group_->setLayout (vL);
148 
149  if (_input->isSet ())
150  {
151  main_->fromValue (_input->value ());
152 
153  if (constant_)
154  constant_->setChecked (true);
155  }
156  else
157  {
158  if (!_input->value ().isEmpty ())
159  main_->fromValue (_input->value ());
160 
161  if (_input->isForceAskSet () && forceAskUser_)
162  {
163  forceAskUser_->setChecked (true);
164  main_->setEnabled (false);
165  default_->setEnabled (false);
166  }
167  else if (optional_)
168  {
169  optional_->setChecked (true);
170  main_->setEnabled (false);
171  default_->setEnabled (false);
172  }
173  }
174 
175  connect (default_, SIGNAL (pressed()), this, SLOT (toDefault()));
176 }
177 
178 //------------------------------------------------------------------------------
179 
182 {
183  if (main_)
184  delete main_;
185  delete group_;
186 }
187 
188 //------------------------------------------------------------------------------
189 
190 // reset to default
191 void ConfigValue::toDefault()
192 {
193  if (main_)
194  main_->toDefault ();
195 }
196 
197 //------------------------------------------------------------------------------
198 
199 void ConfigValue::selectionChange()
200 {
201 
202  if (constant_->isChecked())
203  {
204  main_->setEnabled (true);
205  default_->setEnabled (true);
206  }
207  else
208  {
209  main_->setEnabled (false);
210  default_->setEnabled (false);
211  }
212 }
213 
214 
215 //------------------------------------------------------------------------------
216 }
217 
QString typeString() const
Type.
Definition: inout.cc:71
virtual void fromValue(QString _from)=0
Set configuration to the value of the given string.
virtual TypeWidget * widget(QMap< QString, QString >, QString, QWidget *=NULL)
Returns the configuration widget.
Definition: type.hh:93
QMap< QString, QString > hints() const
Parsed hints for this input/output type.
Definition: inout.hh:88
Context * context() const
Context of element.
Definition: element.hh:85
bool isForceAskSet() const
Return "ForceAsk" flag.
ConfigValue(ElementInput *_input)
Constructor.
Definition: configValue.cc:71
virtual void toDefault()=0
reset the widget to default
const QString & shortDescription() const
Short description.
Definition: inout.hh:79
bool isSet()
Return "set" flag.
QString value() const
Returns value set by user.
Definition: elementInput.hh:96
~ConfigValue()
Destructor.
Definition: configValue.cc:181
InOut * inOut() const
InOut context object.
const Element * element() const
Element of this input/output.
Definition: inout.hh:85
Type * getType(QString _type)
Get type object for given type name.
Definition: context.cc:596
unsigned int state()
VSI::Input state passthrough.