| 394 | } |
| 395 | |
| 396 | QTreeWidgetItem* |
| 397 | ManageUserParamsDialogPrivate::createItemForKnob(const KnobIPtr& knob, |
| 398 | int insertIndex) |
| 399 | { |
| 400 | QTreeWidgetItem* parent = 0; |
| 401 | KnobIPtr parentKnob; |
| 402 | |
| 403 | if (knob) { |
| 404 | parentKnob = knob->getParentKnob(); |
| 405 | } |
| 406 | if (parentKnob) { |
| 407 | for (std::list<TreeItem>::iterator it = items.begin(); it != items.end(); ++it) { |
| 408 | if ( it->knob.get() == parentKnob.get() ) { |
| 409 | parent = it->item; |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | KnobPage* isPage = dynamic_cast<KnobPage*>( knob.get() ); |
| 416 | if (!parent && !isPage) { |
| 417 | //Default to first user page |
| 418 | for (std::list<TreeItem>::iterator it = items.begin(); it != items.end(); ++it) { |
| 419 | KnobPage* isPage = dynamic_cast<KnobPage*>(it->knob.get()); |
| 420 | if (!isPage) { |
| 421 | continue; |
| 422 | } |
| 423 | if (!isPage->isUserKnob()) { |
| 424 | continue; |
| 425 | } |
| 426 | |
| 427 | parent = it->item; |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | TreeItem i; |
| 432 | i.knob = knob; |
| 433 | i.item = new QTreeWidgetItem; |
| 434 | if (parent) { |
| 435 | if ( (insertIndex == -1) || ( insertIndex >= parent->childCount() ) ) { |
| 436 | parent->addChild(i.item); |
| 437 | } else { |
| 438 | parent->insertChild(insertIndex, i.item); |
| 439 | } |
| 440 | parent->setExpanded(true); |
| 441 | } else { |
| 442 | if ( (insertIndex == -1) || ( insertIndex >= tree->topLevelItemCount() ) ) { |
| 443 | tree->addTopLevelItem(i.item); |
| 444 | } else { |
| 445 | tree->insertTopLevelItem(insertIndex, i.item); |
| 446 | } |
| 447 | } |
| 448 | i.item->setExpanded(true); |
| 449 | i.scriptName = QString::fromUtf8( knob->getName().c_str() ); |
| 450 | |
| 451 | i.item->setText( 0, createTextForKnob(i.knob) ); |
| 452 | items.push_back(i); |
| 453 |
no test coverage detected