void ListModel::sort(ListItem* parent, App::SortMode mode) { int count = parent->childCount(); QVector<QPair<ListItem*, int>> sorting(count); for (int i = 0; i < count; ++i) { sorting[i].first = parent->child(i); sorting[i].second = i; } if (!parent->sort(mode)) return; QModelIndexList oldIndexes; QModelIndexList newIndexes; for (QModelIndex idx : persistentIndexList()) { ListItem* item = itemFromIndex(idx); if (!item) continue; if (idx.row() != item->row()) { oldIndexes.append(idx); newIndexes.append(indexFromItem(item)); } } qDebug() << __FUNCTION__ << oldIndexes; qDebug() << __FUNCTION__ << newIndexes; changePersistentIndexList(oldIndexes, newIndexes); emit layoutChanged(); }
QModelIndexList PartitionLabelsView::getIndexesToDraw( const QModelIndex& parent ) const { QModelIndexList list; QAbstractItemModel* modl = model(); if ( !modl ) return list; for ( int row = 0; row < modl->rowCount( parent ); ++row ) { QModelIndex index = modl->index( row, 0, parent ); //HACK: horrible special casing follows. // To save vertical space, we choose to hide short instances of free space. // Arbitrary limit: 10MB. const qint64 maxHiddenB = 10'000'000; if ( index.data( PartitionModel::IsFreeSpaceRole ).toBool() && index.data( PartitionModel::SizeRole ).toLongLong() < maxHiddenB ) continue; list.append( index ); if ( modl->hasChildren( index ) ) list.append( getIndexesToDraw( index ) ); } return list; }
QModelIndexList LYGithubProductBacklogCentralWidget::expandedIndices(const QModelIndex parent){ QModelIndexList retVal; for(int x = 0; x < productBacklog_->model()->rowCount(parent); x++){ if(treeView_->isExpanded(productBacklog_->model()->index(x, 0, parent))){ retVal.append(productBacklog_->model()->index(x, 0, parent)); retVal.append(expandedIndices(productBacklog_->model()->index(x, 0, parent))); } } return retVal; }
void BtBookshelfTreeModel::resetData() { QModelIndexList queue; queue.append(QModelIndex()); do { QModelIndex parent(queue.takeFirst()); emit dataChanged(index(0, 0, parent), index(rowCount(parent) - 1, columnCount() - 1, parent)); for (int i = 0; i < rowCount(parent); i++) { const QModelIndex childIndex(index(i, 0, parent)); if (rowCount(childIndex) > 0) queue.append(childIndex); } } while (!queue.isEmpty()); }
QModelIndexList QgsAttributeTableFilterModel::fidToIndexList( QgsFeatureId fid ) { QModelIndexList indexes; foreach ( QModelIndex idx, masterModel()->idToIndexList( fid ) ) { indexes.append( mapFromMaster( idx ) ); }
QModelIndexList BtTreeModel::allChildren(QModelIndex ndx) { QModelIndexList leafNodes; QList<BtTreeItem*> folders; int i; // Don't send an invalid index or something that isn't a folder if ( ! ndx.isValid() || type(ndx) != BtTreeItem::FOLDER ) return leafNodes; BtTreeItem* start = item(ndx); folders.append(start); while ( ! folders.isEmpty() ) { BtTreeItem* target = folders.takeFirst(); for (i=0; i < target->childCount(); ++i) { BtTreeItem* next = target->child(i); // If a folder, push it onto the folders stack for later processing if ( next->type() == BtTreeItem::FOLDER ) folders.append(next); else // Leafnode leafNodes.append(createIndex(i,0,next)); } } return leafNodes; }
void ContactsTable::onDeleteContact() { //remove selected contacts from inbox model (and database) QSortFilterProxyModel* model = dynamic_cast<QSortFilterProxyModel*>(ui->contact_table->model()); //model->setUpdatesEnabled(false); QItemSelectionModel* selection_model = ui->contact_table->selectionModel(); QModelIndexList sortFilterIndexes = selection_model->selectedRows(); if (sortFilterIndexes.count() == 0) return; if (QMessageBox::question(this, "Delete Contact", "Are you sure you want to delete this contact?") == QMessageBox::Button::No) return; QModelIndexList indexes; foreach(QModelIndex sortFilterIndex, sortFilterIndexes) indexes.append(model->mapToSource(sortFilterIndex)); qSort(indexes); auto sourceModel = model->sourceModel(); for (int i = indexes.count() - 1; i > -1; --i) { auto contact_id = ((AddressBookModel*)sourceModel)->getContact(indexes.at(i)).wallet_index; sourceModel->removeRows(indexes.at(i).row(), 1); Q_EMIT contactDeleted(contact_id); //emit signal so that ContactGui is also deleted } //model->setUpdatesEnabled(true); //TODO Remove fullname/bitname for deleted contacts from QCompleter }
/*! \reimp */ void QStringListModel::sort(int, Qt::SortOrder order) { emit layoutAboutToBeChanged(QList<QPersistentModelIndex>(), VerticalSortHint); QVector<QPair<QString, int> > list; const int lstCount = lst.count(); list.reserve(lstCount); for (int i = 0; i < lstCount; ++i) list.append(QPair<QString, int>(lst.at(i), i)); if (order == Qt::AscendingOrder) std::sort(list.begin(), list.end(), ascendingLessThan); else std::sort(list.begin(), list.end(), decendingLessThan); lst.clear(); QVector<int> forwarding(lstCount); for (int i = 0; i < lstCount; ++i) { lst.append(list.at(i).first); forwarding[list.at(i).second] = i; } QModelIndexList oldList = persistentIndexList(); QModelIndexList newList; const int numOldIndexes = oldList.count(); newList.reserve(numOldIndexes); for (int i = 0; i < numOldIndexes; ++i) newList.append(index(forwarding.at(oldList.at(i).row()), 0)); changePersistentIndexList(oldList, newList); emit layoutChanged(QList<QPersistentModelIndex>(), VerticalSortHint); }
/** * * @param QModelIndexList indexes * @param bool returnSuperParents If TRUE, only indexes of super-parents will be in result list * @return QModelIndexList */ QModelIndexList uniqueRows(QModelIndexList indexes, bool returnSuperParents) { QModelIndexList result; for (QModelIndexList::const_iterator it = indexes.begin(); it != indexes.end(); ++it) { QModelIndex isUnique = *it; Robomongo::BsonTreeItem *item = Robomongo::QtUtils::item<Robomongo::BsonTreeItem*>(isUnique); if (item) { for (QModelIndexList::const_iterator jt = result.begin(); jt != result.end(); ++jt) { Robomongo::BsonTreeItem *jItem = Robomongo::QtUtils::item<Robomongo::BsonTreeItem*>(*jt); if (jItem && jItem->superParent() == item->superParent()) { isUnique = QModelIndex(); break; } } if (isUnique.isValid()) { if (returnSuperParents) { // Move index onto "super parent" element before pushing it into result set QModelIndex parent = isUnique.parent(); while (parent != QModelIndex()) { isUnique = parent; parent = parent.parent(); } } result.append(isUnique); } } } return result; }
/*! \reimp */ void QStringListModel::sort(int, Qt::SortOrder order) { emit layoutAboutToBeChanged(); QList<QPair<QString, int> > list; for (int i = 0; i < lst.count(); ++i) list.append(QPair<QString, int>(lst.at(i), i)); if (order == Qt::AscendingOrder) qSort(list.begin(), list.end(), ascendingLessThan); else qSort(list.begin(), list.end(), decendingLessThan); lst.clear(); QVector<int> forwarding(list.count()); for (int i = 0; i < list.count(); ++i) { lst.append(list.at(i).first); forwarding[list.at(i).second] = i; } QModelIndexList oldList = persistentIndexList(); QModelIndexList newList; for (int i = 0; i < oldList.count(); ++i) newList.append(index(forwarding.at(oldList.at(i).row()), 0)); changePersistentIndexList(oldList, newList); emit layoutChanged(); }
QModelIndexList QgsAttributeTableFilterModel::fidToIndexList( QgsFeatureId fid ) { QModelIndexList indexes; Q_FOREACH ( const QModelIndex& idx, masterModel()->idToIndexList( fid ) ) { indexes.append( mapFromMaster( idx ) ); }
void KCompletionModel::Private::slotMatches(const QStringList &matches) { QModelIndexList indexesToRemove; QHashIterator<QString, QPersistentModelIndex> it(m_reverseIndexes); while (it.hasNext()) { it.next(); if (!matches.contains(it.key())) { indexesToRemove.append(it.value()); } } if (!indexesToRemove.empty()) { removeRows(indexesToRemove); } QList<QPair<QModelIndex, QVariant> > indexesToAppend; QList<QString>::const_iterator strIt; int count = m_strings.size(); for (strIt = matches.constBegin(); strIt != matches.constEnd(); ++strIt) { if (!m_reverseIndexes.contains(*strIt)) { QPair<QModelIndex, QVariant> indexPair; indexPair.first = q->createIndex(count++, 0); indexPair.second = *strIt; indexesToAppend.append(indexPair); } } if (!indexesToAppend.empty()) { insertRows(indexesToAppend); } }
QMimeData *PLModel::mimeData( const QModelIndexList &indexes ) const { PlMimeData *plMimeData = new PlMimeData(); QModelIndexList list; foreach( const QModelIndex &index, indexes ) { if( index.isValid() && index.column() == 0 ) list.append(index); } qSort(list.begin(), list.end(), modelIndexLessThen); AbstractPLItem *item = NULL; foreach( const QModelIndex &index, list ) { if( item ) { AbstractPLItem *testee = getItem( index ); while( testee->parent() ) { if( testee->parent() == item || testee->parent() == item->parent() ) break; testee = testee->parent(); } if( testee->parent() == item ) continue; item = getItem( index ); } else item = getItem( index ); plMimeData->appendItem( static_cast<PLItem*>(item)->inputItem() ); } return plMimeData; }
/* map proxy to real indexes and redirect to sourceModel */ QMimeData *PlaylistTableProxyModel::mimeData(const QModelIndexList &indexes) const { QModelIndexList sourceIndexes; foreach (QModelIndex index, indexes) { sourceIndexes.append(mapToSource(index)); }
static QModelIndexList normalizeIndexes(const QModelIndexList &list) { QModelIndexList res; foreach (const QModelIndex &idx, list) if (idx.column() == 0) res.append(idx); return res; }
void StreamsBrowsePage::itemDoubleClicked(const QModelIndex &index) { if (!static_cast<StreamsModel::Item *>(proxy.mapToSource(index).internalPointer())->isCategory()) { QModelIndexList indexes; indexes.append(index); addItemsToPlayQueue(indexes, false); } }
/*! Returns MIME data for the specified \a indexes in the model. */ QMimeData *QProxyModel::mimeData(const QModelIndexList &indexes) const { Q_D(const QProxyModel); QModelIndexList lst; for (int i = 0; i < indexes.count(); ++i) lst.append(setSourceModel(indexes.at(i))); return d->model->mimeData(lst); }
QModelIndexList TreeView::expanded() const { QModelIndexList list; for (auto&& e : expanded_) { list.append(e); } return list; }
QModelIndexList SearchWidget::removeHiddenItems(QModelIndexList& items){ QModelIndexList toReturn; for(QModelIndexList::iterator it = items.begin(); it != items.end(); ++it){ if(!treeView->isRowHidden(it->row(), it->parent())){ toReturn.append(*it); } } return toReturn; }
void StatisticsProxyModel::Private::sourceLayoutChanged() { QModelIndexList oldList; QModelIndexList newList; for( int i = 0; i < m_proxyIndexes.size(); ++i ) { const QModelIndex oldProxyIndex = m_proxyIndexes.at( i ); const QModelIndex proxyIndexFirstCol = mParent->mapFromSource( m_persistentSourceFirstColumn.at( i ) ); const QModelIndex newProxyIndex = proxyIndexFirstCol.sibling( proxyIndexFirstCol.row(), oldProxyIndex.column() ); if ( newProxyIndex != oldProxyIndex ) { oldList.append( oldProxyIndex ); newList.append( newProxyIndex ); } } mParent->changePersistentIndexList( oldList, newList ); m_persistentSourceFirstColumn.clear(); m_proxyIndexes.clear(); }
QModelIndexList GroupsModel::indexListForValue(const QVariant &value) const { QModelIndexList result; const int i = groupIndex(value.value<Group>()); if (-1 != i) result.append(index(i, 0)); return result; }
QModelIndexList NetworkProxyModel::indexListForValue(const QVariant &value) const { QModelIndexList result; const int i = networkProxyIndex(value.value<NetworkProxy>()); if (-1 != i) result.append(index(i, 0)); return result; }
QModelIndexList TvChannelModel::itemListFromIds(const QStringList &ids) const { QModelIndexList list; for (int index = 0; index < ids.size(); ++index) { QModelIndex itemIndex = itemFromId(ids.at(index)); if (itemIndex.isValid()) list.append(itemIndex); } return list; }
QModelIndexList IdentityModel::indexListForValue(const QVariant &value) const { QModelIndexList result; const int i = identityIndex(value.value<Identity>()); if (-1 != i) result.append(index(i, 0)); return result; }
QModelIndexList SharedFilesDialog::getSelected() { QModelIndexList list = ui.dirTreeView->selectionModel()->selectedIndexes() ; QModelIndexList proxyList ; for (QModelIndexList::iterator index = list.begin(); index != list.end(); ++index ) { proxyList.append(proxyModel->mapToSource(*index)) ; }//for (QModelIndexList::iterator index return proxyList ; }
void BreakWindow::keyPressEvent(QKeyEvent *ev) { if (ev->key() == Qt::Key_Delete) { QItemSelectionModel *sm = selectionModel(); QTC_ASSERT(sm, return); QModelIndexList si = sm->selectedIndexes(); if (si.isEmpty()) si.append(currentIndex().sibling(currentIndex().row(), 0)); deleteBreakpoints(normalizeIndexes(si)); }
QModelIndexList PlaylistModel::get_idxlist_by_id (uint32_t id) { QModelIndexList ret; QList<uint32_t> l = getPosById (id); for (int i = 0; i < l.count (); i++) { ret.append (index (l.at (i), 0)); } return ret; }
bool CQCompartmentDM::clear() { QModelIndexList rows; for (int i = 0; i < mpCompartments->size(); i++) { rows.append(index(i, 0)); } return removeRows(rows); }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- QModelIndexList BookmarksModel::findIndexByPath(const QModelIndex& current, QString filePath) { QModelIndex actual = index(current.row(), BookmarksItem::Name, current.parent()); QModelIndexList list; for (int i = 0; i < rowCount(actual); i++) { QModelIndex pathIndex = index(i, BookmarksItem::Path, actual); if (rowCount(pathIndex) <= 0 && pathIndex.data().toString() == filePath) { list.append(pathIndex); } QModelIndexList subList = findIndexByPath(pathIndex, filePath); list.append(subList); } return list; }
QModelIndexList BaseTreeView::activeRows() const { QItemSelectionModel *selection = selectionModel(); QModelIndexList indices = selection->selectedRows(); if (indices.isEmpty()) { QModelIndex current = selection->currentIndex(); if (current.isValid()) indices.append(current); } return indices; }