Skip to content

Commit

Permalink
implement calculating offset from raster layer, change interval and o…
Browse files Browse the repository at this point in the history
…ffset spin boxes to line edit widgets for precision issues
  • Loading branch information
etiennesky committed Jun 25, 2012
1 parent dce914d commit 94a1210
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 162 deletions.
62 changes: 14 additions & 48 deletions src/app/qgsdecorationgrid.cpp
Expand Up @@ -850,58 +850,24 @@ bool QgsDecorationGrid::getIntervalFromCurrentLayer( double* values )
return false;
}

// TODO add a function in QgsRasterLayer to get x/y resolution from provider
// calculate interval
// TODO add a function in QgsRasterLayer to get x/y resolution from provider,
// because this might not be 100% accurate
QgsRectangle extent = rlayer->extent();
values[0] = fabs( extent.xMaximum() - extent.xMinimum() ) / rlayer->width();
values[1] = fabs( extent.yMaximum() - extent.yMinimum() ) / rlayer->height();
// TODO calculate offset - this is a little tricky...
values[2] = values[3] = 0;

QgsDebugMsg( QString( "xmax: %1 xmin: %2 width: %3 xInterval: %4" ).arg( extent.xMaximum() ).arg( extent.xMinimum() ).arg( rlayer->width() ).arg( values[0] ) );
// calculate offset - when using very high resolution rasters in geographic CRS
// there seems to be a small shift, but this may be due to rendering issues and depends on zoom
double ratio = extent.xMinimum() / values[0];
values[2] = ( ratio - floor( ratio ) ) * values[0];
ratio = extent.yMinimum() / values[1];
values[3] = ( ratio - floor( ratio ) ) * values[1];

QgsDebugMsg( QString( "xmax: %1 xmin: %2 width: %3 xInterval: %4 xOffset: %5" ).arg(
extent.xMaximum() ).arg( extent.xMinimum() ).arg( rlayer->width() ).arg( values[0] ).arg( values[2] ) );
QgsDebugMsg( QString( "ymax: %1 ymin: %2 height: %3 yInterval: %4 yOffset: %5" ).arg(
extent.yMaximum() ).arg( extent.yMinimum() ).arg( rlayer->height() ).arg( values[1] ).arg( values[3] ) );

return true;
}


// TODO preliminary code to calculate offset
// double diff = getClosestPixel( extent.xMaximum(), boundBox2.xMinimum(), boundBox.xMinimum(), dx, True )

// // function ported from ftools doVectorGrid.py
// double getClosestPixel( double startVal, double targetVal, double step, bool isMin )
// {
// bool foundVal = false;
// double tmpVal = startVal;
// bool backOneStep;
// // find pixels covering the extent - slightly inneficient b/c loop on all elements before xMin
// if ( targetVal < startVal )
// {
// backOneStep = ! isMin;
// step = - step;
// // should make sure we don't go into an infinite loop (shouldn't happen)
// while ( ! foundVal )
// {
// if ( tmpVal <= targetVal )
// {
// if ( backOneStep )
// tmpVal -= step;
// return tmpVal;
// }
// tmpVal += step;
// }
// }
// else
// {
// backOneStep = isMin;
// while ( ! foundVal )
// {
// if ( tmpVal >= targetVal )
// {
// if ( backOneStep )
// tmpVal -= step;
// return tmpVal;
// }
// tmpVal += step;
// }
// }
// return 0;
// }
54 changes: 17 additions & 37 deletions src/app/qgsdecorationgriddialog.cpp
Expand Up @@ -71,14 +71,12 @@ void QgsDecorationGridDialog::updateGuiElements()

chkEnable->setChecked( mDeco.enabled() );

mIntervalXSpinBox->setValue( mDeco.gridIntervalX() );
mIntervalYSpinBox->setValue( mDeco.gridIntervalY() );
mOffsetXSpinBox->setValue( mDeco.gridOffsetX() );
mOffsetYSpinBox->setValue( mDeco.gridOffsetY() );
mIntervalXEdit->setText( QString::number( mDeco.gridIntervalX() ) );
mIntervalYEdit->setText( QString::number( mDeco.gridIntervalY() ) );
mOffsetXEdit->setText( QString::number( mDeco.gridOffsetX() ) );
mOffsetYEdit->setText( QString::number( mDeco.gridOffsetY() ) );

mGridTypeComboBox->setCurrentIndex(( int ) mDeco.gridStyle() );
// mCrossWidthSpinBox->setValue( mDeco.crossLength() );
// mAnnotationPositionComboBox->setCurrentIndex(( int ) mDeco.gridAnnotationPosition() );
mDrawAnnotationCheckBox->setChecked( mDeco.showGridAnnotation() );
mAnnotationDirectionComboBox->setCurrentIndex(( int ) mDeco.gridAnnotationDirection() );
mCoordinatePrecisionSpinBox->setValue( mDeco.gridAnnotationPrecision() );
Expand Down Expand Up @@ -113,15 +111,11 @@ void QgsDecorationGridDialog::updateDecoFromGui()
{
mDeco.setDirty( false );
mDeco.setEnabled( chkEnable->isChecked() );
mDeco.setGridIntervalX( mIntervalXSpinBox->value() );
mDeco.setGridIntervalY( mIntervalYSpinBox->value() );
mDeco.setGridOffsetX( mOffsetXSpinBox->value() );
mDeco.setGridOffsetY( mOffsetYSpinBox->value() );
// mDeco.setGridPenWidth( mLineWidthSpinBox->value() );
// if ( mGridTypeComboBox->currentText() == tr( "Cross" ) )
// {
// mDeco.setGridStyle( QgsDecorationGrid::Cross );
// }

mDeco.setGridIntervalX( mIntervalXEdit->text().toDouble() );
mDeco.setGridIntervalY( mIntervalYEdit->text().toDouble() );
mDeco.setGridOffsetX( mOffsetXEdit->text().toDouble() );
mDeco.setGridOffsetY( mOffsetYEdit->text().toDouble() );
if ( mGridTypeComboBox->currentText() == tr( "Marker" ) )
{
mDeco.setGridStyle( QgsDecorationGrid::Marker );
Expand All @@ -130,7 +124,6 @@ void QgsDecorationGridDialog::updateDecoFromGui()
{
mDeco.setGridStyle( QgsDecorationGrid::Line );
}
// mDeco.setCrossLength( mCrossWidthSpinBox->value() );
mDeco.setAnnotationFrameDistance( mDistanceToMapFrameSpinBox->value() );
// if ( mAnnotationPositionComboBox->currentText() == tr( "Inside frame" ) )
// {
Expand Down Expand Up @@ -205,17 +198,6 @@ void QgsDecorationGridDialog::on_buttonBox_rejected()
reject();
}


// void QgsDecorationGridDialog::on_mLineColorButton_clicked()
// {
// QColor newColor = QColorDialog::getColor( mLineColorButton->color() );
// if ( newColor.isValid() )
// {
// mLineColorButton->setColor( newColor );
// mDeco.setGridPenColor( newColor );
// }
// }

void QgsDecorationGridDialog::on_mGridTypeComboBox_currentIndexChanged( int index )
{
mLineSymbolButton->setEnabled( index == QgsDecorationGrid::Line );
Expand All @@ -231,7 +213,6 @@ void QgsDecorationGridDialog::on_mLineSymbolButton_clicked()

QgsLineSymbolV2* lineSymbol = dynamic_cast<QgsLineSymbolV2*>( mLineSymbol->clone() );
QgsSymbolV2PropertiesDialog dlg( lineSymbol, 0, this );
// QgsSymbolV2SelectorDialog dlg( lineSymbol, 0, this );
if ( dlg.exec() == QDialog::Rejected )
{
delete lineSymbol;
Expand All @@ -255,7 +236,6 @@ void QgsDecorationGridDialog::on_mMarkerSymbolButton_clicked()

QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( mMarkerSymbol->clone() );
QgsSymbolV2PropertiesDialog dlg( markerSymbol, 0, this );
// QgsSymbolV2SelectorDialog dlg( markerSymbol, 0, this );
if ( dlg.exec() == QDialog::Rejected )
{
delete markerSymbol;
Expand All @@ -282,10 +262,10 @@ void QgsDecorationGridDialog::on_mPbtnUpdateFromLayer_clicked()
double values[4];
if ( mDeco.getIntervalFromCurrentLayer( values ) )
{
mIntervalXSpinBox->setValue( values[0] );
mIntervalYSpinBox->setValue( values[1] );
mOffsetXSpinBox->setValue( values[2] );
mOffsetYSpinBox->setValue( values[3] );
mIntervalXEdit->setText( QString::number( values[0] ) );
mIntervalYEdit->setText( QString::number( values[1] ) );
mOffsetXEdit->setText( QString::number( values[2] ) );
mOffsetYEdit->setText( QString::number( values[3] ) );
if ( values[0] >= 1 )
mCoordinatePrecisionSpinBox->setValue( 0 );
else
Expand Down Expand Up @@ -315,10 +295,10 @@ void QgsDecorationGridDialog::updateInterval( bool force )
double values[4];
if ( mDeco.getIntervalFromExtent( values, true ) )
{
mIntervalXSpinBox->setValue( values[0] );
mIntervalYSpinBox->setValue( values[1] );
mOffsetXSpinBox->setValue( values[2] );
mOffsetYSpinBox->setValue( values[3] );
mIntervalXEdit->setText( QString::number( values[0] ) );
mIntervalYEdit->setText( QString::number( values[1] ) );
mOffsetXEdit->setText( QString::number( values[2] ) );
mOffsetYEdit->setText( QString::number( values[3] ) );
// also update coord. precision
// if interval >= 1, set precision=0 because we have a rounded value
// else set it to previous default of 3
Expand Down
90 changes: 13 additions & 77 deletions src/ui/qgsdecorationgriddialog.ui
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>628</width>
<width>603</width>
<height>335</height>
</rect>
</property>
Expand Down Expand Up @@ -126,50 +126,6 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mIntervalXSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>125</width>
<height>0</height>
</size>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mIntervalYSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -302,22 +258,6 @@
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QDoubleSpinBox" name="mOffsetXSpinBox">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="mOffsetYLabel">
<property name="text">
Expand All @@ -328,22 +268,6 @@
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QDoubleSpinBox" name="mOffsetYSpinBox">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="8" column="3" rowspan="2" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
Expand All @@ -367,6 +291,18 @@
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mIntervalXEdit"/>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mIntervalYEdit"/>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="mOffsetXEdit"/>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="mOffsetYEdit"/>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit 94a1210

Please sign in to comment.