Skip to content

Commit fe2252d

Browse files
committedJul 18, 2012
Merge branch 'project_scale'
2 parents aea41ee + f5dce33 commit fe2252d

14 files changed

+673
-52
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: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
29732973
mMapCanvas->freeze( false );
29742974
mMapCanvas->refresh();
29752975
mMapCanvas->clearExtentHistory();
2976+
mScaleEdit->updateScales();
29762977

29772978
// set project CRS
29782979
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
@@ -3107,6 +3108,13 @@ void QgisApp::fileOpen()
31073108
}
31083109

31093110
setTitleBarText_( *this );
3111+
3112+
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
3113+
if ( projectScales )
3114+
{
3115+
mScaleEdit->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
3116+
}
3117+
31103118
emit projectRead(); // let plug-ins know that we've read in a new
31113119
// project so that they can check any project
31123120
// specific plug-in state
@@ -3117,7 +3125,6 @@ void QgisApp::fileOpen()
31173125
mMapCanvas->freeze( false );
31183126
mMapCanvas->refresh();
31193127
}
3120-
31213128
} // QgisApp::fileOpen
31223129

31233130

@@ -3170,6 +3177,13 @@ bool QgisApp::addProject( QString projectFile )
31703177
int myAlpha = QgsProject::instance()->readNumEntry( "Gui", "/SelectionColorAlphaPart", defaultAlpha );
31713178
QgsRenderer::setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
31723179

3180+
//load project scales
3181+
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
3182+
if ( projectScales )
3183+
{
3184+
mScaleEdit->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
3185+
}
3186+
31733187
mMapCanvas->updateScale();
31743188
QgsDebugMsg( "Scale restored..." );
31753189

@@ -3302,12 +3316,10 @@ void QgisApp::fileSaveAs()
33023316
}
33033317
} // QgisApp::fileSaveAs
33043318

3305-
33063319
// Open the project file corresponding to the
33073320
// path at the given index in mRecentProjectPaths
33083321
void QgisApp::openProject( QAction *action )
33093322
{
3310-
33113323
// possibly save any pending work before opening a different project
33123324
QString debugme;
33133325
assert( action != NULL );
@@ -3323,7 +3335,6 @@ void QgisApp::openProject( QAction *action )
33233335
int myProjectionEnabledFlag =
33243336
QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectionsEnabled", 0 );
33253337
mMapCanvas->mapRenderer()->setProjectionsEnabled( myProjectionEnabledFlag );
3326-
33273338
} // QgisApp::openProject
33283339

33293340

@@ -3342,7 +3353,6 @@ void QgisApp::openProject( const QString & fileName )
33423353
return;
33433354
}
33443355

3345-
33463356
/**
33473357
Open a raster or vector file; ignore other files.
33483358
Used to process a commandline argument or OpenDocument AppleEvent.
@@ -5284,13 +5294,15 @@ void QgisApp::options()
52845294
return;
52855295
}
52865296

5297+
QSettings mySettings;
5298+
QString oldScales = mySettings.value( "Map/scales", PROJECT_SCALES ).toString();
5299+
52875300
QgsOptions *optionsDialog = new QgsOptions( this );
52885301
if ( optionsDialog->exec() )
52895302
{
52905303
// set the theme if it changed
52915304
setTheme( optionsDialog->theme() );
52925305

5293-
QSettings mySettings;
52945306
mMapCanvas->enableAntiAliasing( mySettings.value( "/qgis/enable_anti_aliasing" ).toBool() );
52955307
mMapCanvas->useImageToRender( mySettings.value( "/qgis/use_qimage_to_render" ).toBool() );
52965308

@@ -5303,6 +5315,11 @@ void QgisApp::options()
53035315

53045316
mRasterFileFilter.clear();
53055317
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
5318+
5319+
if ( oldScales != mySettings.value( "Map/scales", PROJECT_SCALES ).toString() )
5320+
{
5321+
mScaleEdit->updateScales();
5322+
}
53065323
}
53075324

53085325
delete optionsDialog;
@@ -6492,6 +6509,9 @@ void QgisApp::projectProperties()
64926509
// changing things in the project properties dialog box
64936510
connect( pp, SIGNAL( displayPrecisionChanged() ), this,
64946511
SLOT( updateMouseCoordinatePrecision() ) );
6512+
6513+
connect( pp, SIGNAL( scalesChanged( const QStringList & ) ), mScaleEdit,
6514+
SLOT( updateScales( const QStringList & ) ) );
64956515
QApplication::restoreOverrideCursor();
64966516

64976517
//pass any refresh signals off to canvases

‎src/app/qgsoptions.cpp

Lines changed: 124 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
#include "qgsgenericprojectionselector.h"
2323
#include "qgscoordinatereferencesystem.h"
2424
#include "qgstolerance.h"
25+
#include "qgsscaleutils.h"
2526
#include "qgsnetworkaccessmanager.h"
2627
#include "qgsproject.h"
2728

29+
#include <QInputDialog>
2830
#include <QFileDialog>
2931
#include <QSettings>
3032
#include <QColorDialog>
@@ -416,6 +418,21 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
416418
cmbWheelAction->setCurrentIndex( settings.value( "/qgis/wheel_action", 2 ).toInt() );
417419
spinZoomFactor->setValue( settings.value( "/qgis/zoom_factor", 2 ).toDouble() );
418420

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

849-
850866
settings.setValue( "/Map/updateThreshold", spinBoxUpdateThreshold->value() );
851867
//check behaviour so default projection when new layer is added with no
852868
//projection defined...
853869
if ( radPromptForProjection->isChecked() )
854870
{
855-
//
856871
settings.setValue( "/Projections/defaultBehaviour", "prompt" );
857872
}
858873
else if ( radUseProjectProjection->isChecked() )
859874
{
860-
//
861875
settings.setValue( "/Projections/defaultBehaviour", "useProject" );
862876
}
863877
else //assumes radUseGlobalProjection is checked
864878
{
865-
//
866879
settings.setValue( "/Projections/defaultBehaviour", "useGlobal" );
867880
}
868881

@@ -884,11 +897,6 @@ void QgsOptions::saveOptions()
884897
}
885898
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
886899

887-
if ( mDegreesRadioButton->isChecked() )
888-
{
889-
890-
}
891-
892900
QString angleUnitString = "degrees";
893901
if ( mRadiansRadioButton->isChecked() )
894902
{
@@ -900,14 +908,12 @@ void QgsOptions::saveOptions()
900908
}
901909
settings.setValue( "/qgis/measure/angleunits", angleUnitString );
902910

903-
904911
int decimalPlaces = mDecimalPlacesSpinBox->value();
905912
settings.setValue( "/qgis/measure/decimalplaces", decimalPlaces );
906913

907914
bool baseUnit = mKeepBaseUnitCheckBox->isChecked();
908915
settings.setValue( "/qgis/measure/keepbaseunit", baseUnit );
909916

910-
911917
//set the color for selections
912918
QColor myColor = pbnSelectionColor->color();
913919
settings.setValue( "/qgis/default_selection_color_red", myColor.red() );
@@ -972,13 +978,23 @@ void QgsOptions::saveOptions()
972978
settings.setValue( "/qgis/digitizing/offset_quad_seg", mOffsetQuadSegSpinBox->value() );
973979
settings.setValue( "/qgis/digitizing/offset_miter_limit", mCurveOffsetMiterLimitComboBox->value() );
974980

981+
// default scale list
982+
for ( int i = 0; i < mListGlobalScales->count(); ++i )
983+
{
984+
if ( i != 0 )
985+
{
986+
myPaths += ",";
987+
}
988+
myPaths += mListGlobalScales->item( i )->text();
989+
}
990+
settings.setValue( "Map/scales", myPaths );
991+
975992
//
976993
// Locale settings
977994
//
978995
settings.setValue( "locale/userLocale", cboLocale->itemData( cboLocale->currentIndex() ).toString() );
979996
settings.setValue( "locale/overrideFlag", grpLocale->isChecked() );
980997

981-
982998
// Gdal skip driver list
983999
if ( mLoadedGdalDriverList )
9841000
saveGdalDriverList();
@@ -1183,7 +1199,6 @@ void QgsOptions::on_mBtnRemovePluginPath_clicked()
11831199
delete itemToRemove;
11841200
}
11851201

1186-
11871202
void QgsOptions::on_mBtnAddSVGPath_clicked()
11881203
{
11891204
QString myDir = QFileDialog::getExistingDirectory(
@@ -1422,3 +1437,99 @@ void QgsOptions::saveGdalDriverList()
14221437
QSettings mySettings;
14231438
mySettings.setValue( "gdal/skipList", QgsApplication::skippedGdalDrivers().join( " " ) );
14241439
}
1440+
1441+
void QgsOptions::on_pbnAddScale_clicked()
1442+
{
1443+
int myScale = QInputDialog::getInt(
1444+
this,
1445+
tr( "Enter scale" ),
1446+
tr( "Scale denominator" ),
1447+
-1,
1448+
1
1449+
);
1450+
1451+
if ( myScale != -1 )
1452+
{
1453+
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
1454+
newItem->setText( QString( "1:%1" ).arg( myScale ) );
1455+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
1456+
mListGlobalScales->addItem( newItem );
1457+
mListGlobalScales->setCurrentItem( newItem );
1458+
}
1459+
}
1460+
1461+
void QgsOptions::on_pbnRemoveScale_clicked()
1462+
{
1463+
int currentRow = mListGlobalScales->currentRow();
1464+
QListWidgetItem* itemToRemove = mListGlobalScales->takeItem( currentRow );
1465+
delete itemToRemove;
1466+
}
1467+
1468+
void QgsOptions::on_pbnDefaultScaleValues_clicked()
1469+
{
1470+
mListGlobalScales->clear();
1471+
1472+
QStringList myScalesList = PROJECT_SCALES.split( "," );
1473+
QStringList::const_iterator scaleIt = myScalesList.constBegin();
1474+
for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
1475+
{
1476+
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
1477+
newItem->setText( *scaleIt );
1478+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
1479+
mListGlobalScales->addItem( newItem );
1480+
}
1481+
}
1482+
1483+
void QgsOptions::on_pbnImportScales_clicked()
1484+
{
1485+
QString fileName = QFileDialog::getOpenFileName( this, tr( "Load scales" ), ".",
1486+
tr( "XML files (*.xml *.XML)" ) );
1487+
if ( fileName.isEmpty() )
1488+
{
1489+
return;
1490+
}
1491+
1492+
QString msg;
1493+
QStringList myScales;
1494+
if ( !QgsScaleUtils::loadScaleList( fileName, myScales, msg ) )
1495+
{
1496+
QgsDebugMsg( msg );
1497+
}
1498+
1499+
QStringList::const_iterator scaleIt = myScales.constBegin();
1500+
for ( ; scaleIt != myScales.constEnd(); ++scaleIt )
1501+
{
1502+
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
1503+
newItem->setText( *scaleIt );
1504+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
1505+
mListGlobalScales->addItem( newItem );
1506+
}
1507+
}
1508+
1509+
void QgsOptions::on_pbnExportScales_clicked()
1510+
{
1511+
QString fileName = QFileDialog::getSaveFileName( this, tr( "Save scales" ), ".",
1512+
tr( "XML files (*.xml *.XML)" ) );
1513+
if ( fileName.isEmpty() )
1514+
{
1515+
return;
1516+
}
1517+
1518+
// ensure the user never ommited the extension from the file name
1519+
if ( !fileName.toLower().endsWith( ".xml" ) )
1520+
{
1521+
fileName += ".xml";
1522+
}
1523+
1524+
QStringList myScales;
1525+
for ( int i = 0; i < mListGlobalScales->count(); ++i )
1526+
{
1527+
myScales.append( mListGlobalScales->item( i )->text() );
1528+
}
1529+
1530+
QString msg;
1531+
if ( !QgsScaleUtils::saveScaleList( fileName, myScales, msg ) )
1532+
{
1533+
QgsDebugMsg( msg );
1534+
}
1535+
}

‎src/app/qgsoptions.h

Lines changed: 30 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,34 @@ 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_pbnDefaultScaleValues_clicked();
149+
150+
/** Let the user load scales from file
151+
* @note added in QGIS 2.0
152+
*/
153+
void on_pbnImportScales_clicked();
154+
155+
/** Let the user load scales from file
156+
* @note added in QGIS 2.0
157+
*/
158+
void on_pbnExportScales_clicked();
159+
132160
/** Auto slot executed when the active page in the main widget stack is changed
133161
* @note added in 2.0
134162
*/

‎src/app/qgsprojectproperties.cpp

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgsrenderer.h"
3131
#include "qgssnappingdialog.h"
3232
#include "qgsrasterlayer.h"
33+
#include "qgsscaleutils.h"
3334
#include "qgsgenericprojectionselector.h"
3435
#include "qgsstylev2.h"
3536
#include "qgssymbolv2.h"
@@ -39,12 +40,13 @@
3940

4041
//qt includes
4142
#include <QColorDialog>
43+
#include <QInputDialog>
44+
#include <QFileDialog>
4245
#include <QHeaderView> // Qt 4.4
4346
#include <QMessageBox>
4447

4548
//stdc++ includes
4649

47-
4850
QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl )
4951
: QDialog( parent, fl )
5052
, mMapCanvas( mapCanvas )
@@ -113,6 +115,22 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
113115
myColor = QColor( myRedInt, myGreenInt, myBlueInt );
114116
pbnCanvasColor->setColor( myColor );
115117

118+
//get project scales
119+
QStringList myScales = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
120+
if ( !myScales.isEmpty() )
121+
{
122+
QStringList::const_iterator scaleIt = myScales.constBegin();
123+
for ( ; scaleIt != myScales.constEnd(); ++scaleIt )
124+
{
125+
QListWidgetItem* newItem = new QListWidgetItem( lstScales );
126+
newItem->setText( *scaleIt );
127+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
128+
lstScales->addItem( newItem );
129+
}
130+
}
131+
132+
grpProjectScales->setChecked( QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" ) );
133+
116134
QgsMapLayer* currentLayer = 0;
117135

118136
QStringList noIdentifyLayerIdList = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
@@ -423,6 +441,33 @@ void QgsProjectProperties::apply()
423441
QgsProject::instance()->writeEntry( "Gui", "/CanvasColorGreenPart", myColor.green() );
424442
QgsProject::instance()->writeEntry( "Gui", "/CanvasColorBluePart", myColor.blue() );
425443

444+
//save project scales
445+
QStringList myScales;
446+
for ( int i = 0; i < lstScales->count(); ++i )
447+
{
448+
myScales.append( lstScales->item( i )->text() );
449+
}
450+
451+
if ( !myScales.isEmpty() )
452+
{
453+
QgsProject::instance()->writeEntry( "Scales", "/ScalesList", myScales );
454+
QgsProject::instance()->writeEntry( "Scales", "/useProjectScales", grpProjectScales->isChecked() );
455+
}
456+
else
457+
{
458+
QgsProject::instance()->removeEntry( "Scales", "/" );
459+
}
460+
461+
//use global or project scales depending on checkbox state
462+
if ( grpProjectScales->isChecked() )
463+
{
464+
emit scalesChanged( myScales );
465+
}
466+
else
467+
{
468+
emit scalesChanged();
469+
}
470+
426471
QStringList noIdentifyLayerList;
427472
for ( int i = 0; i < twIdentifyLayers->rowCount(); i++ )
428473
{
@@ -695,6 +740,87 @@ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked()
695740
mWMSList->addItems( crsList.values() );
696741
}
697742

743+
void QgsProjectProperties::on_pbnAddScale_clicked()
744+
{
745+
int myScale = QInputDialog::getInt(
746+
this,
747+
tr( "Enter scale" ),
748+
tr( "Scale denominator" ),
749+
-1,
750+
1
751+
);
752+
753+
if ( myScale != -1 )
754+
{
755+
QListWidgetItem* newItem = new QListWidgetItem( lstScales );
756+
newItem->setText( QString( "1:%1" ).arg( myScale ) );
757+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
758+
lstScales->addItem( newItem );
759+
lstScales->setCurrentItem( newItem );
760+
}
761+
}
762+
763+
void QgsProjectProperties::on_pbnRemoveScale_clicked()
764+
{
765+
int currentRow = lstScales->currentRow();
766+
QListWidgetItem* itemToRemove = lstScales->takeItem( currentRow );
767+
delete itemToRemove;
768+
}
769+
770+
void QgsProjectProperties::on_pbnImportScales_clicked()
771+
{
772+
QString fileName = QFileDialog::getOpenFileName( this, tr( "Load scales" ), ".",
773+
tr( "XML files (*.xml *.XML)" ) );
774+
if ( fileName.isEmpty() )
775+
{
776+
return;
777+
}
778+
779+
QString msg;
780+
QStringList myScales;
781+
if ( !QgsScaleUtils::loadScaleList( fileName, myScales, msg ) )
782+
{
783+
QgsDebugMsg( msg );
784+
}
785+
786+
QStringList::const_iterator scaleIt = myScales.constBegin();
787+
for ( ; scaleIt != myScales.constEnd(); ++scaleIt )
788+
{
789+
QListWidgetItem* newItem = new QListWidgetItem( lstScales );
790+
newItem->setText( *scaleIt );
791+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
792+
lstScales->addItem( newItem );
793+
}
794+
}
795+
796+
void QgsProjectProperties::on_pbnExportScales_clicked()
797+
{
798+
QString fileName = QFileDialog::getSaveFileName( this, tr( "Save scales" ), ".",
799+
tr( "XML files (*.xml *.XML)" ) );
800+
if ( fileName.isEmpty() )
801+
{
802+
return;
803+
}
804+
805+
// ensure the user never ommited the extension from the file name
806+
if ( !fileName.toLower().endsWith( ".xml" ) )
807+
{
808+
fileName += ".xml";
809+
}
810+
811+
QStringList myScales;
812+
for ( int i = 0; i < lstScales->count(); ++i )
813+
{
814+
myScales.append( lstScales->item( i )->text() );
815+
}
816+
817+
QString msg;
818+
if ( !QgsScaleUtils::saveScaleList( fileName, myScales, msg ) )
819+
{
820+
QgsDebugMsg( msg );
821+
}
822+
}
823+
698824
void QgsProjectProperties::populateStyles()
699825
{
700826
// Styles - taken from qgsstylev2managerdialog

‎src/app/qgsprojectproperties.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
8383
*/
8484
void on_pbnCanvasColor_clicked();
8585

86+
/*! Let the user add a scale to the list of project scales
87+
* used in scale combobox instead of global ones
88+
* @note added in QGIS 2.0
89+
*/
90+
void on_pbnAddScale_clicked();
91+
92+
/*! Let the user remove a scale from the list of project scales
93+
* used in scale combobox instead of global ones
94+
* @note added in QGIS 2.0
95+
*/
96+
void on_pbnRemoveScale_clicked();
97+
98+
/** Let the user load scales from file
99+
* @note added in QGIS 2.0
100+
*/
101+
void on_pbnImportScales_clicked();
102+
103+
/** Let the user load scales from file
104+
* @note added in QGIS 2.0
105+
*/
106+
void on_pbnExportScales_clicked();
107+
86108
/*!
87109
* Slots for WMS project settings
88110
*/
@@ -117,6 +139,9 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
117139
//! Signal used to inform listeners that the mouse display precision may have changed
118140
void displayPrecisionChanged();
119141

142+
//! Signal used to inform listeners that project scale list may have chnaged
143+
void scalesChanged( const QStringList &scales = QStringList() );
144+
120145
//! let listening canvases know to refresh
121146
void refresh();
122147

‎src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ SET(QGIS_CORE_SRCS
186186
qgsspatialindex.cpp
187187

188188
qgspaintenginehack.cpp
189+
qgsscaleutils.cpp
189190
)
190191

191192
IF(WIN32)
@@ -426,6 +427,7 @@ SET(QGIS_CORE_HDRS
426427
qgsspatialindex.h
427428

428429
qgspaintenginehack.h
430+
qgsscaleutils.h
429431
)
430432

431433
IF (QT_MOBILITY_LOCATION_FOUND)

‎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/core/qgsscaleutils.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/***************************************************************************
2+
qgsscaleutils.cpp
3+
---------------------
4+
begin : July 2012
5+
copyright : (C) 2012 by Alexander Bruy
6+
email : alexander dot bruy at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include <QFile>
17+
#include <QDomDocument>
18+
#include <QTextStream>
19+
20+
#include "qgsscaleutils.h"
21+
22+
bool QgsScaleUtils::saveScaleList( const QString &fileName, const QStringList &scales, QString &errorMessage )
23+
{
24+
QDomDocument doc;
25+
QDomElement root = doc.createElement( "qgsScales" );
26+
root.setAttribute( "version", "1.0" );
27+
doc.appendChild( root );
28+
29+
for ( int i = 0; i < scales.count(); ++i )
30+
{
31+
QDomElement el = doc.createElement( "scale" );
32+
el.setAttribute( "value", scales.at( i ) );
33+
root.appendChild( el );
34+
}
35+
36+
QFile file( fileName );
37+
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
38+
{
39+
errorMessage = QString( "Cannot write file %1:\n%2." ).arg( fileName ).arg( file.errorString() );
40+
return false;
41+
}
42+
43+
QTextStream out( &file );
44+
doc.save( out, 4 );
45+
return true;
46+
}
47+
48+
bool QgsScaleUtils::loadScaleList( const QString &fileName, QStringList &scales, QString &errorMessage )
49+
{
50+
QFile file( fileName );
51+
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
52+
{
53+
errorMessage = QString( "Cannot read file %1:\n%2." ).arg( fileName ).arg( file.errorString() );
54+
return false;
55+
}
56+
57+
QDomDocument doc;
58+
QString errorStr;
59+
int errorLine;
60+
int errorColumn;
61+
62+
if ( !doc.setContent( &file, true, &errorStr, &errorLine, &errorColumn ) )
63+
{
64+
errorMessage = QString( "Parse error at line %1, column %2:\n%3" )
65+
.arg( errorLine )
66+
.arg( errorColumn )
67+
.arg( errorStr );
68+
return false;
69+
}
70+
71+
QDomElement root = doc.documentElement();
72+
if ( root.tagName() != "qgsScales" )
73+
{
74+
errorMessage = "The file is not an scales exchange file.";
75+
return false;
76+
}
77+
78+
QDomElement child = root.firstChildElement();
79+
while ( !child.isNull() )
80+
{
81+
scales.append( child.attribute( "value" ) );
82+
child = child.nextSiblingElement();
83+
}
84+
85+
return true;
86+
}

‎src/core/qgsscaleutils.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/***************************************************************************
2+
qgscaleutils.h
3+
----------------------
4+
begin : July 2012
5+
copyright : (C) 2012 by Alexander Bruy
6+
email : alexander dot bruy at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include <QString>
17+
#include <QStringList>
18+
19+
#ifndef QGSSCALEUTILS_H
20+
#define QGSSCALEUTILS_H
21+
22+
class CORE_EXPORT QgsScaleUtils
23+
{
24+
public:
25+
/** save scales to the given file
26+
* @param fileName the name of the output file
27+
* @param scales the list of scales to save
28+
* @param errorMessage it will contain the error message if something
29+
* went wrong
30+
* @return true on success and false if failed
31+
*/
32+
static bool saveScaleList( const QString &fileName, const QStringList &scales, QString &errorMessage );
33+
34+
/** load scales from the given file
35+
* @param fileName the name of the file to process
36+
* @param scales it will contain loaded scales
37+
* @param errorMessage it will contain the error message if something
38+
* went wrong
39+
* @return true on success and false if failed
40+
*/
41+
static bool loadScaleList( const QString &fileName, QStringList &scales, QString &errorMessage );
42+
};
43+
44+
#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+
}
50+
}
51+
else
52+
{
53+
QStringList::const_iterator scaleIt = scales.constBegin();
54+
for ( ; scaleIt != scales.constEnd(); ++scaleIt )
55+
{
56+
myScalesList.append( *scaleIt );
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
};

‎src/ui/qgsoptionsbase.ui

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<x>0</x>
6868
<y>0</y>
6969
<width>760</width>
70-
<height>1005</height>
70+
<height>887</height>
7171
</rect>
7272
</property>
7373
<layout class="QGridLayout" name="gridLayout">
@@ -858,7 +858,7 @@
858858
<rect>
859859
<x>0</x>
860860
<y>0</y>
861-
<width>760</width>
861+
<width>630</width>
862862
<height>625</height>
863863
</rect>
864864
</property>
@@ -1104,9 +1104,9 @@
11041104
<property name="geometry">
11051105
<rect>
11061106
<x>0</x>
1107-
<y>0</y>
1108-
<width>760</width>
1109-
<height>506</height>
1107+
<y>-313</y>
1108+
<width>762</width>
1109+
<height>750</height>
11101110
</rect>
11111111
</property>
11121112
<layout class="QGridLayout" name="gridLayout_4">
@@ -1360,6 +1360,90 @@
13601360
</layout>
13611361
</widget>
13621362
</item>
1363+
<item row="3" column="0">
1364+
<widget class="QGroupBox" name="groupBox_15">
1365+
<property name="title">
1366+
<string>Predefined scales</string>
1367+
</property>
1368+
<layout class="QGridLayout" name="gridLayout_26">
1369+
<item row="0" column="0">
1370+
<widget class="QListWidget" name="mListGlobalScales"/>
1371+
</item>
1372+
<item row="0" column="1">
1373+
<layout class="QVBoxLayout" name="verticalLayout_3">
1374+
<item>
1375+
<widget class="QToolButton" name="pbnAddScale">
1376+
<property name="text">
1377+
<string>...</string>
1378+
</property>
1379+
<property name="icon">
1380+
<iconset resource="../../images/images.qrc">
1381+
<normaloff>:/images/themes/default/mActionNewAttribute.png</normaloff>:/images/themes/default/mActionNewAttribute.png</iconset>
1382+
</property>
1383+
</widget>
1384+
</item>
1385+
<item>
1386+
<widget class="QToolButton" name="pbnRemoveScale">
1387+
<property name="text">
1388+
<string>...</string>
1389+
</property>
1390+
<property name="icon">
1391+
<iconset resource="../../images/images.qrc">
1392+
<normaloff>:/images/themes/default/mActionDeleteAttribute.png</normaloff>:/images/themes/default/mActionDeleteAttribute.png</iconset>
1393+
</property>
1394+
</widget>
1395+
</item>
1396+
<item>
1397+
<widget class="QToolButton" name="pbnDefaultScaleValues">
1398+
<property name="text">
1399+
<string>...</string>
1400+
</property>
1401+
<property name="icon">
1402+
<iconset resource="../../images/images.qrc">
1403+
<normaloff>:/images/themes/default/mActionCopySelected.png</normaloff>:/images/themes/default/mActionCopySelected.png</iconset>
1404+
</property>
1405+
</widget>
1406+
</item>
1407+
<item>
1408+
<spacer name="verticalSpacer_3">
1409+
<property name="orientation">
1410+
<enum>Qt::Vertical</enum>
1411+
</property>
1412+
<property name="sizeHint" stdset="0">
1413+
<size>
1414+
<width>20</width>
1415+
<height>40</height>
1416+
</size>
1417+
</property>
1418+
</spacer>
1419+
</item>
1420+
<item>
1421+
<widget class="QToolButton" name="pbnImportScales">
1422+
<property name="text">
1423+
<string>...</string>
1424+
</property>
1425+
<property name="icon">
1426+
<iconset resource="../../images/images.qrc">
1427+
<normaloff>:/images/themes/default/mActionFolder.png</normaloff>:/images/themes/default/mActionFolder.png</iconset>
1428+
</property>
1429+
</widget>
1430+
</item>
1431+
<item>
1432+
<widget class="QToolButton" name="pbnExportScales">
1433+
<property name="text">
1434+
<string>...</string>
1435+
</property>
1436+
<property name="icon">
1437+
<iconset resource="../../images/images.qrc">
1438+
<normaloff>:/images/themes/default/mActionFileSave.png</normaloff>:/images/themes/default/mActionFileSave.png</iconset>
1439+
</property>
1440+
</widget>
1441+
</item>
1442+
</layout>
1443+
</item>
1444+
</layout>
1445+
</widget>
1446+
</item>
13631447
</layout>
13641448
</widget>
13651449
</widget>
@@ -1391,8 +1475,8 @@
13911475
<rect>
13921476
<x>0</x>
13931477
<y>0</y>
1394-
<width>778</width>
1395-
<height>436</height>
1478+
<width>270</width>
1479+
<height>93</height>
13961480
</rect>
13971481
</property>
13981482
<layout class="QGridLayout" name="gridLayout_10">
@@ -1472,7 +1556,7 @@
14721556
<rect>
14731557
<x>0</x>
14741558
<y>0</y>
1475-
<width>760</width>
1559+
<width>571</width>
14761560
<height>627</height>
14771561
</rect>
14781562
</property>
@@ -1848,8 +1932,8 @@
18481932
<rect>
18491933
<x>0</x>
18501934
<y>0</y>
1851-
<width>778</width>
1852-
<height>436</height>
1935+
<width>425</width>
1936+
<height>417</height>
18531937
</rect>
18541938
</property>
18551939
<layout class="QGridLayout" name="gridLayout_15">
@@ -2022,8 +2106,8 @@
20222106
<rect>
20232107
<x>0</x>
20242108
<y>0</y>
2025-
<width>760</width>
2026-
<height>551</height>
2109+
<width>519</width>
2110+
<height>584</height>
20272111
</rect>
20282112
</property>
20292113
<layout class="QGridLayout" name="gridLayout_17">
@@ -2119,7 +2203,7 @@
21192203
<rect>
21202204
<x>0</x>
21212205
<y>0</y>
2122-
<width>760</width>
2206+
<width>355</width>
21232207
<height>554</height>
21242208
</rect>
21252209
</property>

‎src/ui/qgsprojectpropertiesbase.ui

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>604</width>
10-
<height>456</height>
10+
<height>588</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -295,6 +295,69 @@
295295
</layout>
296296
</widget>
297297
</item>
298+
<item row="3" column="0">
299+
<widget class="QGroupBox" name="grpProjectScales">
300+
<property name="title">
301+
<string>Project scales</string>
302+
</property>
303+
<property name="checkable">
304+
<bool>true</bool>
305+
</property>
306+
<layout class="QGridLayout" name="gridLayout_7">
307+
<item row="0" column="0">
308+
<widget class="QListWidget" name="lstScales"/>
309+
</item>
310+
<item row="0" column="1">
311+
<layout class="QVBoxLayout" name="verticalLayout">
312+
<item>
313+
<widget class="QToolButton" name="pbnAddScale">
314+
<property name="text">
315+
<string>...</string>
316+
</property>
317+
<property name="icon">
318+
<iconset resource="../../images/images.qrc">
319+
<normaloff>:/images/themes/default/mActionNewAttribute.png</normaloff>:/images/themes/default/mActionNewAttribute.png</iconset>
320+
</property>
321+
</widget>
322+
</item>
323+
<item>
324+
<widget class="QToolButton" name="pbnRemoveScale">
325+
<property name="text">
326+
<string>...</string>
327+
</property>
328+
<property name="icon">
329+
<iconset resource="../../images/images.qrc">
330+
<normaloff>:/images/themes/default/mActionDeleteAttribute.png</normaloff>:/images/themes/default/mActionDeleteAttribute.png</iconset>
331+
</property>
332+
</widget>
333+
</item>
334+
<item>
335+
<widget class="QToolButton" name="pbnImportScales">
336+
<property name="text">
337+
<string>...</string>
338+
</property>
339+
<property name="icon">
340+
<iconset resource="../../images/images.qrc">
341+
<normaloff>:/images/themes/default/mActionFolder.png</normaloff>:/images/themes/default/mActionFolder.png</iconset>
342+
</property>
343+
</widget>
344+
</item>
345+
<item>
346+
<widget class="QToolButton" name="pbnExportScales">
347+
<property name="text">
348+
<string>...</string>
349+
</property>
350+
<property name="icon">
351+
<iconset resource="../../images/images.qrc">
352+
<normaloff>:/images/themes/default/mActionFileSave.png</normaloff>:/images/themes/default/mActionFileSave.png</iconset>
353+
</property>
354+
</widget>
355+
</item>
356+
</layout>
357+
</item>
358+
</layout>
359+
</widget>
360+
</item>
298361
</layout>
299362
</widget>
300363
<widget class="QWidget" name="tab2">
@@ -694,8 +757,8 @@
694757
<rect>
695758
<x>0</x>
696759
<y>0</y>
697-
<width>705</width>
698-
<height>781</height>
760+
<width>637</width>
761+
<height>808</height>
699762
</rect>
700763
</property>
701764
<layout class="QGridLayout" name="gridLayout">

0 commit comments

Comments
 (0)
Please sign in to comment.