Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/qgis/QGIS
Browse files Browse the repository at this point in the history
  • Loading branch information
pcav committed May 18, 2015
2 parents 24974e0 + 0b32606 commit 3e5e2b3
Show file tree
Hide file tree
Showing 41 changed files with 3,343 additions and 642 deletions.
1 change: 1 addition & 0 deletions python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
%Include qgsgeometry.sip
%Include qgsgeometryvalidator.sip
%Include qgsgeometrysimplifier.sip
%Include qgshistogram.sip
%Include qgsmaptopixelgeometrysimplifier.sip
%Include qgsgml.sip
%Include qgsgmlschema.sip
Expand Down
66 changes: 66 additions & 0 deletions python/core/qgshistogram.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/** \ingroup core
* \class QgsHistogram
* \brief Calculator for a numeric histogram from a list of values.
*
* \note Added in version 2.9
*/

class QgsHistogram
{
%TypeHeaderCode
#include "qgshistogram.h"
%End

public:

QgsHistogram();

virtual ~QgsHistogram();

/** Assigns numeric source values for the histogram.
* @param values list of doubles
*/
void setValues( const QList<double>& values );

/** Assigns numeric source values for the histogram from a vector layer's field or as the
* result of an expression.
* @param layer vector layer
* @param fieldOrExpression field name or expression to be evaluated
* @returns true if values were successfully set
*/
bool setValues( QgsVectorLayer* layer, const QString& fieldOrExpression );

/** Calculates the optimal bin width using the Freedman-Diaconis rule. Bins widths are
* determined by the inter-quartile range of values and the number of values.
* @returns optimal width for bins
* @see optimalNumberBins
* @note values must first be specified using @link setValues @endlink
*/
double optimalBinWidth() const;

/** Returns the optimal number of bins for the source values, calculated using the
* Freedman-Diaconis rule. The number of bins are determined by the inter-quartile range
* of values and the number of values.
* @returns optimal number of bins
* @see optimalBinWidth
* @note values must first be specified using @link setValues @endlink
*/
int optimalNumberBins() const;

/** Returns a list of edges for the histogram for a specified number of bins. This list
* will be length bins + 1, as both the first and last value are also included.
* @param bins number of bins
* @return list of bin edges
* @note values must first be specified using @link setValues @endlink
*/
QList<double> binEdges( int bins ) const;

/** Returns the calculated list of the counts for the histogram bins.
* @param bins number of histogram bins
* @return list of histogram counts
* @note values must first be specified using @link setValues @endlink
*/
QList<int> counts( int bins ) const;

};

2 changes: 2 additions & 0 deletions python/gui/gui.sip
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
%Include qgsfilterlineedit.sip
%Include qgsformannotationitem.sip
%Include qgsgenericprojectionselector.sip
%Include qgshistogramwidget.sip
%Include qgshtmlannotationitem.sip
%Include qgsidentifymenu.sip
%Include qgslegendinterface.sip
Expand Down Expand Up @@ -173,6 +174,7 @@
%Include symbology-ng/qgsdatadefinedsymboldialog.sip
%Include symbology-ng/qgsstylev2exportimportdialog.sip
%Include symbology-ng/qgssvgselectorwidget.sip
%Include symbology-ng/qgsgraduatedhistogramwidget.sip

%Include effects/qgseffectdrawmodecombobox.sip
%Include effects/qgspainteffectpropertieswidget.sip
Expand Down
107 changes: 107 additions & 0 deletions python/gui/qgshistogramwidget.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

/** \ingroup gui
* \class QgsHistogramWidget
* \brief Graphical histogram for displaying distributions of field values.
*
* \note Added in version 2.9
*/

class QgsHistogramWidget : QWidget
{
%TypeHeaderCode
#include <qgshistogramwidget.h>
%End

public:

/** QgsHistogramWidget constructor. If layer and fieldOrExp are specified then the histogram
* will be initially populated with the corresponding values.
* @param parent parent widget
* @param layer source vector layer
* @param fieldOrExp field name or expression string
*/
QgsHistogramWidget( QWidget *parent /TransferThis/ = 0, QgsVectorLayer* layer = 0, const QString& fieldOrExp = QString() );

~QgsHistogramWidget();

/** Returns the layer currently associated with the widget.
* @see setLayer
* @see sourceFieldExp
*/
QgsVectorLayer* layer();

/** Returns the source field name or expression used to calculate values displayed
* in the histogram.
* @see setSourceFieldExp
* @see layer
*/
QString sourceFieldExp() const;

/** Sets the pen to use when drawing histogram bars. If set to Qt::NoPen then the
* pen will be automatically calculated. If ranges have been set using @link setGraduatedRanges @endlink
* then the pen and brush will have no effect.
* @param pen histogram pen
* @see pen
* @see setBrush
*/
void setPen( const QPen& pen );

/** Returns the pen used when drawing histogram bars.
* @see setPen
* @see brush
*/
QPen pen() const;

/** Sets the brush used for drawing histogram bars. If ranges have been set using @link setGraduatedRanges @endlink
* then the pen and brush will have no effect.
* @param brush histogram brush
* @see brush
* @see setPen
*/
void setBrush( const QBrush& brush );

/** Returns the brush used when drawing histogram bars.
* @see setBrush
* @see pen
*/
QBrush brush() const;

/** Sets 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.
* @param ranges graduated range list
*/
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.
* @returns graduated range list
* @see setGraduatedRanges
*/
QgsRangeList graduatedRanges() const;

public slots:

/** Triggers a refresh of the histogram when the widget is next repainted.
*/
void refreshHistogram();

/** Sets the vector layer associated with the histogram.
* @param layer source vector layer
* @see setSourceFieldExp
*/
void setLayer( QgsVectorLayer* layer );

/** Sets the source field or expression to use for values in the histogram.
* @param fieldOrExp field name or expression string
* @see setLayer
*/
void setSourceFieldExp( const QString& fieldOrExp );

protected:

/** Updates and redraws the histogram.
*/
virtual void drawHistogram();

virtual void paintEvent( QPaintEvent * event );
};
42 changes: 42 additions & 0 deletions python/gui/symbology-ng/qgsgraduatedhistogramwidget.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

/** \ingroup gui
* \class QgsGraduatedHistogramWidget
* \brief Graphical histogram for displaying distribution of field values and
* editing range breaks for a QgsGraduatedSymbolRendererV2 renderer.
*
* \note Added in version 2.9
*/

class QgsGraduatedHistogramWidget : QWidget
{
%TypeHeaderCode
#include <qgsgraduatedhistogramwidget.h>
%End

public:

/** QgsGraduatedHistogramWidget constructor
* @param parent parent widget
*/
QgsGraduatedHistogramWidget( QWidget *parent /TransferThis/ = 0 );
~QgsGraduatedHistogramWidget();

/** Sets the QgsGraduatedSymbolRendererV2 renderer associated with the histogram.
* The histogram will fetch the ranges from the renderer before every refresh.
* @param renderer associated QgsGraduatedSymbolRendererV2
*/
void setRenderer( QgsGraduatedSymbolRendererV2* renderer );

signals:

/** Emitted when the user modifies the graduated ranges using the histogram widget.
* @param rangesAdded true if the user has added ranges, false if the user has just
* modified existing range breaks
*/
void rangesModified( bool rangesAdded );

protected:

virtual void drawHistogram();

};
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ SET(QGIS_CORE_SRCS
qgsgeometryvalidator.cpp
qgsgml.cpp
qgsgmlschema.cpp
qgshistogram.cpp
qgslayerdefinition.cpp
qgslabel.cpp
qgslabelattributes.cpp
Expand Down Expand Up @@ -510,6 +511,7 @@ SET(QGIS_CORE_HDRS
qgsfontutils.h
qgsgeometry.h
qgsgeometrycache.h
qgshistogram.h
qgslayerdefinition.h
qgslabel.h
qgslabelattributes.h
Expand Down
29 changes: 29 additions & 0 deletions src/core/qgsfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,32 @@ int QgsFeature::fieldNameIndex( const QString& fieldName ) const
}
return -1;
}

QDataStream& operator<<( QDataStream& out, const QgsFeature& feature )
{
out << feature.id();
out << feature.attributes();
if ( feature.geometry() )
{
out << *( feature.geometry() );
}
else
{
QgsGeometry geometry;
out << geometry;
}
out << feature.isValid();
return out;
}

QDataStream& operator>>( QDataStream& in, QgsFeature& feature )
{
QgsFeatureId id;
QgsGeometry* geometry = new QgsGeometry();
bool valid;
in >> id >> feature.attributes() >> *geometry >> valid;
feature.setFeatureId( id );
feature.setGeometry( geometry );
feature.setValid( valid );
return in;
}
10 changes: 10 additions & 0 deletions src/core/qgsfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ class QgsFeatureId
friend uint qHash( const QgsFeatureId &id );
};

/** Writes the feature id to stream out. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFeatureId& featureId );
/** Reads a feature id from stream in into feature id. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFeatureId& featureId );

inline uint qHash( const QgsFeatureId &id )
{
return qHash( id.mId );
Expand Down Expand Up @@ -313,6 +318,11 @@ class CORE_EXPORT QgsFeature

}; // class QgsFeature

/** Writes the feature to stream out. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFeature& feature );
/** Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFeature& feature );

// key = feature id, value = changed attributes
typedef QMap<QgsFeatureId, QgsAttributeMap> QgsChangedAttributesMap;

Expand Down
49 changes: 49 additions & 0 deletions src/core/qgsfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,31 @@ bool QgsField::convertCompatible( QVariant& v ) const
return true;
}

QDataStream& operator<<( QDataStream& out, const QgsField& field )
{
out << field.name();
out << ( quint32 )field.type();
out << field.typeName();
out << field.length();
out << field.precision();
out << field.comment();
return out;
}

QDataStream& operator>>( QDataStream& in, QgsField& field )
{
quint32 type, length, precision;
QString name, typeName, comment;
in >> name >> type >> typeName >> length >> precision >> comment;
field.setName( name );
field.setType(( QVariant::Type )type );
field.setTypeName( typeName );
field.setLength(( int )length );
field.setPrecision(( int )precision );
field.setComment( comment );
return in;
}

////////////////////////////////////////////////////////////////////////////

QgsFields::QgsFields()
Expand Down Expand Up @@ -341,3 +366,27 @@ QgsAttributeList QgsFields::allAttributesList() const
lst.append( i );
return lst;
}

QDataStream& operator<<( QDataStream& out, const QgsFields& fields )
{
out << ( quint32 )fields.size();
for ( int i = 0; i < fields.size(); i++ )
{
out << fields.field( i );
}
return out;
}

QDataStream& operator>>( QDataStream& in, QgsFields& fields )
{
fields.clear();
quint32 size;
in >> size;
for ( quint32 i = 0; i < size; i++ )
{
QgsField field;
in >> field;
fields.append( field );
}
return in;
}
9 changes: 9 additions & 0 deletions src/core/qgsfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class CORE_EXPORT QgsField

Q_DECLARE_METATYPE( QgsField );

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

/** \class QgsFields
* \ingroup core
Expand Down Expand Up @@ -274,4 +278,9 @@ class CORE_EXPORT QgsFields

Q_DECLARE_METATYPE( QgsFields );

/** Writes the fields to stream out. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFields& fields );
/** Reads fields from stream in into fields. QGIS version compatibility is not guaranteed. */
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFields& fields );

#endif
Loading

0 comments on commit 3e5e2b3

Please sign in to comment.