Skip to content

Commit

Permalink
fix ScaleRangeWidget: crash when setting canvas, order of the min/max…
Browse files Browse the repository at this point in the history
… widgets, denom/true scale, raster and rulebased dialogs, tooltip, alignement, etc.
  • Loading branch information
3nids committed May 12, 2014
1 parent 38c694d commit 862367a
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 296 deletions.
38 changes: 9 additions & 29 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@
#include <QVector>

QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanvas* theCanvas, QWidget *parent, Qt::WindowFlags fl )
: QgsOptionsDialogBase( "RasterLayerProperties", parent, fl ),
: QgsOptionsDialogBase( "RasterLayerProperties", parent, fl )
// Constant that signals property not used.
TRSTRING_NOT_SET( tr( "Not Set" ) ),
mRasterLayer( qobject_cast<QgsRasterLayer *>( lyr ) ), mRendererWidget( 0 )
, TRSTRING_NOT_SET( tr( "Not Set" ) )
, mRasterLayer( qobject_cast<QgsRasterLayer *>( lyr ) ), mRendererWidget( 0 )
, mMapCanvas( theCanvas )
{
mGrayMinimumMaximumEstimated = true;
mRGBMinimumMaximumEstimated = true;
Expand All @@ -81,9 +82,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
// and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
initOptionsBase( false );

mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomIn.svg" ) );
mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomOut.svg" ) );

connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );

Expand Down Expand Up @@ -116,17 +114,9 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
connect( lbxPyramidResolutions, SIGNAL( itemSelectionChanged() ), this, SLOT( toggleBuildPyramidsButton() ) );

// set up the scale based layer visibility stuff....
mScaleRangeWidget->setMapCanvas( mMapCanvas );
chkUseScaleDependentRendering->setChecked( lyr->hasScaleBasedVisibility() );
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
{
QStringList scalesList = QgsProject::instance()->readListEntry( "Scales", "/ScalesList" );
cbMinimumScale->updateScales( scalesList );
cbMaximumScale->updateScales( scalesList );
}
cbMinimumScale->setScale( 1.0 / lyr->minimumScale() );
cbMaximumScale->setScale( 1.0 / lyr->maximumScale() );

mScaleRangeWidget->setScaleRange( 1.0 / lyr->maximumScale(), 1.0 / lyr->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales

leNoDataValue->setValidator( new QDoubleValidator( -std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), 1000, this ) );

Expand All @@ -141,7 +131,6 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
pbnImportTransparentPixelValues->setIcon( QgsApplication::getThemeIcon( "/mActionFileOpen.svg" ) );
pbnExportTransparentPixelValues->setIcon( QgsApplication::getThemeIcon( "/mActionFileSave.svg" ) );

mMapCanvas = theCanvas;
mPixelSelectorTool = 0;
if ( mMapCanvas )
{
Expand Down Expand Up @@ -856,8 +845,9 @@ void QgsRasterLayerProperties::apply()

// set up the scale based layer visibility stuff....
mRasterLayer->toggleScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
mRasterLayer->setMinimumScale( 1.0 / cbMinimumScale->scale() );
mRasterLayer->setMaximumScale( 1.0 / cbMaximumScale->scale() );
// caution: layer uses scale denoms, widget uses true scales
mRasterLayer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
mRasterLayer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );

//update the legend pixmap
// pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
Expand Down Expand Up @@ -1717,16 +1707,6 @@ void QgsRasterLayerProperties::toggleBuildPyramidsButton()
}
}

void QgsRasterLayerProperties::on_mMinimumScaleSetCurrentPushButton_clicked()
{
cbMinimumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
}

void QgsRasterLayerProperties::on_mMaximumScaleSetCurrentPushButton_clicked()
{
cbMaximumScale->setScale( 1.0 / QgisApp::instance()->mapCanvas()->mapSettings().scale() );
}

void QgsRasterLayerProperties::on_mResetColorRenderingBtn_clicked()
{
mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgsrasterlayerproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
void on_pbnSaveStyleAs_clicked();
/** Help button */
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
void on_mMinimumScaleSetCurrentPushButton_clicked();
void on_mMaximumScaleSetCurrentPushButton_clicked();

/** Slot to reset all color rendering options to default
* @note added in 1.9
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void QgsVectorLayerProperties::syncToLayer( void )
setDisplayField( layer-> displayField() );

// set up the scale based layer visibility stuff....
mScaleRangeWidget->setFromLayer( layer );
mScaleRangeWidget->setScaleRange( 1.0 / layer->maximumScale(), 1.0 / layer->minimumScale() ); // caution: layer uses scale denoms, widget uses true scales
mScaleVisibilityGroupBox->setChecked( layer->hasScaleBasedVisibility() );
mScaleRangeWidget->setMapCanvas( QgisApp::instance()->mapCanvas() );

Expand Down Expand Up @@ -494,8 +494,9 @@ void QgsVectorLayerProperties::apply()

// set up the scale based layer visibility stuff....
layer->toggleScaleBasedVisibility( mScaleVisibilityGroupBox->isChecked() );
layer->setMinimumScale( 1.0 / mScaleRangeWidget->minimumScale() );
layer->setMaximumScale( 1.0 / mScaleRangeWidget->maximumScale() );
// caution: layer uses scale denoms, widget uses true scales
layer->setMaximumScale( 1.0 / mScaleRangeWidget->minimumScale() );
layer->setMinimumScale( 1.0 / mScaleRangeWidget->maximumScale() );

// provider-specific options
if ( layer->dataProvider() )
Expand Down
98 changes: 69 additions & 29 deletions src/gui/qgsscalerangewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,55 @@
QgsScaleRangeWidget::QgsScaleRangeWidget( QWidget *parent )
: QWidget( parent )
, mCanvas( 0 )
, mMaximumScaleSetCurrentPushButton( 0 )
, mMinimumScaleSetCurrentPushButton( 0 )
{
mLayout = new QGridLayout( this );
mLayout->setContentsMargins( 0, 0, 0, 0 );

QLabel* maxLbl = new QLabel( tr("Maximimum (inclusive)"), this);
QLabel* minLbl = new QLabel( tr("Minimimum (exclusive)"), this);

mMaximumScaleIconLabel = new QLabel(this);
mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomIn.svg" ) );
mMinimumScaleIconLabel = new QLabel(this);
QLabel* minLbl = new QLabel( tr( "Minimimum\n(exclusive)" ), this );
minLbl->setWordWrap( true );
minLbl->setAlignment( Qt::AlignTop );
minLbl->setToolTip( tr( "Minimum scale, i.e. maximum scale denominator. "
"This limit is exclusive, that means the layer will not be displayed on this scale." ) );
QLabel* maxLbl = new QLabel( tr( "Maximimum\n(inclusive)" ), this );
maxLbl->setWordWrap( true );
maxLbl->setAlignment( Qt::AlignTop );
maxLbl->setToolTip( tr( "Maximum scale, i.e. minimum scale denominator. "
"This limit is inclusive, that means the layer will be displayed on this scale." ) );

mMinimumScaleIconLabel = new QLabel( this );
mMinimumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomOut.svg" ) );
mMaximumScaleIconLabel = new QLabel( this );
mMaximumScaleIconLabel->setPixmap( QgsApplication::getThemePixmap( "/mActionZoomIn.svg" ) );

mMaximumScaleComboBox = new QgsScaleComboBox(this);
mMinimumScaleComboBox = new QgsScaleComboBox(this);

mLayout->addWidget(maxLbl, 0, 0);
mLayout->addWidget(mMaximumScaleIconLabel, 0, 1);
mLayout->addWidget(mMaximumScaleComboBox, 0, 2);
mLayout->addWidget(minLbl, 0, 3);
mLayout->addWidget(mMinimumScaleIconLabel, 0, 4);
mLayout->addWidget(mMinimumScaleComboBox, 0, 5);
mMinimumScaleComboBox = new QgsScaleComboBox( this );
mMaximumScaleComboBox = new QgsScaleComboBox( this );
reloadProjectScales();
// add start, add comprehension of scales by settings fake ordered values
mMinimumScaleComboBox->setCurrentIndex( 2 );
mMaximumScaleComboBox->setCurrentIndex( mMinimumScaleComboBox->currentIndex() + 2 );

mLayout->addWidget( minLbl, 0, 0, 2, 1 );
mLayout->addWidget( mMinimumScaleIconLabel, 0, 1 );
mLayout->addWidget( mMinimumScaleComboBox, 0, 2 );
mLayout->addWidget( maxLbl, 0, 3, 2, 1 );
mLayout->addWidget( mMaximumScaleIconLabel, 0, 4 );
mLayout->addWidget( mMaximumScaleComboBox, 0, 5 );

mLayout->setColumnStretch( 0, 0 );
mLayout->setColumnStretch( 1, 0 );
mLayout->setColumnStretch( 2, 3 );
mLayout->setColumnStretch( 3, 0 );
mLayout->setColumnStretch( 4, 0 );
mLayout->setColumnStretch( 5, 3 );
}

QgsScaleRangeWidget::~QgsScaleRangeWidget()
{
}

void QgsScaleRangeWidget::showEvent( QShowEvent * )
void QgsScaleRangeWidget::reloadProjectScales()
{
bool projectScales = QgsProject::instance()->readBoolEntry( "Scales", "/useProjectScales" );
if ( projectScales )
Expand All @@ -61,22 +82,29 @@ void QgsScaleRangeWidget::showEvent( QShowEvent * )

void QgsScaleRangeWidget::setMapCanvas( QgsMapCanvas *mapCanvas )
{
if (mMinimumScaleSetCurrentPushButton)
if ( mMinimumScaleSetCurrentPushButton )
{
delete mMinimumScaleSetCurrentPushButton;
if (mMaximumScaleSetCurrentPushButton)
mMinimumScaleSetCurrentPushButton = 0;
}
if ( mMaximumScaleSetCurrentPushButton )
{
delete mMaximumScaleSetCurrentPushButton;
mMaximumScaleSetCurrentPushButton = 0;
}

if ( !mapCanvas )
return;

mCanvas = mapCanvas;

mMaximumScaleSetCurrentPushButton = new QToolButton();
connect( mMaximumScaleSetCurrentPushButton, SIGNAL(clicked()), this, SLOT(setMaxScaleFromCanvas()));
mMinimumScaleSetCurrentPushButton = new QToolButton();
connect( mMinimumScaleSetCurrentPushButton, SIGNAL(clicked()), this, SLOT(setMinScaleFromCanvas()));
mMinimumScaleSetCurrentPushButton = new QPushButton( tr( "current" ), this );
connect( mMinimumScaleSetCurrentPushButton, SIGNAL( clicked() ), this, SLOT( setMinScaleFromCanvas() ) );
mMaximumScaleSetCurrentPushButton = new QPushButton( tr( "current" ), this );
connect( mMaximumScaleSetCurrentPushButton, SIGNAL( clicked() ), this, SLOT( setMaxScaleFromCanvas() ) );

mLayout->addWidget(mMaximumScaleSetCurrentPushButton, 1,2);
mLayout->addWidget(mMinimumScaleSetCurrentPushButton, 1,5);
mLayout->addWidget( mMinimumScaleSetCurrentPushButton, 1, 2 );
mLayout->addWidget( mMaximumScaleSetCurrentPushButton, 1, 5 );
}

void QgsScaleRangeWidget::setMinimumScale( double scale )
Expand All @@ -99,6 +127,22 @@ double QgsScaleRangeWidget::maximumScale()
return mMaximumScaleComboBox->scale();
}

double QgsScaleRangeWidget::minimumScaleDenom()
{
return qRound( 1.0 / maximumScale() );
}

double QgsScaleRangeWidget::maximumScaleDenom()
{
return qRound( 1.0 / minimumScale() );
}

void QgsScaleRangeWidget::setScaleRange( double min, double max )
{
setMaximumScale( max );
setMinimumScale( min );
}

void QgsScaleRangeWidget::setMinScaleFromCanvas()
{
mMinimumScaleComboBox->setScale( 1.0 / mCanvas->mapSettings().scale() );
Expand All @@ -109,8 +153,4 @@ void QgsScaleRangeWidget::setMaxScaleFromCanvas()
mMaximumScaleComboBox->setScale( 1.0 / mCanvas->mapSettings().scale() );
}

void QgsScaleRangeWidget::setFromLayer( QgsMapLayer *layer )
{
mMinimumScaleComboBox->setScale( 1.0 / layer->minimumScale() );
mMaximumScaleComboBox->setScale( 1.0 / layer->maximumScale() );
}

27 changes: 19 additions & 8 deletions src/gui/qgsscalerangewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <QGridLayout>
#include <QLabel>
#include <QToolButton>
#include <QPushButton>


#include "qgscollapsiblegroupbox.h"
Expand All @@ -35,23 +35,34 @@ class GUI_EXPORT QgsScaleRangeWidget : public QWidget
explicit QgsScaleRangeWidget( QWidget *parent = 0 );
~QgsScaleRangeWidget();

void showEvent( QShowEvent * );

//! set the map canvas which will be used for the current scale buttons
/**
* @brief setMapCanvas set the map canvas which will be used for the current scale buttons
* if not set, the buttons are hidden.
*/
void setMapCanvas( QgsMapCanvas* mapCanvas );

//! return the minimum scale
double minimumScale();

//! return the maximum scale
double maximumScale();

//! return the minimum scale denominator ( = 1 / maximum scale )
double minimumScaleDenom();

//! return the maximum scale denominator ( = 1 / minimum scale )
double maximumScaleDenom();

//! call to reload the project scales and apply them to the 2 scales combo boxes
void reloadProjectScales();

public slots:
void setMinimumScale( double scale );
double minimumScale();

void setMaximumScale( double scale );
double maximumScale();

void setFromLayer( QgsMapLayer* layer );
void setScaleRange( double min, double max );

private slots:
void setMaxScaleFromCanvas();
Expand All @@ -65,8 +76,8 @@ class GUI_EXPORT QgsScaleRangeWidget : public QWidget
QGridLayout* mLayout;
QLabel* mMaximumScaleIconLabel;
QLabel* mMinimumScaleIconLabel;
QToolButton* mMaximumScaleSetCurrentPushButton;
QToolButton* mMinimumScaleSetCurrentPushButton;
QPushButton* mMaximumScaleSetCurrentPushButton;
QPushButton* mMinimumScaleSetCurrentPushButton;
QgsScaleComboBox* mMaximumScaleComboBox;
QgsScaleComboBox* mMinimumScaleComboBox;
};
Expand Down
14 changes: 8 additions & 6 deletions src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,9 @@ QgsRendererRulePropsDialog::QgsRendererRulePropsDialog( QgsRuleBasedRendererV2::
if ( mRule->dependsOnScale() )
{
groupScale->setChecked( true );
spinMinScale->setValue( rule->scaleMinDenom() );
spinMaxScale->setValue( rule->scaleMaxDenom() );
// caution: rule uses scale denom, scale widget uses true scales
mScaleRangeWidget->setMaximumScale( 1.0 / rule->scaleMinDenom() );
mScaleRangeWidget->setMinimumScale( 1.0 / rule->scaleMaxDenom() );
}

if ( mRule->symbol() )
Expand Down Expand Up @@ -655,8 +656,9 @@ void QgsRendererRulePropsDialog::accept()
mRule->setFilterExpression( editFilter->text() );
mRule->setLabel( editLabel->text() );
mRule->setDescription( editDescription->text() );
mRule->setScaleMinDenom( groupScale->isChecked() ? spinMinScale->value() : 0 );
mRule->setScaleMaxDenom( groupScale->isChecked() ? spinMaxScale->value() : 0 );
// caution: rule uses scale denom, scale widget uses true scales
mRule->setScaleMinDenom( groupScale->isChecked() ? mScaleRangeWidget->minimumScaleDenom() : 0 );
mRule->setScaleMaxDenom( groupScale->isChecked() ? mScaleRangeWidget->maximumScaleDenom() : 0 );
mRule->setSymbol( groupSymbol->isChecked() ? mSymbol->clone() : NULL );

QDialog::accept();
Expand Down Expand Up @@ -723,8 +725,8 @@ QVariant QgsRuleBasedRendererV2Model::data( const QModelIndex &index, int role )
{
return rule->filterExpression().isEmpty() ? tr( "(no filter)" ) : rule->filterExpression();
}
case 2: return rule->dependsOnScale() ? _formatScale( rule->scaleMinDenom() ) : QVariant();
case 3: return rule->dependsOnScale() ? _formatScale( rule->scaleMaxDenom() ) : QVariant();
case 2: return rule->dependsOnScale() ? _formatScale( rule->scaleMaxDenom() ) : QVariant();
case 3: return rule->dependsOnScale() ? _formatScale( rule->scaleMinDenom() ) : QVariant();
case 4:
if ( mFeatureCountMap.count( rule ) == 1 )
{
Expand Down
Loading

0 comments on commit 862367a

Please sign in to comment.