Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] editable global scales list
  • Loading branch information
alexbruy committed Jul 18, 2012
1 parent aea41ee commit fbb7b3c
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 39 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() );
};

2 changes: 2 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -5303,6 +5303,8 @@ void QgisApp::options()

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

mScaleEdit->updateScales();
}

delete optionsDialog;
Expand Down
82 changes: 69 additions & 13 deletions src/app/qgsoptions.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgsnetworkaccessmanager.h"
#include "qgsproject.h"

#include <QInputDialog>
#include <QFileDialog>
#include <QSettings>
#include <QColorDialog>
Expand Down Expand Up @@ -416,6 +417,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 +862,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 +896,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 +907,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 +977,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 +1198,6 @@ void QgsOptions::on_mBtnRemovePluginPath_clicked()
delete itemToRemove;
}


void QgsOptions::on_mBtnAddSVGPath_clicked()
{
QString myDir = QFileDialog::getExistingDirectory(
Expand Down Expand Up @@ -1422,3 +1436,45 @@ 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_pbnDefaultValues_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 );
}
}
22 changes: 20 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,24 @@ 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_pbnDefaultValues_clicked();

/** Auto slot executed when the active page in the main widget stack is changed
* @note added in 2.0
*/
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgis.h
Expand Up @@ -152,6 +152,11 @@ const QString GEOWKT =
* @note deprecated in 1.8 due to violation of coding conventions (globals
* should be in all caps).
*/

const QString PROJECT_SCALES =
"1:1000000,1:500000,1:250000,1:100000,1:50000,1:25000,"
"1:10000,1:5000,1:2500,1:1000,1:500";

#ifndef _MSC_VER
Q_DECL_DEPRECATED
#endif
Expand Down
47 changes: 34 additions & 13 deletions src/gui/qgsscalecombobox.cpp
Expand Up @@ -15,26 +15,17 @@
* *
***************************************************************************/

#include "qgis.h"
#include "qgsscalecombobox.h"

#include <QAbstractItemView>
#include <QSettings>

QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent )
{
// make combobox editable and populate with predefined scales
setEditable( true );
addItem( "1:1000000" );
addItem( "1:500000" );
addItem( "1:250000" );
addItem( "1:100000" );
addItem( "1:50000" );
addItem( "1:25000" );
addItem( "1:10000" );
addItem( "1:5000" );
addItem( "1:2500" );
addItem( "1:1000" );
addItem( "1:500" );
updateScales();

setEditable( true );
setInsertPolicy( QComboBox::NoInsert );
setCompleter( 0 );
}
Expand All @@ -43,6 +34,36 @@ QgsScaleComboBox::~QgsScaleComboBox()
{
}

void QgsScaleComboBox::updateScales( const QStringList &scales )
{
QStringList myScalesList;
QString oldScale = currentText();

if ( scales.isEmpty() )
{
QSettings settings;
QString myScales = settings.value( "Map/scales", PROJECT_SCALES ).toString();
if ( !myScales.isEmpty() )
{
myScalesList = myScales.split( "," );
//~ QStringList::const_iterator scaleIt = myScalesList.constBegin();
//~ for ( ; scaleIt != myScalesList.constEnd(); ++scaleIt )
//~ {
//~ addItem( *scaleIt );
//~ }
}
}
else
{
}

blockSignals( true );
clear();
addItems( myScalesList );
setEditText( oldScale );
blockSignals( false );
}

void QgsScaleComboBox::showPopup()
{
QComboBox::showPopup();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsscalecombobox.h
Expand Up @@ -31,6 +31,9 @@ class GUI_EXPORT QgsScaleComboBox : public QComboBox
QgsScaleComboBox( QWidget* parent = 0 );
virtual ~QgsScaleComboBox();

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

protected:
void showPopup();
};
Expand Down

0 comments on commit fbb7b3c

Please sign in to comment.