Skip to content

Commit fbb7b3c

Browse files
committed
[FEATURE] editable global scales list
1 parent aea41ee commit fbb7b3c

File tree

8 files changed

+231
-39
lines changed

8 files changed

+231
-39
lines changed

python/gui/qgsscalecombobox.sip

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ class QgsScaleComboBox : QComboBox
88
#include <qgsscalecombobox.h>
99
%End
1010

11-
public:
11+
public:
1212
QgsScaleComboBox(QWidget * parent = 0);
1313
~QgsScaleComboBox();
14+
15+
public slots:
16+
void updateScales( const QStringList &scales = QStringList() );
1417
};
1518

src/app/qgisapp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5303,6 +5303,8 @@ void QgisApp::options()
53035303

53045304
mRasterFileFilter.clear();
53055305
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
5306+
5307+
mScaleEdit->updateScales();
53065308
}
53075309

53085310
delete optionsDialog;

src/app/qgsoptions.cpp

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgsnetworkaccessmanager.h"
2626
#include "qgsproject.h"
2727

28+
#include <QInputDialog>
2829
#include <QFileDialog>
2930
#include <QSettings>
3031
#include <QColorDialog>
@@ -416,6 +417,21 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
416417
cmbWheelAction->setCurrentIndex( settings.value( "/qgis/wheel_action", 2 ).toInt() );
417418
spinZoomFactor->setValue( settings.value( "/qgis/zoom_factor", 2 ).toDouble() );
418419

420+
// predefined scales for scale combobox
421+
myPaths = settings.value( "Map/scales", PROJECT_SCALES ).toString();
422+
if ( !myPaths.isEmpty() )
423+
{
424+
QStringList myScalesList = myPaths.split( "," );
425+
QStringList::const_iterator scaleIt = myScalesList.constBegin();
426+
for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
427+
{
428+
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
429+
newItem->setText( *scaleIt );
430+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
431+
mListGlobalScales->addItem( newItem );
432+
}
433+
}
434+
419435
//
420436
// Locale settings
421437
//
@@ -846,23 +862,19 @@ void QgsOptions::saveOptions()
846862
settings.setValue( "/Raster/useStandardDeviation", chkUseStandardDeviation->isChecked() );
847863
settings.setValue( "/Raster/defaultStandardDeviation", spnThreeBandStdDev->value() );
848864

849-
850865
settings.setValue( "/Map/updateThreshold", spinBoxUpdateThreshold->value() );
851866
//check behaviour so default projection when new layer is added with no
852867
//projection defined...
853868
if ( radPromptForProjection->isChecked() )
854869
{
855-
//
856870
settings.setValue( "/Projections/defaultBehaviour", "prompt" );
857871
}
858872
else if ( radUseProjectProjection->isChecked() )
859873
{
860-
//
861874
settings.setValue( "/Projections/defaultBehaviour", "useProject" );
862875
}
863876
else //assumes radUseGlobalProjection is checked
864877
{
865-
//
866878
settings.setValue( "/Projections/defaultBehaviour", "useGlobal" );
867879
}
868880

@@ -884,11 +896,6 @@ void QgsOptions::saveOptions()
884896
}
885897
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
886898

887-
if ( mDegreesRadioButton->isChecked() )
888-
{
889-
890-
}
891-
892899
QString angleUnitString = "degrees";
893900
if ( mRadiansRadioButton->isChecked() )
894901
{
@@ -900,14 +907,12 @@ void QgsOptions::saveOptions()
900907
}
901908
settings.setValue( "/qgis/measure/angleunits", angleUnitString );
902909

903-
904910
int decimalPlaces = mDecimalPlacesSpinBox->value();
905911
settings.setValue( "/qgis/measure/decimalplaces", decimalPlaces );
906912

907913
bool baseUnit = mKeepBaseUnitCheckBox->isChecked();
908914
settings.setValue( "/qgis/measure/keepbaseunit", baseUnit );
909915

910-
911916
//set the color for selections
912917
QColor myColor = pbnSelectionColor->color();
913918
settings.setValue( "/qgis/default_selection_color_red", myColor.red() );
@@ -972,13 +977,23 @@ void QgsOptions::saveOptions()
972977
settings.setValue( "/qgis/digitizing/offset_quad_seg", mOffsetQuadSegSpinBox->value() );
973978
settings.setValue( "/qgis/digitizing/offset_miter_limit", mCurveOffsetMiterLimitComboBox->value() );
974979

980+
// default scale list
981+
for ( int i = 0; i < mListGlobalScales->count(); ++i )
982+
{
983+
if ( i != 0 )
984+
{
985+
myPaths += ",";
986+
}
987+
myPaths += mListGlobalScales->item( i )->text();
988+
}
989+
settings.setValue( "Map/scales", myPaths );
990+
975991
//
976992
// Locale settings
977993
//
978994
settings.setValue( "locale/userLocale", cboLocale->itemData( cboLocale->currentIndex() ).toString() );
979995
settings.setValue( "locale/overrideFlag", grpLocale->isChecked() );
980996

981-
982997
// Gdal skip driver list
983998
if ( mLoadedGdalDriverList )
984999
saveGdalDriverList();
@@ -1183,7 +1198,6 @@ void QgsOptions::on_mBtnRemovePluginPath_clicked()
11831198
delete itemToRemove;
11841199
}
11851200

1186-
11871201
void QgsOptions::on_mBtnAddSVGPath_clicked()
11881202
{
11891203
QString myDir = QFileDialog::getExistingDirectory(
@@ -1422,3 +1436,45 @@ void QgsOptions::saveGdalDriverList()
14221436
QSettings mySettings;
14231437
mySettings.setValue( "gdal/skipList", QgsApplication::skippedGdalDrivers().join( " " ) );
14241438
}
1439+
1440+
void QgsOptions::on_pbnAddScale_clicked()
1441+
{
1442+
int myScale = QInputDialog::getInt(
1443+
this,
1444+
tr( "Enter scale" ),
1445+
tr( "Scale denominator" ),
1446+
-1,
1447+
1
1448+
);
1449+
1450+
if ( myScale != -1 )
1451+
{
1452+
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
1453+
newItem->setText( QString( "1:%1" ).arg( myScale ) );
1454+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
1455+
mListGlobalScales->addItem( newItem );
1456+
mListGlobalScales->setCurrentItem( newItem );
1457+
}
1458+
}
1459+
1460+
void QgsOptions::on_pbnRemoveScale_clicked()
1461+
{
1462+
int currentRow = mListGlobalScales->currentRow();
1463+
QListWidgetItem* itemToRemove = mListGlobalScales->takeItem( currentRow );
1464+
delete itemToRemove;
1465+
}
1466+
1467+
void QgsOptions::on_pbnDefaultValues_clicked()
1468+
{
1469+
mListGlobalScales->clear();
1470+
1471+
QStringList myScalesList = PROJECT_SCALES.split( "," );
1472+
QStringList::const_iterator scaleIt = myScalesList.constBegin();
1473+
for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
1474+
{
1475+
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
1476+
newItem->setText( *scaleIt );
1477+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
1478+
mListGlobalScales->addItem( newItem );
1479+
}
1480+
}

src/app/qgsoptions.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
106106
*/
107107
void on_mBtnAddPluginPath_clicked();
108108

109-
/* Let the user remove a path to the list of search paths
109+
/* Let the user remove a path from the list of search paths
110110
* used for finding Plugin libs.
111111
* @note added in QGIS 1.7
112112
*/
@@ -118,7 +118,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
118118
*/
119119
void on_mBtnAddSVGPath_clicked();
120120

121-
/* Let the user remove a path to the list of search paths
121+
/* Let the user remove a path from the list of search paths
122122
* used for finding SVG files.
123123
* @note added in QGIS 1.4
124124
*/
@@ -129,6 +129,24 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
129129
void on_mBrowseCacheDirectory_clicked();
130130
void on_mClearCache_clicked();
131131

132+
/* Let the user add a scale to the list of scales
133+
* used in scale combobox
134+
* @note added in QGIS 2.0
135+
*/
136+
void on_pbnAddScale_clicked();
137+
138+
/* Let the user remove a scale from the list of scales
139+
* used in scale combobox
140+
* @note added in QGIS 2.0
141+
*/
142+
void on_pbnRemoveScale_clicked();
143+
144+
/* Let the user restore default scales
145+
* used in scale combobox
146+
* @note added in QGIS 2.0
147+
*/
148+
void on_pbnDefaultValues_clicked();
149+
132150
/** Auto slot executed when the active page in the main widget stack is changed
133151
* @note added in 2.0
134152
*/

src/core/qgis.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ const QString GEOWKT =
152152
* @note deprecated in 1.8 due to violation of coding conventions (globals
153153
* should be in all caps).
154154
*/
155+
156+
const QString PROJECT_SCALES =
157+
"1:1000000,1:500000,1:250000,1:100000,1:50000,1:25000,"
158+
"1:10000,1:5000,1:2500,1:1000,1:500";
159+
155160
#ifndef _MSC_VER
156161
Q_DECL_DEPRECATED
157162
#endif

src/gui/qgsscalecombobox.cpp

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,17 @@
1515
* *
1616
***************************************************************************/
1717

18+
#include "qgis.h"
1819
#include "qgsscalecombobox.h"
1920

2021
#include <QAbstractItemView>
22+
#include <QSettings>
2123

2224
QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent )
2325
{
24-
// make combobox editable and populate with predefined scales
25-
setEditable( true );
26-
addItem( "1:1000000" );
27-
addItem( "1:500000" );
28-
addItem( "1:250000" );
29-
addItem( "1:100000" );
30-
addItem( "1:50000" );
31-
addItem( "1:25000" );
32-
addItem( "1:10000" );
33-
addItem( "1:5000" );
34-
addItem( "1:2500" );
35-
addItem( "1:1000" );
36-
addItem( "1:500" );
26+
updateScales();
3727

28+
setEditable( true );
3829
setInsertPolicy( QComboBox::NoInsert );
3930
setCompleter( 0 );
4031
}
@@ -43,6 +34,36 @@ QgsScaleComboBox::~QgsScaleComboBox()
4334
{
4435
}
4536

37+
void QgsScaleComboBox::updateScales( const QStringList &scales )
38+
{
39+
QStringList myScalesList;
40+
QString oldScale = currentText();
41+
42+
if ( scales.isEmpty() )
43+
{
44+
QSettings settings;
45+
QString myScales = settings.value( "Map/scales", PROJECT_SCALES ).toString();
46+
if ( !myScales.isEmpty() )
47+
{
48+
myScalesList = myScales.split( "," );
49+
//~ QStringList::const_iterator scaleIt = myScalesList.constBegin();
50+
//~ for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
51+
//~ {
52+
//~ addItem( *scaleIt );
53+
//~ }
54+
}
55+
}
56+
else
57+
{
58+
}
59+
60+
blockSignals( true );
61+
clear();
62+
addItems( myScalesList );
63+
setEditText( oldScale );
64+
blockSignals( false );
65+
}
66+
4667
void QgsScaleComboBox::showPopup()
4768
{
4869
QComboBox::showPopup();

src/gui/qgsscalecombobox.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox
3131
QgsScaleComboBox( QWidget* parent = 0 );
3232
virtual ~QgsScaleComboBox();
3333

34+
public slots:
35+
void updateScales( const QStringList &scales = QStringList() );
36+
3437
protected:
3538
void showPopup();
3639
};

0 commit comments

Comments
 (0)