[FEATURE] editable global scales list

This commit is contained in:
Alexander Bruy 2012-07-05 17:06:04 +03:00
parent aea41eebbc
commit fbb7b3c4e0
8 changed files with 231 additions and 39 deletions

View File

@ -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() );
};

View File

@ -5303,6 +5303,8 @@ void QgisApp::options()
mRasterFileFilter.clear();
QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
mScaleEdit->updateScales();
}
delete optionsDialog;

View File

@ -25,6 +25,7 @@
#include "qgsnetworkaccessmanager.h"
#include "qgsproject.h"
#include <QInputDialog>
#include <QFileDialog>
#include <QSettings>
#include <QColorDialog>
@ -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
//
@ -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" );
}
@ -884,11 +896,6 @@ void QgsOptions::saveOptions()
}
settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );
if ( mDegreesRadioButton->isChecked() )
{
}
QString angleUnitString = "degrees";
if ( mRadiansRadioButton->isChecked() )
{
@ -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() );
@ -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();
@ -1183,7 +1198,6 @@ void QgsOptions::on_mBtnRemovePluginPath_clicked()
delete itemToRemove;
}
void QgsOptions::on_mBtnAddSVGPath_clicked()
{
QString myDir = QFileDialog::getExistingDirectory(
@ -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 );
}
}

View File

@ -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
*/
@ -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
*/
@ -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
*/

View File

@ -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

View File

@ -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 );
}
@ -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();

View File

@ -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();
};

View File

@ -67,7 +67,7 @@
<x>0</x>
<y>0</y>
<width>760</width>
<height>1005</height>
<height>887</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@ -1104,9 +1104,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<height>506</height>
<y>-308</y>
<width>762</width>
<height>750</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
@ -1360,6 +1360,90 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QGroupBox" name="groupBox_15">
<property name="title">
<string>Predefined scales</string>
</property>
<layout class="QGridLayout" name="gridLayout_26">
<item row="0" column="0">
<widget class="QListWidget" name="mListGlobalScales"/>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QToolButton" name="pbnAddScale">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionNewAttribute.png</normaloff>:/images/themes/default/mActionNewAttribute.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="pbnRemoveScale">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDeleteAttribute.png</normaloff>:/images/themes/default/mActionDeleteAttribute.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="pbnDefaultValues">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionCopySelected.png</normaloff>:/images/themes/default/mActionCopySelected.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="pbnImportScales">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFolder.png</normaloff>:/images/themes/default/mActionFolder.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="pbnExportScales">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileSave.png</normaloff>:/images/themes/default/mActionFileSave.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
@ -1392,7 +1476,7 @@
<x>0</x>
<y>0</y>
<width>778</width>
<height>436</height>
<height>437</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_10">
@ -1472,7 +1556,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<width>762</width>
<height>627</height>
</rect>
</property>
@ -1849,7 +1933,7 @@
<x>0</x>
<y>0</y>
<width>778</width>
<height>436</height>
<height>437</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
@ -2022,8 +2106,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<height>551</height>
<width>762</width>
<height>566</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
@ -2119,7 +2203,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<width>762</width>
<height>554</height>
</rect>
</property>