Skip to content

Commit

Permalink
Merge pull request #1576 from leyan/graduatedRenderer
Browse files Browse the repository at this point in the history
Automatic update of label and neighboring ranges boundaries in graduated renderer. Fix #9312. Fix #9900, Fix #10203
  • Loading branch information
NathanW2 committed Sep 14, 2014
2 parents f214a01 + 340d417 commit e52c123
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
61 changes: 61 additions & 0 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
connect( btnGraduatedDelete, SIGNAL( clicked() ), this, SLOT( deleteClasses() ) );
connect( btnDeleteAllClasses, SIGNAL( clicked() ), this, SLOT( deleteAllClasses() ) );
connect( btnGraduatedAdd, SIGNAL( clicked() ), this, SLOT( addClass() ) );
connect( cbxLinkBoundaries, SIGNAL( toggled( bool ) ), this, SLOT( toggleBoundariesLink( bool ) ) );

// initialize from previously set renderer
updateUiFromRenderer();
Expand Down Expand Up @@ -699,11 +700,57 @@ void QgsGraduatedSymbolRendererV2Widget::changeRange( int rangeIdx )
{
double lowerValue = dialog.lowerValue().toDouble();
double upperValue = dialog.upperValue().toDouble();

QString label = createLabel( range.lowerValue(), range.upperValue() );
QString newLabel;

mRenderer->updateRangeUpperValue( rangeIdx, upperValue );
mRenderer->updateRangeLowerValue( rangeIdx, lowerValue );

//If the label was the label automatically generated, we generate a new one for the new range
if ( range.label() == label )
{
newLabel = createLabel( lowerValue, upperValue );
mRenderer->updateRangeLabel( rangeIdx, newLabel );
}

//If the boundaries have to stay linked, we update the ranges above and below, as well as their label if needed
if ( cbxLinkBoundaries->isChecked() )
{
if ( rangeIdx > 0 )
{
const QgsRendererRangeV2& rangeLower = mRenderer->ranges()[rangeIdx - 1];
label = createLabel( rangeLower.lowerValue(), rangeLower.upperValue() );
mRenderer->updateRangeUpperValue( rangeIdx - 1, lowerValue );

if ( label == rangeLower.label() )
{
newLabel = createLabel( rangeLower.lowerValue(), lowerValue );
mRenderer->updateRangeLabel( rangeIdx - 1, newLabel );
}
}

if ( rangeIdx < mRenderer->ranges().size() - 1 )
{
const QgsRendererRangeV2& rangeUpper = mRenderer->ranges()[rangeIdx + 1];
label = createLabel( rangeUpper.lowerValue(), rangeUpper.upperValue() );
mRenderer->updateRangeLowerValue( rangeIdx + 1, upperValue );

if ( label == rangeUpper.label() )
{
newLabel = createLabel( upperValue, rangeUpper.upperValue() );
mRenderer->updateRangeLabel( rangeIdx + 1, newLabel );
}
}
}
}
}

QString QgsGraduatedSymbolRendererV2Widget::createLabel( double lowerValue, double upperValue )
{
return QString::number( lowerValue , 'f', 4 ) + " - " + QString::number( upperValue, 'f', 4 );
}

void QgsGraduatedSymbolRendererV2Widget::addClass()
{
mModel->addClass( mGraduatedSymbol );
Expand All @@ -720,6 +767,20 @@ void QgsGraduatedSymbolRendererV2Widget::deleteAllClasses()
mModel->removeAllRows();
}

void QgsGraduatedSymbolRendererV2Widget::toggleBoundariesLink( bool linked )
{
//If the checkbox controlling the link between boundaries was unchecked and we check it, we have to link the boundaries
//This is done by updating all lower ranges to the upper value of the range above
if ( linked )
{
for ( int i = 1;i < mRenderer->ranges().size();++i )
{
mRenderer->updateRangeLowerValue( i, mRenderer->ranges()[i-1].upperValue() );
}
refreshSymbolView();
}
}

void QgsGraduatedSymbolRendererV2Widget::changeCurrentValue( QStandardItem * item )
{
if ( item->column() == 2 )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget
void deleteClasses();
/**Removes all classes from the classification*/
void deleteAllClasses();
/**Toggle the link between classes boundaries */
void toggleBoundariesLink( bool linked );

void rotationFieldChanged( QString fldName );
void sizeScaleFieldChanged( QString fldName );
Expand All @@ -115,6 +117,8 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget
void changeRangeSymbol( int rangeIdx );
void changeRange( int rangeIdx );

QString createLabel( double lowerValue, double upperValue );

void changeSelectedSymbols();

QList<QgsSymbolV2*> selectedSymbols();
Expand Down
12 changes: 11 additions & 1 deletion src/ui/qgsgraduatedsymbolrendererv2widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>505</width>
<width>615</width>
<height>339</height>
</rect>
</property>
Expand Down Expand Up @@ -240,6 +240,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbxLinkBoundaries">
<property name="text">
<string>Link classes boundaries</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
Expand Down

0 comments on commit e52c123

Please sign in to comment.