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 //== INCLUDES =================================================================
45 #include <QVBoxLayout>
46 #include <QFrame>
47
48 #include "../scene/elementInput.hh"
49 #include "../parser/type.hh"
50 #include "../parser/element.hh"
51 #include "../parser/context.hh"
52
53 #include "configValue.hh"
54
55 //== NAMESPACES ===============================================================
56 namespace VSI {
57
58 //=============================================================================
59 //
60 // CLASS VSI::ConfigValue - IMPLEMENTATION
61 //
62 //=============================================================================
63
65 ConfigValue::ConfigValue (ElementInput *_input) :
66 input_ (_input),
67 main_ (0),
68 constant_ (0),
69 optional_ (0),
70 forceAskUser_ (0),
71 buttonGroup_ (0)
72 {
73 group_ = new QGroupBox (_input->inOut ()->shortDescription ());
74 group_->setCheckable (false);
75
76 Type *t = _input->inOut ()->element ()->context ()->getType (_input->inOut ()->typeString ());
77 if (!t)
78 return;
79
80 QVBoxLayout *vL = new QVBoxLayout;
81 QHBoxLayout *hL = new QHBoxLayout;
82
83 if (_input->state () & Input::Optional || !(_input->state () & Input::NoExternalInput) ||
84 !(_input->state () & Input::NoRuntimeUserInput))
85 {
86 QHBoxLayout *bL = new QHBoxLayout;
87 QString dI = (_input->state () & Input::NoExternalInput) ? "" : "Direct Input / ";
88
89 buttonGroup_ = new QButtonGroup (this);
90
91 constant_ = new QRadioButton ("Constant value");
92 if (_input->state () & Input::Optional)
93 {
94 optional_ = new QRadioButton (dI + "Optional");
95 if (!(_input->state () & Input::NoRuntimeUserInput))
96 {
97 forceAskUser_ = new QRadioButton ("Ask during execution");
98 buttonGroup_->addButton (forceAskUser_, 2);
99 }
100 }
101 else
102 optional_ = new QRadioButton (dI + "Ask during execution");
103 buttonGroup_->addButton (optional_, 0);
104 buttonGroup_->addButton (constant_, 1);
105
106 bL->addWidget (optional_);
107 bL->addWidget (constant_);
108 if (forceAskUser_)
109 {
110 bL->addWidget (forceAskUser_);
111 buttonGroup_->addButton (forceAskUser_, 2);
112 }
113
114 vL->addLayout (bL);
115
116 QFrame *f = new QFrame ();
117
118 f->setFrameStyle (QFrame::HLine | QFrame::Plain);
119 vL->addWidget (f);
120
121 connect (buttonGroup_, SIGNAL (buttonClicked (int)),
122 this, SLOT (selectionChange()));
123 }
124
125
126 main_ = t->widget (_input->inOut ()->hints (), _input->inOut ()->typeString ());
127
128 hL->addWidget (main_);
129 hL->setStretchFactor (main_, 2);
130
131 QFrame *f = new QFrame ();
132
133 f->setFrameStyle (QFrame::VLine | QFrame::Plain);
134 hL->addWidget (f);
135
136 default_ = new QPushButton ("Default");
137 hL->addWidget (default_);
138
139 vL->addLayout (hL);
140 vL->addStretch(1);
141 group_->setLayout (vL);
142
143 if (_input->isSet ())
144 {
145 main_->fromValue (_input->value ());
146
147 if (constant_)
148 constant_->setChecked (true);
149 }
150 else
151 {
152 if (!_input->value ().isEmpty ())
153 main_->fromValue (_input->value ());
154
155 if (_input->isForceAskSet () && forceAskUser_)
156 {
157 forceAskUser_->setChecked (true);
158 main_->setEnabled (false);
159 default_->setEnabled (false);
160 }
161 else if (optional_)
162 {
163 optional_->setChecked (true);
164 main_->setEnabled (false);
165 default_->setEnabled (false);
166 }
167 }
168
169 connect (default_, SIGNAL (pressed()), this, SLOT (toDefault()));
170 }
171
172 //------------------------------------------------------------------------------
173
175 ConfigValue::~ ConfigValue ()
176 {
177 if (main_)
178 delete main_;
179 delete group_;
180 }
181
182 //------------------------------------------------------------------------------
183
184 // reset to default
185 void ConfigValue::toDefault()
186 {
187 if (main_)
188 main_->toDefault ();
189 }
190
191 //------------------------------------------------------------------------------
192
193 void ConfigValue::selectionChange()
194 {
195
196 if (constant_->isChecked())
197 {
198 main_->setEnabled (true);
199 default_->setEnabled (true);
200 }
201 else
202 {
203 main_->setEnabled (false);
204 default_->setEnabled (false);
205 }
206 }
207
208
209 //------------------------------------------------------------------------------
210 }
211
VSI::InOut::hints
QMap< QString, QString > hints() const
Parsed hints for this input/output type.
Definition: inout.hh:82
VSI::ElementInOut::inOut
InOut * inOut() const
InOut context object.
Definition: elementInOut.hh:110
VSI::Type::widget
virtual TypeWidget * widget(QMap< QString, QString >, QString, QWidget *=NULL)
Returns the configuration widget.
Definition: type.hh:87
VSI::ElementInput::state
unsigned int state()
VSI::Input state passthrough.
Definition: elementInput.cc:128
VSI::Type
Definition: type.hh:65
VSI::ElementInput::value
QString value() const
Returns value set by user.
Definition: elementInput.hh:90
VSI::ElementInput
Definition: elementInput.hh:67
VSI::InOut::element
const Element * element() const
Element of this input/output.
Definition: inout.hh:79
VSI::InOut::typeString
QString typeString() const
Type.
Definition: inout.cc:65
VSI::TypeWidget::fromValue
virtual void fromValue(QString _from)=0
Set configuration to the value of the given string.
VSI::Context::getType
Type * getType(QString _type)
Get type object for given type name.
Definition: context.cc:590
VSI::ElementInput::isSet
bool isSet()
Return "set" flag.
Definition: elementInput.cc:199
VSI::ConfigValue::ConfigValue
ConfigValue(ElementInput *_input)
Constructor.
Definition: configValue.cc:65
VSI::Element::context
Context * context() const
Context of element.
Definition: element.hh:79
VSI::TypeWidget::toDefault
virtual void toDefault()=0
reset the widget to default
VSI
Definition: baseWidget.cc:72
VSI::ElementInput::isForceAskSet
bool isForceAskSet() const
Return "ForceAsk" flag.
Definition: elementInput.hh:108
VSI::InOut::shortDescription
const QString & shortDescription() const
Short description.
Definition: inout.hh:73