Skip to content

Commit

Permalink
Merge branch 'project_scale'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jul 18, 2012
2 parents aea41ee + f5dce33 commit fe2252d
Show file tree
Hide file tree
Showing 14 changed files with 673 additions and 52 deletions.
5 changes: 4 additions & 1 deletion python/gui/qgsscalecombobox.sip
Expand Up @@ -8,8 +8,11 @@ class QgsScaleComboBox : QComboBox
#include <qgsscalecombobox.h>
%End

public:
public:
QgsScaleComboBox(QWidget * parent = 0);
~QgsScaleComboBox();

public slots:
void updateScales( const QStringList &scales = QStringList() );
};

32 changes: 26 additions & 6 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 @@ -5284,13 +5294,15 @@ void QgisApp::options()
return;
}

QSettings mySettings;
QString oldScales = mySettings.value( "Map/scales", PROJECT_SCALES ).toString();

QgsOptions *optionsDialog = new QgsOptions( this );
if ( optionsDialog->exec() )
{
// set the theme if it changed
setTheme( optionsDialog->theme() );

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

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

mRasterFileFilter.clear();
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );

if ( oldScales != mySettings.value( "Map/scales", PROJECT_SCALES ).toString() )
{
mScaleEdit->updateScales();
}
}

delete optionsDialog;
Expand Down Expand Up @@ -6492,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
137 changes: 124 additions & 13 deletions src/app/qgsoptions.cpp
Expand Up @@ -22,9 +22,11 @@
#include "qgsgenericprojectionselector.h"
#include "qgscoordinatereferencesystem.h"
#include "qgstolerance.h"
#include "qgsscaleutils.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsproject.h"

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

// predefined scales for scale combobox
myPaths = settings.value( "Map/scales", PROJECT_SCALES ).toString();
if ( !myPaths.isEmpty() )
{
QStringList myScalesList = myPaths.split( "," );
QStringList::const_iterator scaleIt = myScalesList.constBegin();
for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
{
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
newItem->setText( *scaleIt );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListGlobalScales->addItem( newItem );
}
}

//
// Locale settings
//
Expand Down Expand Up @@ -846,23 +863,19 @@ void QgsOptions::saveOptions()
settings.setValue( "/Raster/useStandardDeviation", chkUseStandardDeviation->isChecked() );
settings.setValue( "/Raster/defaultStandardDeviation", spnThreeBandStdDev->value() );


settings.setValue( "/Map/updateThreshold", spinBoxUpdateThreshold->value() );
//check behaviour so default projection when new layer is added with no
//projection defined...
if ( radPromptForProjection->isChecked() )
{
//
settings.setValue( "/Projections/defaultBehaviour", "prompt" );
}
else if ( radUseProjectProjection->isChecked() )
{
//
settings.setValue( "/Projections/defaultBehaviour", "useProject" );
}
else //assumes radUseGlobalProjection is checked
{
//
settings.setValue( "/Projections/defaultBehaviour", "useGlobal" );
}

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

if ( mDegreesRadioButton->isChecked() )
{

}

QString angleUnitString = "degrees";
if ( mRadiansRadioButton->isChecked() )
{
Expand All @@ -900,14 +908,12 @@ void QgsOptions::saveOptions()
}
settings.setValue( "/qgis/measure/angleunits", angleUnitString );


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

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


//set the color for selections
QColor myColor = pbnSelectionColor->color();
settings.setValue( "/qgis/default_selection_color_red", myColor.red() );
Expand Down Expand Up @@ -972,13 +978,23 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/digitizing/offset_quad_seg", mOffsetQuadSegSpinBox->value() );
settings.setValue( "/qgis/digitizing/offset_miter_limit", mCurveOffsetMiterLimitComboBox->value() );

// default scale list
for ( int i = 0; i < mListGlobalScales->count(); ++i )
{
if ( i != 0 )
{
myPaths += ",";
}
myPaths += mListGlobalScales->item( i )->text();
}
settings.setValue( "Map/scales", myPaths );

//
// Locale settings
//
settings.setValue( "locale/userLocale", cboLocale->itemData( cboLocale->currentIndex() ).toString() );
settings.setValue( "locale/overrideFlag", grpLocale->isChecked() );


// Gdal skip driver list
if ( mLoadedGdalDriverList )
saveGdalDriverList();
Expand Down Expand Up @@ -1183,7 +1199,6 @@ void QgsOptions::on_mBtnRemovePluginPath_clicked()
delete itemToRemove;
}


void QgsOptions::on_mBtnAddSVGPath_clicked()
{
QString myDir = QFileDialog::getExistingDirectory(
Expand Down Expand Up @@ -1422,3 +1437,99 @@ void QgsOptions::saveGdalDriverList()
QSettings mySettings;
mySettings.setValue( "gdal/skipList", QgsApplication::skippedGdalDrivers().join( " " ) );
}

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

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

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

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

QStringList myScalesList = PROJECT_SCALES.split( "," );
QStringList::const_iterator scaleIt = myScalesList.constBegin();
for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
{
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
newItem->setText( *scaleIt );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListGlobalScales->addItem( newItem );
}
}

void QgsOptions::on_pbnImportScales_clicked()
{
QString fileName = QFileDialog::getOpenFileName( this, tr( "Load scales" ), ".",
tr( "XML files (*.xml *.XML)" ) );
if ( fileName.isEmpty() )
{
return;
}

QString msg;
QStringList myScales;
if ( !QgsScaleUtils::loadScaleList( fileName, myScales, msg ) )
{
QgsDebugMsg( msg );
}

QStringList::const_iterator scaleIt = myScales.constBegin();
for ( ; scaleIt != myScales.constEnd(); ++scaleIt )
{
QListWidgetItem* newItem = new QListWidgetItem( mListGlobalScales );
newItem->setText( *scaleIt );
newItem->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mListGlobalScales->addItem( newItem );
}
}

void QgsOptions::on_pbnExportScales_clicked()
{
QString fileName = QFileDialog::getSaveFileName( this, tr( "Save scales" ), ".",
tr( "XML files (*.xml *.XML)" ) );
if ( fileName.isEmpty() )
{
return;
}

// ensure the user never ommited the extension from the file name
if ( !fileName.toLower().endsWith( ".xml" ) )
{
fileName += ".xml";
}

QStringList myScales;
for ( int i = 0; i < mListGlobalScales->count(); ++i )
{
myScales.append( mListGlobalScales->item( i )->text() );
}

QString msg;
if ( !QgsScaleUtils::saveScaleList( fileName, myScales, msg ) )
{
QgsDebugMsg( msg );
}
}
32 changes: 30 additions & 2 deletions src/app/qgsoptions.h
Expand Up @@ -106,7 +106,7 @@ class QgsOptions : public QDialog, private Ui::QgsOptionsBase
*/
void on_mBtnAddPluginPath_clicked();

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

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

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

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

/** Let the user restore default scales
* used in scale combobox
* @note added in QGIS 2.0
*/
void on_pbnDefaultScaleValues_clicked();

/** Let the user load scales from file
* @note added in QGIS 2.0
*/
void on_pbnImportScales_clicked();

/** Let the user load scales from file
* @note added in QGIS 2.0
*/
void on_pbnExportScales_clicked();

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

0 comments on commit fe2252d

Please sign in to comment.