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
49 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
50
51 #include "objectSelectionWidget.hh"
52 #include "objectPickDialog.hh"
53
54 //== NAMESPACES ===============================================================
55
56 //=============================================================================
57 //
58 // CLASS ObjectSelectionWidget - IMPLEMENTATION
59 //
60 //=============================================================================
61
63 ObjectSelectionWidget::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
97 for (PluginFunctions::BaseObjectIterator o_it; o_it != PluginFunctions::baseObjectsEnd(); ++o_it) {
98
99 bool ok = true;
100
101 if (!flags_.empty ())
102 {
103 bool found = false;
104 foreach (QString flag, flags_)
105 if (o_it->flag (flag))
106 {
107 found = true;
108 break;
109 }
110
111 if (!found)
112 ok = false;
113 }
114
115 if (!types_.empty ())
116 {
117 if (!types_.contains (typeName (o_it->dataType())))
118 ok = false;
119 }
120
121 if (o_it->isGroup() && !withGroups_)
122 continue;
123
124 if (ok)
125 {
126 combo_->addItem (o_it->name() + " (" + QString::number (o_it->id ()) + ")", QVariant (o_it->id()));
127 n_ok++;
128 }
129 }
130
131 if (n_ok < 2)
132 {
133 pickButton_->setEnabled (false);
134 combo_->setEnabled (false);
135 }
136 }
137
139 ObjectSelectionWidget::~ ObjectSelectionWidget()
140 {
141 for (PluginFunctions::BaseObjectIterator o_it; o_it != PluginFunctions::baseObjectsEnd(); ++o_it) {
142 o_it->setFlag("vsi_objectId_selected", false);
143 }
144 }
145
146 //------------------------------------------------------------------------------
147
148 void ObjectSelectionWidget::showPickDialog()
149 {
150 ObjectPickDialog d(flags_, types_, withGroups_);
151 d.selectedId (combo_->itemData (combo_->currentIndex()).toInt ());
152
153 if (d.exec () == QDialog::Accepted)
154 combo_->setCurrentIndex (combo_->findData (QVariant (d.selectedId())));
155 }
156
157 //------------------------------------------------------------------------------
158
159
ObjectPickDialog::selectedId
unsigned int selectedId()
Current selected object.
Definition: objectPickDialog.cc:198
PluginFunctions.hh
ObjectPickDialog
Definition: objectPickDialog.hh:69
PluginFunctions::BaseObjectIterator
Core Data Iterator used to iterate over all objects (Including groups)
Definition: PluginFunctions.hh:675
ObjectSelectionWidget::ObjectSelectionWidget
ObjectSelectionWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
Definition: objectSelectionWidget.cc:63
typeName
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
Definition: Types.cc:154
PluginFunctions::baseObjectsEnd
DLLEXPORT BaseObjectIterator baseObjectsEnd()
Return Iterator to Object End.
Definition: PluginFunctionsBaseIterator.cc:186