Skip to content

Commit

Permalink
[FEATURE] project scale list (if used - overrides global predefined s…
Browse files Browse the repository at this point in the history
…cales)
  • Loading branch information
alexbruy committed Jul 18, 2012
1 parent c4299f4 commit fc3e49b
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 33 deletions.
23 changes: 18 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -2973,6 +2973,7 @@ void QgisApp::fileNew( bool thePromptToSaveFlag, bool forceBlank )
mMapCanvas->freeze( false );
mMapCanvas->refresh();
mMapCanvas->clearExtentHistory();
mScaleEdit->updateScales();

// set project CRS
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
Expand Down Expand Up @@ -3107,6 +3108,13 @@ void QgisApp::fileOpen()
}

setTitleBarText_( *this );

bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
{
mScaleEdit->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
}

emit projectRead(); // let plug-ins know that we've read in a new
// project so that they can check any project
// specific plug-in state
Expand All @@ -3117,7 +3125,6 @@ void QgisApp::fileOpen()
mMapCanvas->freeze( false );
mMapCanvas->refresh();
}

} // QgisApp::fileOpen


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

//load project scales
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
{
mScaleEdit->updateScales( QgsProject::instance()->readListEntry( "Scales", "/ScalesList" ) );
}

mMapCanvas->updateScale();
QgsDebugMsg( "Scale restored..." );

Expand Down Expand Up @@ -3302,12 +3316,10 @@ void QgisApp::fileSaveAs()
}
} // QgisApp::fileSaveAs


// Open the project file corresponding to the
// path at the given index in mRecentProjectPaths
void QgisApp::openProject( QAction *action )
{

// possibly save any pending work before opening a different project
QString debugme;
assert( action != NULL );
Expand All @@ -3323,7 +3335,6 @@ void QgisApp::openProject( QAction *action )
int myProjectionEnabledFlag =
QgsProject::instance()->readNumEntry( "SpatialRefSys", "/ProjectionsEnabled", 0 );
mMapCanvas->mapRenderer()->setProjectionsEnabled( myProjectionEnabledFlag );

} // QgisApp::openProject


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


/**
Open a raster or vector file; ignore other files.
Used to process a commandline argument or OpenDocument AppleEvent.
Expand Down Expand Up @@ -6499,6 +6509,9 @@ void QgisApp::projectProperties()
// changing things in the project properties dialog box
connect( pp, SIGNAL( displayPrecisionChanged() ), this,
SLOT( updateMouseCoordinatePrecision() ) );

connect( pp, SIGNAL( scalesChanged( const QStringList & ) ), mScaleEdit,
SLOT( updateScales( const QStringList & ) ) );
QApplication::restoreOverrideCursor();

//pass any refresh signals off to canvases
Expand Down
14 changes: 7 additions & 7 deletions src/app/qgsoptions.cpp
Expand Up @@ -1440,12 +1440,12 @@ void QgsOptions::saveGdalDriverList()
void QgsOptions::on_pbnAddScale_clicked()
{
int myScale = QInputDialog::getInt(
this,
tr( "Enter scale" ),
tr( "Scale denominator" ),
-1,
1
);
this,
tr( "Enter scale" ),
tr( "Scale denominator" ),
-1,
1
);

if ( myScale != -1 )
{
Expand All @@ -1464,7 +1464,7 @@ void QgsOptions::on_pbnRemoveScale_clicked()
delete itemToRemove;
}

void QgsOptions::on_pbnDefaultValues_clicked()
void QgsOptions::on_pbnDefaultScaleValues_clicked()
{
mListGlobalScales->clear();

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsoptions.h
Expand Up @@ -145,7 +145,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
* used in scale combobox
* @note added in QGIS 2.0
*/
void on_pbnDefaultValues_clicked();
void on_pbnDefaultScaleValues_clicked();

/** Auto slot executed when the active page in the main widget stack is changed
* @note added in 2.0
Expand Down
72 changes: 71 additions & 1 deletion src/app/qgsprojectproperties.cpp
Expand Up @@ -39,12 +39,12 @@

//qt includes
#include <QColorDialog>
#include <QInputDialog>
#include <QHeaderView> // Qt 4.4
#include <QMessageBox>

//stdc++ includes


QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *parent, Qt::WFlags fl )
: QDialog( parent, fl )
, mMapCanvas( mapCanvas )
Expand Down Expand Up @@ -113,6 +113,22 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
myColor = QColor( myRedInt, myGreenInt, myBlueInt );
pbnCanvasColor->setColor( myColor );

//get project scales
QStringList myScales = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
if ( !myScales.isEmpty() )
{
QStringList::const_iterator scaleIt = myScales.constBegin();
for ( ; scaleIt != myScales.constEnd(); ++scaleIt )
{
QListWidgetItem* newItem = new QListWidgetItem( lstScales );
newItem->setText( *scaleIt );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
lstScales->addItem( newItem );
}
}

grpProjectScales->setChecked( QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" ) );

QgsMapLayer* currentLayer = 0;

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

//save project scales
QStringList myScales;
for ( int i = 0; i < lstScales->count(); ++i )
{
myScales.append( lstScales->item( i )->text() );
}

if ( !myScales.isEmpty() )
{
QgsProject::instance()->writeEntry( "Scales", "/ScalesList", myScales );
QgsProject::instance()->writeEntry( "Scales", "/useProjectScales", grpProjectScales->isChecked() );
}
else
{
QgsProject::instance()->removeEntry( "Scales", "/" );
}

//use global or project scales depending on checkbox state
if ( grpProjectScales->isChecked() )
{
emit scalesChanged( myScales );
}
else
{
emit scalesChanged();
}

QStringList noIdentifyLayerList;
for ( int i = 0; i < twIdentifyLayers->rowCount(); i++ )
{
Expand Down Expand Up @@ -695,6 +738,33 @@ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked()
mWMSList->addItems( crsList.values() );
}

void QgsProjectProperties::on_pbnAddScale_clicked()
{
int myScale = QInputDialog::getInt(
this,
tr( "Enter scale" ),
tr( "Scale denominator" ),
-1,
1
);

if ( myScale != -1 )
{
QListWidgetItem* newItem = new QListWidgetItem( lstScales );
newItem->setText( QString( "1:%1" ).arg( myScale ) );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
lstScales->addItem( newItem );
lstScales->setCurrentItem( newItem );
}
}

void QgsProjectProperties::on_pbnRemoveScale_clicked()
{
int currentRow = lstScales->currentRow();
QListWidgetItem* itemToRemove = lstScales->takeItem( currentRow );
delete itemToRemove;
}

void QgsProjectProperties::populateStyles()
{
// Styles - taken from qgsstylev2managerdialog
Expand Down
15 changes: 15 additions & 0 deletions src/app/qgsprojectproperties.h
Expand Up @@ -83,6 +83,18 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
*/
void on_pbnCanvasColor_clicked();

/*! Let the user add a scale to the list of project scales
* used in scale combobox instead of global ones
* @note added in QGIS 2.0
*/
void on_pbnAddScale_clicked();

/*! Let the user remove a scale from the list of project scales
* used in scale combobox instead of global ones
* @note added in QGIS 2.0
*/
void on_pbnRemoveScale_clicked();

/*!
* Slots for WMS project settings
*/
Expand Down Expand Up @@ -117,6 +129,9 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
//! Signal used to inform listeners that the mouse display precision may have changed
void displayPrecisionChanged();

//! Signal used to inform listeners that project scale list may have chnaged
void scalesChanged( const QStringList &scales = QStringList() );

//! let listening canvases know to refresh
void refresh();

Expand Down
10 changes: 5 additions & 5 deletions src/gui/qgsscalecombobox.cpp
Expand Up @@ -46,15 +46,15 @@ void QgsScaleComboBox::updateScales( const QStringList &scales )
if ( !myScales.isEmpty() )
{
myScalesList = myScales.split( "," );
//~ QStringList::const_iterator scaleIt = myScalesList.constBegin();
//~ for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
//~ {
//~ addItem( *scaleIt );
//~ }
}
}
else
{
QStringList::const_iterator scaleIt = scales.constBegin();
for ( ; scaleIt != scales.constEnd(); ++scaleIt )
{
myScalesList.append( *scaleIt );
}
}

blockSignals( true );
Expand Down
22 changes: 11 additions & 11 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -858,7 +858,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<width>630</width>
<height>625</height>
</rect>
</property>
Expand Down Expand Up @@ -1104,7 +1104,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-308</y>
<y>-313</y>
<width>762</width>
<height>750</height>
</rect>
Expand Down Expand Up @@ -1394,7 +1394,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="pbnDefaultValues">
<widget class="QToolButton" name="pbnDefaultScaleValues">
<property name="text">
<string>...</string>
</property>
Expand Down Expand Up @@ -1475,8 +1475,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>778</width>
<height>437</height>
<width>270</width>
<height>93</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_10">
Expand Down Expand Up @@ -1556,7 +1556,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>762</width>
<width>571</width>
<height>627</height>
</rect>
</property>
Expand Down Expand Up @@ -1932,8 +1932,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>778</width>
<height>437</height>
<width>425</width>
<height>417</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
Expand Down Expand Up @@ -2106,8 +2106,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>762</width>
<height>566</height>
<width>519</width>
<height>584</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
Expand Down Expand Up @@ -2203,7 +2203,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>762</width>
<width>355</width>
<height>554</height>
</rect>
</property>
Expand Down

0 comments on commit fc3e49b

Please sign in to comment.