void CatalogueDialog::okButtonClicked() { bool close = false; QPushButton *button = qobject_cast<QPushButton *>( sender() ); if( !button ) close = false; else { if( button->objectName() == "showCloseButton" ) close = true; } QTreeWidgetItem *item = treeWidget->currentItem(); if( !item ) return; int count = item->childCount(); if( count == 0 ) { QString str = item->text(0); emit pageRequested(str); if( close ) accept(); } }
void TestHelpSelectingDialog::showTheoryNodes() { QTreeWidgetItem *root = new QTreeWidgetItem(); for (int i = 0; i < theoryNodes.length(); i++) { KeyStorageNode currentNode = theoryNodes.at(i); QList<Key> keys = currentNode.getInnerKeys(); for (int j = 0; j < keys.length(); j++) { Key currentKey = keys.at(j); addKey(root, currentKey, currentNode.getPluginName(), i, Qt::UserRole); } } ui->treeWidgetChangeTheme->clear(); while (root->childCount() != 0) { ui->treeWidgetChangeTheme->addTopLevelItem(root->takeChild(0)); } delete root; ui->treeWidgetChangeTheme->sortByColumn(0, Qt::AscendingOrder); }
// Test if a node can be erased in the graph : the condition is that none of its children has a menu modify opened bool GraphModeler::isNodeErasable ( BaseNode* node) { QTreeWidgetItem* item = graphListener->items[node]; if(item == NULL) { return false; } // check if there is already a dialog opened for that item in the graph std::map< void*, QTreeWidgetItem*>::iterator it; for (it = map_modifyDialogOpened.begin(); it != map_modifyDialogOpened.end(); ++it) { if (it->second == item) return false; } //check the item childs for(int i=0 ; i<item->childCount() ; i++) { QTreeWidgetItem *child = item->child(i); for( it = map_modifyDialogOpened.begin(); it != map_modifyDialogOpened.end(); ++it) { if( it->second == child) return false; } } return true; }
//============================================================== // Load Stands + Parking //============================================================== int AirportsWidget::load_parking_node(QString airport_code){ //* Create the Parkings Node QTreeWidgetItem *parkingParent = new QTreeWidgetItem(); parkingParent->setText(0, "Parking" ); parkingParent->setIcon(0, QIcon(":/icon/folder")); treeWidgetAirportInfo->addTopLevelItem(parkingParent); treeWidgetAirportInfo->setItemExpanded(parkingParent, true); //* DB query QSqlQuery query(mainObject->db); query.prepare("SELECT stand, heading, lat, lng FROM stands WHERE airport_code = ? ORDER BY stand ASC;"); query.bindValue(0, airport_code); query.exec(); //* No results so create a "none node" if(query.size() == 0){ QTreeWidgetItem *item = new QTreeWidgetItem(parkingParent); item->setText(0, tr("-- None --")); return 0; } //* Loop and add the Stands while(query.next()){ QTreeWidgetItem *item = new QTreeWidgetItem(parkingParent); item->setText(CI_NODE, query.value(0).toString()); item->setText(CI_SETTING_KEY, QString("stand_").append(query.value(0).toString())); } //* return the count return parkingParent->childCount(); }
void Tree::trier(int forme) { // fichiers SF2 par ordre alphabétique int max = this->topLevelItemCount(); QTreeWidgetItem *child; this->sortItems(0, Qt::AscendingOrder); // colonne 5 ne fonctionne pas ?! for (int i = 0; i < max; i ++) this->topLevelItem(i)->sortChildren(5, Qt::AscendingOrder); if (forme) { // Mise en forme (expanded / collapsed) for (int i = 0; i < max; i++) { child = this->topLevelItem(i); child->setExpanded(1); for (int j = 0; j < child->childCount(); j++) { child->child(j)->setExpanded(0); for (int k = 0; k < child->child(j)->childCount(); k++) { child->child(j)->child(k)->setExpanded(0); } } } } }
void ComplexActionDialog::saveComplexAction() { QList<QTreeWidgetItem *> items = ui->ruleTreeWidget->findItems(QString("*"), Qt::MatchWrap | Qt::MatchWildcard); if (items.isEmpty()) { return; } QList<RuleElement *> ruleElements; int column = 0; for (int i = 0; i < ui->ruleTreeWidget->topLevelItemCount(); ++i) { QTreeWidgetItem *item = ui->ruleTreeWidget->topLevelItem(i); if (item->childCount() > 0) { ruleElements.append(parseRuleTreeItem(item)); } else { ruleElements.append(new RuleElement(item->text(column), QList<RuleElement *>() , mWidgetItemCustomPropertyList.repeatCountByItem(item) , mWidgetItemCustomPropertyList.isKeyActionByItem(item) , mWidgetItemCustomPropertyList.durationByItem(item))); } } //printRuleElements(ruleElements); if (mComplexActionNameDialog->isScenario()) { mComplexUserActionGenerator->generateScenario(mComplexActionNameDialog->complexActionName(), ruleElements, mComplexActionNameDialog->actionStatus()); } else { mComplexUserActionGenerator->generateComplexAction(mComplexActionNameDialog->complexActionName() , ruleElements); } }
void InstrumentWizard::on_downButton_clicked() { QList<QTreeWidgetItem*> wi = partiturList->selectedItems(); if (wi.isEmpty()) return; QTreeWidgetItem* item = wi.front(); if (item->type() == PART_LIST_ITEM) { bool isExpanded = partiturList->isItemExpanded(item); int idx = partiturList->indexOfTopLevelItem(item); int n = partiturList->topLevelItemCount(); if (idx < (n-1)) { partiturList->selectionModel()->clear(); QTreeWidgetItem* item = partiturList->takeTopLevelItem(idx); partiturList->insertTopLevelItem(idx+1, item); partiturList->setItemExpanded(item, isExpanded); partiturList->setItemSelected(item, true); } } else { QTreeWidgetItem* parent = item->parent(); int idx = parent->indexOfChild(item); int n = parent->childCount(); if (idx < (n-1)) { partiturList->selectionModel()->clear(); QTreeWidgetItem* item = parent->takeChild(idx); parent->insertChild(idx+1, item); partiturList->setItemSelected(item, true); } } }
/** * Slot for adding an attribute to the tree. * @param listItem the new attribute to add */ void RefactoringAssistant::attributeAdded(UMLClassifierListItem *listItem) { UMLAttribute *att = static_cast<UMLAttribute*>(listItem); DEBUG(DBG_SRC) << "attribute = " << att->name(); //:TODO: UMLClassifier *parent = dynamic_cast<UMLClassifier*>(att->parent()); if (!parent) { uWarning() << att->name() << " - Parent of attribute is not a classifier!"; return; } QTreeWidgetItem *item = findListViewItem(parent); if (!item) { uWarning() << "Parent is not in tree!"; return; } for (int i = 0; i < item->childCount(); ++i) { QTreeWidgetItem *folder = item->child(i); if (folder->text(1) == QLatin1String("attributes")) { item = new QTreeWidgetItem(folder, QStringList(att->name())); m_umlObjectMap[item] = att; connect(att, SIGNAL(modified()), this, SLOT(objectModified())); setVisibilityIcon(item, att); DEBUG(DBG_SRC) << "attribute = " << att->name() << " added!"; //:TODO: break; } } }
void BookmarksSideBar::removeBookmark(const BookmarksModel::Bookmark &bookmark) { if (bookmark.folder == QLatin1String("unsorted")) { QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(bookmark.title, Qt::MatchExactly); if (list.count() == 0) { return; } QTreeWidgetItem* item = list.at(0); if (item && item->data(0, Qt::UserRole + 10).toInt() == bookmark.id) { ui->bookmarksTree->deleteItem(item); } } else { QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(BookmarksModel::toTranslatedFolder(bookmark.folder), Qt::MatchExactly); if (list.count() == 0) { return; } QTreeWidgetItem* parentItem = list.at(0); if (!parentItem) { return; } for (int i = 0; i < parentItem->childCount(); i++) { QTreeWidgetItem* item = parentItem->child(i); if (!item) { continue; } if (item->text(0) == bookmark.title && item->data(0, Qt::UserRole + 10).toInt() == bookmark.id) { ui->bookmarksTree->deleteItem(item); return; } } } }
/* Update Money for Money Tree */ void MainWindow::updateMoneyTree(QTreeWidgetItem *item){ if (item){ if (item->parent()){ item = item->parent(); } int count = item->childCount(); int total = 0; for (int i = 0; i < count; i++){ total += item->child(i)->text(1).toInt(); } item->setText(1,QString::number(total)); } else { int TopCount = ui->moneytree->topLevelItemCount(); QTreeWidgetItem * topItem ; int childCount ; int total; for (int i = 0; i < TopCount; i++){ topItem = ui->moneytree->topLevelItem(i); childCount = topItem->childCount(); total = 0; for (int j = 0; j < childCount; j++){ total += topItem->child(j)->text(1).toInt(); } topItem->setText(1,QString::number(total)); } } }
/** * Slot for adding an operation to the tree. * @param listItem the new operation to add */ void RefactoringAssistant::operationAdded(UMLClassifierListItem *listItem) { UMLOperation *op = static_cast<UMLOperation*>(listItem); DEBUG(DBG_SRC) << "operation = " << op->name(); //:TODO: UMLClassifier *parent = dynamic_cast<UMLClassifier*>(op->parent()); if (!parent) { uWarning() << op->name() << " - Parent of operation is not a classifier!"; return; } QTreeWidgetItem *item = findListViewItem(parent); if (!item) { return; } for (int i = 0; i < item->childCount(); ++i) { QTreeWidgetItem *folder = item->child(i); if (folder->text(1) == QLatin1String("operations")) { item = new QTreeWidgetItem(folder, QStringList(op->name())); m_umlObjectMap[item] = op; connect(op, SIGNAL(modified()), this, SLOT(objectModified())); setVisibilityIcon(item, op); DEBUG(DBG_SRC) << "operation = " << op->name() << " added!"; //:TODO: break; } } }
void US_NoiseLoader::itemsSelected( void ) { QList< QTreeWidgetItem* > selitems = tw_noises->selectedItems(); int nsels = selitems.size(); lw_selects->clear(); if ( nsels == 0 ) return; for ( int ii = 0; ii < nsels; ii++ ) { QTreeWidgetItem* item = selitems[ ii ]; QString itemtext = item->text( 0 ); if ( itemtext.contains( "_noise" ) ) { // Select an individual noise lw_selects->addItem( itemtext ); } else if ( itemtext.contains( "Model" ) ) { // Select all the noises associated with a model for ( int jj = 0; jj < item->childCount(); jj++ ) { lw_selects->addItem( item->child( jj )->text( 0 ) ); } } } }
PacketTreeItem* PacketTreeView::find(regina::NPacket* packet) { if (! packet) return 0; // Start at the root of the tree and work down. // Note that the root packet itself will not be found by this routine. // Also, note that the invisible root item might not be a PacketTreeItem, // and we should not try to cast it as such. QTreeWidgetItem* root = invisibleRootItem(); int itemCount = 0; PacketTreeItem* item; regina::NPacket* current; while (itemCount < root->childCount()) { item = dynamic_cast<PacketTreeItem*>(root->child(itemCount++)); current = item->getPacket(); if (current == packet) return item; if (current && current->isGrandparentOf(packet)) { root = item; itemCount = 0; } } return 0; }
void ColorDialog::favoritesItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { Q_UNUSED(previous); QTreeWidgetItem *root = ui_->listFavorites->invisibleRootItem(); if (!current) { ui_->buttonRemove->setEnabled(false); ui_->buttonMoveUp->setEnabled(false); ui_->buttonMoveDown->setEnabled(false); return; } else { ui_->buttonRemove->setEnabled(true); if (root->indexOfChild(current) != 0) ui_->buttonMoveUp->setEnabled(true); else ui_->buttonMoveUp->setEnabled(false); if (root->indexOfChild(current) != root->childCount() - 1) ui_->buttonMoveDown->setEnabled(true); else ui_->buttonMoveDown->setEnabled(false); } int cid = current->data(0, Qt::UserRole).toInt(); ui_->listColors->setCurrentItem(ui_->listColors->invisibleRootItem()->child(colorMap_[cid])); }
void Configuration::addToTree(ConfigItem* item) { // Find the parent of this item by following the tree through all but the // last item in the path QTreeWidgetItem* parent = _tree->invisibleRootItem(); const QStringList& path = item->path(); QStringList::const_iterator last = path.end(); --last; for (QStringList::const_iterator i = path.begin(); i != last; ++i) { QTreeWidgetItem* next = nullptr; for (int j = 0; j < parent->childCount(); ++j) { QTreeWidgetItem* child = parent->child(j); if (child->text(0) == *i) { next = child; break; } } if (!next) { // Create this item next = new QTreeWidgetItem(parent); next->setText(0, *i); } parent = next; } // Create a tree item item->_treeItem = new QTreeWidgetItem(parent); item->_treeItem->setFlags(item->_treeItem->flags() | Qt::ItemIsEditable); item->_treeItem->setData(0, ConfigItemRole, QVariant::fromValue(item)); item->_treeItem->setText(0, path.back()); item->setupItem(); }
//--------------------------------------------------------------------------- void StationDialog::writeStations(void) { if(m_ui->stationTree->topLevelItemCount() == 0) return; QSettings reg(inifile, QSettings::IniFormat); QTreeWidgetItem *child; QTreeWidgetItem *item; QStringList keys; QString key; int j, i = 0; QFile file(inifile); if(file.exists(inifile)) file.remove(); keys << "Lon"; keys << "Lat"; keys << "Alt"; while((item = m_ui->stationTree->topLevelItem(i))) { key.sprintf("Station-%d", i++); reg.beginGroup(key); reg.setValue("Name", item->text(0)); for(j=0; j<item->childCount(); j++) { child = item->child(j); reg.setValue(keys.at(j), child->text(0)); } reg.endGroup(); } }
void CollectionTreeWidget::cleanUp(QTreeWidgetItem *parent = NULL, int level = CollectionTreeWidget::LevelNone) { // If parent is null, process all artists and its children nodes if (parent == NULL) { cleanUp(invisibleRootItem(), CollectionTreeWidget::LevelNone); } // if we have a parent, process it else { // If it's an artist, enter it if (level < CollectionTreeWidget::LevelAlbum) { int childCount = parent->childCount(); for (int i = 0; i < childCount; i++) { TreeLevel newLevel = (TreeLevel)(level + 1); cleanUp(parent->child(i), newLevel); } } // If it's an album and it has no songs, remove it! else { if (parent->childCount() == 0) { QTreeWidgetItem *parentParent = parent->parent(); delete parent; // If artist has no more albums, remove it too if (parentParent->childCount() == 0) delete parentParent; } } } }
void TemplKatalogView::slEditTemplate() { TemplKatalogListView* listview = static_cast<TemplKatalogListView*>(getListView()); if( listview ) { QTreeWidgetItem *item = listview->currentItem(); if( listview->isChapter(item) ) { // check if the chapter is empty. If so, switch to slNewTempalte() // if there others, open the chapter. if( !listview->isRoot( item ) && item->childCount() == 0 ) { slNewTemplate(); } else { // do nothing. } } else { // the clicked item is not a chapter FloskelTemplate *currTempl = static_cast<FloskelTemplate*> (listview->currentItemData()); if( currTempl ) { QTreeWidgetItem *item = (QTreeWidgetItem*) listview->currentItem(); openDialog( item, currTempl, false ); } } } }
void InstrumentWizard::on_removeButton_clicked() { QList<QTreeWidgetItem*> wi = partiturList->selectedItems(); if (wi.isEmpty()) return; QTreeWidgetItem* item = wi.front(); QTreeWidgetItem* parent = item->parent(); if (parent) { if (((StaffListItem*)item)->op == ITEM_ADD) { if (parent->childCount() == 1) { partiturList->takeTopLevelItem(partiturList->indexOfTopLevelItem(parent)); delete parent; } else { parent->takeChild(parent->indexOfChild(item)); delete item; } } else { ((StaffListItem*)item)->op = ITEM_DELETE; partiturList->setItemHidden(item, true); } } else { if (((PartListItem*)item)->op == ITEM_ADD) delete item; else { ((PartListItem*)item)->op = ITEM_DELETE; partiturList->setItemHidden(item, true); } } partiturList->clearSelection(); emit completeChanged(partiturList->topLevelItemCount() > 0); }
int QTreeWidgetItemProto::childCount() const { QTreeWidgetItem *item = qscriptvalue_cast<QTreeWidgetItem*>(thisObject()); if (item) return item->childCount(); return 0; }
void PreferencesDialog::initCategoryList() { d->connectionItem = new QTreeWidgetItem(categoryList); if (MPDConnection::instance()->isConnected()) d->serverItem = new QTreeWidgetItem(d->connectionItem); d->looknfeelItem = new QTreeWidgetItem(categoryList); d->looknfeelItem->setExpanded(true); d->libraryItem = new QTreeWidgetItem(d->looknfeelItem); d->directoriesItem = new QTreeWidgetItem(d->looknfeelItem); d->playlistItem = new QTreeWidgetItem(d->looknfeelItem); d->iconsItem = new QTreeWidgetItem(d->looknfeelItem); d->stylesItem = new QTreeWidgetItem(d->looknfeelItem); d->coverArtItem = new QTreeWidgetItem(categoryList); d->dynamicPlaylistItem = new QTreeWidgetItem(categoryList); d->localeItem = new QTreeWidgetItem(categoryList); d->notificationsItem = new QTreeWidgetItem(categoryList); d->shortcutsItem = new QTreeWidgetItem(categoryList); d->tagguesserItem = new QTreeWidgetItem(categoryList); d->trayIconItem = new QTreeWidgetItem(categoryList); d->trayIconItem->setIcon(0, QIcon(":/icons/qmpdclient16.png")); d->lastFmItem = new QTreeWidgetItem(categoryList); d->lastFmItem->setIcon(0, QIcon(":/icons/as.png")); // Make item-index relations for (int i = 0, index = 0; i < categoryList->topLevelItemCount(); i++, index++) { QTreeWidgetItem *item = categoryList->topLevelItem(i); item->setExpanded(true); item->setData(0, Qt::UserRole, index); for (int j = 0; j < item->childCount(); j++) item->child(j)->setData(0, Qt::UserRole, ++index); } }
void PackageProperties::populateFileWidget() { treeWidget->clear(); treeWidget->header()->hide(); QStringList files = curPkg.files(); foreach(const QString &file, files) { QStringList splitted = file.split(QChar('/')); QTreeWidgetItem *parentItem = 0; foreach(const QString &spl, splitted) { if (spl.isEmpty()) continue; if (parentItem) { bool there = false; int j = parentItem->childCount(); for (int i = 0; i != j; i++) { if (parentItem->child(i)->text(0) == spl) { there = true; parentItem = parentItem->child(i); continue; } } if (!there) parentItem->addChild(new QTreeWidgetItem(parentItem, (QStringList) spl)); } else { QList<QTreeWidgetItem*> list = treeWidget->findItems(spl, Qt::MatchExactly); if (!list.isEmpty()) { parentItem = list.first(); } else { treeWidget->insertTopLevelItem(0, new QTreeWidgetItem(treeWidget, (QStringList) spl)); } } } }
void EventEditor::commit() { if(!m_bOneTimeSetupDone)return; // nothing to commit saveLastEditedItem(); KviKvsEventManager::instance()->removeAllScriptAppHandlers(); int count=m_pTreeWidget->topLevelItemCount(); for (int i=0;i<count;i++) { QTreeWidgetItem * it = m_pTreeWidget->topLevelItem(i); int ccount = it->childCount(); if(ccount > 0) { QString szContext; for(int j=0;j<ccount;j++) { QTreeWidgetItem * ch = it->child(j); szContext = QString("%1::%2").arg(((EventEditorEventTreeWidgetItem *)it)->m_szName,((EventEditorHandlerTreeWidgetItem *)ch)->m_szName); KviKvsScriptEventHandler * s = KviKvsScriptEventHandler::createInstance( // msvc workaround ((EventEditorHandlerTreeWidgetItem *)ch)->m_szName, szContext, ((EventEditorHandlerTreeWidgetItem *)ch)->m_szBuffer, ((EventEditorHandlerTreeWidgetItem *)ch)->m_bEnabled ); KviKvsEventManager::instance()->addAppHandler(((EventEditorEventTreeWidgetItem *)it)->m_uEventIdx,s); } } } g_pApp->saveAppEvents(); }
void MusicBrowser::setupDirectoryTree(QTreeWidgetItem *directoryItem) { QDir directory(directoryItem->text(2)); QFileInfoList files; QStringList nameFilters = QStringList(); QString temp_string; nameFilters << "*.aiff" << "*.AIFF"; nameFilters << "*.flac" << "*.FLAC"; nameFilters << "*.mid" << "*.MID" << "*.midi" << "*.MIDI"; nameFilters << "*.mp3" << "*.MP3"; nameFilters << "*.ogg" << "*.OGG"; nameFilters << "*.it" << "*.IT"; nameFilters << "*.mod" << "*.MOD"; nameFilters << "*.s3m" << "*.S3M"; nameFilters << "*.wav" << "*.WAV"; directory.setFilter(QDir::AllDirs|QDir::Files|QDir::NoSymLinks|QDir::NoDotAndDotDot|QDir::Readable); directory.setNameFilters(nameFilters); directory.setSorting(QDir::Name|QDir::DirsFirst|QDir::IgnoreCase); files = directory.entryInfoList(); for (int i = 0, numfiles = files.size(); i < numfiles; ++i) { QCoreApplication::processEvents(); if (files[i].isDir()) { QTreeWidgetItem *newDirItem = new QTreeWidgetItem; newDirItem->setIcon(0, QIcon(":/icons/folder.png")); newDirItem->setText(0, files[i].fileName()); newDirItem->setText(1, "dir"); newDirItem->setText(2, directoryItem->text(2) + QString("/") + files[i].fileName()); newDirItem->setFlags(Qt::ItemIsEnabled); setupDirectoryTree(newDirItem); if (newDirItem->childCount() > 0) directoryItem->addChild(newDirItem); } else { QTreeWidgetItem *newFileItem = new QTreeWidgetItem; newFileItem->setIcon(0, QIcon(":/icons/music.png")); newFileItem->setText(0, files[i].fileName()); temp_string = files[i].suffix().toLower(); if (temp_string == "aiff") newFileItem->setText(1, "1"); else if (temp_string == "flac") newFileItem->setText(1, "2"); else if (temp_string == "mid" || temp_string == "midi") newFileItem->setText(1, "3"); else if (temp_string == "mp3") newFileItem->setText(1, "4"); else if (temp_string == "ogg") newFileItem->setText(1, "5"); else if (temp_string == "it" || temp_string == "mod" || temp_string == "s3m") newFileItem->setText(1, "6"); else if (temp_string == "wav") newFileItem->setText(1, "7"); newFileItem->setText(2, directoryItem->text(2) + QString("/") + files[i].fileName()); directoryItem->addChild(newFileItem); musicItems.append(newFileItem); } } }
void Tree::displayElement(EltID id) { if (_displayedElements.contains(id)) return; _displayedElements << id; // Affichage QTreeWidgetItem *child; int max = this->topLevelItemCount(); for (int i = 0; i < max; i++) { child = this->topLevelItem(i); if (child->text(1).toInt() == id.indexSf2) { if (id.typeElement == elementSmpl) child = child->child(0); else if (id.typeElement == elementInst) child = child->child(1); else child = child->child(2); int numChilds = child->childCount(); for (int j = 0; j < numChilds; j++) { // Affichage de la sous-arborescence if (child->child(j)->text(3).toInt() == id.indexElt) child->child(j)->setHidden(false); } } } }
void NotificationTreeItem::setData(int column, int role, const QVariant &value, bool checkState) { if (checkState && role == Qt::CheckStateRole) { Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt()); if (state != Qt::PartiallyChecked) { for (int row = 0; row != childCount(); ++row) static_cast<NotificationTreeItem*>(child(row))->setData(0, role, state, false); } QTreeWidgetItem *parent = this->parent(); if (parent) { QVariant parentState = value; for (int i = 0, n = parent->childCount(); i < n; ++i) { QTreeWidgetItem *child = parent->child(i); if (child == this) continue; if (parentState != child->data(0, role)) { parentState = Qt::PartiallyChecked; break; } } static_cast<NotificationTreeItem*>(parent)->setData(0, role, parentState, false); } } QTreeWidgetItem::setData(column, role, value); }
void RSSImp::loadFoldersOpenState() { QStringList open_folders = Preferences::instance()->getRssOpenFolders(); foreach (const QString& var_path, open_folders) { QStringList path = var_path.split("\\"); QTreeWidgetItem* parent = 0; foreach (const QString& name, path) { int nbChildren = 0; if (parent) nbChildren = parent->childCount(); else nbChildren = m_feedList->topLevelItemCount(); for (int i = 0; i < nbChildren; ++i) { QTreeWidgetItem* child; if (parent) child = parent->child(i); else child = m_feedList->topLevelItem(i); if (m_feedList->getRSSItem(child)->id() == name) { parent = child; parent->setExpanded(true); qDebug("expanding folder %s", qPrintable(name)); break; } } }
//向上递归判断 void XMLInfoDialog::updateParentItem(QTreeWidgetItem *item) { QTreeWidgetItem* parent = item->parent(); if (parent == NULL) return; //选中的子节点个数 int selectedCount = 0; int childCount = parent->childCount(); for (int i = 0; i < childCount; i++) { QTreeWidgetItem* childItem = parent->child(i); if (childItem->checkState(0) == Qt::Checked) selectedCount++; } if (selectedCount <= 0) { parent->setCheckState(0, Qt::Unchecked);//全没选状态 } else if (selectedCount > 0 && selectedCount < childCount) { parent->setCheckState(0, Qt::PartiallyChecked);//设置为部分选中状态 updateParentItem(parent); } else if (selectedCount == childCount) { parent->setCheckState(0, Qt::Checked);//全选中状态 } }
// Set current bus. void qtractorBusForm::setBus ( qtractorBus *pBus ) { // Get the device view root item... QTreeWidgetItem *pRootItem = NULL; if (pBus) { switch (pBus->busType()) { case qtractorTrack::Audio: pRootItem = m_pAudioRoot; break; case qtractorTrack::Midi: pRootItem = m_pMidiRoot; break; default: break; } } // Is the root present? if (pRootItem == NULL) { stabilizeForm(); return; } // For each child, test for identity... int iChildCount = pRootItem->childCount(); for (int i = 0; i < iChildCount; ++i) { QTreeWidgetItem *pItem = pRootItem->child(i); // If identities match, select as current device item. qtractorBusListItem *pBusItem = static_cast<qtractorBusListItem *> (pItem); if (pBusItem && pBusItem->bus() == pBus) { m_ui.BusListView->setCurrentItem(pItem); break; } } }
void ResourceManager::on_twResources_customContextMenuRequested(const QPoint &pos) { QTreeWidgetItem *item = twResources->itemAt(pos); if (item != NULL) { if (item->childCount() > 0) { QMenu *popupMenu = new QMenu(this); QAction *action; popupMenu->addAction(aCheckAll); popupMenu->addAction(aCheckAllRecursively); popupMenu->addAction(aUncheckAll); popupMenu->addAction(aUncheckAllRecursively); action = popupMenu->exec(QCursor::pos()); if (action == aCheckAll) setCheckState(item, Qt::Checked); else if (action == aCheckAllRecursively) setCheckStateRecursively(item, Qt::Checked); else if (action == aUncheckAll) setCheckState(item, Qt::Unchecked); else if (action == aUncheckAllRecursively) setCheckStateRecursively(item, Qt::Unchecked); } } }