bool BtBookshelfFilterModel::hiddenFilterAcceptsRow(int row, const QModelIndex & parent) const { if (m_showHidden && m_showShown) return true; const QAbstractItemModel * const m = sourceModel(); Q_ASSERT(m != 0); const QModelIndex itemIndex = m->index(row, m_hiddenFilterColumn, parent); const int numChildren = m->rowCount(itemIndex); if (numChildren == 0) { if (static_cast<Qt::CheckState>(m->data(itemIndex, m_hiddenFilterRole).toBool())) return m_showHidden; return m_showShown; } for (int i = 0; i < numChildren; i++) if (filterAcceptsRow(i, itemIndex)) return true; return false; }
bool PlayableProxyModel::dupeFilterAcceptsRow( int sourceRow, PlayableItem* pi, const QModelIndex& sourceParent, PlayableProxyModelFilterMemo& memo ) const { if ( !m_hideDupeItems ) return true; for ( int i = 0; i < sourceRow; i++ ) { PlayableItem* di = itemFromIndex( sourceModel()->index( i, 0, sourceParent ) ); if ( !di ) continue; bool b = ( pi->query() && pi->query()->equals( di->query() ) ) || ( pi->album() && pi->album() == di->album() ) || ( pi->artist() && pi->artist()->name() == di->artist()->name() ); if ( b && filterAcceptsRowInternal( i, di, sourceParent, memo ) ) return false; } return true; }
void HistoryTreeModel::setSourceModel(QAbstractItemModel *newSourceModel) { if (sourceModel()) { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); disconnect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); } QAbstractProxyModel::setSourceModel(newSourceModel); if (newSourceModel) { connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(layoutChanged()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); } reset(); }
DISABLE_COMPILER_WARNINGS #include <QApplication> #include <QKeyEvent> #include <QLineEdit> #include <QPlainTextEdit> #include <QSortFilterProxyModel> #include <QTextEdit> #include <QTimer> RESTORE_COMPILER_WARNINGS // Item rename handling void CFileListItemDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const { QStyledItemDelegate::setEditorData(editor, index); auto lineEditor = dynamic_cast<QLineEdit*>(editor); assert_r(lineEditor); assert_and_return_r(index.isValid(), ); auto sortModel = dynamic_cast<const QSortFilterProxyModel*>(index.model()); assert_and_return_message_r(sortModel, "Something has changed in the model hierarchy", ); auto model = dynamic_cast<const CFileListModel*>(sortModel->sourceModel()); assert_and_return_message_r(model, "Something has changed in the model hierarchy", ); auto hash = model->itemHash(sortModel->mapToSource(index)); const auto item = CController::get().itemByHash(model->panelPosition(), hash); if (item.isValid() && item.isFile()) { const QString itemName = lineEditor->text(); const int dot = itemName.lastIndexOf('.'); if (dot != -1) { QTimer::singleShot(0, Qt::CoarseTimer, lineEditor, [=]() { lineEditor->setSelection(0, dot); }); } } }
bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourceParent*/) const { GamesModel *model = qobject_cast<GamesModel *>(sourceModel()); if (!model) return false; const ServerInfo_Game &game = model->getGame(sourceRow); if (!unavailableGamesVisible) { if (game.player_count() == game.max_players()) return false; if (game.started()) return false; if (!(ownUser->user_level() & ServerInfo_User::IsRegistered)) if (game.only_registered()) return false; } if (!passwordProtectedGamesVisible && game.with_password()) return false; if (!gameNameFilter.isEmpty()) if (!QString::fromStdString(game.description()).contains(gameNameFilter, Qt::CaseInsensitive)) return false; if (!creatorNameFilter.isEmpty()) if (!QString::fromStdString(game.creator_info().name()).contains(creatorNameFilter, Qt::CaseInsensitive)) return false; QSet<int> gameTypes; for (int i = 0; i < game.game_types_size(); ++i) gameTypes.insert(game.game_types(i)); if (!gameTypeFilter.isEmpty() && gameTypes.intersect(gameTypeFilter).isEmpty()) return false; if ((maxPlayersFilterMin != -1) && (game.max_players() < maxPlayersFilterMin)) return false; if ((maxPlayersFilterMax != -1) && (game.max_players() > maxPlayersFilterMax)) return false; return true; }
QModelIndex GroupProxyModel::mapToSource(const QModelIndex &proxyIndex) const { if (! proxyIndex.isValid()) return QModelIndex(); if (proxyIndex.model() != this) return QModelIndex(); int srcRow; int srcCol; QModelIndex parent = proxyIndex.parent(); if (parent.isValid()) { Group* gr = groups[parent.row()]; srcRow = gr->at(proxyIndex.row()); srcCol = (proxyIndex.row() <= groupId) ? proxyIndex.row() : proxyIndex.row() + 1; } else { Group* gr = groups[proxyIndex.row()]; srcRow = gr->first(); srcCol = groupId; } return sourceModel()->index(srcRow, srcCol); }
bool WarningsModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent); QAbstractItemModel *sourceItemModel = sourceModel(); Models::ArtItemsModel *artItemsModel = dynamic_cast<Models::ArtItemsModel *>(sourceItemModel); Q_ASSERT(artItemsModel != NULL); Models::ArtworkMetadata *metadata = artItemsModel->getArtwork(sourceRow); bool rowIsOk = false; if (metadata != NULL) { Common::WarningFlags warningsFlags = metadata->getWarningsFlags(); bool anyWarnings = warningsFlags != Common::WarningFlags::None; rowIsOk = anyWarnings; if (m_ShowOnlySelected) { rowIsOk = metadata->isSelected() && anyWarnings; } } return rowIsOk; }
bool TvShowProxyModel::hasAcceptedChildren(int source_row, const QModelIndex &source_parent) const { QModelIndex item = sourceModel()->index(source_row, 0, source_parent); if (!item.isValid()) { //qDebug() << "item invalid" << source_parent << source_row; return false; } //check if there are children int childCount = item.model()->rowCount(item); if (childCount == 0) return false; for (int i = 0; i < childCount; ++i) { if (filterAcceptsRowItself(i, item)) return true; //recursive call -> NOTICE that this is depth-first searching, you're probably better off with breadth first search... if (hasAcceptedChildren(i, item)) return true; } return false; }
bool ModListSortProxy::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { if (!data->hasUrls() && (sortColumn() != ModList::COL_PRIORITY)) { QWidget *wid = qApp->activeWindow()->findChild<QTreeView*>("modList"); MessageDialog::showMessage(tr("Drag&Drop is only supported when sorting by priority"), wid); return false; } if ((row == -1) && (column == -1)) { return sourceModel()->dropMimeData(data, action, -1, -1, mapToSource(parent)); } // in the regular model, when dropping between rows, the row-value passed to // the sourceModel is inconsistent between ascending and descending ordering. // This should fix that if (sortOrder() == Qt::DescendingOrder) { --row; } QModelIndex proxyIndex = index(row, column, parent); QModelIndex sourceIndex = mapToSource(proxyIndex); return this->sourceModel()->dropMimeData(data, action, sourceIndex.row(), sourceIndex.column(), sourceIndex.parent()); }
void QmlProfilerStatisticsMainView::displayTypeIndex(int typeIndex) { if (typeIndex < 0) { setCurrentIndex(QModelIndex()); } else { auto sortModel = qobject_cast<const QSortFilterProxyModel *>(model()); QTC_ASSERT(sortModel, return); QAbstractItemModel *sourceModel = sortModel->sourceModel(); QTC_ASSERT(sourceModel, return); QModelIndex sourceIndex = sourceModel->index(qMin(typeIndex, sourceModel->rowCount() - 1), MainCallCount); QTC_ASSERT(sourceIndex.data(TypeIdRole).toInt() == typeIndex, return); setCurrentIndex(sourceIndex.data(SortRole).toInt() > 0 ? sortModel->mapFromSource(sourceIndex) : QModelIndex()); } // show in callers/callees subwindow emit propagateTypeIndex(typeIndex); }
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override { auto index0 = sourceModel()->index(sourceRow, 0, sourceParent); const auto& model = _data->modelinfo.at(index0.internalId()); switch (model->type()) { case ModelDataType::VehicleInfo: if (!_showCars) return false; break; case ModelDataType::PedInfo: if (!_showPeds) return false; break; default: if (!_showMisc) return false; break; } return !(!_name.empty() && model->name.find(_name) == std::string::npos); }
bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); int status = index.data(TransactionTableModel::StatusRole).toInt(); if (!showInactive && status == TransactionStatus::Conflicted) return false; int type = index.data(TransactionTableModel::TypeRole).toInt(); if (!(TYPE(type) & typeFilter)) return false; bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool(); if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No) return false; if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes) return false; QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime(); if (datetime < dateFrom || datetime > dateTo) return false; QString address = index.data(TransactionTableModel::AddressRole).toString(); QString label = index.data(TransactionTableModel::LabelRole).toString(); QString txid = index.data(TransactionTableModel::TxHashRole).toString(); if (!address.contains(m_search_string, Qt::CaseInsensitive) && ! label.contains(m_search_string, Qt::CaseInsensitive) && ! txid.contains(m_search_string, Qt::CaseInsensitive)) { return false; } qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong()); if (amount < minAmount) return false; return true; }
bool DBFRedactorSortFilterProxyModel::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const { bool res = true; int i = 0; foreach(FilterItem item, m_filter) { bool tempRes = true; if (i++ == 0) item.filterOperator = AND; const QVariant& data = sourceModel()->index(source_row, item.column, source_parent).data(Qt::DisplayRole); switch (item.uslovie) { case Equal: tempRes = data.toString().contains(item.regExp) && data.toString().remove(item.regExp).isEmpty(); break; case NotEqual: tempRes = !(data.toString().contains(item.regExp) && data.toString().remove(item.regExp).isEmpty()); break; case Smaller: tempRes =QString::compare(data.toString(), item.regExp.pattern(), item.regExp.caseSensitivity()) < 0; break; case SmallerOrEqual: tempRes = QString::compare(data.toString(), item.regExp.pattern(), item.regExp.caseSensitivity()) <= 0; break; case Lager: tempRes = QString::compare(data.toString(), item.regExp.pattern(), item.regExp.caseSensitivity()) > 0; break; case LagerOrEqual: tempRes = QString::compare(data.toString(), item.regExp.pattern(), item.regExp.caseSensitivity()) >= 0; break; } switch (item.filterOperator) { case AND: res &= tempRes; break; case OR: res |= tempRes; break; } }
bool QFPseudoTreeModelSortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QFPseudoTreeModel* tree=qobject_cast<QFPseudoTreeModel*>(sourceModel()); if (tree) { QModelIndex idx=tree->index(sourceRow, 0, sourceParent); if (idx.isValid()) { if (tree->isFolder(idx)) { QList<int> c=tree->folderContentsRows(idx); for (int i=0; i<c.size(); i++) { if (filterAcceptsRow(c[i], sourceParent)) { return true; } } return false; } else { return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); } } } else { return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); } return true; }
bool LibraryFilterProxyModel::hasAcceptedChildren(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex item = sourceModel()->index(sourceRow, 0, sourceParent); if (!item.isValid()) { return false; } // Check if there are children int childCount = item.model()->rowCount(item); if (childCount == 0) { return false; } for (int i = 0; i < childCount; ++i) { if (filterAcceptsRowItself(i, item)) { return true; } // Recursive call if (hasAcceptedChildren(i, item)) { return true; } } return false; }
bool SortFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QRegExp rx = filterRegExp(); if (rx.isEmpty()) return true; QAbstractItemModel *model = sourceModel(); if (filterRole().isEmpty()) { QHash<int, QByteArray> roles = roleNames(); QHashIterator<int, QByteArray> it(roles); while (it.hasNext()) { it.next(); QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); QString key = model->data(sourceIndex, it.key()).toString(); if (key.contains(rx)) return true; } return false; } QModelIndex sourceIndex = model->index(sourceRow, 0, sourceParent); if (!sourceIndex.isValid()) return true; QString key = model->data(sourceIndex, roleKey(filterRole())).toString(); return key.contains(rx); }
bool SnippetFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex & sourceParent) const { if (filter_.isEmpty()) { // No filtering needed... return true; } QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); QStandardItem* item = SnippetStore::self()->itemFromIndex( index ); if (!item) return false; Snippet* snippet = dynamic_cast<Snippet*>( item ); if (snippet) { if ( snippet->text().contains( filter_) ) return true; else return false; } // if it's not a snippet; allow it... return true; }
bool DirViewProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (!filterEnabled) { return true; } if (!isChildOfRoot(sourceParent)) { return true; } const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); DirViewItem *item = static_cast<DirViewItem *>(index.internalPointer()); QModelIndex idx=index.parent(); QStringList strings; // Traverse back up tree, so we get parent strings... while (idx.isValid()) { DirViewItem *i = static_cast<DirViewItem *>(idx.internalPointer()); if (DirViewItem::Type_Dir!=i->type()) { break; } strings << i->data(); idx=idx.parent(); } if (DirViewItem::Type_Dir==item->type()) { // Check *all* children... if (filterAcceptsDirViewItem(item, strings)) { return true; } } else { strings << item->data(); return matchesFilter(strings); } return false; }
bool ActionFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { if (Size > 1) return true; // only filter first-level if (sourceParent.isValid()) return true; const QModelIndex &sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent); if (ActionRole != sourceIndex.data(ItemTypeRole).value<int>()) return true; QAction *action = sourceIndex.data(ActionRole).value<QAction *>(); if (!action) return false; if (Size <= 1 && HideWhenModelSingle.contains(action)) return false; if (Size == 0 && HideWhenModelEmpty.contains(action)) return false; return true; }
bool DirPlaylistTrackFilterProxyModel::filterAcceptsRow( int source_row, const QModelIndex& source_parent ) const { QModelIndex index = sourceModel()->index( source_row, 0, source_parent ); QVariant qvar = index.data( KDirModel::FileItemRole ); if( !qvar.canConvert<KFileItem>() ) return false; KFileItem item = qvar.value<KFileItem>(); if( item.name() == "." ) return false; if( item.isDir() || Playlists::isPlaylist( item.url() ) || MetaFile::Track::isTrack( item.url() ) ) { return QSortFilterProxyModel::filterAcceptsRow( source_row, source_parent ); } return false; }
bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); int type = index.data(TransactionTableModel::TypeRole).toInt(); QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime(); QString address = index.data(TransactionTableModel::AddressRole).toString(); QString label = index.data(TransactionTableModel::LabelRole).toString(); qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong()); int status = index.data(TransactionTableModel::StatusRole).toInt(); if(!showInactive && (status == TransactionStatus::Conflicted || status == TransactionStatus::NotAccepted)) return false; if(!(TYPE(type) & typeFilter)) return false; if(datetime < dateFrom || datetime > dateTo) return false; if (!address.contains(addrPrefix, Qt::CaseInsensitive) && !label.contains(addrPrefix, Qt::CaseInsensitive)) return false; if(amount < minAmount) return false; return true; }
void FeedsView::contextMenuEvent(QContextMenuEvent *event) { const QModelIndex clicked_index = indexAt(event->pos()); if (clicked_index.isValid()) { const QModelIndex mapped_index = model()->mapToSource(clicked_index); RootItem *clicked_item = sourceModel()->itemForIndex(mapped_index); if (clicked_item->kind() == RootItemKind::Category) { // Display context menu for categories. initializeContextMenuCategories(clicked_item)->exec(event->globalPos()); } else if (clicked_item->kind() == RootItemKind::Feed) { // Display context menu for feeds. initializeContextMenuFeeds(clicked_item)->exec(event->globalPos()); } else { initializeContextMenuOtherItem(clicked_item)->exec(event->globalPos()); } } else { // Display menu for empty space. initializeContextMenuEmptySpace()->exec(event->globalPos()); } }
bool FileViewSortProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const { FileViewTreeItem* rightItem = static_cast<FileViewTreeItem*>(right.internalPointer()); FileViewTreeItem* lefttItem = static_cast<FileViewTreeItem*>(left.internalPointer()); if(rightItem->GetType() != lefttItem->GetType()) { return lefttItem->GetType() == FileViewTreeItem::FOLDER; } int sortCol = sortColumn(); switch (sortCol) { case 0: { return lefttItem->GetName().compare(rightItem->GetName(), Qt::CaseInsensitive) < 0; } case 1: { libtorrent::size_type szLeft = sourceModel()->data(left).toLongLong(); libtorrent::size_type szRight = sourceModel()->data(right).toLongLong(); return szLeft < szRight; } case 2: { float leftReady = sourceModel()->data(left).toFloat(); float rightReady = sourceModel()->data(right).toFloat(); return leftReady < rightReady; } case 3: { int leftPriority = sourceModel()->data(left).toInt(); int rightPriority = sourceModel()->data(right).toInt(); return leftPriority < rightPriority; } } return true; }
bool SimpleFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); if(!m_complexHandling) { return (sourceModel()->data(index0, qutim_sdk_0_3::DescriptionRole).toString().contains(filterRegExp()) || sourceModel()->data(index0).toString().contains(filterRegExp())); } if(index0.child(0, 0).isValid()) { for(int i = 0; index0.child(i, 0).isValid(); ++i) { if(sourceModel()->data(index0.child(i, 0)).toString().contains(filterRegExp()) || sourceModel()->data(index0.child(i, 0), qutim_sdk_0_3::DescriptionRole) .toString().contains(filterRegExp())) return true; } } else { return (sourceModel()->data(index0, qutim_sdk_0_3::DescriptionRole).toString().contains(filterRegExp()) || sourceModel()->data(index0).toString().contains(filterRegExp())); } return false; }
bool SortFilterMilkReceptionTable::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { const auto indexDelivererId = sourceModel()->index(sourceRow, RMT_ID_DELIVERER, sourceParent), indexMilkPointId = sourceModel()->index(sourceRow, RMT_MILK_POINT_ID, sourceParent), indexDeliveryDate = sourceModel()->index(sourceRow, RMT_DELIVERY_DATE, sourceParent); const auto delivererId = sourceModel()->data(indexDelivererId).toLongLong(), milkPointId = sourceModel()->data(indexMilkPointId).toLongLong(); const auto deliveryDate = sourceModel()->data(indexDeliveryDate).toDate(); bool isDelivererAccepted = true, isMilkPointAccepted = true, isDateAccepted = true; if (isNeedFilterByDelivId()) isDelivererAccepted = (m_delivererId == delivererId); if (utm::isAutoIncrIdIsValid(m_milkPointId)) isMilkPointAccepted = (milkPointId == m_milkPointId); if (m_dateMin.isValid() && m_dateMax.isValid()) isDateAccepted = (deliveryDate >= m_dateMin && deliveryDate <= m_dateMax); return isDelivererAccepted && isMilkPointAccepted && isDateAccepted; }
void TreeProxyModel::setSourceModel(QAbstractItemModel* model) { if (sourceModel()) { disconnect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); disconnect(sourceModel(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(sourceRowsInserted(QModelIndex,int,int))); disconnect(sourceModel(), SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(sourceRowsRemoved(QModelIndex,int,int))); } QAbstractProxyModel::setSourceModel(model); if (model) { connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(sourceReset())); connect(sourceModel(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(sourceRowsInserted(QModelIndex,int,int))); connect(sourceModel(), SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(sourceRowsRemoved(QModelIndex,int,int))); } reset(); }
bool HistoryCompletionModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { // We give a bonus to hits that match on a word boundary so that e.g. "dot.kde.org" // is a better result for typing "dot" than "slashdot.org". However, we only look // for the string in the host name, not the entire url, since while it makes sense // to e.g. give "www.phoronix.com" a bonus for "ph", it does _not_ make sense to // give "www.yadda.com/foo.php" the bonus. int frecency_l = sourceModel()->data(left, HistoryFilterModel::FrecencyRole).toInt(); QString url_l = sourceModel()->data(left, HistoryModel::UrlRole).toUrl().host(); QString title_l = sourceModel()->data(left, HistoryModel::TitleRole).toString(); if (m_wordMatcher.indexIn(url_l) != -1 || m_wordMatcher.indexIn(title_l) != -1) frecency_l *= 2; int frecency_r = sourceModel()->data(right, HistoryFilterModel::FrecencyRole).toInt(); QString url_r = sourceModel()->data(right, HistoryModel::UrlRole).toUrl().host(); QString title_r = sourceModel()->data(right, HistoryModel::TitleRole).toString(); if (m_wordMatcher.indexIn(url_r) != -1 || m_wordMatcher.indexIn(title_r) != -1) frecency_r *= 2; // sort results in descending frecency-derived score return (frecency_r < frecency_l); }
bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { const int column = sortColumn(); if (column == TorrentModelItem::TR_NAME) { QVariant vL = left.data(); QVariant vR = right.data(); if (!(vL.isValid() && vR.isValid())) return QSortFilterProxyModel::lessThan(left, right); Q_ASSERT(vL.isValid()); Q_ASSERT(vR.isValid()); bool res = false; if (misc::naturalSort(vL.toString(), vR.toString(), res)) return res; return QSortFilterProxyModel::lessThan(left, right); } else if (column == TorrentModelItem::TR_ADD_DATE || column == TorrentModelItem::TR_SEED_DATE || column == TorrentModelItem::TR_SEEN_COMPLETE_DATE) { QDateTime vL = left.data().toDateTime(); QDateTime vR = right.data().toDateTime(); //not valid dates should be sorted at the bottom. if (!vL.isValid()) return false; if (!vR.isValid()) return true; return vL < vR; } else if (column == TorrentModelItem::TR_PRIORITY) { const int vL = left.data().toInt(); const int vR = right.data().toInt(); // Seeding torrents should be sorted by their completed date instead. if (vL == -1 && vR == -1) { QAbstractItemModel *model = sourceModel(); const QDateTime dateL = model->data(model->index(left.row(), TorrentModelItem::TR_SEED_DATE)).toDateTime(); const QDateTime dateR = model->data(model->index(right.row(), TorrentModelItem::TR_SEED_DATE)).toDateTime(); //not valid dates should be sorted at the bottom. if (!dateL.isValid()) return false; if (!dateR.isValid()) return true; return dateL < dateR; } // Seeding torrents should be at the bottom if (vL == -1) return false; if (vR == -1) return true; return vL < vR; } else if (column == TorrentModelItem::TR_PEERS || column == TorrentModelItem::TR_SEEDS) { int left_active = left.data().toInt(); int left_total = left.data(Qt::UserRole).toInt(); int right_active = right.data().toInt(); int right_total = right.data(Qt::UserRole).toInt(); // Active peers/seeds take precedence over total peers/seeds. if (left_active == right_active) return (left_total < right_total); else return (left_active < right_active); } else if (column == TorrentModelItem::TR_ETA) { const QAbstractItemModel *model = sourceModel(); const int prioL = model->data(model->index(left.row(), TorrentModelItem::TR_PRIORITY)).toInt(); const int prioR = model->data(model->index(right.row(), TorrentModelItem::TR_PRIORITY)).toInt(); const qlonglong etaL = left.data().toLongLong(); const qlonglong etaR = right.data().toLongLong(); const bool ascend = (sortOrder() == Qt::AscendingOrder); const bool invalidL = (etaL < 0 || etaL >= MAX_ETA); const bool invalidR = (etaR < 0 || etaR >= MAX_ETA); const bool seedingL = (prioL < 0); const bool seedingR = (prioR < 0); bool activeL; bool activeR; switch (model->data(model->index(left.row(), TorrentModelItem::TR_STATUS)).toInt()) { case TorrentModelItem::STATE_DOWNLOADING: case TorrentModelItem::STATE_DOWNLOADING_META: case TorrentModelItem::STATE_STALLED_DL: case TorrentModelItem::STATE_SEEDING: case TorrentModelItem::STATE_STALLED_UP: activeL = true; break; default: activeL = false; } switch (model->data(model->index(right.row(), TorrentModelItem::TR_STATUS)).toInt()) { case TorrentModelItem::STATE_DOWNLOADING: case TorrentModelItem::STATE_DOWNLOADING_META: case TorrentModelItem::STATE_STALLED_DL: case TorrentModelItem::STATE_SEEDING: case TorrentModelItem::STATE_STALLED_UP: activeR = true; break; default: activeR = false; } // Sorting rules prioritized. // 1. Active torrents at the top // 2. Seeding torrents at the bottom // 3. Torrents with invalid ETAs at the bottom if (activeL != activeR) return activeL; if (seedingL != seedingR) { if (seedingL) return !ascend; else return ascend; } if (invalidL && invalidR) { if (seedingL) { //Both seeding QDateTime dateL = model->data(model->index(left.row(), TorrentModelItem::TR_SEED_DATE)).toDateTime(); QDateTime dateR = model->data(model->index(right.row(), TorrentModelItem::TR_SEED_DATE)).toDateTime(); //not valid dates should be sorted at the bottom. if (!dateL.isValid()) return false; if (!dateR.isValid()) return true; return dateL < dateR; } else return prioL < prioR; } else if ((invalidL == false) && (invalidR == false)) return QSortFilterProxyModel::lessThan(left, right); else return !invalidL; } return QSortFilterProxyModel::lessThan(left, right); }
KDevelop::ProjectModel * ProjectProxyModel::projectModel() const { return qobject_cast<KDevelop::ProjectModel*>( sourceModel() ); }
bool PrettyMailboxModel::hasChildren(const QModelIndex &parent) const { return sourceModel()->hasChildren(mapToSource(parent)); }