MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
abstract3Dtreeitem.cpp
Go to the documentation of this file.
1//=============================================================================================================
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "abstract3Dtreeitem.h"
40#include "../common/metatreeitem.h"
41
42//=============================================================================================================
43// QT INCLUDES
44//=============================================================================================================
45
46#include <Qt3DExtras/QPhongMaterial>
47
48//=============================================================================================================
49// EIGEN INCLUDES
50//=============================================================================================================
51
52//=============================================================================================================
53// USED NAMESPACES
54//=============================================================================================================
55
56using namespace DISP3DLIB;
57
58//=============================================================================================================
59// DEFINE MEMBER METHODS
60//=============================================================================================================
61
62Abstract3DTreeItem::Abstract3DTreeItem(QEntity* p3DEntityParent, int iType, const QString& text)
63: QStandardItem(text)
64, Renderable3DEntity(p3DEntityParent)
65, m_iType(iType)
66{
67 initItem();
68}
69
70//=============================================================================================================
71
73{
74 this->setToolTip("Abstract 3D Tree Item");
75
76 //Transformation
77 QList<QStandardItem*> list;
78 QVariant data;
79
81 m_pItemTransformationOptions = new MetaTreeItem(MetaTreeItemTypes::UnknownItem, "Transformation");
82 }
83
84 m_pItemTransformationOptions->setEditable(false);
85 list.clear();
87 list << new QStandardItem("The transformation options");
88 this->appendRow(list);
89
90 MetaTreeItem *itemXTrans = new MetaTreeItem(MetaTreeItemTypes::TranslateX, QString::number(0));
91 itemXTrans->setEditable(true);
92 connect(itemXTrans, &MetaTreeItem::dataChanged,
94 list.clear();
95 list << itemXTrans;
96 list << new QStandardItem(itemXTrans->toolTip());
97 m_pItemTransformationOptions->appendRow(list);
98
99 MetaTreeItem *itemYTrans = new MetaTreeItem(MetaTreeItemTypes::TranslateY, QString::number(0));
100 itemYTrans->setEditable(true);
101 connect(itemYTrans, &MetaTreeItem::dataChanged,
103 list.clear();
104 list << itemYTrans;
105 list << new QStandardItem(itemYTrans->toolTip());
106 m_pItemTransformationOptions->appendRow(list);
107
108 MetaTreeItem *itemZTrans = new MetaTreeItem(MetaTreeItemTypes::TranslateZ, QString::number(0));
109 itemZTrans->setEditable(true);
110 connect(itemZTrans, &MetaTreeItem::dataChanged,
112 list.clear();
113 list << itemZTrans;
114 list << new QStandardItem(itemZTrans->toolTip());
115 m_pItemTransformationOptions->appendRow(list);
116
117 float fScale = 1.0f;
118 MetaTreeItem *itemScale = new MetaTreeItem(MetaTreeItemTypes::Scale, QString::number(fScale));
119 itemScale->setEditable(true);
120 connect(itemScale, &MetaTreeItem::dataChanged,
122 list.clear();
123 list << itemScale;
124 list << new QStandardItem(itemZTrans->toolTip());
125 data.setValue(fScale);
126 itemScale->setData(data, MetaTreeItemRoles::Scale);
127 m_pItemTransformationOptions->appendRow(list);
128
129 //Color
131 m_pItemAppearanceOptions = new MetaTreeItem(MetaTreeItemTypes::UnknownItem, "Appearance");
132 }
133
134 m_pItemAppearanceOptions->setEditable(false);
135 list.clear();
137 list << new QStandardItem("The color options");
138 this->appendRow(list);
139
140 float fAlpha = 0.75f;
141 MetaTreeItem *itemAlpha = new MetaTreeItem(MetaTreeItemTypes::AlphaValue, QString("%1").arg(fAlpha));
142 connect(itemAlpha, &MetaTreeItem::dataChanged,
144 list.clear();
145 list << itemAlpha;
146 list << new QStandardItem(itemAlpha->toolTip());
147 m_pItemAppearanceOptions->appendRow(list);
148 data.setValue(fAlpha);
149 itemAlpha->setData(data, MetaTreeItemRoles::AlphaValue);
150
151 MetaTreeItem* pItemSurfCol = new MetaTreeItem(MetaTreeItemTypes::Color, "Color");
152 connect(pItemSurfCol, &MetaTreeItem::dataChanged,
154 list.clear();
155 list << pItemSurfCol;
156 list << new QStandardItem(pItemSurfCol->toolTip());
157 m_pItemAppearanceOptions->appendRow(list);
158 data.setValue(QColor(100,100,100));
159 pItemSurfCol->setData(data, MetaTreeItemRoles::Color);
160 pItemSurfCol->setData(data, Qt::DecorationRole);
161
162 //Do the connects
165}
166
167//=============================================================================================================
168
169void Abstract3DTreeItem::setData(const QVariant& value, int role)
170{
171 QStandardItem::setData(value, role);
172
173 switch(role) {
174 case Qt::CheckStateRole:{
175 emit checkStateChanged(this->checkState());
176 break;
177 }
178 }
179}
180
181//=============================================================================================================
182
183int Abstract3DTreeItem::type() const
184{
185 return m_iType;
186}
187
188//=============================================================================================================
189
190QList<QStandardItem*> Abstract3DTreeItem::findChildren(int type)
191{
192 QList<QStandardItem*> itemList;
193
194 if(this->hasChildren()) {
195 for(int row = 0; row<this->rowCount(); row++) {
196 for(int col = 0; col<this->columnCount(); col++) {
197 if(this->child(row, col)->type() == type) {
198 itemList.append(this->child(row, col));
199 }
200 }
201 }
202 }
203
204 return itemList;
205}
206
207//=============================================================================================================
208
209QList<QStandardItem*> Abstract3DTreeItem::findChildren(const QString& text)
210{
211 QList<QStandardItem*> itemList;
212
213 if(this->hasChildren()) {
214 for(int row = 0; row<this->rowCount(); row++) {
215 for(int col = 0; col<this->columnCount(); col++) {
216 if(this->child(row, col)->text() == text) {
217 itemList.append(this->child(row, col));
218 }
219 }
220 }
221 }
222
223 return itemList;
224}
225
226//=============================================================================================================
227
229{
230 this->appendRow(newItem);
231
232 return *this;
233}
234
235//=============================================================================================================
236
238{
239 this->appendRow(&newItem);
240
241 return *this;
242}
243
244//=============================================================================================================
245
246Eigen::MatrixX4f Abstract3DTreeItem::createVertColor(int numVert, const QColor& color)
247{
248 Eigen::MatrixX4f matColor(numVert,4);
249
250 for(int i = 0; i < numVert; ++i) {
251 matColor(i,0) = color.redF();
252 matColor(i,1) = color.greenF();
253 matColor(i,2) = color.blueF();
254 matColor(i,3) = color.alphaF();
255 }
256
257 return matColor;
258}
259
260//=============================================================================================================
261
263{
264 QVariant data;
265 data.setValue(fAlpha);
266
267 onAlphaChanged(data);
268}
269
270//=============================================================================================================
271
272void Abstract3DTreeItem::onCheckStateChanged(const Qt::CheckState& checkState)
273{
274 for(int i = 0; i<this->rowCount(); i++) {
275 if(this->child(i)->isCheckable()) {
276 this->child(i)->setCheckState(checkState);
277 }
278 }
279
280 this->setVisible(checkState == Qt::Unchecked ? false : true);
281}
282
283//=============================================================================================================
284
285void Abstract3DTreeItem::onTranslationXChanged(const QVariant& fTransX)
286{
287 if(fTransX.canConvert<float>()) {
288 QVector3D position = this->position();
289 position.setX(fTransX.toFloat());
290 this->setPosition(position);
291 }
292}
293
294//=============================================================================================================
295
296void Abstract3DTreeItem::onTranslationYChanged(const QVariant& fTransY)
297{
298 if(fTransY.canConvert<float>()) {
299 QVector3D position = this->position();
300 position.setY(fTransY.toFloat());
301 this->setPosition(position);
302 }
303}
304
305//=============================================================================================================
306
307void Abstract3DTreeItem::onTranslationZChanged(const QVariant& fTransZ)
308{
309 if(fTransZ.canConvert<float>()) {
310 QVector3D position = this->position();
311 position.setZ(fTransZ.toFloat());
312 this->setPosition(position);
313 }
314}
315
316//=============================================================================================================
317
318void Abstract3DTreeItem::onScaleChanged(const QVariant& fScale)
319{
320 if(fScale.canConvert<float>()) {
321 this->setScale(fScale.toFloat());
322 }
323}
324
325//=============================================================================================================
326
327void Abstract3DTreeItem::onColorChanged(const QVariant& color)
328{
329 //ka = ambient for standard QT materials, overlaod onColorchanged() if you use your own materials (i.e. fssurfacetreeitem)
330 this->setMaterialParameter(color, "ka");
331}
332
333//=============================================================================================================
334
335void Abstract3DTreeItem::onAlphaChanged(const QVariant& fAlpha)
336{
337 this->setMaterialParameter(fAlpha, "alpha");
338}
339
Abstract3DTreeItem class declaration.
Base class for renederable 3D QEntities.
virtual void setVisible(bool state)
virtual void setScale(float scale)
virtual void setPosition(const QVector3D &position)
virtual void setMaterialParameter(const QVariant &data, const QString &sParameterName)
Provides the basic tree item.
QPointer< MetaTreeItem > m_pItemTransformationOptions
virtual void onTranslationZChanged(const QVariant &fTransZ)
virtual void onAlphaChanged(const QVariant &fAlpha)
virtual void onTranslationXChanged(const QVariant &fTransX)
QList< QStandardItem * > findChildren(int type)
static Eigen::MatrixX4f createVertColor(int numVert, const QColor &color=QColor(0, 49, 69))
virtual void onCheckStateChanged(const Qt::CheckState &checkState)
Abstract3DTreeItem & operator<<(Abstract3DTreeItem *newItem)
virtual void onTranslationYChanged(const QVariant &fTransY)
void checkStateChanged(const Qt::CheckState &checkState)
virtual void onScaleChanged(const QVariant &fScale)
Abstract3DTreeItem(QEntity *p3DEntityParent=0, int iType=Data3DTreeModelItemTypes::UnknownItem, const QString &text="")
void setData(const QVariant &value, int role=Qt::UserRole+1)
virtual void onColorChanged(const QVariant &color)
QPointer< MetaTreeItem > m_pItemAppearanceOptions
Provides a generic brain tree item.
void dataChanged(const QVariant &data)
void setData(const QVariant &value, int role=Qt::UserRole+1)