Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
objectIdWidget.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 <QHBoxLayout>
52 #include <QPushButton>
53 #include <QComboBox>
54 
56 
57 #include "objectIdWidget.hh"
58 #include "objectPickDialog.hh"
59 
60 //== NAMESPACES ===============================================================
61 namespace VSI {
62 
63 //=============================================================================
64 //
65 // CLASS VSI::ObjectIdWidget - IMPLEMENTATION
66 //
67 //=============================================================================
68 
70 ObjectIdWidget::ObjectIdWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent) :
71  TypeWidget (_hints, _typeName, _parent),
72  pickButton_ (0),
73  combo_ (0)
74 {
75  int n_ok = 0;
76 
77  QHBoxLayout *hL = new QHBoxLayout;
78 
79  combo_ = new QComboBox ();
80  pickButton_ = new QPushButton (tr("Pick Object"));
81 
82  hL->addWidget (combo_);
83  hL->setStretchFactor (combo_, 1);
84  hL->addWidget (pickButton_);
85 
86  if (_hints.contains ("flags"))
87  flags_ = _hints["flags"].split(',');
88 
89  if (_hints.contains ("types"))
90  types_ = _hints["types"].split(',');
91 
92  if (flags_.contains("all", Qt::CaseInsensitive))
93  flags_.clear ();
94 
95  withGroups_ = types_.contains("Group");
96 
97  if (types_.contains("All"))
98  types_.clear ();
99 
100  setLayout (hL);
101 
102  connect (pickButton_, SIGNAL (pressed()), this, SLOT (showPickDialog ()));
103 
105 
106  bool ok = true;
107 
108  if (!flags_.empty ())
109  {
110  bool found = false;
111  foreach (QString flag, flags_)
112  if (o_it->flag (flag))
113  {
114  found = true;
115  break;
116  }
117 
118  if (!found)
119  ok = false;
120  }
121 
122  if (!types_.empty ())
123  {
124  if (!types_.contains (typeName (o_it->dataType())))
125  ok = false;
126  }
127 
128  if (o_it->isGroup() && !withGroups_)
129  continue;
130 
131  if (ok)
132  {
133  combo_->addItem (o_it->name() + " (" + QString::number (o_it->id ()) + ")", QVariant (o_it->id()));
134  n_ok++;
135  }
136  }
137 
138  if (n_ok < 2)
139  {
140  pickButton_->setEnabled (false);
141  combo_->setEnabled (false);
142  }
143 }
144 
147 {
149  o_it->setFlag("vsi_objectId_selected", false);
150  }
151 }
152 
153 //------------------------------------------------------------------------------
154 
157 {
158  if (combo_->count ())
159  {
160  return QString::number (combo_->itemData (combo_->currentIndex()).toInt ());
161  }
162  else
163  return 0;
164 }
165 
166 //------------------------------------------------------------------------------
167 
169 void ObjectIdWidget::fromValue(QString _from)
170 {
171  combo_->setCurrentIndex (combo_->findData (QVariant (_from.toInt ())));
172 }
173 
174 //------------------------------------------------------------------------------
175 
178 {
179  combo_->setCurrentIndex (0);
180 }
181 
182 //------------------------------------------------------------------------------
183 
184 void ObjectIdWidget::showPickDialog()
185 {
186  ObjectPickDialog d(flags_, types_, withGroups_);
187  d.selectedId (combo_->itemData (combo_->currentIndex()).toInt ());
188 
189  if (d.exec () == QDialog::Accepted)
190  combo_->setCurrentIndex (combo_->findData (QVariant (d.selectedId())));
191 }
192 
193 //------------------------------------------------------------------------------
194 }
195 
196 
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
Definition: Types.cc:165
~ObjectIdWidget()
Destructor.
Core Data Iterator used to iterate over all objects (Including groups)
void fromValue(QString _from)
Read value from string.
QString toValue()
Convert current value to string.
ObjectIdWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
void toDefault()
Reset to default.