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