Skip to content

Commit fc3e49b

Browse files
committedJul 18, 2012
[FEATURE] project scale list (if used - overrides global predefined scales)
1 parent c4299f4 commit fc3e49b

File tree

8 files changed

+194
-33
lines changed

8 files changed

+194
-33
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 18 additions & 5 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.
@@ -6499,6 +6509,9 @@ void QgisApp::projectProperties()
64996509
// changing things in the project properties dialog box
65006510
connect( pp, SIGNAL( displayPrecisionChanged() ), this,
65016511
SLOT( updateMouseCoordinatePrecision() ) );
6512+
6513+
connect( pp, SIGNAL( scalesChanged( const QStringList & ) ), mScaleEdit,
6514+
SLOT( updateScales( const QStringList & ) ) );
65026515
QApplication::restoreOverrideCursor();
65036516

65046517
//pass any refresh signals off to canvases

‎src/app/qgsoptions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,12 +1440,12 @@ void QgsOptions::saveGdalDriverList()
14401440
void QgsOptions::on_pbnAddScale_clicked()
14411441
{
14421442
int myScale = QInputDialog::getInt(
1443-
this,
1444-
tr( "Enter scale" ),
1445-
tr( "Scale denominator" ),
1446-
-1,
1447-
1
1448-
);
1443+
this,
1444+
tr( "Enter scale" ),
1445+
tr( "Scale denominator" ),
1446+
-1,
1447+
1
1448+
);
14491449

14501450
if ( myScale != -1 )
14511451
{
@@ -1464,7 +1464,7 @@ void QgsOptions::on_pbnRemoveScale_clicked()
14641464
delete itemToRemove;
14651465
}
14661466

1467-
void QgsOptions::on_pbnDefaultValues_clicked()
1467+
void QgsOptions::on_pbnDefaultScaleValues_clicked()
14681468
{
14691469
mListGlobalScales->clear();
14701470

‎src/app/qgsoptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
145145
* used in scale combobox
146146
* @note added in QGIS 2.0
147147
*/
148-
void on_pbnDefaultValues_clicked();
148+
void on_pbnDefaultScaleValues_clicked();
149149

150150
/** Auto slot executed when the active page in the main widget stack is changed
151151
* @note added in 2.0

‎src/app/qgsprojectproperties.cpp

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939

4040
//qt includes
4141
#include <QColorDialog>
42+
#include <QInputDialog>
4243
#include <QHeaderView> // Qt 4.4
4344
#include <QMessageBox>
4445

4546
//stdc++ includes
4647

47-
4848
QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl )
4949
: QDialog( parent, fl )
5050
, mMapCanvas( mapCanvas )
@@ -113,6 +113,22 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
113113
myColor = QColor( myRedInt, myGreenInt, myBlueInt );
114114
pbnCanvasColor->setColor( myColor );
115115

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

118134
QStringList noIdentifyLayerIdList = QgsProject::instance()->readListEntry( "Identify", "/disabledLayers" );
@@ -423,6 +439,33 @@ void QgsProjectProperties::apply()
423439
QgsProject::instance()->writeEntry( "Gui", "/CanvasColorGreenPart", myColor.green() );
424440
QgsProject::instance()->writeEntry( "Gui", "/CanvasColorBluePart", myColor.blue() );
425441

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

741+
void QgsProjectProperties::on_pbnAddScale_clicked()
742+
{
743+
int myScale = QInputDialog::getInt(
744+
this,
745+
tr( "Enter scale" ),
746+
tr( "Scale denominator" ),
747+
-1,
748+
1
749+
);
750+
751+
if ( myScale != -1 )
752+
{
753+
QListWidgetItem* newItem = new QListWidgetItem( lstScales );
754+
newItem->setText( QString( "1:%1" ).arg( myScale ) );
755+
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
756+
lstScales->addItem( newItem );
757+
lstScales->setCurrentItem( newItem );
758+
}
759+
}
760+
761+
void QgsProjectProperties::on_pbnRemoveScale_clicked()
762+
{
763+
int currentRow = lstScales->currentRow();
764+
QListWidgetItem* itemToRemove = lstScales->takeItem( currentRow );
765+
delete itemToRemove;
766+
}
767+
698768
void QgsProjectProperties::populateStyles()
699769
{
700770
// Styles - taken from qgsstylev2managerdialog

‎src/app/qgsprojectproperties.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ 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+
8698
/*!
8799
* Slots for WMS project settings
88100
*/
@@ -117,6 +129,9 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
117129
//! Signal used to inform listeners that the mouse display precision may have changed
118130
void displayPrecisionChanged();
119131

132+
//! Signal used to inform listeners that project scale list may have chnaged
133+
void scalesChanged( const QStringList &scales = QStringList() );
134+
120135
//! let listening canvases know to refresh
121136
void refresh();
122137

‎src/gui/qgsscalecombobox.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ void QgsScaleComboBox::updateScales( const QStringList &scales )
4646
if ( !myScales.isEmpty() )
4747
{
4848
myScalesList = myScales.split( "," );
49-
//~ QStringList::const_iterator scaleIt = myScalesList.constBegin();
50-
//~ for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
51-
//~ {
52-
//~ addItem( *scaleIt );
53-
//~ }
5449
}
5550
}
5651
else
5752
{
53+
QStringList::const_iterator scaleIt = scales.constBegin();
54+
for ( ; scaleIt != scales.constEnd(); ++scaleIt )
55+
{
56+
myScalesList.append( *scaleIt );
57+
}
5858
}
5959

6060
blockSignals( true );

‎src/ui/qgsoptionsbase.ui

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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,7 +1104,7 @@
11041104
<property name="geometry">
11051105
<rect>
11061106
<x>0</x>
1107-
<y>-308</y>
1107+
<y>-313</y>
11081108
<width>762</width>
11091109
<height>750</height>
11101110
</rect>
@@ -1394,7 +1394,7 @@
13941394
</widget>
13951395
</item>
13961396
<item>
1397-
<widget class="QToolButton" name="pbnDefaultValues">
1397+
<widget class="QToolButton" name="pbnDefaultScaleValues">
13981398
<property name="text">
13991399
<string>...</string>
14001400
</property>
@@ -1475,8 +1475,8 @@
14751475
<rect>
14761476
<x>0</x>
14771477
<y>0</y>
1478-
<width>778</width>
1479-
<height>437</height>
1478+
<width>270</width>
1479+
<height>93</height>
14801480
</rect>
14811481
</property>
14821482
<layout class="QGridLayout" name="gridLayout_10">
@@ -1556,7 +1556,7 @@
15561556
<rect>
15571557
<x>0</x>
15581558
<y>0</y>
1559-
<width>762</width>
1559+
<width>571</width>
15601560
<height>627</height>
15611561
</rect>
15621562
</property>
@@ -1932,8 +1932,8 @@
19321932
<rect>
19331933
<x>0</x>
19341934
<y>0</y>
1935-
<width>778</width>
1936-
<height>437</height>
1935+
<width>425</width>
1936+
<height>417</height>
19371937
</rect>
19381938
</property>
19391939
<layout class="QGridLayout" name="gridLayout_15">
@@ -2106,8 +2106,8 @@
21062106
<rect>
21072107
<x>0</x>
21082108
<y>0</y>
2109-
<width>762</width>
2110-
<height>566</height>
2109+
<width>519</width>
2110+
<height>584</height>
21112111
</rect>
21122112
</property>
21132113
<layout class="QGridLayout" name="gridLayout_17">
@@ -2203,7 +2203,7 @@
22032203
<rect>
22042204
<x>0</x>
22052205
<y>0</y>
2206-
<width>762</width>
2206+
<width>355</width>
22072207
<height>554</height>
22082208
</rect>
22092209
</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.