Skip to content

Commit bde4ff9

Browse files
authored
Merge pull request #4169 from nyalldawson/props_gui
[FEATURE] Interactive curve editing for property overrides
2 parents 66888fe + 7da28d1 commit bde4ff9

19 files changed

Lines changed: 1812 additions & 80 deletions

python/core/qgshistogram.sip

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ class QgsHistogram
2222
*/
2323
void setValues( const QList<double>& values );
2424

25-
/** Assigns numeric source values for the histogram from a vector layer's field or as the
26-
* result of an expression.
27-
* @param layer vector layer
28-
* @param fieldOrExpression field name or expression to be evaluated
29-
* @returns true if values were successfully set
30-
*/
31-
bool setValues( QgsVectorLayer* layer, const QString& fieldOrExpression );
25+
bool setValues( const QgsVectorLayer* layer, const QString& fieldOrExpression, QgsFeedback* feedback = 0 );
3226

3327
/** Calculates the optimal bin width using the Freedman-Diaconis rule. Bins widths are
3428
* determined by the inter-quartile range of values and the number of values.

python/core/qgspropertytransformer.sip

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
class QgsCurveTransform
2+
{
3+
%TypeHeaderCode
4+
#include <qgspropertytransformer.h>
5+
%End
6+
7+
public:
8+
9+
QgsCurveTransform();
10+
QgsCurveTransform( const QList< QgsPoint >& controlPoints );
11+
~QgsCurveTransform();
12+
QgsCurveTransform( const QgsCurveTransform& other );
13+
14+
//QgsCurveTransform& operator=( const QgsCurveTransform& other );
15+
16+
QList< QgsPoint > controlPoints() const;
17+
18+
void setControlPoints( const QList< QgsPoint >& points );
19+
20+
void addControlPoint( double x, double y );
21+
22+
void removeControlPoint( double x, double y );
23+
24+
double y( double x ) const;
25+
26+
QVector< double > y( const QVector< double >& x ) const;
27+
28+
bool readXml( const QDomElement& elem, const QDomDocument& doc );
29+
30+
bool writeXml( QDomElement& transformElem, QDomDocument& doc ) const;
31+
32+
};
133
class QgsPropertyTransformer
234
{
335
%TypeHeaderCode
@@ -28,6 +60,8 @@ class QgsPropertyTransformer
2860

2961
QgsPropertyTransformer( double minValue = 0.0, double maxValue = 1.0 );
3062

63+
QgsPropertyTransformer( const QgsPropertyTransformer& other );
64+
3165
virtual ~QgsPropertyTransformer();
3266

3367
virtual Type transformerType() const = 0;
@@ -46,11 +80,18 @@ class QgsPropertyTransformer
4680

4781
void setMaxValue( double max );
4882

83+
QgsCurveTransform* curveTransform() const;
84+
85+
void setCurveTransform( QgsCurveTransform* transform /Transfer/ );
86+
4987
virtual QVariant transform( const QgsExpressionContext& context, const QVariant& value ) const = 0;
5088
virtual QString toExpression( const QString& baseExpression ) const = 0;
5189

5290
static QgsPropertyTransformer* fromExpression( const QString& expression, QString& baseExpression /Out/, QString& fieldName /Out/ ) /Factory/;
5391

92+
protected:
93+
94+
double transformNumeric( double input ) const;
5495
};
5596
class QgsGenericNumericTransformer : QgsPropertyTransformer
5697
{
@@ -66,6 +107,8 @@ class QgsGenericNumericTransformer : QgsPropertyTransformer
66107
double nullOutput = 0.0,
67108
double exponent = 1.0 );
68109

110+
QgsGenericNumericTransformer( const QgsGenericNumericTransformer& other );
111+
69112
virtual Type transformerType() const;
70113
virtual QgsGenericNumericTransformer* clone() /Factory/;
71114
virtual bool writeXml( QDomElement& transformerElem, QDomDocument& doc ) const;
@@ -108,6 +151,8 @@ class QgsSizeScaleTransformer : QgsPropertyTransformer
108151
double nullSize = 0.0,
109152
double exponent = 1.0 );
110153

154+
QgsSizeScaleTransformer( const QgsSizeScaleTransformer& other );
155+
111156
virtual Type transformerType() const;
112157
virtual QgsSizeScaleTransformer* clone() /Factory/;
113158
virtual bool writeXml( QDomElement& transformerElem, QDomDocument& doc ) const;

python/core/qgsvectorlayer.sip

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,27 +1352,9 @@ class QgsVectorLayer : QgsMapLayer, QgsExpressionContextGenerator
13521352
QgsExpressionContext* context = nullptr,
13531353
bool* ok = nullptr ) const;
13541354

1355-
/** Fetches all values from a specified field name or expression.
1356-
* @param fieldOrExpression field name or an expression string
1357-
* @param ok will be set to false if field or expression is invalid, otherwise true
1358-
* @param selectedOnly set to true to get values from selected features only
1359-
* @returns list of fetched values
1360-
* @note added in QGIS 2.9
1361-
* @see getDoubleValues
1362-
*/
1363-
QList< QVariant > getValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false ) const;
1355+
QList< QVariant > getValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, QgsFeedback* feedback = 0 ) const;
13641356

1365-
/** Fetches all double values from a specified field name or expression. Null values or
1366-
* invalid expression results are skipped.
1367-
* @param fieldOrExpression field name or an expression string evaluating to a double value
1368-
* @param ok will be set to false if field or expression is invalid, otherwise true
1369-
* @param selectedOnly set to true to get values from selected features only
1370-
* @param nullCount optional pointer to integer to store number of null values encountered in
1371-
* @returns list of fetched values
1372-
* @note added in QGIS 2.9
1373-
* @see getValues
1374-
*/
1375-
QList< double > getDoubleValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int* nullCount = 0 ) const;
1357+
QList< double > getDoubleValues( const QString &fieldOrExpression, bool &ok, bool selectedOnly = false, int* nullCount = 0, QgsFeedback* feedback = 0 ) const;
13761358

13771359
/** Set the blending mode used for rendering each feature */
13781360
void setFeatureBlendMode( QPainter::CompositionMode blendMode );

python/gui/gui.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
%Include qgsconfigureshortcutsdialog.sip
5252
%Include qgscredentialdialog.sip
5353
%Include qgscustomdrophandler.sip
54+
%Include qgscurveeditorwidget.sip
5455
%Include qgsdetaileditemdata.sip
5556
%Include qgsdetaileditemdelegate.sip
5657
%Include qgsdetaileditemwidget.sip
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class QgsCurveEditorWidget : QWidget
2+
{
3+
%TypeHeaderCode
4+
#include <qgscurveeditorwidget.h>
5+
%End
6+
7+
public:
8+
9+
QgsCurveEditorWidget( QWidget* parent /TransferThis/ = 0, const QgsCurveTransform& curve = QgsCurveTransform() );
10+
~QgsCurveEditorWidget();
11+
12+
QgsCurveTransform curve() const;
13+
14+
void setCurve( const QgsCurveTransform& curve );
15+
void setHistogramSource( const QgsVectorLayer* layer, const QString& expression );
16+
double minHistogramValueRange() const;
17+
double maxHistogramValueRange() const;
18+
19+
public slots:
20+
void setMinHistogramValueRange( double minValueRange );
21+
void setMaxHistogramValueRange( double maxValueRange );
22+
23+
signals:
24+
25+
void changed();
26+
27+
protected:
28+
29+
virtual void keyPressEvent( QKeyEvent *event );
30+
31+
};

src/core/qgshistogram.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ void QgsHistogram::setValues( const QList<double> &values )
4747
prepareValues();
4848
}
4949

50-
bool QgsHistogram::setValues( QgsVectorLayer *layer, const QString &fieldOrExpression )
50+
bool QgsHistogram::setValues( const QgsVectorLayer *layer, const QString &fieldOrExpression, QgsFeedback* feedback )
5151
{
5252
mValues.clear();
5353
if ( !layer )
5454
return false;
5555

5656
bool ok;
57-
mValues = layer->getDoubleValues( fieldOrExpression, ok );
57+
mValues = layer->getDoubleValues( fieldOrExpression, ok, false, nullptr, feedback );
5858
if ( !ok )
5959
return false;
6060

src/core/qgshistogram.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <QList>
2222

2323
#include "qgis_core.h"
24+
#include "qgsfeedback.h"
2425

2526
class QgsVectorLayer;
2627

@@ -49,9 +50,10 @@ class CORE_EXPORT QgsHistogram
4950
* result of an expression.
5051
* @param layer vector layer
5152
* @param fieldOrExpression field name or expression to be evaluated
53+
* @param feedback optional feedback object to allow cancelation of calculation
5254
* @returns true if values were successfully set
5355
*/
54-
bool setValues( QgsVectorLayer* layer, const QString& fieldOrExpression );
56+
bool setValues( const QgsVectorLayer* layer, const QString& fieldOrExpression, QgsFeedback* feedback = nullptr );
5557

5658
/** Calculates the optimal bin width using the Freedman-Diaconis rule. Bins widths are
5759
* determined by the inter-quartile range of values and the number of values.

0 commit comments

Comments
 (0)