Skip to content
Permalink
Browse files

Automatic update of label and neighboring ranges boundaries

  • Loading branch information
leyan committed Sep 4, 2014
1 parent 5c5deec commit 340d4178eed929b1c797877be8a65f54556454e8
@@ -417,6 +417,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();
@@ -702,11 +703,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 );
@@ -723,6 +770,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 )
@@ -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 );
@@ -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();
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>505</width>
<width>615</width>
<height>339</height>
</rect>
</property>
@@ -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">

0 comments on commit 340d417

Please sign in to comment.
You can’t perform that action at this time.