Skip to content
Permalink
Browse files

Fix some syncing issues relating to graduated histogram widget

  • Loading branch information
nyalldawson committed May 19, 2015
1 parent 824a395 commit 721667067957a82ee1cc0081f1b03b5c71e228ba
@@ -85,6 +85,10 @@ class QgsHistogramWidget : QWidget
*/
void refreshHistogram();

/** Triggers a refresh and immediate redraw of the histogram.
*/
void refreshAndRedraw();

/** Sets the vector layer associated with the histogram.
* @param layer source vector layer
* @see setSourceFieldExp
@@ -65,9 +65,9 @@ QgsHistogramWidget::QgsHistogramWidget( QWidget *parent, QgsVectorLayer* layer,
mMeanCheckBox->setChecked( settings.value( "/HistogramWidget/showMean", false ).toBool() );
mStdevCheckBox->setChecked( settings.value( "/HistogramWidget/showStdev", false ).toBool() );

connect( mBinsSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( refreshHistogram() ) );
connect( mMeanCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( refreshHistogram() ) );
connect( mStdevCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( refreshHistogram() ) );
connect( mBinsSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( refreshAndRedraw() ) );
connect( mMeanCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( refreshAndRedraw() ) );
connect( mStdevCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( refreshAndRedraw() ) );

mGridPen = QPen( QColor( 0, 0, 0, 40 ) );
mMeanPen = QPen( QColor( 10, 10, 10, 220 ) );
@@ -88,6 +88,17 @@ QgsHistogramWidget::~QgsHistogramWidget()
settings.setValue( "/HistogramWidget/showStdev", mStdevCheckBox->isChecked() );
}

static bool _rangesByLower( const QgsRendererRangeV2& a, const QgsRendererRangeV2& b )
{
return a.lowerValue() < b.lowerValue() ? -1 : 0;
}

void QgsHistogramWidget::setGraduatedRanges( const QgsRangeList &ranges )
{
mRanges = ranges;
qSort( mRanges.begin(), mRanges.end(), _rangesByLower );
}

void QgsHistogramWidget::setLayer( QgsVectorLayer *layer )
{
if ( layer == mVectorLayer )
@@ -103,6 +114,12 @@ void QgsHistogramWidget::refreshHistogram()
mRedrawRequired = true;
}

void QgsHistogramWidget::refreshAndRedraw()
{
refreshHistogram();
drawHistogram();
}

void QgsHistogramWidget::setSourceFieldExp( const QString &fieldOrExp )
{
if ( fieldOrExp == mSourceFieldExp )
@@ -109,7 +109,7 @@ class GUI_EXPORT QgsHistogramWidget : public QWidget, private Ui::QgsHistogramWi
* @param ranges graduated range list
* @see graduatedRanges
*/
void setGraduatedRanges( const QgsRangeList& ranges ) { mRanges = ranges; }
void setGraduatedRanges( const QgsRangeList& ranges );

/** Returns the graduated ranges associated with the histogram. If set, the ranges will be used to colour the histogram
* bars and for showing vertical dividers at the histogram breaks.
@@ -124,6 +124,10 @@ class GUI_EXPORT QgsHistogramWidget : public QWidget, private Ui::QgsHistogramWi
*/
void refreshHistogram();

/** Triggers a refresh and immediate redraw of the histogram.
*/
void refreshAndRedraw();

/** Sets the vector layer associated with the histogram.
* @param layer source vector layer
* @see setSourceFieldExp
@@ -82,7 +82,7 @@ void QgsGraduatedHistogramWidget::drawHistogram()
if ( !mRenderer )
return;

mRanges = mRenderer->ranges();
setGraduatedRanges( mRenderer->ranges() );
QgsHistogramWidget::drawHistogram();

// histo picker
@@ -123,7 +123,7 @@ void QgsGraduatedHistogramWidget::mouseRelease( double value )
if ( value <= mRenderer->ranges().at( closestRangeIndex ).lowerValue() ||
value >= mRenderer->ranges().at( closestRangeIndex + 1 ).upperValue() )
{
refreshHistogram();
refreshAndRedraw();
return;
}

@@ -138,7 +138,7 @@ void QgsGraduatedHistogramWidget::mouseRelease( double value )
emit rangesModified( true );
}

drawHistogram();
refreshAndRedraw();
}

void QgsGraduatedHistogramWidget::findClosestRange( double value, int &closestRangeIndex, int& pixelDistance ) const
@@ -514,7 +514,6 @@ void QgsGraduatedSymbolRendererV2Widget::connectUpdateHandlers()
connect( minSizeSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( reapplySizes() ) );
connect( maxSizeSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( reapplySizes() ) );


connect( mModel, SIGNAL( rowsMoved() ), this, SLOT( rowsMoved() ) );
connect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged() ) );
}
@@ -606,7 +605,7 @@ void QgsGraduatedSymbolRendererV2Widget::updateUiFromRenderer( bool updateCount
viewGraduated->resizeColumnToContents( 1 );
viewGraduated->resizeColumnToContents( 2 );

mHistogramWidget->refreshHistogram();
mHistogramWidget->refreshAndRedraw();

connectUpdateHandlers();
}
@@ -874,6 +873,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeRangeSymbol( int rangeIdx )
}

mRenderer->updateRangeSymbol( rangeIdx, newSymbol );
mHistogramWidget->refreshHistogram();
}

void QgsGraduatedSymbolRendererV2Widget::changeRange( int rangeIdx )
@@ -909,22 +909,26 @@ void QgsGraduatedSymbolRendererV2Widget::changeRange( int rangeIdx )
}
}
}
mHistogramWidget->refreshHistogram();
}

void QgsGraduatedSymbolRendererV2Widget::addClass()
{
mModel->addClass( mGraduatedSymbol );
mHistogramWidget->refreshHistogram();
}

void QgsGraduatedSymbolRendererV2Widget::deleteClasses()
{
QList<int> classIndexes = selectedClasses();
mModel->deleteRows( classIndexes );
mHistogramWidget->refreshHistogram();
}

void QgsGraduatedSymbolRendererV2Widget::deleteAllClasses()
{
mModel->removeAllRows();
mHistogramWidget->refreshHistogram();
}

bool QgsGraduatedSymbolRendererV2Widget::rowsOrdered()
@@ -1075,7 +1079,6 @@ void QgsGraduatedSymbolRendererV2Widget::rowsMoved()

void QgsGraduatedSymbolRendererV2Widget::modelDataChanged()
{
mHistogramWidget->refreshHistogram();
}

void QgsGraduatedSymbolRendererV2Widget::keyPressEvent( QKeyEvent* event )

0 comments on commit 7216670

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