2016-08-06 11:01:42 +02:00
|
|
|
class QgsRendererCategory
|
2012-09-24 02:28:15 +02:00
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
2016-08-07 17:33:22 +02:00
|
|
|
#include <qgscategorizedsymbolrenderer.h>
|
2012-09-24 02:28:15 +02:00
|
|
|
%End
|
|
|
|
public:
|
|
|
|
|
|
|
|
//! takes ownership of symbol
|
2016-08-06 11:01:42 +02:00
|
|
|
QgsRendererCategory( const QVariant& value, QgsSymbol* symbol /Transfer/, const QString& label, bool render = true );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
//! copy constructor
|
2016-08-06 11:01:42 +02:00
|
|
|
QgsRendererCategory( const QgsRendererCategory& cat );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
~QgsRendererCategory();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
QVariant value() const;
|
2016-08-05 08:09:43 +02:00
|
|
|
QgsSymbol* symbol() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
QString label() const;
|
|
|
|
|
|
|
|
void setValue( const QVariant &value );
|
2016-08-05 08:09:43 +02:00
|
|
|
void setSymbol( QgsSymbol* s /Transfer/ );
|
2013-06-23 16:00:16 +02:00
|
|
|
void setLabel( const QString &label );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-07-04 20:49:26 +02:00
|
|
|
// @note added in 2.5
|
|
|
|
bool renderState() const;
|
|
|
|
void setRenderState( bool render );
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
// debugging
|
2013-07-22 21:41:44 +02:00
|
|
|
QString dump() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-10-24 09:34:13 +10:00
|
|
|
void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const;
|
2016-01-04 22:51:18 +11:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
void swap( QgsRendererCategory & other );
|
2012-09-24 02:28:15 +02:00
|
|
|
};
|
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
typedef QList<QgsRendererCategory> QgsCategoryList;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
class QgsCategorizedSymbolRenderer : QgsFeatureRenderer
|
2012-09-24 02:28:15 +02:00
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
2016-08-07 17:33:22 +02:00
|
|
|
#include <qgscategorizedsymbolrenderer.h>
|
2012-09-24 02:28:15 +02:00
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
QgsCategorizedSymbolRenderer( const QString& attrName = QString(), const QgsCategoryList& categories = QgsCategoryList() );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
virtual ~QgsCategorizedSymbolRenderer();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-11-08 19:18:00 +00:00
|
|
|
//! @note available in python as symbolForFeature2
|
2016-09-12 16:50:14 +10:00
|
|
|
virtual QgsSymbol* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-11-08 19:18:00 +00:00
|
|
|
//! @note available in python as originalSymbolForFeature2
|
2016-09-12 16:50:14 +10:00
|
|
|
virtual QgsSymbol* originalSymbolForFeature( QgsFeature& feature, QgsRenderContext& context );
|
2014-09-25 12:00:45 +02:00
|
|
|
|
2015-07-22 10:46:13 +02:00
|
|
|
virtual void startRender( QgsRenderContext& context, const QgsFields& fields );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
virtual void stopRender( QgsRenderContext& context );
|
|
|
|
|
2016-10-03 10:39:41 +02:00
|
|
|
virtual QSet<QString> usedAttributes() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2013-07-22 21:41:44 +02:00
|
|
|
virtual QString dump() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
virtual QgsCategorizedSymbolRenderer* clone() const /Factory/;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
|
|
|
|
|
|
|
|
//! returns bitwise OR-ed capabilities of the renderer
|
2016-08-06 11:01:42 +02:00
|
|
|
virtual QgsFeatureRenderer::Capabilities capabilities();
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-12-04 07:28:31 +11:00
|
|
|
virtual QString filter( const QgsFields& fields = QgsFields() );
|
|
|
|
|
2015-11-08 19:18:00 +00:00
|
|
|
//! @note available in python as symbols2
|
2016-09-12 16:50:14 +10:00
|
|
|
virtual QgsSymbolList symbols( QgsRenderContext& context );
|
2016-01-27 09:58:47 +11:00
|
|
|
|
|
|
|
/** Update all the symbols but leave categories and colors. This method also sets the source
|
|
|
|
* symbol for the renderer.
|
|
|
|
* @param sym source symbol to use for categories. Ownership is not transferred.
|
|
|
|
* @see setSourceSymbol()
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2016-08-05 08:09:43 +02:00
|
|
|
void updateSymbols( QgsSymbol * sym );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
const QgsCategoryList& categories() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
//! return index of category with specified value (-1 if not found)
|
2015-10-07 11:55:34 +11:00
|
|
|
int categoryIndexForValue( const QVariant& val );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-07-04 20:49:26 +02:00
|
|
|
//! return index of category with specified label (-1 if not found or not unique)
|
|
|
|
//! @note added in 2.5
|
2015-10-07 11:55:34 +11:00
|
|
|
int categoryIndexForLabel( const QString& val );
|
2014-07-04 20:49:26 +02:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
bool updateCategoryValue( int catIndex, const QVariant &value );
|
2016-08-05 08:09:43 +02:00
|
|
|
bool updateCategorySymbol( int catIndex, QgsSymbol* symbol /Transfer/ );
|
2015-10-07 11:55:34 +11:00
|
|
|
bool updateCategoryLabel( int catIndex, const QString& label );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-07-04 20:49:26 +02:00
|
|
|
//! @note added in 2.5
|
|
|
|
bool updateCategoryRenderState( int catIndex, bool render );
|
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
void addCategory( const QgsRendererCategory &category );
|
2012-09-24 02:28:15 +02:00
|
|
|
bool deleteCategory( int catIndex );
|
|
|
|
void deleteAllCategories();
|
|
|
|
|
2013-06-23 16:00:16 +02:00
|
|
|
//! Moves the category at index position from to index position to.
|
|
|
|
void moveCategory( int from, int to );
|
|
|
|
|
|
|
|
void sortByValue( Qt::SortOrder order = Qt::AscendingOrder );
|
|
|
|
void sortByLabel( Qt::SortOrder order = Qt::AscendingOrder );
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
QString classAttribute() const;
|
2015-10-07 11:55:34 +11:00
|
|
|
void setClassAttribute( const QString& attr );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
//! create renderer from XML element
|
2016-08-06 11:01:42 +02:00
|
|
|
static QgsFeatureRenderer* create( QDomElement& element ) /Factory/;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
|
|
|
//! store renderer info to XML element
|
|
|
|
virtual QDomElement save( QDomDocument& doc );
|
|
|
|
|
|
|
|
//! return a list of symbology items for the legend
|
|
|
|
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
|
|
|
|
|
|
|
|
//! return a list of item text / symbol
|
2014-01-27 09:22:24 +01:00
|
|
|
//! @note not available in python bindings
|
2015-10-07 11:55:34 +11:00
|
|
|
// virtual QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = QString() );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-10-08 23:47:51 +11:00
|
|
|
//! @note added in 2.10
|
|
|
|
QgsLegendSymbolListV2 legendSymbolItemsV2() const;
|
|
|
|
|
2016-01-25 13:05:36 +11:00
|
|
|
virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context );
|
|
|
|
|
2016-01-27 09:58:47 +11:00
|
|
|
/** Returns the renderer's source symbol, which is the base symbol used for the each categories' symbol before applying
|
|
|
|
* the categories' color.
|
|
|
|
* @see setSourceSymbol()
|
|
|
|
* @see sourceColorRamp()
|
|
|
|
*/
|
2016-08-05 08:09:43 +02:00
|
|
|
QgsSymbol* sourceSymbol();
|
2016-01-27 09:58:47 +11:00
|
|
|
|
|
|
|
/** Sets the source symbol for the renderer, which is the base symbol used for the each categories' symbol before applying
|
|
|
|
* the categories' color.
|
|
|
|
* @param sym source symbol, ownership is transferred to the renderer
|
|
|
|
* @see sourceSymbol()
|
|
|
|
* @see setSourceColorRamp()
|
|
|
|
*/
|
2016-08-05 08:09:43 +02:00
|
|
|
void setSourceSymbol( QgsSymbol* sym /Transfer/ );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2016-01-27 09:58:47 +11:00
|
|
|
/** Returns the source color ramp, from which each categories' color is derived.
|
|
|
|
* @see setSourceColorRamp()
|
|
|
|
* @see sourceSymbol()
|
|
|
|
*/
|
2016-08-24 10:56:29 +10:00
|
|
|
QgsColorRamp* sourceColorRamp();
|
2015-09-01 16:06:35 +10:00
|
|
|
|
|
|
|
/** Sets the source color ramp.
|
|
|
|
* @param ramp color ramp. Ownership is transferred to the renderer
|
2016-01-27 09:58:47 +11:00
|
|
|
* @see sourceColorRamp()
|
|
|
|
* @see setSourceSymbol()
|
2015-09-01 16:06:35 +10:00
|
|
|
*/
|
2016-08-24 10:56:29 +10:00
|
|
|
void setSourceColorRamp( QgsColorRamp* ramp /Transfer/ );
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2015-09-01 16:06:35 +10:00
|
|
|
/** Update the color ramp used and all symbols colors.
|
|
|
|
* @param ramp color ramp. Ownership is transferred to the renderer
|
|
|
|
* @note added in 2.5
|
|
|
|
*/
|
2016-11-29 13:51:19 +07:00
|
|
|
void updateColorRamp( QgsColorRamp* ramp /Transfer/ );
|
2014-09-20 18:30:12 +12:00
|
|
|
|
2014-07-04 20:49:26 +02:00
|
|
|
//! items of symbology items in legend should be checkable
|
2014-11-21 01:17:21 +01:00
|
|
|
//! @note added in 2.5
|
2014-07-04 20:49:26 +02:00
|
|
|
virtual bool legendSymbolItemsCheckable() const;
|
|
|
|
|
|
|
|
//! item in symbology was checked
|
|
|
|
// @note added in 2.5
|
2015-10-07 11:55:34 +11:00
|
|
|
virtual bool legendSymbolItemChecked( const QString& key );
|
2014-07-04 20:49:26 +02:00
|
|
|
|
2016-08-05 08:09:43 +02:00
|
|
|
virtual void setLegendSymbolItem( const QString& key, QgsSymbol* symbol /Transfer/ );
|
2015-12-08 06:32:23 +11:00
|
|
|
|
2014-07-04 20:49:26 +02:00
|
|
|
//! item in symbology was checked
|
|
|
|
// @note added in 2.5
|
2015-10-07 11:55:34 +11:00
|
|
|
virtual void checkLegendSymbolItem( const QString& key, bool state = true );
|
2014-07-04 20:49:26 +02:00
|
|
|
|
2014-09-20 18:30:12 +12:00
|
|
|
//! If supported by the renderer, return classification attribute for the use in legend
|
|
|
|
//! @note added in 2.6
|
2014-11-13 23:13:13 +01:00
|
|
|
virtual QString legendClassificationAttribute() const;
|
2014-09-20 18:30:12 +12:00
|
|
|
|
2016-08-06 11:01:42 +02:00
|
|
|
//! creates a QgsCategorizedSymbolRenderer from an existing renderer.
|
2014-08-24 08:31:36 +08:00
|
|
|
//! @note added in 2.5
|
2014-08-30 10:16:23 -06:00
|
|
|
//! @returns a new renderer if the conversion was possible, otherwise 0.
|
2016-08-06 11:01:42 +02:00
|
|
|
static QgsCategorizedSymbolRenderer* convertFromRenderer( const QgsFeatureRenderer *renderer ) /Factory/;
|
2014-08-24 08:31:36 +08:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
protected:
|
|
|
|
void rebuildHash();
|
|
|
|
|
2016-08-05 08:09:43 +02:00
|
|
|
QgsSymbol* skipRender();
|
2016-01-04 22:51:18 +11:00
|
|
|
|
2016-08-05 08:09:43 +02:00
|
|
|
QgsSymbol* symbolForValue( const QVariant& value );
|
2014-01-14 17:23:16 +01:00
|
|
|
|
|
|
|
private:
|
2016-08-06 11:01:42 +02:00
|
|
|
QgsCategorizedSymbolRenderer( const QgsCategorizedSymbolRenderer & );
|
|
|
|
QgsCategorizedSymbolRenderer & operator=( const QgsCategorizedSymbolRenderer & );
|
2012-09-24 02:28:15 +02:00
|
|
|
};
|
|
|
|
|