Developer documentation | Axl-2.5.1

axlInspectorObjectManagerTree.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectManagerTree.cpp ---
2  *
3  * Author: Julien Wintz
4  * Copyright (C) 2008 - Julien Wintz, Inria.
5  * Created: Thu Mar 17 18:34:33 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Wed Nov 9 14:19:15 2011 (+0100)
8  * By: Julien Wintz
9  * Update #: 46
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
21 
25 
28 
29 #include <dtkCoreSupport/dtkAbstractData.h>
30 #include <axlCore/axlDataDynamic.h>
31 #include <axlCore/axlDouble.h>
32 #include <axlCore/axlInteger.h>
33 
34 class axlInspectorObjectManagerTreePrivate
35 {
36 public:
37  axlInspectorObjectController *scene_manager;
38 
39  QHash<dtkAbstractData *, QString> treeWidgetItem;
40 
41  bool append;
42 };
43 
44 axlInspectorObjectManagerTree::axlInspectorObjectManagerTree(QWidget *parent) : QTreeWidget(parent), d(new axlInspectorObjectManagerTreePrivate)
45 {
46  this->setAttribute(Qt::WA_MacShowFocusRect, false);
47  this->setCursor(Qt::ArrowCursor);
48  this->setFrameShape(QFrame::NoFrame);
49  this->setHeaderLabels(QStringList() << "Object" << "Type" << "Mode" << "");
50  this->header()->setSectionsClickable(true);
51  this->setColumnWidth(0, 50);
52  this->setColumnWidth(1, 50);
53  this->setColumnWidth(2, 50);
54  this->setColumnWidth(3, 16);
55  this->setSelectionMode(QAbstractItemView::ExtendedSelection);
56 
57  d->append = false;
58  connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(onAllItemClickStatedChanged()));
59  connect(this, SIGNAL(itemExpanded(QTreeWidgetItem *)),this, SLOT(onItemExpanded(QTreeWidgetItem *)));
60  connect(this, SIGNAL(itemDoubleClicked(QTreeWidgetItem *,int)), this, SLOT(onDoubleClickStateChanged(QTreeWidgetItem *,int)));
61  connect(this, SIGNAL(itemClicked(QTreeWidgetItem *,int)), this, SLOT(onItemClickedStateChanged(QTreeWidgetItem *,int)));
62  connect(this->header(),SIGNAL(sectionClicked(int)), this, SLOT(onVisibilityHeaderClick(int)));
63 }
64 
66 {
67  delete d;
68 
69  d = NULL;
70 }
71 
73 {
74  d->scene_manager = controller;
75  connect(d->scene_manager, SIGNAL(inserted()), this, SIGNAL(inserted()));
76 }
77 
79  if (!(index == 3))
80  return;
81 
82  bool showAll = 1;
83  axlInspectorObjectManagerTreeItem *axlCurrentItem;
84 
85  // if at least one visible -> hide all, if all hidden -> show all
86  for (int i = 0; i<this->topLevelItemCount(); i++){
87  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(this->topLevelItem(i));
88  if (axlCurrentItem->checkState(3) == Qt::Checked){
89  showAll = 0;
90  break;
91  }
92  }
93 
94  for (int i = 0; i<this->topLevelItemCount(); i++){
95  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(this->topLevelItem(i));
96  axlCurrentItem->setCheckState(3,showAll ? Qt::Checked:Qt::Unchecked);
97  itemVisibilityChanged(this->topLevelItem(i), showAll);
98  }
99 
100 }
101 
102 void axlInspectorObjectManagerTree::remove(dtkAbstractData *data)
103 {
104  if(!data) {
105  qDebug() << DTK_PRETTY_FUNCTION << "data is NULL";
106  }
107 
108  if(dynamic_cast<axlDataDynamic *>(data)){
109  axlDataDynamic *axldata = dynamic_cast<axlDataDynamic *>(data);
110  disconnect(axldata, SIGNAL(destroyed(QObject *)),this, SLOT(remove(QObject*)));
111  }
112  axlInspectorObjectManagerTreeItem *item = d->scene_manager->item(data);
113  delete item;
114  d->scene_manager->remove(data);
115  d->treeWidgetItem.remove(data);
116 
117  //update data is the data come from a composite
118  if(axlAbstractDataComposite *composite = dynamic_cast<axlAbstractDataComposite *>(data->parent()))
119  {
120  composite->remove(data);
121  }
122 }
123 
125 {
126 
127  if(!data) {
128  qDebug() << DTK_PRETTY_FUNCTION << "data is NULL";
129  }
130 
131  if(axlDataDynamic *axldata = dynamic_cast<axlDataDynamic *>(data)){
132 
133  disconnect(axldata, SIGNAL(destroyed(QObject *)),this, SLOT(remove(QObject*)));
134  axlInspectorObjectManagerTreeItem *item = d->scene_manager->item(axldata);
135  delete item;
136 
137  QList<dtkAbstractData *> dataRemoved;
138  dataRemoved << axldata;
139  emit dataSetRemoved(dataRemoved);
140 
141  d->scene_manager->remove(axldata);
142  d->treeWidgetItem.remove(axldata);
143 
144 
145  }
146 }
147 
148 void axlInspectorObjectManagerTree::onDataRemoved(QList<dtkAbstractData *> dataToRemoved)
149 {
150 
151  foreach(dtkAbstractData *data, dataToRemoved)
152  this->remove(data);
153 }
154 
155 
157 {
158  if(!data) {
159  qDebug() << DTK_PRETTY_FUNCTION << "data is NULL";
161  }
162 
163  QString treeItemNameObject = data->objectName();
164  int numOcurrence = d->treeWidgetItem.count(d->treeWidgetItem.key(data->objectName()));
165 
166  if(treeItemNameObject == data->identifier() || numOcurrence > 0)
167  //if(numOcurrence > 0)
168  {
169  treeItemNameObject += QString::number(d->treeWidgetItem.size());
170  }
171 
172  QString typeQString = data->identifier();
173  if (axlDataDynamic *dataDynamic = dynamic_cast<axlDataDynamic *>(data)){
174  if(dataDynamic->process() && dataDynamic->outputs()){
175  typeQString = dataDynamic->process()->identifier();
176  typeQString.remove("axl");
177  typeQString.remove("abstract");
178 
179  }else{
180  qDebug() << Q_FUNC_INFO << "this dynamic data has no process available";
182  }
183 
184  }
185 
186 
187  axlInspectorObjectManagerTreeItem *item = new axlInspectorObjectManagerTreeItem(this, QStringList() << treeItemNameObject << typeQString << "Passive" << "");
188  item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
189  item->setCheckState(3, Qt::Checked);
190  item->setToolTip(0,data->description());
191  item->setToolTip(1,data->description());
192  item->setToolTip(2,data->description());
193  item->setToolTip(3,data->description());
194 
195  d->scene_manager->insert(data, item);
196  d->treeWidgetItem.insert(data, treeItemNameObject);
197  data->setObjectName(treeItemNameObject);
198 
199  if(axlDataDynamic *dataDynamic = dynamic_cast<axlDataDynamic *>(data)){
200  connect(dataDynamic, SIGNAL(destroyed(QObject *)),this, SLOT(remove(QObject*)));
201 
202  // //output name
203  // if(dataDynamic->outputs()){
204  // QString outputnameObject = dataDynamic->outputs()->objectName();
205  // outputnameObject+=QString::number(d->treeWidgetItem.size());
206  // dataDynamic->outputs()->setObjectName(outputnameObject);
207  // }
208 
209  // double inputs name, the same as the dynamic object
210  foreach(axlAbstractData *axlData, dataDynamic->inputs()){
211  if(dynamic_cast<axlDouble *>(axlData)){
212  axlData->setObjectName(data->name());
213  }
214  }
215  }
216 
217  //add child if data type is composite
218 
219  if(axlAbstractDataComposite *composite = dynamic_cast<axlAbstractDataComposite *>(data))
220  {
221  for(int i = 0; i < composite->count(); i++)
222  {
223  dtkAbstractData *compositeChild = composite->get(i);
225  itemChild->setFlags( Qt::ItemIsEnabled |Qt::ItemIsSelectable | Qt::ItemIsUserCheckable );
226  itemChild->setCheckState(3, Qt::Checked);
227  itemChild->setText(0, compositeChild->objectName());
228  //itemChild->setText(1, "Data");
229  itemChild->setText(1, compositeChild->identifier());
230  itemChild->setText(2, "Passive");
231  itemChild->setText(3, "");
232  itemChild->setToolTip(0,compositeChild->description());
233  itemChild->setToolTip(1,compositeChild->description());
234  itemChild->setToolTip(2,compositeChild->description());
235  itemChild->setToolTip(3,compositeChild->description());
236  d->scene_manager->insert(compositeChild, itemChild);
237  d->treeWidgetItem.insert(compositeChild, compositeChild->objectName());
238 
239  }
240  }
241 
242  // init of color child
243  /*axlInspectorObjectManagerTreeItem *colorItem = new axlInspectorObjectManagerTreeItem(item);
244  colorItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEditable);
245  colorItem->setText(0, "Color");
246  colorItem->setText(1, "0");
247  colorItem->setText(2, "0");
248  colorItem->setText(3, "0");
249  QColor color(colorItem->text(1).toInt(), colorItem->text(2).toInt(), colorItem->text(3).toInt());
250  colorItem->setBackgroundColor(1, color);
251 
252  // init of shader child
253  axlInspectorObjectManagerTreeItem *shaderItem = new axlInspectorObjectManagerTreeItem(item);
254  shaderItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEditable);
255  shaderItem->setText(0, "Shader");*/
256 
257 
258 
259  return item;
260 }
261 
263 {
264  axlInspectorObjectManagerTreeItem *currentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(item);
265 
266  dtkAbstractData *data = d->scene_manager->data(currentItem);
267 
268 
269  if(currentItem->text(2) != "Editable"){
270  if(dynamic_cast<axlAbstractData *>(data)->editable())
271  emit stateChanged(data, 2);
272  }
273 
274  this->updateAxlTreeWidgetItem(currentItem, 2);
275 
276 
277 }
278 
279 QList<dtkAbstractData *> axlInspectorObjectManagerTree::dataSet(void)
280 {
281  QList<dtkAbstractData *> dataSet;
282  for(int i = 0; i < this->topLevelItemCount(); i++)
283  {
284  dataSet << d->treeWidgetItem.key(this->topLevelItem(i)->text(0));
285  }
286 
287  return dataSet;
288 }
289 
290 void axlInspectorObjectManagerTree::onStateChanged(dtkAbstractData *data, int mode)
291 {
292  axlInspectorObjectManagerTreeItem *currentItem = d->scene_manager->item(data);
293 
294  disconnect(this, SIGNAL(itemSelectionChanged()), this, SLOT(onAllItemClickStatedChanged()));
295 
296  this->updateAxlTreeWidgetItem(currentItem,mode);
297 
298  connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(onAllItemClickStatedChanged()));
299 
300 
301  axlInspectorObjectManagerTreeItem *axlCurrentItem = NULL;
302  dtkAbstractData *currentData = NULL;
303 
304  // Creation on a list of dtkAbstractData in correspondance with the selectedItems list
305  QList<dtkAbstractData *> dataSelected;
306 
307  for(int i = 0; i < this->topLevelItemCount(); i++)
308  {
309  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(this->topLevelItem(i));
310 
311  if(!axlCurrentItem)
312  return;
313 
314  //if(axlCurrentItem->checkState(3) && axlCurrentItem->isSelected() && (axlCurrentItem->text(2) == "Passive" || axlCurrentItem->text(2) == "Selected") )
315  if(axlCurrentItem->checkState(3) && axlCurrentItem->isSelected() && (axlCurrentItem->text(2) == "Passive" || axlCurrentItem->text(2) == "Selected") )
316 
317  {
318  currentData = d->scene_manager->data(axlCurrentItem);
319  dataSelected.push_back(currentData);
320  }
321 
322 
323  for(int j = 0 ; j < axlCurrentItem->childCount(); j++)
324  {
325  axlInspectorObjectManagerTreeItem *axlCurrentItemChild = dynamic_cast<axlInspectorObjectManagerTreeItem *>(axlCurrentItem->child(j));
326 
327  if(!axlCurrentItemChild)
328  return;
329 
330  // if(axlCurrentItemChild->checkState(3) && axlCurrentItemChild->isSelected() && (axlCurrentItemChild->text(2) == "Passive" || axlCurrentItemChild->text(2) == "Selected") )
331  if(axlCurrentItemChild->checkState(3) && axlCurrentItemChild->isSelected())
332  {
333  currentData = d->scene_manager->data(axlCurrentItemChild);
334  dataSelected.push_back(currentData);
335  }
336  }
337  }
338  if(dataSelected.size() != 0)
339  emit dataSetSelected(dataSelected);
340 
341 }
342 
343 
344 void axlInspectorObjectManagerTree::onDoubleClickStateChanged(QTreeWidgetItem* currentItem, int column)
345 {
346  axlInspectorObjectManagerTreeItem *axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(currentItem);
347 
348  if(!axlCurrentItem)
349  return;
350 
351  dtkAbstractData *data = d->scene_manager->data(axlCurrentItem);
352  if(!data)
353  return;
354 
355 
356  if(axlCurrentItem->checkState(3) && column != 3)
357  {
358  if(axlCurrentItem->text(2) == "Passive")
359  {
360  this->updateAxlTreeWidgetItem(axlCurrentItem, 2);
361 
362  emit stateChanged(data, 2);
363  }
364  else if(axlCurrentItem->text(2) == "Selected")
365  {
366  this->updateAxlTreeWidgetItem(axlCurrentItem, 2);
367 
368  emit stateChanged(data, 2);
369 
370  }
371  else if(axlCurrentItem->text(2) == "Editable")
372  {
373  this->updateAxlTreeWidgetItem(axlCurrentItem, 1);
374 
375  emit stateChanged(data, 1);
376 
377  }
378  }
379 }
380 
382 {
383  QTreeWidgetItem *currentItem = NULL;
384  QTreeWidgetItem *currentItemChild = NULL;
385  axlInspectorObjectManagerTreeItem *axlCurrentItem = NULL;
386  dtkAbstractData *data = NULL;
387 
388  // Creation on a list of dtkAbstractData in correspondance with the selectedItems list
389  QList<dtkAbstractData *> dataSelected;
390 
391  for(int i = 0; i < this->topLevelItemCount(); i++)
392  {
393  currentItem = this->topLevelItem(i);
394  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(currentItem);
395 
396  if(!axlCurrentItem)
397  return;
398 
399  if(axlCurrentItem->checkState(3) && axlCurrentItem->isSelected() && (axlCurrentItem->text(2) == "Passive" || axlCurrentItem->text(2) == "Selected") )
400  {
401  this->updateAxlTreeWidgetItem(axlCurrentItem, 1);
402  data = d->scene_manager->data(axlCurrentItem);
403  dataSelected.push_back(data);
404 
405  emit stateChanged(data, 1);
406  //emit selected(data);
407  }
408  else if(axlCurrentItem->checkState(3) && (!axlCurrentItem->isSelected()) && (axlCurrentItem->text(2) == "Selected" || axlCurrentItem->text(2) == "Editable"))
409  {
410  data = d->scene_manager->data(axlCurrentItem);
411  axlAbstractDataComposite *dataComposite = dynamic_cast<axlAbstractDataComposite *>(data);
412  if(dataComposite != NULL && axlCurrentItem->text(2) == "Editable"){}
413  else
414  {
415  this->updateAxlTreeWidgetItem(axlCurrentItem, 0);
416 
417  emit stateChanged(data, 0);
418  }
419  }
420  for(int j = 0 ; j < currentItem->childCount(); j++)
421  {
422  currentItemChild = currentItem->child(j);
423  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(currentItemChild);
424 
425  if(!axlCurrentItem)
426  return;
427 
428  if(axlCurrentItem->checkState(3) && axlCurrentItem->isSelected() && (axlCurrentItem->text(2) == "Passive" || axlCurrentItem->text(2) == "Selected") )
429  {
430  this->updateAxlTreeWidgetItem(axlCurrentItem, 1);
431  data = d->scene_manager->data(axlCurrentItem);
432  dataSelected.push_back(data);
433 
434  emit stateChanged(data, 1);
435  //emit selected(data);
436  }
437  else if(axlCurrentItem->checkState(3) && (!axlCurrentItem->isSelected()) && (axlCurrentItem->text(2) == "Selected" || axlCurrentItem->text(2) == "Editable"))
438  {
439  this->updateAxlTreeWidgetItem(axlCurrentItem, 0);
440  data = d->scene_manager->data(axlCurrentItem);
441 
442  emit stateChanged(data, 0);
443  }
444  }
445 
446  }
447 
448 
449  emit dataSetSelected(dataSelected);
450 }
451 
452 void axlInspectorObjectManagerTree::onItemClickedStateChanged(QTreeWidgetItem *currentItem, int column)
453 {
454  axlInspectorObjectManagerTreeItem *axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(currentItem);
455  /*axlInspectorObjectManagerTreeItem *axlFatherCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(currentItem->parent());
456 
457  dtkAbstractData *dataFather = NULL;
458 
459  this->updateAxlTreeWidgetItem(axlFatherCurrentItem, 2);
460  dataFather = d->scene_manager->data(axlFatherCurrentItem);
461  emit stateChanged(dataFather, 2);*/
462 
463  if(!axlCurrentItem)
464  return;
465 
466  dtkAbstractData *data = d->scene_manager->data(axlCurrentItem);
467 
468  if(!data)
469  return;
470 
471 
472  if(column == 3){
473  itemVisibilityChanged(currentItem, (axlCurrentItem->checkState(3) == Qt::Checked));
474  //emit actorVisibilityChanged(data, axlCurrentItem->checkState(3));
475  }
476 
477  //emit selected(data);
478 }
479 
480 void axlInspectorObjectManagerTree::itemVisibilityChanged(QTreeWidgetItem *currentItem, bool itemVisibility)
481 {
482  if(currentItem->childCount() == 0)
483  {
484  axlInspectorObjectManagerTreeItem *axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(currentItem);
485  dtkAbstractData *data = d->scene_manager->data(axlCurrentItem);
486  emit actorVisibilityChanged(data, itemVisibility);
487  }
488  else
489  {
490 
491  axlInspectorObjectManagerTreeItem *axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(currentItem);
492  dtkAbstractData *data = d->scene_manager->data(axlCurrentItem);
493  if(dynamic_cast<axlDataDynamic *>(data)){
494  emit actorVisibilityChanged(data, itemVisibility);
495  }else{
496  delete data;
497  delete axlCurrentItem;
498  }
499  for(int i = 0 ; i < currentItem->childCount(); i++)
500  {
501  currentItem->child(i)->setCheckState(3, itemVisibility ? Qt::Checked : Qt::Unchecked);
502  itemVisibilityChanged(currentItem->child(i), itemVisibility);
503  }
504  }
505 }
506 
507 
509 {
510  d->append = append;
511 }
512 
513 
514 void axlInspectorObjectManagerTree::updateAxlTreeWidgetItem(axlInspectorObjectManagerTreeItem *axlCurrentItem, int mode)
515 {
516  if(mode==0)
517  {
518  axlCurrentItem->setText(2,"Passive");
519  axlCurrentItem->setSelected(false);
520  axlCurrentItem->setExpanded(false);
521  }
522  else if(mode==1)
523  {
524  axlCurrentItem->setText(2,"Selected");
525  axlCurrentItem->setSelected(true);
526  if(QTreeWidgetItem *parent = axlCurrentItem->parent())
527  parent->setSelected(false);
528  }
529  else if(mode==2 )
530  {
531  if(dynamic_cast<axlDataDynamic *>(d->scene_manager->data(axlCurrentItem))){
532  axlDataDynamic *dynamicData = dynamic_cast<axlDataDynamic *>(d->scene_manager->data(axlCurrentItem));
533  axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(dynamicData->outputs());
534  if(axlData->editable()){
535  axlCurrentItem->setText(2,"Editable");
536  axlCurrentItem->setSelected(true);
537  if(QTreeWidgetItem *parent = axlCurrentItem->parent())
538  parent->setSelected(false);
539  }
540  }else{
541  axlCurrentItem->setText(2,"Editable");
542  axlCurrentItem->setSelected(true);
543  if(QTreeWidgetItem *parent = axlCurrentItem->parent())
544  parent->setSelected(false);
545  }
546  }
547 
548 
549  if(d->scene_manager->data(axlCurrentItem)){
550  axlCurrentItem->setToolTip(0, d->scene_manager->data(axlCurrentItem)->description());
551  axlCurrentItem->setToolTip(1, d->scene_manager->data(axlCurrentItem)->description());
552  axlCurrentItem->setToolTip(2, d->scene_manager->data(axlCurrentItem)->description());
553  axlCurrentItem->setToolTip(3, d->scene_manager->data(axlCurrentItem)->description());
554  }
555 }
556 
558 {
559  dtkAbstractData *data = NULL;
560  axlInspectorObjectManagerTreeItem *axlCurrentItem = NULL;
561 
562  if(event->key() == Qt::Key_E){
563  for (int i = 0 ; i < this->selectedItems().size() ; i++)
564  {
565  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(this->selectedItems().at(i));
566  if(axlCurrentItem->text(2) == "Selected")
567  {
568  if(dynamic_cast<axlDataDynamic *>(d->scene_manager->data(axlCurrentItem))){
569  axlDataDynamic *dynamicData = dynamic_cast<axlDataDynamic *>(d->scene_manager->data(axlCurrentItem));
570  axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(dynamicData->outputs());
571  if(axlData->editable()){
572  axlCurrentItem->setText(2,"Editable");
573  data = d->scene_manager->data(axlCurrentItem);
574  emit stateChanged(data, 2);
575  }
576  }else{
577  axlCurrentItem->setText(2,"Editable");
578  data = d->scene_manager->data(axlCurrentItem);
579  emit stateChanged(data, 2);
580  }
581  }
582  }
583  } else if(event->key() == Qt::Key_U){
584  for(int i = 0 ; i < this->selectedItems().size() ; i++)
585  {
586  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(this->selectedItems().at(i));
587  if(axlCurrentItem->text(2) == "Editable")
588  {
589  axlCurrentItem->setText(2,"Selected");
590  data = d->scene_manager->data(axlCurrentItem);
591  emit stateChanged(data, 1);
592  }
593  }
594  } else if(event->key() == Qt::Key_Delete ||
595  (event->key() == Qt::Key_X && event->modifiers().testFlag(Qt::ControlModifier))){
596  deleteTreeWidgetItems(this->selectedItems());
597 
598 // QList<dtkAbstractData *> dataRemoved;
599 // QList<dtkAbstractData *> dataNotDynamicList;
600 // QList<axlDataDynamic *> dataDynamicList;
601 // while( !this->selectedItems().isEmpty())
602 // {
603 // // delete also the children
604 // foreach(auto i, this->selectedItems().first()->takeChildren()) {
605 // axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(i);
606 // data = d->scene_manager->data(axlCurrentItem);
607 // removeTreeItems(data, dataNotDynamicList, dataDynamicList);
608 // }
609 // axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *>(this->selectedItems().first());
610 // data = d->scene_manager->data(axlCurrentItem);
617 // removeTreeItems(data, dataNotDynamicList, dataDynamicList);
618 // }
619 //
620 // //delete output that should not be deleted twice.
621 // foreach(dtkAbstractData *data, dataNotDynamicList){
622 // foreach (axlDataDynamic *dynamicData, dataDynamicList) {
623 // if(!dynamicData->isNotOutputProcess(data)){
624 // dataNotDynamicList.removeOne(data);
625 // }
626 // }
627 // }
628 //
629 //
630 // //fill data list to be sent.
631 // foreach(dtkAbstractData *data, dataNotDynamicList){
632 // dataRemoved << data;
633 // }
634 // foreach(axlDataDynamic *data, dataDynamicList){
635 // dataRemoved << data;
636 // }
637 //
638 // emit dataSetRemoved(dataRemoved);
639 //
640 // while (!dataRemoved.isEmpty()){
641 //
642 // delete dataRemoved.takeLast();
643 // }
644  } else if ((event->key() == Qt::Key_A) && (event->modifiers().testFlag(Qt::ControlModifier)))
645  this->selectAll();
646 }
647 
649  // list with all the items
650  QList<QTreeWidgetItem*> itemList;
651  for(int i=0;i<this->topLevelItemCount();i++)
652  itemList<<this->topLevelItem(i);
653  deleteTreeWidgetItems(itemList);
654 
655 // dtkAbstractData *data = NULL;
656 //
657 // QList<dtkAbstractData *> dataRemoved;
658 // QList<dtkAbstractData *> dataNotDynamicList;
659 // QList<axlDataDynamic *> dataDynamicList;
664 // // while there are still items
665 // while (this->topLevelItemCount() > 0) {
666 // // delete the first (starting from its children)
667 // foreach(auto i, this->topLevelItem(0)->takeChildren()) {
668 // data = d->treeWidgetItem.key(i->text(0));
669 // removeTreeItems(data, dataNotDynamicList, dataDynamicList);
670 // }
671 //
672 // data = d->treeWidgetItem.key(this->topLevelItem(0)->text(0));
673 // removeTreeItems(data, dataNotDynamicList, dataDynamicList);
674 // }
675 //
676 // //delete output that should not be deleted twice.
677 //
678 // foreach(dtkAbstractData *data, dataNotDynamicList) {
679 // foreach(axlDataDynamic *dynamicData, dataDynamicList) {
680 // if (!dynamicData->isNotOutputProcess(data))
681 // dataNotDynamicList.removeOne(data);
682 // }
683 // }
684 //
685 // //fill data list to be sent.
686 //
687 // foreach(dtkAbstractData *data, dataNotDynamicList) {
688 // dataRemoved << data;
689 // }
690 //
691 // foreach(axlDataDynamic *data, dataDynamicList) {
692 // dataRemoved << data;
693 // }
694 //
695 // emit dataSetRemoved(dataRemoved);
696 //
697 // while (!dataRemoved.isEmpty()) {
698 // delete dataRemoved.takeLast();
699 // }
700 
701 }
702 
703 void axlInspectorObjectManagerTree::removeTreeItems(dtkAbstractData *data, QList<dtkAbstractData *> &dataNotDynamicList, QList<axlDataDynamic *> &dataDynamicList) {
704  this->remove(data);
705  if (!dynamic_cast<axlDataDynamic *> (data)) {
706  dataNotDynamicList << data;
707  } else {
708  dataDynamicList << dynamic_cast<axlDataDynamic *> (data);
709  }
710 }
711 
712 void axlInspectorObjectManagerTree::deleteTreeWidgetItems(QList<QTreeWidgetItem*> itemsList){
713 
714  dtkAbstractData *data = NULL;
715  axlInspectorObjectManagerTreeItem *axlCurrentItem = NULL;
716 
717  QList<dtkAbstractData *> dataRemoved;
718  QList<dtkAbstractData *> dataNotDynamicList;
719  QList<axlDataDynamic *> dataDynamicList;
720 
721  // for each item
722  foreach(auto it, itemsList){
723  // delete if any children
724  foreach(auto i, it->takeChildren()) {
725  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *> (i);
726  data = d->scene_manager->data(axlCurrentItem);
727  removeTreeItems(data, dataNotDynamicList, dataDynamicList);
728  }
729  // then delete parent
730  axlCurrentItem = dynamic_cast<axlInspectorObjectManagerTreeItem *> (it);
731  data = d->scene_manager->data(axlCurrentItem);
732  // this->remove(data);
733  // if(!dynamic_cast<axlDataDynamic *>(data)){
734  // dataNotDynamicList <<data;
735  // }else{
736  // dataDynamicList << dynamic_cast<axlDataDynamic *>(data);
737  // }
738  removeTreeItems(data, dataNotDynamicList, dataDynamicList);
739  }
740 
741  //delete output that should not be deleted twice.
742 
743  foreach(dtkAbstractData *data, dataNotDynamicList) {
744 
745  foreach(axlDataDynamic *dynamicData, dataDynamicList) {
746  if (!dynamicData->isNotOutputProcess(data)) {
747  dataNotDynamicList.removeOne(data);
748  }
749  }
750  }
751 
752  //fill data list to be sent.
753  foreach(dtkAbstractData *data, dataNotDynamicList){
754  dataRemoved << data;
755  }
756  foreach(axlDataDynamic *data, dataDynamicList){
757  dataRemoved << data;
758  }
759 
760  emit dataSetRemoved(dataRemoved);
761 
762  while (!dataRemoved.isEmpty()){
763  delete dataRemoved.takeLast();
764  }
765 
766 }
void stateChanged(dtkAbstractData *data, int mode)
QList< dtkAbstractData * > dataSet(void)
void dataSetSelected(QList< dtkAbstractData * > data)
const bool & editable(void)
void actorVisibilityChanged(dtkAbstractData *data, bool actorVisibility)
axlAbstractData * outputs(void)
Return the first output of the list.
void onStateChanged(dtkAbstractData *data, int mode)
Class axlDataDynamic defines a dynamic object.
void onItemClickedStateChanged(QTreeWidgetItem *currentItem, int column)
bool isNotOutputProcess(dtkAbstractData *data)
Check whether the data is an output of the process.
void dataSetRemoved(QList< dtkAbstractData * > dataSetRemoved)
void setController(axlInspectorObjectController *controller)
void onDoubleClickStateChanged(QTreeWidgetItem *currentItem, int column)
Class axlAbstractData defines an API for all type of axel data.
void onDataRemoved(QList< dtkAbstractData * > dataToRemoved)
axlInspectorObjectManagerTreeItem * insert(axlAbstractData *data)