Skip to content
Permalink
Browse files

Implementation of graduated renderer breakpoint editor, minus SIP for…

… editor
  • Loading branch information
ccrook committed Sep 24, 2014
1 parent 2f706bc commit a5911e78b7f3000768808799dcaa72a0027a1214
@@ -108,12 +108,31 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
Mode mode() const;
void setMode( Mode mode );
void updateClasses( QgsVectorLayer *vlayer, Mode mode, int nclasses );

QString units();
//! Evaluates the data expression and returns the list of values from the layer
//! @param vlayer The layer for which to evaluate the expression
//! @note Added in 2.6
QList<double> getDataValues( QgsVectorLayer *vlayer );

//! Return the units string used to generate default classification labels
//! @note Added in 2.6
QString units() const ;
//! Set the units string used to generate default classification labels
//! @param units The string appended to classification labels
//! @param updateRanges If true then ranges ending with the old unit string are updated to the new.
//! @note Added in 2.6
void setUnits( QString units, bool updateRanges=true );

//! Return the number of decimal places used to generate labels
//! @note Added in 2.6
int decimalPlaces() const;
//! Reset the number of decimal places used to generate labels
//! @param decimalPlaces the number of decimal places
//! @param updateRanges if true then ranges currently using the default label will be updated
//! @note Added in 2.6
void setDecimalPlaces( int decimalPlaces, bool updateRanges=true );
//! Determine an appropriate number of decimal places based on the minimum class interval
//! @param updateRanges if true then ranges currently using the default label will be updated
//! @note Added in 2.6
void calculateDecimalPlaces( bool updateRanges=true );

static QgsGraduatedSymbolRendererV2* createRenderer(
@@ -153,9 +172,9 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
/** Update the color ramp used. Also updates all symbols colors.
* Doesn't alter current breaks.
*/
void updateColorRamp( QgsVectorColorRampV2* ramp /Transfer/, bool inverted = false );
void updateColorRamp( QgsVectorColorRampV2* ramp /Transfer/ = 0, bool inverted = false );

/** Update the all symbols but leave breaks and colors. */
/** Update all the symbols but leave breaks and colors. */
void updateSymbols( QgsSymbolV2* sym /Transfer/ );

//! @note added in 1.6
@@ -833,40 +833,61 @@ QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::createRenderer(
return r;
}

QList<double> QgsGraduatedSymbolRendererV2::getDataValues( QgsVectorLayer *vlayer )
{
QList<double> values;
QScopedPointer<QgsExpression> expression;
int attrNum = vlayer->fieldNameIndex( mAttrName );

if ( attrNum == -1 )
{
// try to use expression
expression.reset( new QgsExpression( mAttrName ) );
if ( expression->hasParserError() || !expression->prepare( vlayer->pendingFields() ) )
return values; // should have a means to report errors
}

QgsFeature f;
QStringList lst;
if ( expression.isNull() )
lst.append( mAttrName );
else
lst = expression->referencedColumns();

QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( lst, vlayer->pendingFields() ) );

// create list of non-null attribute values
while ( fit.nextFeature( f ) )
{
QVariant v = expression.isNull() ? f.attribute( attrNum ) : expression->evaluate( f );
if ( !v.isNull() )
values.append( v.toDouble() );
}
return values;
}

void QgsGraduatedSymbolRendererV2::updateClasses( QgsVectorLayer *vlayer, Mode mode, int nclasses )
{
// Custom classes are not recalculated
setMode(mode);
if( mode == Custom ) return;



if ( nclasses < 1 ) nclasses=1;

int attrNum = vlayer->fieldNameIndex( mAttrName );
QList<double> values;
bool valuesLoaded=false;
double minimum;
double maximum;

QScopedPointer<QgsExpression> expression;
int attrNum = vlayer->fieldNameIndex( mAttrName );

if ( attrNum == -1 )
{
// try to use expression
expression.reset( new QgsExpression( mAttrName ) );
if ( expression->hasParserError() || !expression->prepare( vlayer->pendingFields() ) )
return; // should have a means to report errors

QList<double> values;
QgsFeatureIterator fit = vlayer->getFeatures();
QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
values << expression->evaluate( feature ).toDouble();
}
values=getDataValues( vlayer );
qSort( values );
minimum = values.first();
maximum = values.last();
valuesLoaded=true;
}
else
{
@@ -888,22 +909,11 @@ void QgsGraduatedSymbolRendererV2::updateClasses( QgsVectorLayer *vlayer, Mode m
else if ( mode == Quantile || mode == Jenks || mode == StdDev )
{
// get values from layer
QList<double> values;
QgsFeature f;
QStringList lst;
if ( expression.isNull() )
lst.append( mAttrName );
else
lst = expression->referencedColumns();

QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( lst, vlayer->pendingFields() ) );

// create list of non-null attribute values
while ( fit.nextFeature( f ) )
if( ! valuesLoaded )
{
QVariant v = expression.isNull() ? f.attribute( attrNum ) : expression->evaluate( f );
if ( !v.isNull() )
values.append( v.toDouble() );
values=getDataValues( vlayer );
}

// calculate the breaks
@@ -928,7 +938,7 @@ void QgsGraduatedSymbolRendererV2::updateClasses( QgsVectorLayer *vlayer, Mode m

double lower, upper = minimum;
QString label;
mRanges.clear();
deleteAllClasses();

// "breaks" list contains all values at class breaks plus maximum as last break

@@ -1211,8 +1221,11 @@ void QgsGraduatedSymbolRendererV2::setSourceColorRamp( QgsVectorColorRampV2* ram
void QgsGraduatedSymbolRendererV2::updateColorRamp( QgsVectorColorRampV2 *ramp, bool inverted )
{
int i = 0;
if( ramp ) this->setSourceColorRamp( ramp );
this->setInvertedColorRamp( inverted );
if( ramp )
{
this->setSourceColorRamp( ramp );
this->setInvertedColorRamp( inverted );
}

foreach ( QgsRendererRangeV2 range, mRanges )
{
@@ -131,13 +131,37 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

Mode mode() const { return mMode; }
void setMode( Mode mode ) { mMode = mode; }
//! Recalculate classes for a layer
//! @param vlayer The layer being rendered (from which data values are calculated)
//! @param mode The calculation mode
//! @param nclasses The number of classes to calculate (approximate for some modes)
//! @note Added in 2.6
void updateClasses( QgsVectorLayer *vlayer, Mode mode, int nclasses );
//! Evaluates the data expression and returns the list of values from the layer
//! @param vlayer The layer for which to evaluate the expression
//! @note Added in 2.6
QList<double> getDataValues( QgsVectorLayer *vlayer );

//! Return the units string used to generate default classification labels
//! @note Added in 2.6
QString units() const { return mUnits; }
//! Set the units string used to generate default classification labels
//! @param units The string appended to classification labels
//! @param updateRanges If true then ranges ending with the old unit string are updated to the new.
//! @note Added in 2.6
void setUnits( QString units, bool updateRanges=true );

//! Return the number of decimal places used to generate labels
//! @note Added in 2.6
int decimalPlaces() const { return mDecimalPlaces; }
//! Reset the number of decimal places used to generate labels
//! @param decimalPlaces the number of decimal places
//! @param updateRanges if true then ranges currently using the default label will be updated
//! @note Added in 2.6
void setDecimalPlaces( int decimalPlaces, bool updateRanges=true );
//! Determine an appropriate number of decimal places based on the minimum class interval
//! @param updateRanges if true then ranges currently using the default label will be updated
//! @note Added in 2.6
void calculateDecimalPlaces( bool updateRanges=true );

static QgsGraduatedSymbolRendererV2* createRenderer(
@@ -177,7 +201,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
/** Update the color ramp used. Also updates all symbols colors.
* Doesn't alter current breaks.
*/
void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );
void updateColorRamp( QgsVectorColorRampV2* ramp=0, bool inverted = false );

/** Update all the symbols but leave breaks and colors. */
void updateSymbols( QgsSymbolV2* sym );
@@ -202,19 +226,19 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
virtual bool legendSymbolItemsCheckable() const;

//! item in symbology was checked
// @note added in 2.5
//! @note added in 2.6
virtual bool legendSymbolItemChecked( QString key );

//! item in symbology was checked
// @note added in 2.5
//! @note added in 2.6
virtual void checkLegendSymbolItem( QString key, bool state = true );

//! If supported by the renderer, return classification attribute for the use in legend
//! @note added in 2.6
virtual QString legendClassificationAttribute() const { return classAttribute(); }

//! creates a QgsGraduatedSymbolRendererV2 from an existing renderer.
//! @note added in 2.5
//! @note added in 2.6
//! @returns a new renderer if the conversion was possible, otherwise 0.
static QgsGraduatedSymbolRendererV2* convertFromRenderer( const QgsFeatureRendererV2 *renderer );

@@ -18,6 +18,7 @@ symbology-ng/qgssymbollayerv2widget.cpp
symbology-ng/qgsrendererv2widget.cpp
symbology-ng/qgssinglesymbolrendererv2widget.cpp
symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
symbology-ng/qgsgraduatedrendererclasseditor.cpp
symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
symbology-ng/qgsrulebasedrendererv2widget.cpp
symbology-ng/qgsinvertedpolygonrendererwidget.cpp
@@ -245,6 +246,7 @@ symbology-ng/qgssymbollayerv2widget.h
symbology-ng/qgssinglesymbolrendererv2widget.h
symbology-ng/qgscategorizedsymbolrendererv2widget.h
symbology-ng/qgsdatadefinedsymboldialog.h
symbology-ng/qgsgraduatedrendererclasseditor.h
symbology-ng/qgsgraduatedsymbolrendererv2widget.h
symbology-ng/qgsrulebasedrendererv2widget.h
symbology-ng/qgsinvertedpolygonrendererwidget.h
@@ -202,4 +202,4 @@ void QgsAttributeTypeLoadDialog::accept()
//store data to output variable
loadDataToValueMap();
QDialog::accept();
}
}

0 comments on commit a5911e7

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