/*! \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); }
/** * @brief ComponentsModel::updateAll */ void ComponentsModel::updateAllComponents() { int componentsCount = count(m_Components, m_display); QModelIndexList out; out.reserve(componentsCount); for (int i = 0; i < componentsCount; ++i) { out << index(i, 1); } emit showButtons(out); }
QModelIndexList QgsAttributeTableModel::idToIndexList( QgsFeatureId id ) const { QModelIndexList indexes; int row = idToRow( id ); int columns = columnCount(); indexes.reserve( columns ); for ( int column = 0; column < columns; ++column ) { indexes.append( index( row, column ) ); } return indexes; }
/*! \reimp */ QModelIndexList QIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const { Q_D(const QIdentityProxyModel); Q_ASSERT(start.isValid() ? start.model() == this : true); if (!d->model) return QModelIndexList(); const QModelIndexList sourceList = d->model->match(mapToSource(start), role, value, hits, flags); QModelIndexList::const_iterator it = sourceList.constBegin(); const QModelIndexList::const_iterator end = sourceList.constEnd(); QModelIndexList proxyList; proxyList.reserve(sourceList.count()); for ( ; it != end; ++it) proxyList.append(mapFromSource(*it)); return proxyList; }
QModelIndexList ModelChain::indexListForValue(const QVariant &value) const { if (!Model || !KaduModel) return QModelIndexList(); QModelIndexList indexes = KaduModel->indexListForValue(value); QModelIndexList result; const int size = indexes.size(); result.reserve(size); for (int i = 0; i < size; i++) { QModelIndex index = indexes.at(i); for (auto proxyModel : ProxyModels) index = proxyModel->mapFromSource(index); result.append(index); } return result; }
void KrVfsModel::clear() { if(!_vfiles.count()) return; emit layoutAboutToBeChanged(); // clear persistent indexes QModelIndexList oldPersistentList = persistentIndexList(); QModelIndexList newPersistentList; #if QT_VERSION >= 0x040700 newPersistentList.reserve(oldPersistentList.size()); #endif for (int i=0; i< oldPersistentList.size(); ++i) newPersistentList.append(QModelIndex()); changePersistentIndexList(oldPersistentList, newPersistentList); _vfiles.clear(); _vfileNdx.clear(); _nameNdx.clear(); _dummyVfile = 0; emit layoutChanged(); }