Skip to content

Commit fe2252d

Browse files
committed
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
*/

0 commit comments

Comments
 (0)