Skip to content

Commit 3e5e2b3

Browse files
committed
Merge branch 'master' of https://github.com/qgis/QGIS
2 parents 24974e0 + 0b32606 commit 3e5e2b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3343
-642
lines changed

python/core/core.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
%Include qgsgeometry.sip
4444
%Include qgsgeometryvalidator.sip
4545
%Include qgsgeometrysimplifier.sip
46+
%Include qgshistogram.sip
4647
%Include qgsmaptopixelgeometrysimplifier.sip
4748
%Include qgsgml.sip
4849
%Include qgsgmlschema.sip

python/core/qgshistogram.sip

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/** \ingroup core
2+
* \class QgsHistogram
3+
* \brief Calculator for a numeric histogram from a list of values.
4+
*
5+
* \note Added in version 2.9
6+
*/
7+
8+
class QgsHistogram
9+
{
10+
%TypeHeaderCode
11+
#include "qgshistogram.h"
12+
%End
13+
14+
public:
15+
16+
QgsHistogram();
17+
18+
virtual ~QgsHistogram();
19+
20+
/** Assigns numeric source values for the histogram.
21+
* @param values list of doubles
22+
*/
23+
void setValues( const QList<double>& values );
24+
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 );
32+
33+
/** Calculates the optimal bin width using the Freedman-Diaconis rule. Bins widths are
34+
* determined by the inter-quartile range of values and the number of values.
35+
* @returns optimal width for bins
36+
* @see optimalNumberBins
37+
* @note values must first be specified using @link setValues @endlink
38+
*/
39+
double optimalBinWidth() const;
40+
41+
/** Returns the optimal number of bins for the source values, calculated using the
42+
* Freedman-Diaconis rule. The number of bins are determined by the inter-quartile range
43+
* of values and the number of values.
44+
* @returns optimal number of bins
45+
* @see optimalBinWidth
46+
* @note values must first be specified using @link setValues @endlink
47+
*/
48+
int optimalNumberBins() const;
49+
50+
/** Returns a list of edges for the histogram for a specified number of bins. This list
51+
* will be length bins + 1, as both the first and last value are also included.
52+
* @param bins number of bins
53+
* @return list of bin edges
54+
* @note values must first be specified using @link setValues @endlink
55+
*/
56+
QList<double> binEdges( int bins ) const;
57+
58+
/** Returns the calculated list of the counts for the histogram bins.
59+
* @param bins number of histogram bins
60+
* @return list of histogram counts
61+
* @note values must first be specified using @link setValues @endlink
62+
*/
63+
QList<int> counts( int bins ) const;
64+
65+
};
66+

python/gui/gui.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
%Include qgsfilterlineedit.sip
5757
%Include qgsformannotationitem.sip
5858
%Include qgsgenericprojectionselector.sip
59+
%Include qgshistogramwidget.sip
5960
%Include qgshtmlannotationitem.sip
6061
%Include qgsidentifymenu.sip
6162
%Include qgslegendinterface.sip
@@ -173,6 +174,7 @@
173174
%Include symbology-ng/qgsdatadefinedsymboldialog.sip
174175
%Include symbology-ng/qgsstylev2exportimportdialog.sip
175176
%Include symbology-ng/qgssvgselectorwidget.sip
177+
%Include symbology-ng/qgsgraduatedhistogramwidget.sip
176178

177179
%Include effects/qgseffectdrawmodecombobox.sip
178180
%Include effects/qgspainteffectpropertieswidget.sip

python/gui/qgshistogramwidget.sip

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
2+
/** \ingroup gui
3+
* \class QgsHistogramWidget
4+
* \brief Graphical histogram for displaying distributions of field values.
5+
*
6+
* \note Added in version 2.9
7+
*/
8+
9+
class QgsHistogramWidget : QWidget
10+
{
11+
%TypeHeaderCode
12+
#include <qgshistogramwidget.h>
13+
%End
14+
15+
public:
16+
17+
/** QgsHistogramWidget constructor. If layer and fieldOrExp are specified then the histogram
18+
* will be initially populated with the corresponding values.
19+
* @param parent parent widget
20+
* @param layer source vector layer
21+
* @param fieldOrExp field name or expression string
22+
*/
23+
QgsHistogramWidget( QWidget *parent /TransferThis/ = 0, QgsVectorLayer* layer = 0, const QString& fieldOrExp = QString() );
24+
25+
~QgsHistogramWidget();
26+
27+
/** Returns the layer currently associated with the widget.
28+
* @see setLayer
29+
* @see sourceFieldExp
30+
*/
31+
QgsVectorLayer* layer();
32+
33+
/** Returns the source field name or expression used to calculate values displayed
34+
* in the histogram.
35+
* @see setSourceFieldExp
36+
* @see layer
37+
*/
38+
QString sourceFieldExp() const;
39+
40+
/** Sets the pen to use when drawing histogram bars. If set to Qt::NoPen then the
41+
* pen will be automatically calculated. If ranges have been set using @link setGraduatedRanges @endlink
42+
* then the pen and brush will have no effect.
43+
* @param pen histogram pen
44+
* @see pen
45+
* @see setBrush
46+
*/
47+
void setPen( const QPen& pen );
48+
49+
/** Returns the pen used when drawing histogram bars.
50+
* @see setPen
51+
* @see brush
52+
*/
53+
QPen pen() const;
54+
55+
/** Sets the brush used for drawing histogram bars. If ranges have been set using @link setGraduatedRanges @endlink
56+
* then the pen and brush will have no effect.
57+
* @param brush histogram brush
58+
* @see brush
59+
* @see setPen
60+
*/
61+
void setBrush( const QBrush& brush );
62+
63+
/** Returns the brush used when drawing histogram bars.
64+
* @see setBrush
65+
* @see pen
66+
*/
67+
QBrush brush() const;
68+
69+
/** Sets the graduated ranges associated with the histogram. If set, the ranges will be used to colour the histogram
70+
* bars and for showing vertical dividers at the histogram breaks.
71+
* @param ranges graduated range list
72+
*/
73+
void setGraduatedRanges( const QgsRangeList& ranges );
74+
75+
/** Returns the graduated ranges associated with the histogram. If set, the ranges will be used to colour the histogram
76+
* bars and for showing vertical dividers at the histogram breaks.
77+
* @returns graduated range list
78+
* @see setGraduatedRanges
79+
*/
80+
QgsRangeList graduatedRanges() const;
81+
82+
public slots:
83+
84+
/** Triggers a refresh of the histogram when the widget is next repainted.
85+
*/
86+
void refreshHistogram();
87+
88+
/** Sets the vector layer associated with the histogram.
89+
* @param layer source vector layer
90+
* @see setSourceFieldExp
91+
*/
92+
void setLayer( QgsVectorLayer* layer );
93+
94+
/** Sets the source field or expression to use for values in the histogram.
95+
* @param fieldOrExp field name or expression string
96+
* @see setLayer
97+
*/
98+
void setSourceFieldExp( const QString& fieldOrExp );
99+
100+
protected:
101+
102+
/** Updates and redraws the histogram.
103+
*/
104+
virtual void drawHistogram();
105+
106+
virtual void paintEvent( QPaintEvent * event );
107+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
/** \ingroup gui
3+
* \class QgsGraduatedHistogramWidget
4+
* \brief Graphical histogram for displaying distribution of field values and
5+
* editing range breaks for a QgsGraduatedSymbolRendererV2 renderer.
6+
*
7+
* \note Added in version 2.9
8+
*/
9+
10+
class QgsGraduatedHistogramWidget : QWidget
11+
{
12+
%TypeHeaderCode
13+
#include <qgsgraduatedhistogramwidget.h>
14+
%End
15+
16+
public:
17+
18+
/** QgsGraduatedHistogramWidget constructor
19+
* @param parent parent widget
20+
*/
21+
QgsGraduatedHistogramWidget( QWidget *parent /TransferThis/ = 0 );
22+
~QgsGraduatedHistogramWidget();
23+
24+
/** Sets the QgsGraduatedSymbolRendererV2 renderer associated with the histogram.
25+
* The histogram will fetch the ranges from the renderer before every refresh.
26+
* @param renderer associated QgsGraduatedSymbolRendererV2
27+
*/
28+
void setRenderer( QgsGraduatedSymbolRendererV2* renderer );
29+
30+
signals:
31+
32+
/** Emitted when the user modifies the graduated ranges using the histogram widget.
33+
* @param rangesAdded true if the user has added ranges, false if the user has just
34+
* modified existing range breaks
35+
*/
36+
void rangesModified( bool rangesAdded );
37+
38+
protected:
39+
40+
virtual void drawHistogram();
41+
42+
};

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ SET(QGIS_CORE_SRCS
107107
qgsgeometryvalidator.cpp
108108
qgsgml.cpp
109109
qgsgmlschema.cpp
110+
qgshistogram.cpp
110111
qgslayerdefinition.cpp
111112
qgslabel.cpp
112113
qgslabelattributes.cpp
@@ -510,6 +511,7 @@ SET(QGIS_CORE_HDRS
510511
qgsfontutils.h
511512
qgsgeometry.h
512513
qgsgeometrycache.h
514+
qgshistogram.h
513515
qgslayerdefinition.h
514516
qgslabel.h
515517
qgslabelattributes.h

src/core/qgsfeature.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,32 @@ int QgsFeature::fieldNameIndex( const QString& fieldName ) const
252252
}
253253
return -1;
254254
}
255+
256+
QDataStream& operator<<( QDataStream& out, const QgsFeature& feature )
257+
{
258+
out << feature.id();
259+
out << feature.attributes();
260+
if ( feature.geometry() )
261+
{
262+
out << *( feature.geometry() );
263+
}
264+
else
265+
{
266+
QgsGeometry geometry;
267+
out << geometry;
268+
}
269+
out << feature.isValid();
270+
return out;
271+
}
272+
273+
QDataStream& operator>>( QDataStream& in, QgsFeature& feature )
274+
{
275+
QgsFeatureId id;
276+
QgsGeometry* geometry = new QgsGeometry();
277+
bool valid;
278+
in >> id >> feature.attributes() >> *geometry >> valid;
279+
feature.setFeatureId( id );
280+
feature.setGeometry( geometry );
281+
feature.setValid( valid );
282+
return in;
283+
}

src/core/qgsfeature.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ class QgsFeatureId
6464
friend uint qHash( const QgsFeatureId &id );
6565
};
6666

67+
/** Writes the feature id to stream out. QGIS version compatibility is not guaranteed. */
68+
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFeatureId& featureId );
69+
/** Reads a feature id from stream in into feature id. QGIS version compatibility is not guaranteed. */
70+
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFeatureId& featureId );
71+
6772
inline uint qHash( const QgsFeatureId &id )
6873
{
6974
return qHash( id.mId );
@@ -313,6 +318,11 @@ class CORE_EXPORT QgsFeature
313318

314319
}; // class QgsFeature
315320

321+
/** Writes the feature to stream out. QGIS version compatibility is not guaranteed. */
322+
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFeature& feature );
323+
/** Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed. */
324+
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFeature& feature );
325+
316326
// key = feature id, value = changed attributes
317327
typedef QMap<QgsFeatureId, QgsAttributeMap> QgsChangedAttributesMap;
318328

src/core/qgsfield.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,31 @@ bool QgsField::convertCompatible( QVariant& v ) const
176176
return true;
177177
}
178178

179+
QDataStream& operator<<( QDataStream& out, const QgsField& field )
180+
{
181+
out << field.name();
182+
out << ( quint32 )field.type();
183+
out << field.typeName();
184+
out << field.length();
185+
out << field.precision();
186+
out << field.comment();
187+
return out;
188+
}
189+
190+
QDataStream& operator>>( QDataStream& in, QgsField& field )
191+
{
192+
quint32 type, length, precision;
193+
QString name, typeName, comment;
194+
in >> name >> type >> typeName >> length >> precision >> comment;
195+
field.setName( name );
196+
field.setType(( QVariant::Type )type );
197+
field.setTypeName( typeName );
198+
field.setLength(( int )length );
199+
field.setPrecision(( int )precision );
200+
field.setComment( comment );
201+
return in;
202+
}
203+
179204
////////////////////////////////////////////////////////////////////////////
180205

181206
QgsFields::QgsFields()
@@ -341,3 +366,27 @@ QgsAttributeList QgsFields::allAttributesList() const
341366
lst.append( i );
342367
return lst;
343368
}
369+
370+
QDataStream& operator<<( QDataStream& out, const QgsFields& fields )
371+
{
372+
out << ( quint32 )fields.size();
373+
for ( int i = 0; i < fields.size(); i++ )
374+
{
375+
out << fields.field( i );
376+
}
377+
return out;
378+
}
379+
380+
QDataStream& operator>>( QDataStream& in, QgsFields& fields )
381+
{
382+
fields.clear();
383+
quint32 size;
384+
in >> size;
385+
for ( quint32 i = 0; i < size; i++ )
386+
{
387+
QgsField field;
388+
in >> field;
389+
fields.append( field );
390+
}
391+
return in;
392+
}

src/core/qgsfield.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ class CORE_EXPORT QgsField
156156

157157
Q_DECLARE_METATYPE( QgsField );
158158

159+
/** Writes the field to stream out. QGIS version compatibility is not guaranteed. */
160+
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsField& field );
161+
/** Reads a field from stream in into field. QGIS version compatibility is not guaranteed. */
162+
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsField& field );
159163

160164
/** \class QgsFields
161165
* \ingroup core
@@ -274,4 +278,9 @@ class CORE_EXPORT QgsFields
274278

275279
Q_DECLARE_METATYPE( QgsFields );
276280

281+
/** Writes the fields to stream out. QGIS version compatibility is not guaranteed. */
282+
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFields& fields );
283+
/** Reads fields from stream in into fields. QGIS version compatibility is not guaranteed. */
284+
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFields& fields );
285+
277286
#endif

0 commit comments

Comments
 (0)