void KACLListView::slotEditEntry() { QTreeWidgetItem * current = currentItem(); if ( !current ) return; KACLListViewItem *item = static_cast<KACLListViewItem*>( current ); int allowedTypes = item->type | NamedUser | NamedGroup; bool itemWasMask = item->type == Mask; if ( !m_hasMask || itemWasMask ) allowedTypes |= Mask; int allowedDefaultTypes = item->type | NamedUser | NamedGroup; if ( !findDefaultItemByType( Mask ) ) allowedDefaultTypes |= Mask; if ( !hasDefaultEntries() ) allowedDefaultTypes |= User | Group; EditACLEntryDialog dlg( this, item, allowedUsers( false, item ), allowedGroups( false, item ), allowedUsers( true, item ), allowedGroups( true, item ), allowedTypes, allowedDefaultTypes, m_allowDefaults ); dlg.exec(); if ( itemWasMask && item->type != Mask ) { m_hasMask = false; m_mask = 0; } if ( !itemWasMask && item->type == Mask ) { m_mask = item->value; m_hasMask = true; } calculateEffectiveRights(); sortItems( sortColumn(), Qt::AscendingOrder ); }
void TableEditor::columnClicked(int col) { if(!sorting()) return; //if(col==lastSortCol) asc=!asc; else lastSortCol=col,asc=TRUE; sortColumn(col,1,1); emit sorted(); }
bool FileTreeSortProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const { FileTreeItem* leftItem = static_cast<FileTreeItem*>(left.internalPointer()); FileTreeItem* rightItem = static_cast<FileTreeItem*>(right.internalPointer()); bool leftIsFolder = leftItem->childCount() > 0; bool rightIsFolder = rightItem->childCount() > 0; if (leftIsFolder != rightIsFolder) { return leftIsFolder; } int sortCol = sortColumn(); switch (sortCol) { case 0: { return leftItem->data(sortCol).toString().compare(rightItem->data(sortCol).toString(), Qt::CaseInsensitive) < 0; } case 1: { return leftItem->data(sortCol).toULongLong() < rightItem->data(sortCol).toULongLong(); } default: { return true; } } }
/*Make up-triangle matrix*/ void ConverterUV::diagonalized() { for(int i = 0; i < matrix.size(); i++) { sortColumn(i); if(matrix[i][i] != 0) { qreal norm = matrix[i][i]; for(int k = i; k < matrix.size(); k++) { matrix[i][k] /= norm; } rightPart[i] /= norm; for(int j = i + 1; j < matrix.size(); j++) { if(matrix[j][i] != 0) { qreal coeff = matrix[j][i]; for(int k = i; k < matrix.size(); k++) { matrix[j][k] -= (coeff * matrix[i][k]); } rightPart[j] -= coeff * rightPart[i]; } } } } }
// ---------------------------------------------------------------------------- // ArchiveEntryList::sortItems // // Sorts the list items depending on the current sorting column // ---------------------------------------------------------------------------- void ArchiveEntryList::sortItems() { lv_current = this; std::sort(items.begin(), items.end(), [&](long left, long right) { auto le = getEntry(left, false); auto re = getEntry(right, false); // Check entries exist (just to be needlessly safe) if (!le || !re) return sort_descend ? right < left : left < right; // Sort folder->entry first if (le->getType() == EntryType::folderType() && re->getType() != EntryType::folderType()) return true; if (re->getType() == EntryType::folderType() && le->getType() != EntryType::folderType()) return false; // Sort folder<->folder or entry<->entry int result = 0; // Size sort if (col_size >= 0 && col_size == sortColumn()) result = entrySize(left) - entrySize(right); // Index sort else if (col_index >= 0 && col_index == sortColumn()) result = 0; // Name sort else if (col_name >= 0 && col_name == sortColumn()) { const wxChar* reName = re->getName().c_str(); result = le->getName().CompareTo(reName, string::ignoreCase); } // Other (default) sort else return VirtualListView::defaultSort(left, right); // If sort values are equal, just sort by index if (result == 0) result = left - right; return sort_descend ? result > 0 : result < 0; }); }
void KACLListView::slotAddEntry() { int allowedTypes = NamedUser | NamedGroup; if ( !m_hasMask ) allowedTypes |= Mask; int allowedDefaultTypes = NamedUser | NamedGroup; if ( !findDefaultItemByType( Mask ) ) allowedDefaultTypes |= Mask; if ( !hasDefaultEntries() ) allowedDefaultTypes |= User | Group; EditACLEntryDialog dlg( this, 0, allowedUsers( false ), allowedGroups( false ), allowedUsers( true ), allowedGroups( true ), allowedTypes, allowedDefaultTypes, m_allowDefaults ); dlg.exec(); KACLListViewItem *item = dlg.item(); if ( !item ) return; // canceled if ( item->type == Mask && !item->isDefault ) { m_hasMask = true; m_mask = item->value; } if ( item->isDefault && !hasDefaultEntries() ) { // first default entry, fill in what is needed if ( item->type != User ) { unsigned short v = findDefaultItemByType( User )->value; new KACLListViewItem( this, User, v, true ); } if ( item->type != Group ) { unsigned short v = findDefaultItemByType( Group )->value; new KACLListViewItem( this, Group, v, true ); } if ( item->type != Others ) { unsigned short v = findDefaultItemByType( Others )->value; new KACLListViewItem( this, Others, v, true ); } } const KACLListViewItem *defaultMaskItem = findDefaultItemByType( Mask ); if ( item->isDefault && !defaultMaskItem ) { unsigned short v = calculateMaskValue( true ); new KACLListViewItem( this, Mask, v, true ); } if ( !item->isDefault && !m_hasMask && ( item->type == Group || item->type == NamedUser || item->type == NamedGroup ) ) { // auto-add a mask entry unsigned short v = calculateMaskValue( false ); new KACLListViewItem( this, Mask, v, false ); m_hasMask = true; m_mask = v; } calculateEffectiveRights(); sortItems( sortColumn(), Qt::AscendingOrder ); setCurrentItem( item ); // QTreeWidget doesn't seem to emit, in this case, and we need to update // the buttons... if ( topLevelItemCount() == 1 ) emit currentItemChanged( item, item ); }
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const { QFileSystemModel *fsm = qobject_cast<QFileSystemModel*>(sourceModel()); bool asc = (sortOrder() == Qt::AscendingOrder ? true : false) ; QFileInfo leftFileInfo = fsm->fileInfo(left); QFileInfo rightFileInfo = fsm->fileInfo(right); // If Dot move in the beginning if (sourceModel()->data(left).toString() == ".") return asc; if (sourceModel()->data(right).toString() == ".") return !asc; // If DotAndDot move in the beginning if (sourceModel()->data(left).toString() == "..") return asc; if (sourceModel()->data(right).toString() == "..") return !asc; // Move dirs upper if (!leftFileInfo.isDir() && rightFileInfo.isDir()) return !asc; if (leftFileInfo.isDir() && !rightFileInfo.isDir()) return asc; /*If sorting by Size (Take real size, not Display one 10<2)*/ if ((sortColumn()==1) && (!leftFileInfo.isDir() && !rightFileInfo.isDir())) { if (leftFileInfo.size() < rightFileInfo.size()) return true; if (leftFileInfo.size() > rightFileInfo.size()) return false; } /*If sorting by Date Modified (Take real date, not Display one 01-10-2014<02-01-1980)*/ if (sortColumn()==3) { if (leftFileInfo.lastModified() < rightFileInfo.lastModified()) return true; if (leftFileInfo.lastModified() > rightFileInfo.lastModified()) return false; } //Columns found here:https://qt.gitorious.org/qt/qt/source/9e8abb63ba4609887d988ee15ba6daee0b01380e:src/gui/dialogs/qfilesystemmodel.cpp return QSortFilterProxyModel::lessThan(left, right); }
void QgsAttributeTableFilterModel::setSelectedOnTop( bool selectedOnTop ) { mSelectedOnTop = selectedOnTop; if ( sortColumn() == -1 ) { sort( 0, sortOrder() ); } invalidate(); }
void FolderModel::updateQueries() { if ( !m_query.isEmpty() ) { QStringList columns = m_sortColumns.value( sortColumn() ); QString order = ( sortOrder() == Qt::AscendingOrder ) ? "ASC" : "DESC"; QStringList parts; foreach ( const QString& part, columns ) parts.append( QString( "%1 %2" ).arg( part, order ) ); int id = m_columns.value( sortColumn() ); if ( id != Column_ID && id != Column_CreatedDate ) parts.append( "i.issue_id ASC" ); m_order = parts.join( ", " ); refresh(); }
void DataViewTable::columnClicked(int col) { if (col == sort_column_) { sort_ascending_ = !sort_ascending_; } else { sort_ascending_ = true; sort_column_ = col; } horizontalHeader()->setSortIndicator(col, sort_ascending_); sortColumn(sort_column_, sort_ascending_, true); }
void ProRataProteinTable::colClickedForSorting( int iColumn ) { if( iColumn == iCurrentColumnSorted ) { if( bIsCurrentSortAscending ) { sortColumn( iColumn, false ); } else { sortColumn( iColumn, true ); } } else { sortColumn( iColumn, true ); } }
bool UrlSortFilterProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const { if (sortColumn() == 2) { QVariant leftData = sourceModel()->data(left, Qt::UserRole + 1); QVariant rightData = sourceModel()->data(right, Qt::UserRole + 1); return leftData.toDateTime() < rightData.toDateTime(); } return QSortFilterProxyModel::lessThan(left, right); }
void QgsAttributeTableFilterModel::selectionChanged() { if ( ShowSelected == mFilterMode ) { invalidateFilter(); } else if ( mSelectedOnTop ) { sort( sortColumn(), sortOrder() ); invalidate(); } }
bool SearchSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { switch (sortColumn()) { case NAME: case ENGINE_URL: { QString vL = left.data().toString(); QString vR = right.data().toString(); return Utils::String::naturalCompareCaseInsensitive(vL, vR); } default: return base::lessThan(left, right); }; }
/*! \brief the press event on an header \param index index of the header has been pressed */ void CustomTreeWidget::onHeaderClicked(int index) { if(index == sortColumn()){ if(sort == Qt::AscendingOrder){ sort = Qt::DescendingOrder; }else{ sort = Qt::AscendingOrder; } }else{ sort = Qt::AscendingOrder; } sortByColumn(index,sort); }
bool SearchSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { switch (sortColumn()) { case NAME: case ENGINE_URL: { const QString strL = left.data().toString(); const QString strR = right.data().toString(); const int result = Utils::String::naturalCompare(strL, strR, Qt::CaseInsensitive); return (result < 0); } break; default: return base::lessThan(left, right); }; }
void QgsAttributeTableFilterModel::setSelectedOnTop( bool selectedOnTop ) { if ( mSelectedOnTop != selectedOnTop ) { mSelectedOnTop = selectedOnTop; int column = sortColumn(); Qt::SortOrder order = sortOrder(); // set default sort values if they are not correctly set if ( column < 0 || ( order != Qt::AscendingOrder && order != Qt::DescendingOrder ) ) { sort( 0, Qt::AscendingOrder ); invalidate(); } } }
void ProRataProteinTable::populateTable( const vector< ProteinInfo *> &vpProteinInfo ) { //emit flushGraph(); vproInfo.clear(); vproInfo.resize( vpProteinInfo.size() ); copy( vpProteinInfo.begin(), vpProteinInfo.end(), vproInfo.begin() ); sortColumn( iCurrentColumnSorted, bIsCurrentSortAscending ); //populateTable(); //qtwTable->resizeColumnToContents( 0 ); //qtwTable->resizeColumnToContents( 1 ); //qtwTable->resizeColumnToContents( 2 ); //qtwTable->resizeColumnToContents( 3 ); //qtwTable->horizontalHeader()->resizeSection( 0, 70 ); qtwTable->horizontalHeader()->setStretchLastSection( true ); }
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 TorrentContentFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { switch (sortColumn()) { case TorrentContentModelItem::COL_NAME: { QString vL = left.data().toString(); QString vR = right.data().toString(); TorrentContentModelItem::ItemType leftType = m_model->itemType(m_model->index(left.row(), 0, left.parent())); TorrentContentModelItem::ItemType rightType = m_model->itemType(m_model->index(right.row(), 0, right.parent())); if (leftType == rightType) return Utils::String::naturalCompareCaseInsensitive(vL, vR); else if (leftType == TorrentContentModelItem::FolderType && sortOrder() == Qt::AscendingOrder) return true; else return false; } }; return QSortFilterProxyModel::lessThan(left, right); }
void ProRataPeptideTable::newProteinClicked( ProteinInfo * pproInfo ) { if (!(pproInfo)) { vpepInfo.clear(); populateTable(); return; } vpepInfo.clear(); vpepInfo = pproInfo->getPeptideInfo(); //populateTable(); // qtwTable->horizontalHeader()->setSortIndicator( iCurrentColumnSorted, Qt::AscendingOrder ); //qtwTable->horizontalHeader()->setSortIndicator( 0, Qt::AscendingOrder ); qtwTable->horizontalHeader()->setStretchLastSection( true ); // colClickedForSorting( iCurrentColumnSorted ); sortColumn( iCurrentColumnSorted, bIsCurrentSortAscending ); }
void CSMWorld::InfoTableProxyModel::sourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { refreshFilter(); if (mLastAddedSourceRow != -1 && topLeft.row() <= mLastAddedSourceRow && bottomRight.row() >= mLastAddedSourceRow) { // Now the topic of the last added row is set, // so we can re-sort the model to ensure the corrent position of this row int column = sortColumn(); Qt::SortOrder order = sortOrder(); sort(mInfoColumnIndex); // Restore the correct position of an added row sort(column, order); // Restore the original sort order emit rowAdded(getRecordId(mLastAddedSourceRow).toUtf8().constData()); // Make sure that we perform a re-sorting only in the first dataChanged() after a row insertion mLastAddedSourceRow = -1; } }
bool TorrentContentFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { switch (sortColumn()) { case TorrentContentModelItem::COL_NAME: { const TorrentContentModelItem::ItemType leftType = m_model->itemType(m_model->index(left.row(), 0, left.parent())); const TorrentContentModelItem::ItemType rightType = m_model->itemType(m_model->index(right.row(), 0, right.parent())); if (leftType == rightType) { const QString strL = left.data().toString(); const QString strR = right.data().toString(); return Utils::String::naturalLessThan<Qt::CaseInsensitive>(strL, strR); } if ((leftType == TorrentContentModelItem::FolderType) && (sortOrder() == Qt::AscendingOrder)) { return true; } return false; } default: return QSortFilterProxyModel::lessThan(left, right); }; }
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 UsersModel::updateQueries() { QString order = ( sortOrder() == Qt::AscendingOrder ) ? "ASC" : "DESC"; switch ( sortColumn() ) { case 0: m_order = QString( "u.user_name COLLATE LOCALE %1" ).arg( order ); break; case 1: m_order = QString( "u.user_login COLLATE LOCALE %1" ).arg( order ); break; case 2: m_order = QString( "p.pref_value COLLATE LOCALE %1" ).arg( order ); break; case 3: m_order = QString( "u.user_access %1" ).arg( order ); break; } refresh(); }
bool ListModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { if (sortColumn() == 0) { QFileSystemModel *fsm = qobject_cast<QFileSystemModel*>(sourceModel()); bool asc = sortOrder() == Qt::AscendingOrder ? true : false; QFileInfo leftFileInfo = fsm->fileInfo(left); QFileInfo rightFileInfo = fsm->fileInfo(right); if (sourceModel()->data(left).toString() == "..") return asc; if (sourceModel()->data(right).toString() == "..") return !asc; if (!leftFileInfo.isDir() && rightFileInfo.isDir()) { return !asc; } if (leftFileInfo.isDir() && !rightFileInfo.isDir()) { return asc; } } return QSortFilterProxyModel::lessThan(left, right); }
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); }
bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const { const int column = sortColumn(); if (column == TorrentModel::TR_NAME) { QVariant vL = left.data(); QVariant vR = right.data(); if (!vL.isValid() || !vR.isValid() || (vL == vR)) return lowerPositionThan(left, right); bool res = false; if (Utils::String::naturalSort(vL.toString(), vR.toString(), res)) return res; return QSortFilterProxyModel::lessThan(left, right); } else if (column == TorrentModel::TR_ADD_DATE || column == TorrentModel::TR_SEED_DATE || column == TorrentModel::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 == TorrentModel::TR_PRIORITY) { return lowerPositionThan(left, right); } else if (column == TorrentModel::TR_PEERS || column == TorrentModel::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) { if (left_total == right_total) return lowerPositionThan(left, right); return (left_total < right_total); } else { return (left_active < right_active); } } else if (column == TorrentModel::TR_ETA) { TorrentModel *model = qobject_cast<TorrentModel *>(sourceModel()); const int prioL = model->data(model->index(left.row(), TorrentModel::TR_PRIORITY)).toInt(); const int prioR = model->data(model->index(right.row(), TorrentModel::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 activeR = TorrentFilter::ActiveTorrent.match(model->torrentHandle(model->index(right.row()))); bool activeL = TorrentFilter::ActiveTorrent.match(model->torrentHandle(model->index(right.row()))); // 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(), TorrentModel::TR_SEED_DATE)).toDateTime(); QDateTime dateR = model->data(model->index(right.row(), TorrentModel::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 && !invalidR) { return etaL < etaR; } else { return !invalidL; } } else if (column == TorrentModel::TR_LAST_ACTIVITY) { const qlonglong vL = left.data().toLongLong(); const qlonglong vR = right.data().toLongLong(); if (vL == -1) return false; if (vR == -1) return true; return vL < vR; } else if (column == TorrentModel::TR_RATIO_LIMIT) { const qreal vL = left.data().toDouble(); const qreal vR = right.data().toDouble(); if (vL == -1) return false; if (vR == -1) return true; return vL < vR; } if (left.data() == right.data()) return lowerPositionThan(left, right); return QSortFilterProxyModel::lessThan(left, right); }
void QvvMainWindow::slotSortColumn1() { sortColumn( 1 ); };
void QvvMainWindow::slotSortColumn3() { sortColumn( 3 ); };