29 #include <dtkCoreSupport/dtkAbstractData.h>
34 class axlInspectorObjectManagerTreePrivate
39 QHash<dtkAbstractData *, QString> treeWidgetItem;
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);
59 connect(
this, SIGNAL(itemExpanded(QTreeWidgetItem *)),
this, SLOT(
onItemExpanded(QTreeWidgetItem *)));
60 connect(
this, SIGNAL(itemDoubleClicked(QTreeWidgetItem *,
int)),
this, SLOT(
onDoubleClickStateChanged(QTreeWidgetItem *,
int)));
74 d->scene_manager = controller;
86 for (
int i = 0; i<this->topLevelItemCount(); i++){
88 if (axlCurrentItem->checkState(3) == Qt::Checked){
94 for (
int i = 0; i<this->topLevelItemCount(); i++){
96 axlCurrentItem->setCheckState(3,showAll ? Qt::Checked:Qt::Unchecked);
97 itemVisibilityChanged(this->topLevelItem(i), showAll);
105 qDebug() << DTK_PRETTY_FUNCTION <<
"data is NULL";
108 if(dynamic_cast<axlDataDynamic *>(data)){
110 disconnect(axldata, SIGNAL(destroyed(QObject *)),
this, SLOT(
remove(QObject*)));
114 d->scene_manager->remove(data);
115 d->treeWidgetItem.remove(data);
120 composite->remove(data);
128 qDebug() << DTK_PRETTY_FUNCTION <<
"data is NULL";
131 if(
axlDataDynamic *axldata = dynamic_cast<axlDataDynamic *>(data)){
133 disconnect(axldata, SIGNAL(destroyed(QObject *)),
this, SLOT(
remove(QObject*)));
137 QList<dtkAbstractData *> dataRemoved;
138 dataRemoved << axldata;
141 d->scene_manager->remove(axldata);
142 d->treeWidgetItem.remove(axldata);
151 foreach(dtkAbstractData *data, dataToRemoved)
159 qDebug() << DTK_PRETTY_FUNCTION <<
"data is NULL";
163 QString treeItemNameObject = data->objectName();
164 int numOcurrence = d->treeWidgetItem.count(d->treeWidgetItem.key(data->objectName()));
166 if(treeItemNameObject == data->identifier() || numOcurrence > 0)
169 treeItemNameObject += QString::number(d->treeWidgetItem.size());
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");
180 qDebug() << Q_FUNC_INFO <<
"this dynamic data has no process available";
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());
195 d->scene_manager->insert(data, item);
196 d->treeWidgetItem.insert(data, treeItemNameObject);
197 data->setObjectName(treeItemNameObject);
199 if(
axlDataDynamic *dataDynamic = dynamic_cast<axlDataDynamic *>(data)){
200 connect(dataDynamic, SIGNAL(destroyed(QObject *)),
this, SLOT(
remove(QObject*)));
211 if(dynamic_cast<axlDouble *>(axlData)){
212 axlData->setObjectName(data->name());
221 for(
int i = 0; i < composite->count(); i++)
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());
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());
266 dtkAbstractData *data = d->scene_manager->data(currentItem);
269 if(currentItem->text(2) !=
"Editable"){
270 if(dynamic_cast<axlAbstractData *>(data)->editable())
274 this->updateAxlTreeWidgetItem(currentItem, 2);
281 QList<dtkAbstractData *>
dataSet;
282 for(
int i = 0; i < this->topLevelItemCount(); i++)
284 dataSet << d->treeWidgetItem.key(this->topLevelItem(i)->text(0));
296 this->updateAxlTreeWidgetItem(currentItem,mode);
302 dtkAbstractData *currentData = NULL;
305 QList<dtkAbstractData *> dataSelected;
307 for(
int i = 0; i < this->topLevelItemCount(); i++)
315 if(axlCurrentItem->checkState(3) && axlCurrentItem->isSelected() && (axlCurrentItem->text(2) ==
"Passive" || axlCurrentItem->text(2) ==
"Selected") )
318 currentData = d->scene_manager->data(axlCurrentItem);
319 dataSelected.push_back(currentData);
323 for(
int j = 0 ; j < axlCurrentItem->childCount(); j++)
327 if(!axlCurrentItemChild)
331 if(axlCurrentItemChild->checkState(3) && axlCurrentItemChild->isSelected())
333 currentData = d->scene_manager->data(axlCurrentItemChild);
334 dataSelected.push_back(currentData);
338 if(dataSelected.size() != 0)
351 dtkAbstractData *data = d->scene_manager->data(axlCurrentItem);
356 if(axlCurrentItem->checkState(3) && column != 3)
358 if(axlCurrentItem->text(2) ==
"Passive")
360 this->updateAxlTreeWidgetItem(axlCurrentItem, 2);
364 else if(axlCurrentItem->text(2) ==
"Selected")
366 this->updateAxlTreeWidgetItem(axlCurrentItem, 2);
371 else if(axlCurrentItem->text(2) ==
"Editable")
373 this->updateAxlTreeWidgetItem(axlCurrentItem, 1);
383 QTreeWidgetItem *currentItem = NULL;
384 QTreeWidgetItem *currentItemChild = NULL;
386 dtkAbstractData *data = NULL;
389 QList<dtkAbstractData *> dataSelected;
391 for(
int i = 0; i < this->topLevelItemCount(); i++)
393 currentItem = this->topLevelItem(i);
399 if(axlCurrentItem->checkState(3) && axlCurrentItem->isSelected() && (axlCurrentItem->text(2) ==
"Passive" || axlCurrentItem->text(2) ==
"Selected") )
401 this->updateAxlTreeWidgetItem(axlCurrentItem, 1);
402 data = d->scene_manager->data(axlCurrentItem);
403 dataSelected.push_back(data);
408 else if(axlCurrentItem->checkState(3) && (!axlCurrentItem->isSelected()) && (axlCurrentItem->text(2) ==
"Selected" || axlCurrentItem->text(2) ==
"Editable"))
410 data = d->scene_manager->data(axlCurrentItem);
412 if(dataComposite != NULL && axlCurrentItem->text(2) ==
"Editable"){}
415 this->updateAxlTreeWidgetItem(axlCurrentItem, 0);
420 for(
int j = 0 ; j < currentItem->childCount(); j++)
422 currentItemChild = currentItem->child(j);
428 if(axlCurrentItem->checkState(3) && axlCurrentItem->isSelected() && (axlCurrentItem->text(2) ==
"Passive" || axlCurrentItem->text(2) ==
"Selected") )
430 this->updateAxlTreeWidgetItem(axlCurrentItem, 1);
431 data = d->scene_manager->data(axlCurrentItem);
432 dataSelected.push_back(data);
437 else if(axlCurrentItem->checkState(3) && (!axlCurrentItem->isSelected()) && (axlCurrentItem->text(2) ==
"Selected" || axlCurrentItem->text(2) ==
"Editable"))
439 this->updateAxlTreeWidgetItem(axlCurrentItem, 0);
440 data = d->scene_manager->data(axlCurrentItem);
466 dtkAbstractData *data = d->scene_manager->data(axlCurrentItem);
473 itemVisibilityChanged(currentItem, (axlCurrentItem->checkState(3) == Qt::Checked));
480 void axlInspectorObjectManagerTree::itemVisibilityChanged(QTreeWidgetItem *currentItem,
bool itemVisibility)
482 if(currentItem->childCount() == 0)
485 dtkAbstractData *data = d->scene_manager->data(axlCurrentItem);
492 dtkAbstractData *data = d->scene_manager->data(axlCurrentItem);
493 if(dynamic_cast<axlDataDynamic *>(data)){
497 delete axlCurrentItem;
499 for(
int i = 0 ; i < currentItem->childCount(); i++)
501 currentItem->child(i)->setCheckState(3, itemVisibility ? Qt::Checked : Qt::Unchecked);
502 itemVisibilityChanged(currentItem->child(i), itemVisibility);
518 axlCurrentItem->setText(2,
"Passive");
519 axlCurrentItem->setSelected(
false);
520 axlCurrentItem->setExpanded(
false);
524 axlCurrentItem->setText(2,
"Selected");
525 axlCurrentItem->setSelected(
true);
526 if(QTreeWidgetItem *parent = axlCurrentItem->parent())
527 parent->setSelected(
false);
531 if(dynamic_cast<axlDataDynamic *>(d->scene_manager->data(axlCurrentItem))){
535 axlCurrentItem->setText(2,
"Editable");
536 axlCurrentItem->setSelected(
true);
537 if(QTreeWidgetItem *parent = axlCurrentItem->parent())
538 parent->setSelected(
false);
541 axlCurrentItem->setText(2,
"Editable");
542 axlCurrentItem->setSelected(
true);
543 if(QTreeWidgetItem *parent = axlCurrentItem->parent())
544 parent->setSelected(
false);
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());
559 dtkAbstractData *data = NULL;
562 if(event->key() == Qt::Key_E){
563 for (
int i = 0 ; i < this->selectedItems().size() ; i++)
566 if(axlCurrentItem->text(2) ==
"Selected")
568 if(dynamic_cast<axlDataDynamic *>(d->scene_manager->data(axlCurrentItem))){
572 axlCurrentItem->setText(2,
"Editable");
573 data = d->scene_manager->data(axlCurrentItem);
577 axlCurrentItem->setText(2,
"Editable");
578 data = d->scene_manager->data(axlCurrentItem);
583 }
else if(event->key() == Qt::Key_U){
584 for(
int i = 0 ; i < this->selectedItems().size() ; i++)
587 if(axlCurrentItem->text(2) ==
"Editable")
589 axlCurrentItem->setText(2,
"Selected");
590 data = d->scene_manager->data(axlCurrentItem);
594 }
else if(event->key() == Qt::Key_Delete ||
595 (
event->key() == Qt::Key_X &&
event->modifiers().testFlag(Qt::ControlModifier))){
596 deleteTreeWidgetItems(this->selectedItems());
644 }
else if ((event->key() == Qt::Key_A) && (event->modifiers().testFlag(Qt::ControlModifier)))
650 QList<QTreeWidgetItem*> itemList;
651 for(
int i=0;i<this->topLevelItemCount();i++)
652 itemList<<this->topLevelItem(i);
653 deleteTreeWidgetItems(itemList);
703 void axlInspectorObjectManagerTree::removeTreeItems(dtkAbstractData *data, QList<dtkAbstractData *> &dataNotDynamicList, QList<axlDataDynamic *> &dataDynamicList) {
705 if (!dynamic_cast<axlDataDynamic *> (data)) {
706 dataNotDynamicList << data;
708 dataDynamicList << dynamic_cast<axlDataDynamic *> (data);
712 void axlInspectorObjectManagerTree::deleteTreeWidgetItems(QList<QTreeWidgetItem*> itemsList){
714 dtkAbstractData *data = NULL;
717 QList<dtkAbstractData *> dataRemoved;
718 QList<dtkAbstractData *> dataNotDynamicList;
719 QList<axlDataDynamic *> dataDynamicList;
722 foreach(
auto it, itemsList){
724 foreach(
auto i, it->takeChildren()) {
726 data = d->scene_manager->data(axlCurrentItem);
727 removeTreeItems(data, dataNotDynamicList, dataDynamicList);
731 data = d->scene_manager->data(axlCurrentItem);
738 removeTreeItems(data, dataNotDynamicList, dataDynamicList);
743 foreach(dtkAbstractData *data, dataNotDynamicList) {
747 dataNotDynamicList.removeOne(data);
753 foreach(dtkAbstractData *data, dataNotDynamicList){
762 while (!dataRemoved.isEmpty()){
763 delete dataRemoved.takeLast();
void stateChanged(dtkAbstractData *data, int mode)
void keyPressEvent(QKeyEvent *event)
QList< dtkAbstractData * > dataSet(void)
void remove(dtkAbstractData *data)
void onAllItemClickStatedChanged()
void removeAllItems(void)
void dataSetSelected(QList< dtkAbstractData * > data)
const bool & editable(void)
void onVisibilityHeaderClick(int index)
void actorVisibilityChanged(dtkAbstractData *data, bool actorVisibility)
axlAbstractData * outputs(void)
Return the first output of the list.
void setAppendMode(bool append)
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)
axlInspectorObjectManagerTree(QWidget *parent=0)
void onItemExpanded(QTreeWidgetItem *)
~axlInspectorObjectManagerTree(void)
Class axlAbstractData defines an API for all type of axel data.
void onDataRemoved(QList< dtkAbstractData * > dataToRemoved)
axlInspectorObjectManagerTreeItem * insert(axlAbstractData *data)