Developer Documentation
objectSelectionWidget.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 "objectSelectionWidget.hh"
58 #include "objectPickDialog.hh"
59 
60 //== NAMESPACES ===============================================================
61 
62 //=============================================================================
63 //
64 // CLASS ObjectSelectionWidget - IMPLEMENTATION
65 //
66 //=============================================================================
67 
69 ObjectSelectionWidget::ObjectSelectionWidget(QMap< QString, QString > &_hints, QString /*_typeName*/, QWidget * /*_parent*/) :
70  QWidget(0),
71  pickButton_ (0),
72  combo_ (0)
73 {
74  int n_ok = 0;
75 
76  QHBoxLayout *hL = new QHBoxLayout;
77 
78  combo_ = new QComboBox ();
79  pickButton_ = new QPushButton (tr("Pick Object"));
80 
81  hL->addWidget (combo_);
82  hL->setStretchFactor (combo_, 1);
83  hL->addWidget (pickButton_);
84 
85  if (_hints.contains ("flags"))
86  flags_ = _hints["flags"].split(',');
87 
88  if (_hints.contains ("types"))
89  types_ = _hints["types"].split(',');
90 
91  if (flags_.contains("all", Qt::CaseInsensitive))
92  flags_.clear ();
93 
94  withGroups_ = types_.contains("Group");
95 
96  if (types_.contains("All"))
97  types_.clear ();
98 
99  setLayout (hL);
100 
101  connect (pickButton_, SIGNAL (pressed()), this, SLOT (showPickDialog ()));
102 
104 
105  bool ok = true;
106 
107  if (!flags_.empty ())
108  {
109  bool found = false;
110  foreach (QString flag, flags_)
111  if (o_it->flag (flag))
112  {
113  found = true;
114  break;
115  }
116 
117  if (!found)
118  ok = false;
119  }
120 
121  if (!types_.empty ())
122  {
123  if (!types_.contains (typeName (o_it->dataType())))
124  ok = false;
125  }
126 
127  if (o_it->isGroup() && !withGroups_)
128  continue;
129 
130  if (ok)
131  {
132  combo_->addItem (o_it->name() + " (" + QString::number (o_it->id ()) + ")", QVariant (o_it->id()));
133  n_ok++;
134  }
135  }
136 
137  if (n_ok < 2)
138  {
139  pickButton_->setEnabled (false);
140  combo_->setEnabled (false);
141  }
142 }
143 
146 {
148  o_it->setFlag("vsi_objectId_selected", false);
149  }
150 }
151 
152 //------------------------------------------------------------------------------
153 
154 void ObjectSelectionWidget::showPickDialog()
155 {
156  ObjectPickDialog d(flags_, types_, withGroups_);
157  d.selectedId (combo_->itemData (combo_->currentIndex()).toInt ());
158 
159  if (d.exec () == QDialog::Accepted)
160  combo_->setCurrentIndex (combo_->findData (QVariant (d.selectedId())));
161 }
162 
163 //------------------------------------------------------------------------------
164 
165 
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
unsigned int selectedId()
Current selected object.
ObjectSelectionWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
Definition: Types.cc:165
Core Data Iterator used to iterate over all objects (Including groups)