Skip to content

Commit

Permalink
De-duplicate code when adding scales to the list of scales.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebDieBln committed Dec 11, 2015
1 parent 44fae1a commit 7671626
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
QStringList myScalesList = myPaths.split( ',' );
Q_FOREACH ( const QString& scale, myScalesList )
{
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
newItem->setText( scale );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListGlobalScales->addItem( newItem );
addScaleToScaleList( scale );
}
}

Expand Down Expand Up @@ -1922,10 +1919,7 @@ void QgsOptions::on_pbnAddScale_clicked()

if ( myScale != -1 )
{
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
newItem->setText( QString( "1:%1" ).arg( myScale ) );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListGlobalScales->addItem( newItem );
QListWidgetItem* newItem = addScaleToScaleList( QString( "1:%1" ).arg( myScale ) );
mListGlobalScales->setCurrentItem( newItem );
}
}
Expand All @@ -1944,10 +1938,7 @@ void QgsOptions::on_pbnDefaultScaleValues_clicked()
QStringList myScalesList = PROJECT_SCALES.split( ',' );
Q_FOREACH ( const QString& scale, myScalesList )
{
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
newItem->setText( scale );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListGlobalScales->addItem( newItem );
addScaleToScaleList( scale );
}
}

Expand All @@ -1969,10 +1960,7 @@ void QgsOptions::on_pbnImportScales_clicked()

Q_FOREACH ( const QString& scale, myScales )
{
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
newItem->setText( scale );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListGlobalScales->addItem( newItem );
addScaleToScaleList( scale );
}
}

Expand Down Expand Up @@ -2161,3 +2149,12 @@ void QgsOptions::on_mButtonExportColors_clicked()
return;
}
}

QListWidgetItem* QgsOptions::addScaleToScaleList( const QString &newScale )
{
QListWidgetItem* newItem = new QListWidgetItem();
newItem->setText( newScale );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListGlobalScales->addItem( newItem );
return newItem;
}
2 changes: 2 additions & 0 deletions src/app/qgsoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption

void saveDefaultDatumTransformations();

QListWidgetItem* addScaleToScaleList( const QString &newScale );

protected:
QgisAppStyleSheet* mStyleSheetBuilder;
QMap<QString, QVariant> mStyleSheetNewOpts;
Expand Down

0 comments on commit 7671626

Please sign in to comment.