Skip to content
Permalink
Browse files

Modernize code

  • Loading branch information
nyalldawson committed Apr 20, 2018
1 parent c961b1f commit 463a64651fa7898e8f75ceb87a471472395c910d
@@ -304,7 +304,7 @@ bool QgsCategorizedSymbolRendererModel::dropMimeData( const QMimeData *data, Qt:
if ( to == -1 ) to = mRenderer->categories().size(); // out of rang ok, will be decreased
for ( int i = rows.size() - 1; i >= 0; i-- )
{
QgsDebugMsg( QString( "move %1 to %2" ).arg( rows[i] ).arg( to ) );
QgsDebugMsg( QStringLiteral( "move %1 to %2" ).arg( rows[i] ).arg( to ) );
int t = to;
// moveCategory first removes and then inserts
if ( rows[i] < t ) t--;
@@ -355,7 +355,6 @@ void QgsCategorizedSymbolRendererModel::sort( int column, Qt::SortOrder order )
mRenderer->sortByLabel( order );
}
emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->categories().size(), 0 ) );
QgsDebugMsg( "Done" );
}

void QgsCategorizedSymbolRendererModel::updateSymbology()
@@ -400,11 +399,11 @@ QgsCategorizedSymbolRendererWidget::QgsCategorizedSymbolRendererWidget( QgsVecto
// (null renderer means "no previous renderer")
if ( renderer )
{
mRenderer = QgsCategorizedSymbolRenderer::convertFromRenderer( renderer );
mRenderer.reset( QgsCategorizedSymbolRenderer::convertFromRenderer( renderer ) );
}
if ( !mRenderer )
{
mRenderer = new QgsCategorizedSymbolRenderer( QLatin1String( "" ), QgsCategoryList() );
mRenderer = qgis::make_unique< QgsCategorizedSymbolRenderer >( QString(), QgsCategoryList() );
}

QString attrName = mRenderer->classAttribute();
@@ -430,10 +429,10 @@ QgsCategorizedSymbolRendererWidget::QgsCategorizedSymbolRendererWidget( QgsVecto
btnColorRamp->setRandomColorRamp();
}

mCategorizedSymbol = QgsSymbol::defaultSymbol( mLayer->geometryType() );
mCategorizedSymbol.reset( QgsSymbol::defaultSymbol( mLayer->geometryType() ) );

mModel = new QgsCategorizedSymbolRendererModel( this );
mModel->setRenderer( mRenderer );
mModel->setRenderer( mRenderer.get() );

// update GUI from renderer
updateUiFromRenderer();
@@ -481,9 +480,7 @@ QgsCategorizedSymbolRendererWidget::QgsCategorizedSymbolRendererWidget( QgsVecto

QgsCategorizedSymbolRendererWidget::~QgsCategorizedSymbolRendererWidget()
{
delete mRenderer;
delete mModel;
delete mCategorizedSymbol;
}

void QgsCategorizedSymbolRendererWidget::updateUiFromRenderer()
@@ -503,8 +500,7 @@ void QgsCategorizedSymbolRendererWidget::updateUiFromRenderer()
// set source symbol
if ( mRenderer->sourceSymbol() )
{
delete mCategorizedSymbol;
mCategorizedSymbol = mRenderer->sourceSymbol()->clone();
mCategorizedSymbol.reset( mRenderer->sourceSymbol()->clone() );
updateCategorizedSymbolIcon();
}

@@ -517,7 +513,7 @@ void QgsCategorizedSymbolRendererWidget::updateUiFromRenderer()

QgsFeatureRenderer *QgsCategorizedSymbolRendererWidget::renderer()
{
return mRenderer;
return mRenderer.get();
}

void QgsCategorizedSymbolRendererWidget::changeSelectedSymbols()
@@ -559,7 +555,7 @@ void QgsCategorizedSymbolRendererWidget::changeCategorizedSymbol()

void QgsCategorizedSymbolRendererWidget::updateCategorizedSymbolIcon()
{
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mCategorizedSymbol, btnChangeCategorizedSymbol->iconSize() );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mCategorizedSymbol.get(), btnChangeCategorizedSymbol->iconSize() );
btnChangeCategorizedSymbol->setIcon( icon );
}

@@ -675,7 +671,7 @@ void QgsCategorizedSymbolRendererWidget::addCategories()
#endif

QgsCategoryList cats;
_createCategories( cats, unique_vals, mCategorizedSymbol );
_createCategories( cats, unique_vals, mCategorizedSymbol.get() );
bool deleteExisting = false;

if ( !mOldClassificationAttribute.isEmpty() &&
@@ -738,18 +734,17 @@ void QgsCategorizedSymbolRendererWidget::addCategories()
*/

// recreate renderer
QgsCategorizedSymbolRenderer *r = new QgsCategorizedSymbolRenderer( attrName, cats );
std::unique_ptr< QgsCategorizedSymbolRenderer > r = qgis::make_unique< QgsCategorizedSymbolRenderer >( attrName, cats );
r->setSourceSymbol( mCategorizedSymbol->clone() );
std::unique_ptr< QgsColorRamp > ramp( btnColorRamp->colorRamp() );
if ( ramp )
r->setSourceColorRamp( ramp->clone() );

if ( mModel )
{
mModel->setRenderer( r );
mModel->setRenderer( r.get() );
}
delete mRenderer;
mRenderer = r;
mRenderer = std::move( r );
if ( ! keepExistingColors && ramp )
applyColorRamp();
emit widgetChanged();
@@ -859,7 +854,7 @@ void QgsCategorizedSymbolRendererWidget::refreshSymbolView()

void QgsCategorizedSymbolRendererWidget::showSymbolLevels()
{
showSymbolLevelsDialog( mRenderer );
showSymbolLevelsDialog( mRenderer.get() );
}

void QgsCategorizedSymbolRendererWidget::rowsMoved()
@@ -953,8 +948,7 @@ void QgsCategorizedSymbolRendererWidget::cleanUpSymbolSelector( QgsPanelWidget *
void QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget()
{
QgsSymbolSelectorWidget *dlg = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
delete mCategorizedSymbol;
mCategorizedSymbol = dlg->symbol()->clone();
mCategorizedSymbol.reset( dlg->symbol()->clone() );

updateCategorizedSymbolIcon();

@@ -983,7 +977,7 @@ void QgsCategorizedSymbolRendererWidget::updateSymbolsFromWidget()
return;
}

mRenderer->updateSymbols( mCategorizedSymbol );
mRenderer->updateSymbols( mCategorizedSymbol.get() );
emit widgetChanged();
}

@@ -1040,7 +1034,7 @@ QgsExpressionContext QgsCategorizedSymbolRendererWidget::createExpressionContext

void QgsCategorizedSymbolRendererWidget::dataDefinedSizeLegend()
{
QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( mCategorizedSymbol ); // this should be only enabled for marker symbols
QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( mCategorizedSymbol.get() ); // this should be only enabled for marker symbols
QgsDataDefinedSizeLegendWidget *panel = createDataDefinedSizeLegendWidget( s, mRenderer->dataDefinedSizeLegend() );
if ( panel )
{
@@ -180,9 +180,9 @@ class GUI_EXPORT QgsCategorizedSymbolRendererWidget : public QgsRendererWidget,
void keyPressEvent( QKeyEvent *event ) override;

protected:
QgsCategorizedSymbolRenderer *mRenderer = nullptr;
std::unique_ptr< QgsCategorizedSymbolRenderer > mRenderer;

QgsSymbol *mCategorizedSymbol = nullptr;
std::unique_ptr< QgsSymbol > mCategorizedSymbol;

QgsCategorizedSymbolRendererModel *mModel = nullptr;

@@ -305,7 +305,7 @@ bool QgsGraduatedSymbolRendererModel::dropMimeData( const QMimeData *data, Qt::D
if ( to == -1 ) to = mRenderer->ranges().size(); // out of rang ok, will be decreased
for ( int i = rows.size() - 1; i >= 0; i-- )
{
QgsDebugMsg( QString( "move %1 to %2" ).arg( rows[i] ).arg( to ) );
QgsDebugMsg( QStringLiteral( "move %1 to %2" ).arg( rows[i] ).arg( to ) );
int t = to;
// moveCategory first removes and then inserts
if ( rows[i] < t ) t--;
@@ -356,7 +356,6 @@ void QgsGraduatedSymbolRendererModel::sort( int column, Qt::SortOrder order )
}
emit rowsMoved();
emit dataChanged( createIndex( 0, 0 ), createIndex( mRenderer->ranges().size(), 0 ) );
QgsDebugMsg( "Done" );
}

void QgsGraduatedSymbolRendererModel::updateSymbology( bool resetModel )
@@ -444,11 +443,11 @@ QgsGraduatedSymbolRendererWidget::QgsGraduatedSymbolRendererWidget( QgsVectorLay
// (null renderer means "no previous renderer")
if ( renderer )
{
mRenderer = QgsGraduatedSymbolRenderer::convertFromRenderer( renderer );
mRenderer.reset( QgsGraduatedSymbolRenderer::convertFromRenderer( renderer ) );
}
if ( !mRenderer )
{
mRenderer = new QgsGraduatedSymbolRenderer( QLatin1String( "" ), QgsRangeList() );
mRenderer = qgis::make_unique< QgsGraduatedSymbolRenderer >( QString(), QgsRangeList() );
}

// setup user interface
@@ -485,7 +484,7 @@ QgsGraduatedSymbolRendererWidget::QgsGraduatedSymbolRendererWidget( QgsVectorLay

viewGraduated->setStyle( new QgsGraduatedSymbolRendererViewStyle( viewGraduated ) );

mGraduatedSymbol = QgsSymbol::defaultSymbol( mLayer->geometryType() );
mGraduatedSymbol.reset( QgsSymbol::defaultSymbol( mLayer->geometryType() ) );

methodComboBox->blockSignals( true );
methodComboBox->addItem( QStringLiteral( "Color" ) );
@@ -536,7 +535,7 @@ QgsGraduatedSymbolRendererWidget::QgsGraduatedSymbolRendererWidget( QgsVectorLay
btnAdvanced->setMenu( advMenu );

mHistogramWidget->setLayer( mLayer );
mHistogramWidget->setRenderer( mRenderer );
mHistogramWidget->setRenderer( mRenderer.get() );
connect( mHistogramWidget, &QgsGraduatedHistogramWidget::rangesModified, this, &QgsGraduatedSymbolRendererWidget::refreshRanges );
connect( mExpressionWidget, static_cast < void ( QgsFieldExpressionWidget::* )( const QString & ) >( &QgsFieldExpressionWidget::fieldChanged ), mHistogramWidget, &QgsHistogramWidget::setSourceFieldExp );

@@ -549,20 +548,18 @@ void QgsGraduatedSymbolRendererWidget::mSizeUnitWidget_changed()
mGraduatedSymbol->setOutputUnit( mSizeUnitWidget->unit() );
mGraduatedSymbol->setMapUnitScale( mSizeUnitWidget->getMapUnitScale() );
updateGraduatedSymbolIcon();
mRenderer->updateSymbols( mGraduatedSymbol );
mRenderer->updateSymbols( mGraduatedSymbol.get() );
refreshSymbolView();
}

QgsGraduatedSymbolRendererWidget::~QgsGraduatedSymbolRendererWidget()
{
delete mRenderer;
delete mModel;
delete mGraduatedSymbol;
}

QgsFeatureRenderer *QgsGraduatedSymbolRendererWidget::renderer()
{
return mRenderer;
return mRenderer.get();
}

// Connect/disconnect event handlers which trigger updating renderer
@@ -622,12 +619,11 @@ void QgsGraduatedSymbolRendererWidget::updateUiFromRenderer( bool updateCount )
// set source symbol
if ( mRenderer->sourceSymbol() )
{
delete mGraduatedSymbol;
mGraduatedSymbol = mRenderer->sourceSymbol()->clone();
mGraduatedSymbol.reset( mRenderer->sourceSymbol()->clone() );
updateGraduatedSymbolIcon();
}

mModel->setRenderer( mRenderer );
mModel->setRenderer( mRenderer.get() );
viewGraduated->setModel( mModel );

if ( mGraduatedSymbol )
@@ -756,8 +752,7 @@ void QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector( QgsPanelWidget *co
void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
{
QgsSymbolSelectorWidget *dlg = qobject_cast<QgsSymbolSelectorWidget *>( sender() );
delete mGraduatedSymbol;
mGraduatedSymbol = dlg->symbol()->clone();
mGraduatedSymbol.reset( dlg->symbol()->clone() );

mSizeUnitWidget->blockSignals( true );
mSizeUnitWidget->setUnit( mGraduatedSymbol->outputUnit() );
@@ -786,7 +781,7 @@ void QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget()
else
{
updateGraduatedSymbolIcon();
mRenderer->updateSymbols( mGraduatedSymbol );
mRenderer->updateSymbols( mGraduatedSymbol.get() );
}

refreshSymbolView();
@@ -866,14 +861,14 @@ void QgsGraduatedSymbolRendererWidget::reapplyColorRamp()
return;

mRenderer->updateColorRamp( ramp.release() );
mRenderer->updateSymbols( mGraduatedSymbol );
mRenderer->updateSymbols( mGraduatedSymbol.get() );
refreshSymbolView();
}

void QgsGraduatedSymbolRendererWidget::reapplySizes()
{
mRenderer->setSymbolSizes( minSizeSpinBox->value(), maxSizeSpinBox->value() );
mRenderer->updateSymbols( mGraduatedSymbol );
mRenderer->updateSymbols( mGraduatedSymbol.get() );
refreshSymbolView();
}

@@ -893,7 +888,7 @@ void QgsGraduatedSymbolRendererWidget::updateGraduatedSymbolIcon()
if ( !mGraduatedSymbol )
return;

QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mGraduatedSymbol, btnChangeGraduatedSymbol->iconSize() );
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mGraduatedSymbol.get(), btnChangeGraduatedSymbol->iconSize() );
btnChangeGraduatedSymbol->setIcon( icon );
}

@@ -1005,7 +1000,7 @@ void QgsGraduatedSymbolRendererWidget::changeRange( int rangeIdx )

void QgsGraduatedSymbolRendererWidget::addClass()
{
mModel->addClass( mGraduatedSymbol );
mModel->addClass( mGraduatedSymbol.get() );
mHistogramWidget->refresh();
}

@@ -1147,7 +1142,7 @@ void QgsGraduatedSymbolRendererWidget::refreshSymbolView()

void QgsGraduatedSymbolRendererWidget::showSymbolLevels()
{
showSymbolLevelsDialog( mRenderer );
showSymbolLevelsDialog( mRenderer.get() );
}

void QgsGraduatedSymbolRendererWidget::rowsMoved()
@@ -1190,7 +1185,7 @@ void QgsGraduatedSymbolRendererWidget::keyPressEvent( QKeyEvent *event )

void QgsGraduatedSymbolRendererWidget::dataDefinedSizeLegend()
{
QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( mGraduatedSymbol ); // this should be only enabled for marker symbols
QgsMarkerSymbol *s = static_cast<QgsMarkerSymbol *>( mGraduatedSymbol.get() ); // this should be only enabled for marker symbols
QgsDataDefinedSizeLegendWidget *panel = createDataDefinedSizeLegendWidget( s, mRenderer->dataDefinedSizeLegend() );
if ( panel )
{
@@ -154,9 +154,9 @@ class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, pr
void keyPressEvent( QKeyEvent *event ) override;

private:
QgsGraduatedSymbolRenderer *mRenderer = nullptr;
std::unique_ptr< QgsGraduatedSymbolRenderer > mRenderer;

QgsSymbol *mGraduatedSymbol = nullptr;
std::unique_ptr< QgsSymbol > mGraduatedSymbol;

int mRowSelected;

0 comments on commit 463a646

Please sign in to comment.
You can’t perform that action at this time.