Skip to content

Commit

Permalink
Don't reset output size on radius change (fix #8090)
Browse files Browse the repository at this point in the history
Prevent input of invalid output size by changing to spin boxes for rows and columns
  • Loading branch information
nyalldawson committed Jun 26, 2013
1 parent 5e760dd commit 65aa1d5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
41 changes: 20 additions & 21 deletions src/plugins/heatmap/heatmapgui.cpp
Expand Up @@ -37,7 +37,8 @@
//standard includes

HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
: QDialog( parent, fl ),
mRows( 500 )
{
setupUi( this );

Expand Down Expand Up @@ -79,6 +80,8 @@ HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )
mFormatCombo->setCurrentIndex( myTiffIndex );

updateBBox();
updateSize();

//finally set right the ok button
enableOrDisableOkButton();
}
Expand Down Expand Up @@ -149,22 +152,22 @@ void HeatmapGui::on_advancedGroupBox_toggled( bool enabled )
}
}

void HeatmapGui::on_rowLineEdit_editingFinished()
void HeatmapGui::on_mRowsSpinBox_editingFinished()
{
mRows = rowLineEdit->text().toInt();
mRows = mRowsSpinBox->value();
mYcellsize = mBBox.height() / mRows;
mXcellsize = mYcellsize;
mColumns = mBBox.width() / mXcellsize + 1;
mColumns = max( mBBox.width() / mXcellsize, 1 );

updateSize();
}

void HeatmapGui::on_columnLineEdit_editingFinished()
void HeatmapGui::on_mColumnsSpinBox_editingFinished()
{
mColumns = columnLineEdit->text().toInt();
mColumns = mColumnsSpinBox->value();
mXcellsize = mBBox.width() / mColumns;
mYcellsize = mXcellsize;
mRows = mBBox.height() / mYcellsize + 1;
mRows = max( mBBox.height() / mYcellsize, 1 );

updateSize();
}
Expand All @@ -173,8 +176,8 @@ void HeatmapGui::on_cellXLineEdit_editingFinished()
{
mXcellsize = cellXLineEdit->text().toDouble();
mYcellsize = mXcellsize;
mRows = mBBox.height() / mYcellsize + 1;
mColumns = mBBox.width() / mXcellsize + 1;
mRows = max( mBBox.height() / mYcellsize, 1 );
mColumns = max( mBBox.width() / mXcellsize, 1 );

updateSize();
}
Expand All @@ -183,8 +186,8 @@ void HeatmapGui::on_cellYLineEdit_editingFinished()
{
mYcellsize = cellYLineEdit->text().toDouble();
mXcellsize = mYcellsize;
mRows = mBBox.height() / mYcellsize + 1;
mColumns = mBBox.width() / mXcellsize + 1;
mRows = max( mBBox.height() / mYcellsize, 1 );
mColumns = max( mBBox.width() / mXcellsize, 1 );

updateSize();
}
Expand Down Expand Up @@ -316,8 +319,8 @@ void HeatmapGui::populateFields()

void HeatmapGui::updateSize()
{
rowLineEdit->setText( QString::number( mRows ) );
columnLineEdit->setText( QString::number( mColumns ) );
mRowsSpinBox->setValue( mRows );
mColumnsSpinBox->setValue( mColumns );
cellXLineEdit->setText( QString::number( mXcellsize ) );
cellYLineEdit->setText( QString::number( mYcellsize ) );
}
Expand Down Expand Up @@ -363,17 +366,13 @@ void HeatmapGui::updateBBox()
mBBox.setYMinimum( mBBox.yMinimum() - radiusInMapUnits );
mBBox.setXMaximum( mBBox.xMaximum() + radiusInMapUnits );
mBBox.setYMaximum( mBBox.yMaximum() + radiusInMapUnits );
mRows = 500;

// Leave number of rows the same, and calculate new corresponding cell size and number of columns
mYcellsize = mBBox.height() / mRows;
mXcellsize = mYcellsize;
// +1 should be added wherever a fractional part of cell might occur
mColumns = mBBox.width() / mXcellsize + 1;
mRows += 1;
mColumns = max( mBBox.width() / mXcellsize, 1 );

if ( advancedGroupBox->isChecked() )
{
updateSize();
}
updateSize();
}

double HeatmapGui::mapUnitsOf( double meters, QgsCoordinateReferenceSystem layerCrs )
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/heatmap/heatmapgui.h
Expand Up @@ -114,8 +114,8 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
void on_mBrowseButton_clicked();
void on_mOutputRasterLineEdit_editingFinished();
void on_advancedGroupBox_toggled( bool enabled );
void on_rowLineEdit_editingFinished();
void on_columnLineEdit_editingFinished();
void on_mRowsSpinBox_editingFinished();
void on_mColumnsSpinBox_editingFinished();
void on_cellXLineEdit_editingFinished();
void on_cellYLineEdit_editingFinished();
void on_radiusFieldCombo_currentIndexChanged( int index );
Expand Down
26 changes: 20 additions & 6 deletions src/plugins/heatmap/heatmapguibase.ui
Expand Up @@ -130,7 +130,7 @@
<string>Rows</string>
</property>
<property name="buddy">
<cstring>rowLineEdit</cstring>
<cstring>mRowsSpinBox</cstring>
</property>
</widget>
</item>
Expand All @@ -150,7 +150,7 @@
<string>Columns</string>
</property>
<property name="buddy">
<cstring>columnLineEdit</cstring>
<cstring>mColumnsSpinBox</cstring>
</property>
</widget>
</item>
Expand All @@ -165,10 +165,24 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="rowLineEdit"/>
<widget class="QSpinBox" name="mRowsSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="columnLineEdit"/>
<widget class="QSpinBox" name="mColumnsSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="cellXLineEdit"/>
Expand Down Expand Up @@ -292,8 +306,8 @@
<tabstop>mBufferLineEdit</tabstop>
<tabstop>mRadiusUnitCombo</tabstop>
<tabstop>advancedGroupBox</tabstop>
<tabstop>rowLineEdit</tabstop>
<tabstop>columnLineEdit</tabstop>
<tabstop>mRowsSpinBox</tabstop>
<tabstop>mColumnsSpinBox</tabstop>
<tabstop>cellXLineEdit</tabstop>
<tabstop>cellYLineEdit</tabstop>
<tabstop>kernelShapeCombo</tabstop>
Expand Down

0 comments on commit 65aa1d5

Please sign in to comment.