Skip to content

Commit

Permalink
Replace deprecated qSort/qStableSort/qGreater/qLess with std:: algs
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 7, 2017
1 parent 8408777 commit 3ed6f5b
Show file tree
Hide file tree
Showing 56 changed files with 99 additions and 99 deletions.
6 changes: 3 additions & 3 deletions src/analysis/network/qgsvectorlayerdirector.cpp
Expand Up @@ -233,7 +233,7 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const

QgsPointCompare pointCompare( builder->topologyTolerance() );

qSort( points.begin(), points.end(), pointCompare );
std::sort( points.begin(), points.end(), pointCompare );
QVector< QgsPoint >::iterator tmp = std::unique( points.begin(), points.end() );
points.resize( tmp - points.begin() );

Expand All @@ -243,7 +243,7 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
for ( i = 0; i < snappedPoints.size() ; ++i )
snappedPoints[ i ] = *( my_binary_search( points.begin(), points.end(), snappedPoints[ i ], pointCompare ) );

qSort( pointLengthMap.begin(), pointLengthMap.end(), TiePointInfoCompare );
std::sort( pointLengthMap.begin(), pointLengthMap.end(), TiePointInfoCompare );

{
// fill attribute list 'la'
Expand All @@ -264,7 +264,7 @@ void QgsVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const
tmpAttr.push_back( *it2 );
}
}
qSort( tmpAttr.begin(), tmpAttr.end() );
std::sort( tmpAttr.begin(), tmpAttr.end() );

int lastAttrId = -1;
for ( it2 = tmpAttr.begin(); it2 != tmpAttr.end(); ++it2 )
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/qgszonalstatistics.cpp
Expand Up @@ -277,7 +277,7 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )
changeAttributeMap.insert( meanIndex, QVariant( mean ) );
if ( mStatistics & QgsZonalStatistics::Median )
{
qSort( featureStats.values.begin(), featureStats.values.end() );
std::sort( featureStats.values.begin(), featureStats.values.end() );
int size = featureStats.values.count();
bool even = ( size % 2 ) < 1;
double medianValue;
Expand Down Expand Up @@ -311,7 +311,7 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )
if ( mStatistics & QgsZonalStatistics::Minority || mStatistics & QgsZonalStatistics::Majority )
{
QList<int> vals = featureStats.valueCount.values();
qSort( vals.begin(), vals.end() );
std::sort( vals.begin(), vals.end() );
if ( mStatistics & QgsZonalStatistics::Minority )
{
float minorityKey = featureStats.valueCount.key( vals.first() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposer.cpp
Expand Up @@ -3984,7 +3984,7 @@ void QgsComposer::populatePrintComposersMenu()
if ( acts.size() > 1 )
{
// sort actions in case main app's aboutToShow slot has not yet
qSort( acts.begin(), acts.end(), cmpByText_ );
std::sort( acts.begin(), acts.end(), cmpByText_ );
}
mPrintComposersMenu->addActions( acts );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -726,7 +726,7 @@ void QgsComposerLegendWidget::on_mRemoveToolButton_clicked()
Q_FOREACH ( QgsLayerTreeLayer* nodeLayer, nodesWithRemoval.keys() )
{
QList<int> toDelete = nodesWithRemoval[nodeLayer];
qSort( toDelete.begin(), toDelete.end(), qGreater<int>() );
std::sort( toDelete.begin(), toDelete.end(), std::greater<int>() );
QList<int> order = QgsMapLayerLegendUtils::legendNodeOrder( nodeLayer );

Q_FOREACH ( int i, toDelete )
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -1553,7 +1553,7 @@ void QgisApp::readSettings()
{
projectKeys.append( key.toInt() );
}
qSort( projectKeys );
std::sort( projectKeys.begin(), projectKeys.end() );

Q_FOREACH ( int key, projectKeys )
{
Expand Down Expand Up @@ -2108,7 +2108,7 @@ void QgisApp::createToolBars()
}

// sort actions in toolbar menu
qSort( toolbarMenuActions.begin(), toolbarMenuActions.end(), cmpByText_ );
std::sort( toolbarMenuActions.begin(), toolbarMenuActions.end(), cmpByText_ );

mToolbarMenu->addActions( toolbarMenuActions );

Expand Down Expand Up @@ -6930,7 +6930,7 @@ void QgisApp::on_mPrintComposersMenu_aboutToShow()
if ( acts.size() > 1 )
{
// sort actions by text
qSort( acts.begin(), acts.end(), cmpByText_ );
std::sort( acts.begin(), acts.end(), cmpByText_ );
}
mPrintComposersMenu->addActions( acts );
}
Expand Down Expand Up @@ -12040,7 +12040,7 @@ QMenu* QgisApp::createPopupMenu()
}
}

qSort( panels.begin(), panels.end(), cmpByText_ );
std::sort( panels.begin(), panels.end(), cmpByText_ );
QWidgetAction* panelstitle = new QWidgetAction( menu );
QLabel* plabel = new QLabel( QStringLiteral( "<b>%1</b>" ).arg( tr( "Panels" ) ) );
plabel->setMargin( 3 );
Expand All @@ -12058,7 +12058,7 @@ QMenu* QgisApp::createPopupMenu()
tlabel->setAlignment( Qt::AlignHCenter );
toolbarstitle->setDefaultWidget( tlabel );
menu->addAction( toolbarstitle );
qSort( toolbars.begin(), toolbars.end(), cmpByText_ );
std::sort( toolbars.begin(), toolbars.end(), cmpByText_ );
Q_FOREACH ( QAction* a, toolbars )
{
menu->addAction( a );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributeactiondialog.cpp
Expand Up @@ -134,7 +134,7 @@ void QgsAttributeActionDialog::insertRow( int row, const QgsAction& action )
item = new QTableWidgetItem();
item->setFlags( item->flags() & ~( Qt::ItemIsEditable ) );
QStringList actionScopes = action.actionScopes().toList();
qSort( actionScopes );
std::sort( actionScopes.begin(), actionScopes.end() );
item->setText( actionScopes.join( QStringLiteral( ", " ) ) );
item->setData( Qt::UserRole, QVariant::fromValue<QSet<QString>>( action.actionScopes() ) );
mAttributeActionTable->setItem( row, ActionScopes, item );
Expand Down Expand Up @@ -338,7 +338,7 @@ void QgsAttributeActionDialog::itemDoubleClicked( QTableWidgetItem* item )

QTableWidgetItem* item = mAttributeActionTable->item( row, ActionScopes );
QStringList actionScopes = actionProperties.actionScopes().toList();
qSort( actionScopes );
std::sort( actionScopes.begin(), actionScopes.end() );
item->setText( actionScopes.join( QStringLiteral( ", " ) ) );
item->setData( Qt::UserRole, QVariant::fromValue<QSet<QString>>( actionProperties.actionScopes() ) );

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -551,7 +551,7 @@ void QgsBrowserDockWidget::addSelectedLayers()

// get a sorted list of selected indexes
QModelIndexList list = mBrowserView->selectionModel()->selectedIndexes();
qSort( list );
std::sort( list.begin(), list.end() );

// If any of the layer items are QGIS we just open and exit the loop
Q_FOREACH ( const QModelIndex& index, list )
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -202,7 +202,7 @@ int QgsAtlasComposition::updateFeatures()
if ( !mFeatureKeys.isEmpty() )
{
FieldSorter sorter( mFeatureKeys, mSortAscending );
qSort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
std::sort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
}

emit numberFeaturesChanged( mFeatureIds.size() );
Expand Down Expand Up @@ -750,7 +750,7 @@ void QgsAtlasComposition::setPredefinedScales( const QVector<qreal>& scales )
{
mPredefinedScales = scales;
// make sure the list is sorted
qSort( mPredefinedScales.begin(), mPredefinedScales.end() );
std::sort( mPredefinedScales.begin(), mPredefinedScales.end() );
}

QgsGeometry QgsAtlasComposition::currentGeometry( const QgsCoordinateReferenceSystem& crs ) const
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerattributetablemodelv2.cpp
Expand Up @@ -406,7 +406,7 @@ bool QgsComposerAttributeTableColumnModelV2::moveColumnInSortRank( QgsComposerTa
sortedColumns.append( currentColumn );
}
}
qStableSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
std::stable_sort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
int columnPos = sortedColumns.indexOf( column );

if (( columnPos == 0 && direction == ShiftUp )
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposerattributetablev2.cpp
Expand Up @@ -526,7 +526,7 @@ bool QgsComposerAttributeTableV2::getTableContents( QgsComposerTableContents &co
{
c.setSortColumn( sortColumns.at( i ).first );
c.setAscending( sortColumns.at( i ).second );
qStableSort( contents.begin(), contents.end(), c );
std::stable_sort( contents.begin(), contents.end(), c );
}

recalculateTableSize();
Expand Down Expand Up @@ -608,7 +608,7 @@ QList<QPair<int, bool> > QgsComposerAttributeTableV2::sortAttributes() const
}

//sort columns by rank
qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
std::sort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );

//generate list of column index, bool for sort direction (to match 2.0 api)
QList<QPair<int, bool> > attributesBySortRank;
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerhtml.cpp
Expand Up @@ -405,7 +405,7 @@ double QgsComposerHtml::findNearbyPageBreak( double yPos )
}

//sort candidate rows by number of changes ascending, row number descending
qSort( candidates.begin(), candidates.end(), candidateSort );
std::sort( candidates.begin(), candidates.end(), candidateSort );
//first candidate is now the largest row with smallest number of changes

//ok, now take the mid point of the best candidate position
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermapgrid.cpp
Expand Up @@ -1974,7 +1974,7 @@ QgsComposerMapGrid::BorderSide QgsComposerMapGrid::borderForLineCoord( QPointF p
distanceToSide << qMakePair( p.y(), QgsComposerMapGrid::Top );
distanceToSide << qMakePair( mComposerMap->rect().height() - p.y(), QgsComposerMapGrid::Bottom );

qSort( distanceToSide.begin(), distanceToSide.end(), sortByDistance );
std::sort( distanceToSide.begin(), distanceToSide.end(), sortByDistance );
return distanceToSide.at( 0 ).second;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermodel.cpp
Expand Up @@ -351,7 +351,7 @@ bool QgsComposerModel::dropMimeData( const QMimeData *data,
//move dropped items

//first sort them by z-order
qSort( droppedItems.begin(), droppedItems.end(), zOrderDescending );
std::sort( droppedItems.begin(), droppedItems.end(), zOrderDescending );

//calculate position in z order list to drop items at
int destPos = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/core/fieldformatter/qgsvaluerelationfieldformatter.cpp
Expand Up @@ -137,11 +137,11 @@ QgsValueRelationFieldFormatter::ValueRelationCache QgsValueRelationFieldFormatte

if ( config.value( "OrderByValue" ).toBool() )
{
qSort( cache.begin(), cache.end(), orderByValueLessThan );
std::sort( cache.begin(), cache.end(), orderByValueLessThan );
}
else
{
qSort( cache.begin(), cache.end(), orderByKeyLessThan );
std::sort( cache.begin(), cache.end(), orderByKeyLessThan );
}

return cache;
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -1005,7 +1005,7 @@ QMimeData* QgsLayerTreeModel::mimeData( const QModelIndexList& indexes ) const
{
// Sort the indexes. Depending on how the user selected the items, the indexes may be unsorted.
QModelIndexList sortedIndexes = indexes;
qSort( sortedIndexes.begin(), sortedIndexes.end(), qLess<QModelIndex>() );
std::sort( sortedIndexes.begin(), sortedIndexes.end(), std::less<QModelIndex>() );

QList<QgsLayerTreeNode*> nodesFinal = indexes2nodes( sortedIndexes, true );

Expand Down
4 changes: 2 additions & 2 deletions src/core/pal/costcalculator.cpp
Expand Up @@ -109,7 +109,7 @@ void CostCalculator::setPolygonCandidatesCost( int nblp, QList< LabelPosition* >
{
toSort << lPos.at( i );
}
qSort( toSort.begin(), toSort.end(), candidateSortShrink );
std::sort( toSort.begin(), toSort.end(), candidateSortShrink );
for ( int i = 0; i < nblp; ++i )
{
lPos[i] = toSort.at( i );
Expand Down Expand Up @@ -181,7 +181,7 @@ int CostCalculator::finalizeCandidatesCosts( Feats* feat, int max_p, RTree <Feat
max_p = feat->lPos.count();
//
// sort candidates list, best label to worst
qSort( feat->lPos.begin(), feat->lPos.end(), candidateSortGrow );
std::sort( feat->lPos.begin(), feat->lPos.end(), candidateSortGrow );

// try to exclude all conflitual labels (good ones have cost < 1 by pruning)
double discrim = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/feature.cpp
Expand Up @@ -1601,7 +1601,7 @@ int FeaturePart::createCandidates( QList< LabelPosition*>& lPos,
}
}

qSort( lPos.begin(), lPos.end(), CostCalculator::candidateSortGrow );
std::sort( lPos.begin(), lPos.end(), CostCalculator::candidateSortGrow );
return lPos.count();
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/pal/problem.cpp
Expand Up @@ -2277,7 +2277,7 @@ QList<LabelPosition*> * Problem::getSolution( bool returnInactive )
// if features collide, order by size, so smaller ones appear on top
if ( returnInactive )
{
qSort( solList->begin(), solList->end(), compareLabelArea );
std::sort( solList->begin(), solList->end(), compareLabelArea );
}

return solList;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsbrowsermodel.cpp
Expand Up @@ -153,7 +153,7 @@ void QgsBrowserModel::addRootItems()
QList<QgsDataItem *> providerGroup = providerMap.values( key );
if ( providerGroup.size() > 1 )
{
qSort( providerGroup.begin(), providerGroup.end(), cmpByDataItemName_ );
std::sort( providerGroup.begin(), providerGroup.end(), cmpByDataItemName_ );
}

Q_FOREACH ( QgsDataItem * ditem, providerGroup )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgscolorramp.cpp
Expand Up @@ -273,7 +273,7 @@ void QgsGradientColorRamp::setStops( const QgsGradientStopsList &stops )
mStops = stops;

//sort stops by offset
qSort( mStops.begin(), mStops.end(), stopLessThan );
std::sort( mStops.begin(), mStops.end(), stopLessThan );
}

void QgsGradientColorRamp::addStopsToGradient( QGradient* gradient, double alpha )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsexpressioncontext.cpp
Expand Up @@ -166,7 +166,7 @@ QStringList QgsExpressionContextScope::filteredVariableNames() const
filtered << variable;
}
QgsExpressionContextVariableCompare cmp( *this );
qSort( filtered.begin(), filtered.end(), cmp );
std::sort( filtered.begin(), filtered.end(), cmp );

return filtered;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfeatureiterator.cpp
Expand Up @@ -165,7 +165,7 @@ void QgsAbstractFeatureIterator::setupOrderBy( const QList<QgsFeatureRequest::Or
mCachedFeatures.append( indexedFeature );
}

qSort( mCachedFeatures.begin(), mCachedFeatures.end(), QgsExpressionSorter( preparedOrderBys ) );
std::sort( mCachedFeatures.begin(), mCachedFeatures.end(), QgsExpressionSorter( preparedOrderBys ) );

mFeatureIterator = mCachedFeatures.constBegin();
mUseCachedFeatures = true;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgshistogram.cpp
Expand Up @@ -31,7 +31,7 @@ QgsHistogram::QgsHistogram()

void QgsHistogram::prepareValues()
{
qSort( mValues.begin(), mValues.end() );
std::sort( mValues.begin(), mValues.end() );

QgsStatisticalSummary s;
s.setStatistics( QgsStatisticalSummary::Max | QgsStatisticalSummary::Min | QgsStatisticalSummary::InterQuartileRange );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgslabelingengine.cpp
Expand Up @@ -327,7 +327,7 @@ void QgsLabelingEngine::run( QgsRenderContext& context )
painter->setRenderHint( QPainter::Antialiasing );

// sort labels
qSort( labels->begin(), labels->end(), QgsLabelSorter( mMapSettings ) );
std::sort( labels->begin(), labels->end(), QgsLabelSorter( mMapSettings ) );

// draw the labels
QList<pal::LabelPosition*>::iterator it = labels->begin();
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaprendererjob.cpp
Expand Up @@ -383,7 +383,7 @@ void QgsMapRendererJob::logRenderingTime( const LayerRenderJobs& jobs )
elapsed.insert( job.renderingTime, job.layer ? job.layer->id() : QString() );

QList<int> tt( elapsed.uniqueKeys() );
qSort( tt.begin(), tt.end(), qGreater<int>() );
std::sort( tt.begin(), tt.end(), std::greater<int>() );
Q_FOREACH ( int t, tt )
{
QgsMessageLog::logMessage( tr( "%1 ms: %2" ).arg( t ).arg( QStringList( elapsed.values( t ) ).join( QStringLiteral( ", " ) ) ), tr( "Rendering" ) );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsstatisticalsummary.cpp
Expand Up @@ -135,7 +135,7 @@ void QgsStatisticalSummary::finalize()
|| mStatistics & QgsStatisticalSummary::ThirdQuartile
|| mStatistics & QgsStatisticalSummary::InterQuartileRange )
{
qSort( mValues.begin(), mValues.end() );
std::sort( mValues.begin(), mValues.end() );
bool even = ( mCount % 2 ) < 1;
if ( even )
{
Expand Down Expand Up @@ -212,7 +212,7 @@ void QgsStatisticalSummary::finalize()
if ( mStatistics & QgsStatisticalSummary::Minority || mStatistics & QgsStatisticalSummary::Majority )
{
QList<int> valueCounts = mValueCount.values();
qSort( valueCounts.begin(), valueCounts.end() );
std::sort( valueCounts.begin(), valueCounts.end() );
if ( mStatistics & QgsStatisticalSummary::Minority )
{
mMinority = mValueCount.key( valueCounts.first() );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectordataprovider.cpp
Expand Up @@ -670,7 +670,7 @@ QStringList QgsVectorDataProvider::availableEncodings()
}

// Do case-insensitive sorting of encodings
qSort( sEncodings.begin(), sEncodings.end(), _compareEncodings );
std::sort( sEncodings.begin(), sEncodings.end(), _compareEncodings );

return sEncodings;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -2327,7 +2327,7 @@ bool QgsVectorLayer::deleteAttributes( QList<int> attrs )
// Remove multiple occurrences of same attribute
attrs = attrs.toSet().toList();

qSort( attrs.begin(), attrs.end(), qGreater<int>() );
std::sort( attrs.begin(), attrs.end(), std::greater<int>() );

Q_FOREACH ( int attr, attrs )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayereditbuffer.cpp
Expand Up @@ -678,7 +678,7 @@ void QgsVectorLayerEditBuffer::handleAttributeAdded( int index )
// go through renamed attributes and adapt
QList< int > sortedRenamedIndices = mRenamedAttributes.keys();
//sort keys
qSort( sortedRenamedIndices.begin(), sortedRenamedIndices.end(), qGreater< int >() );
std::sort( sortedRenamedIndices.begin(), sortedRenamedIndices.end(), std::greater< int >() );
Q_FOREACH ( int renameIndex, sortedRenamedIndices )
{
if ( renameIndex >= index )
Expand Down Expand Up @@ -717,7 +717,7 @@ void QgsVectorLayerEditBuffer::handleAttributeDeleted( int index )
// go through rename attributes and adapt
QList< int > sortedRenamedIndices = mRenamedAttributes.keys();
//sort keys
qSort( sortedRenamedIndices.begin(), sortedRenamedIndices.end() );
std::sort( sortedRenamedIndices.begin(), sortedRenamedIndices.end() );
int last = -1;
mRenamedAttributes.remove( index );
Q_FOREACH ( int renameIndex, sortedRenamedIndices )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerundocommand.cpp
Expand Up @@ -417,7 +417,7 @@ void QgsVectorLayerUndoCommandDeleteAttribute::redo()
if ( mProviderField )
{
mBuffer->mDeletedAttributeIds.append( mOriginIndex );
qSort( mBuffer->mDeletedAttributeIds ); // keep it sorted
std::sort( mBuffer->mDeletedAttributeIds.begin(), mBuffer->mDeletedAttributeIds.end() ); // keep it sorted
}
else
{
Expand Down

0 comments on commit 3ed6f5b

Please sign in to comment.