[Conditional Styles] Better defaults

Add QgsConditionalLayerStyles to hold row and field styles
This commit is contained in:
Nathan Woodrow 2015-08-25 21:08:52 +10:00
parent 83115cd16a
commit 2f60a5f85c
17 changed files with 333 additions and 296 deletions

View File

@ -42,7 +42,6 @@
%Include qgsfeatureiterator.sip
%Include qgsfeaturerequest.sip
%Include qgsfield.sip
%Include qgsfielduiproperties.sip
%Include qgsgeometryvalidator.sip
%Include qgsgeometrysimplifier.sip
%Include qgshistogram.sip

View File

@ -1,3 +1,48 @@
typedef QList<QgsConditionalStyle> QgsConditionalStyles;
/**
* @brief The QgsConditionalLayerStyles class holds conditional style information
* for a layer. This includes field styles and full row styles.
*/
class QgsConditionalLayerStyles
{
%TypeHeaderCode
#include <qgsconditionalstyle.h>
%End
public:
QgsConditionalLayerStyles();
QList<QgsConditionalStyle> rowStyles();
/**
* @brief Set the conditional styles that apply to full rows of data in the attribute table.
* Each row will check be checked against each rule.
* @param styles The styles to assign to all the rows
* @note added in QGIS 2.12
*/
void setRowStyles( QList<QgsConditionalStyle> styles );
/**
* @brief Set the conditional styles for the field UI properties.
* @param styles
*/
void setFieldStyles( QString fieldName, QList<QgsConditionalStyle> styles );
/**
* @brief Returns the conditional styles set for the field UI properties
* @return A list of conditional styles that have been set.
*/
QList<QgsConditionalStyle> fieldStyles( QString fieldName );
/** Reads field ui properties specific state from Dom node.
*/
virtual bool readXml( const QDomNode& node );
/** Write field ui properties specific state from Dom node.
*/
virtual bool writeXml( QDomNode & node, QDomDocument & doc ) const;
};
/** \class QgsConditionalStyle
* \ingroup core
* Conditional styling for a rule.
@ -9,7 +54,9 @@ class QgsConditionalStyle
%End
public:
QgsConditionalStyle();
QgsConditionalStyle( const QgsConditionalStyle& other );
QgsConditionalStyle( QString rule );
~QgsConditionalStyle();
/**
* @brief Check if the rule matches using the given value and feature
@ -74,29 +121,43 @@ class QgsConditionalStyle
*/
QString name() const;
/**
* @brief The symbol used to generate the icon for the style
* @return The QgsSymbolV2 used for the icon
*/
QgsSymbolV2* symbol() const;
/**
* @brief The icon set for style generated from the set symbol
* @return A QPixmap that was set for the icon using the symbol
*/
QPixmap icon() const;
/**
* @brief The symbol used to generate the icon for the style
* @return The QgsSymbolV2 used for the icon
*/
QgsSymbolV2* symbol() const;
/**
* @brief The text color set for style
* @return QColor for text color
*/
QColor textColor() const;
/**
* @brief Check if the text color is valid for render.
* Valid colors are non invalid QColors and a color with a > 0 alpha
* @return True of the color set for text is valid.
*/
bool validTextColor() const;
/**
* @brief The background color for style
* @return QColor for background color
*/
QColor backgroundColor() const;
/**
* @brief Check if the background color is valid for render.
* Valid colors are non invalid QColors and a color with a > 0 alpha
* @return True of the color set for background is valid.
*/
bool validBackgroundColor() const;
/**
* @brief The font for the style
* @return QFont for the style
@ -124,7 +185,7 @@ class QgsConditionalStyle
* @return A condtional style that matches the value and feature.
* Check with QgsCondtionalStyle::isValid()
*/
static QList<QgsConditionalStyle> matchingConditionalStyles( QList<QgsConditionalStyle> styles, QVariant value, QgsFeature* feature );
static QList<QgsConditionalStyle> matchingConditionalStyles( QList<QgsConditionalStyle> styles, QVariant value, QgsExpressionContext& context );
/**
* @brief Find and return the matching style for the value and feature.
@ -133,7 +194,7 @@ class QgsConditionalStyle
* @return A condtional style that matches the value and feature.
* Check with QgsCondtionalStyle::isValid()
*/
static QgsConditionalStyle matchingConditionalStyle( QList<QgsConditionalStyle> styles, QVariant value, QgsFeature* feature );
static QgsConditionalStyle matchingConditionalStyle( QList<QgsConditionalStyle> styles, QVariant value, QgsExpressionContext& context );
/**
* @brief Compress a list of styles into a single style. This can be used to stack the elements of the

View File

@ -1,36 +0,0 @@
/** \class QgsFieldUIProperties
* \ingroup core
* Holds extra UI properties for a field.
*
* Currently this object holds information about conditional styles but in future will hold
* things like field widgets, etc
*/
class QgsFieldUIProperties
{
%TypeHeaderCode
#include <qgsfielduiproperties.h>
%End
public:
QgsFieldUIProperties();
/**
* @brief Set the conditional styles for the field UI properties.
* @param styles
*/
void setConditionalStyles( QList<QgsConditionalStyle> styles );
/**
* @brief Returns the conditional styles set for the field UI properties
* @return A list of conditional styles that have been set.
*/
const QList<QgsConditionalStyle> conditionalStyles();
/** Reads field ui properties specific state from Dom node.
*/
virtual bool readXml( const QDomNode& node );
/** Write field ui properties specific state from Dom node.
*/
virtual bool writeXml( QDomNode & node, QDomDocument & doc ) const;
};

View File

@ -1243,22 +1243,13 @@ class QgsVectorLayer : QgsMapLayer
bool simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const;
/**
* @brief Return the field properties that have been set for the given field.
* Field UI properties hold extra UI information for a field that can be used in the UI.
* @param fieldName The field name to get the field properties for.
* @return Return the UI properties set for the field. Returns a new QgsFieldUIProperties if
* none is currently set for the field.
* @brief Return the conditional styles that are set for this layer. Style information is
* used to render conditional formatting in the attribute table.
* @return Return a \class QgsConditionalLayerStyles object holding the conditional attribute
* style information. Style information is generic and can be used for anything.
* @note added in QGIS 2.12
*/
QgsFieldUIProperties fieldUIProperties( QString fieldName );
/**
* @brief Set the the field UI properties for a given field.
* @param fieldName The field name.
* @param props The properties to assign to a field.
* @note added in QGIS 2.12
*/
void setFieldUIProperties( QString fieldName, QgsFieldUIProperties props );
QgsConditionalLayerStyles *conditionalStyles() const;
public slots:
/**

View File

@ -58,6 +58,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../core
${CMAKE_CURRENT_SOURCE_DIR}/../core/geometry
${CMAKE_CURRENT_SOURCE_DIR}/../core/raster
${CMAKE_CURRENT_SOURCE_DIR}/../core/symbology-ng
${CMAKE_CURRENT_SOURCE_DIR}/../gui
${CMAKE_CURRENT_SOURCE_DIR}/../gui/attributetable
${CMAKE_CURRENT_SOURCE_DIR}/../gui/editorwidgets

View File

@ -26,6 +26,7 @@
#include "qgsencodingfiledialog.h"
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
#include "qgsconditionalstyle.h"
#include "qgsmaplayerregistry.h"
#include "qgsproviderregistry.h"
#include "qgsvectorlayer.h"

View File

@ -102,7 +102,6 @@ SET(QGIS_CORE_SRCS
qgsfeaturerequest.cpp
qgsfeaturestore.cpp
qgsfield.cpp
qgsfielduiproperties.cpp
qgsfontutils.cpp
qgsgeometrycache.cpp
qgsgeometrysimplifier.cpp
@ -546,7 +545,6 @@ SET(QGIS_CORE_HDRS
qgsfeaturerequest.h
qgsfeaturestore.h
qgsfield.h
qgsfielduiproperties.h
qgsfield_p.h
qgsfontutils.h
qgsgeometrycache.h

View File

@ -6,14 +6,113 @@
#include "qgssymbollayerv2utils.h"
#include "qgsmarkersymbollayerv2.h"
QgsConditionalLayerStyles::QgsConditionalLayerStyles()
: mRowStyles( QList<QgsConditionalStyle>() )
{}
QList<QgsConditionalStyle> QgsConditionalLayerStyles::rowStyles()
{
return mRowStyles;
}
void QgsConditionalLayerStyles::setRowStyles( QList<QgsConditionalStyle> styles )
{
mRowStyles = styles;
}
void QgsConditionalLayerStyles::setFieldStyles( QString fieldName, QList<QgsConditionalStyle> styles )
{
mFieldStyles.insert( fieldName, styles );
}
QList<QgsConditionalStyle> QgsConditionalLayerStyles::fieldStyles( QString fieldName )
{
if ( mFieldStyles.contains( fieldName ) )
{
return mFieldStyles[fieldName];
}
return QList<QgsConditionalStyle>();
}
bool QgsConditionalLayerStyles::writeXml( QDomNode &node, QDomDocument &doc ) const
{
QDomElement stylesel = doc.createElement( "conditionalstyles" );
QDomElement rowel = doc.createElement( "rowstyles" );
foreach ( QgsConditionalStyle style, mRowStyles )
{
style.writeXml( rowel, doc );
}
stylesel.appendChild( rowel );
QDomElement fieldsel = doc.createElement( "fieldstyles" );
foreach ( const QString field, mFieldStyles.keys() )
{
QDomElement fieldel = doc.createElement( "fieldstyle" );
fieldel.setAttribute( "fieldname", field );
QgsConditionalStyles styles = mFieldStyles[field];
foreach ( QgsConditionalStyle style, styles )
{
style.writeXml( fieldel, doc );
}
fieldsel.appendChild( fieldel );
}
stylesel.appendChild( fieldsel );
node.appendChild( stylesel );
return true;
}
bool QgsConditionalLayerStyles::readXml( const QDomNode &node )
{
QDomElement condel = node.firstChildElement( "conditionalstyles" );
mRowStyles.clear();
mFieldStyles.clear();
QDomElement rowstylesel = condel.firstChildElement( "rowstyles" );
QDomNodeList nodelist = rowstylesel.toElement().elementsByTagName( "style" );
for ( int i = 0;i < nodelist.count(); i++ )
{
QDomElement styleElm = nodelist.at( i ).toElement();
QgsConditionalStyle style = QgsConditionalStyle();
style.readXml( styleElm );
mRowStyles.append( style );
}
QDomElement fieldstylesel = condel.firstChildElement( "fieldstyles" );
nodelist = fieldstylesel.toElement().elementsByTagName( "fieldstyle" );
QList<QgsConditionalStyle> styles;
for ( int i = 0;i < nodelist.count(); i++ )
{
styles.clear();
QDomElement fieldel = nodelist.at( i ).toElement();
QString fieldName = fieldel.attribute( "fieldname" );
QDomNodeList stylenodelist = fieldel.toElement().elementsByTagName( "style" );
for ( int i = 0;i < stylenodelist.count(); i++ )
{
QDomElement styleElm = stylenodelist.at( i ).toElement();
QgsConditionalStyle style = QgsConditionalStyle();
style.readXml( styleElm );
styles.append( style );
}
mFieldStyles.insert( fieldName, styles );
}
return true;
}
QgsConditionalStyle::QgsConditionalStyle()
: mValid( false )
, mSymbol( 0 )
, mBackColor( QColor( 0, 0, 0, 0 ) )
, mTextColor( Qt::black )
{}
QgsConditionalStyle::QgsConditionalStyle( QString rule )
: mValid( false )
, mSymbol( 0 )
, mBackColor( QColor( 0, 0, 0, 0 ) )
, mTextColor( Qt::black )
{
setRule( rule );
}
@ -91,7 +190,7 @@ QPixmap QgsConditionalStyle::renderPreview()
QPainter painter( &pixmap );
if ( mBackColor.isValid() )
if ( validBackgroundColor() )
painter.setBrush( mBackColor );
QRect rect = QRect( 0, 0, 64, 32 );
@ -99,7 +198,7 @@ QPixmap QgsConditionalStyle::renderPreview()
painter.drawRect( rect );
painter.drawPixmap( 8, 8, icon() );
if ( mTextColor.isValid() )
if ( validTextColor() )
painter.setPen( mTextColor );
else
painter.setPen( Qt::black );
@ -113,22 +212,32 @@ QPixmap QgsConditionalStyle::renderPreview()
return pixmap;
}
QList<QgsConditionalStyle> QgsConditionalStyle::matchingConditionalStyles( QList<QgsConditionalStyle> styles, QVariant value, QgsFeature *feature )
bool QgsConditionalStyle::validBackgroundColor() const
{
return ( backgroundColor().isValid() && backgroundColor().alpha() != 0 );
}
bool QgsConditionalStyle::validTextColor() const
{
return ( textColor().isValid() && textColor().alpha() != 0 );
}
QList<QgsConditionalStyle> QgsConditionalStyle::matchingConditionalStyles( QList<QgsConditionalStyle> styles, QVariant value, QgsExpressionContext& context )
{
QList<QgsConditionalStyle> matchingstyles;
foreach ( QgsConditionalStyle style, styles )
{
if ( style.matches( value, feature ) )
if ( style.matches( value, context ) )
matchingstyles.append( style );
}
return matchingstyles;
}
QgsConditionalStyle QgsConditionalStyle::matchingConditionalStyle( QList<QgsConditionalStyle> styles, QVariant value, QgsFeature *feature )
QgsConditionalStyle QgsConditionalStyle::matchingConditionalStyle( QList<QgsConditionalStyle> styles, QVariant value, QgsExpressionContext& context )
{
foreach ( QgsConditionalStyle style, styles )
{
if ( style.matches( value, feature ) )
if ( style.matches( value, context ) )
return style;
}
return QgsConditionalStyle();

View File

@ -10,6 +10,55 @@
#include "qgsfeature.h"
#include "qgssymbolv2.h"
class QgsConditionalStyle;
typedef QList<QgsConditionalStyle> QgsConditionalStyles;
/**
* @brief The QgsConditionalLayerStyles class holds conditional style information
* for a layer. This includes field styles and full row styles.
*/
class CORE_EXPORT QgsConditionalLayerStyles
{
public:
QgsConditionalLayerStyles();
QList<QgsConditionalStyle> rowStyles();
/**
* @brief Set the conditional styles that apply to full rows of data in the attribute table.
* Each row will check be checked against each rule.
* @param styles The styles to assign to all the rows
* @note added in QGIS 2.12
*/
void setRowStyles( QList<QgsConditionalStyle> styles );
/**
* @brief Set the conditional styles for the field UI properties.
* @param styles
*/
void setFieldStyles( QString fieldName, QList<QgsConditionalStyle> styles );
/**
* @brief Returns the conditional styles set for the field UI properties
* @return A list of conditional styles that have been set.
*/
QList<QgsConditionalStyle> fieldStyles( QString fieldName );
/** Reads field ui properties specific state from Dom node.
*/
virtual bool readXml( const QDomNode& node );
/** Write field ui properties specific state from Dom node.
*/
virtual bool writeXml( QDomNode & node, QDomDocument & doc ) const;
private:
QHash<QString, QgsConditionalStyles> mFieldStyles;
QList<QgsConditionalStyle> mRowStyles;
};
/** \class QgsFieldFormat
* Conditional styling for a rule.
*/
@ -104,11 +153,25 @@ class CORE_EXPORT QgsConditionalStyle
*/
QColor textColor() const { return mTextColor; }
/**
* @brief Check if the text color is valid for render.
* Valid colors are non invalid QColors and a color with a > 0 alpha
* @return True of the color set for text is valid.
*/
bool validTextColor() const;
/**
* @brief The background color for style
* @return QColor for background color
*/
QColor backgroundColor() const { return mBackColor; }
/**
* @brief Check if the background color is valid for render.
* Valid colors are non invalid QColors and a color with a > 0 alpha
* @return True of the color set for background is valid.
*/
bool validBackgroundColor() const;
/**
* @brief The font for the style
* @return QFont for the style
@ -136,7 +199,7 @@ class CORE_EXPORT QgsConditionalStyle
* @return A condtional style that matches the value and feature.
* Check with QgsCondtionalStyle::isValid()
*/
static QList<QgsConditionalStyle> matchingConditionalStyles( QList<QgsConditionalStyle> styles, QVariant value, QgsFeature* feature );
static QList<QgsConditionalStyle> matchingConditionalStyles( QList<QgsConditionalStyle> styles, QVariant value, QgsExpressionContext& context );
/**
* @brief Find and return the matching style for the value and feature.
@ -145,7 +208,7 @@ class CORE_EXPORT QgsConditionalStyle
* @return A condtional style that matches the value and feature.
* Check with QgsCondtionalStyle::isValid()
*/
static QgsConditionalStyle matchingConditionalStyle( QList<QgsConditionalStyle> styles, QVariant value, QgsFeature* feature );
static QgsConditionalStyle matchingConditionalStyle( QList<QgsConditionalStyle> styles, QVariant value, QgsExpressionContext& context );
/**
* @brief Compress a list of styles into a single style. This can be used to stack the elements of the

View File

@ -1,46 +0,0 @@
#include <QDomElement>
#include "qgsconditionalstyle.h"
#include "qgsfielduiproperties.h"
QgsFieldUIProperties::QgsFieldUIProperties()
: mStyles( QList<QgsConditionalStyle>() )
{}
void QgsFieldUIProperties::setConditionalStyles( QList<QgsConditionalStyle> styles )
{
mStyles = styles;
}
QList<QgsConditionalStyle> QgsFieldUIProperties::conditionalStyles()
{
return mStyles;
}
bool QgsFieldUIProperties::writeXml( QDomNode &node, QDomDocument &doc ) const
{
QDomElement stylesel = doc.createElement( "conditionalstyles" );
foreach ( QgsConditionalStyle style, mStyles )
{
style.writeXml( stylesel, doc );
}
node.appendChild( stylesel );
return true;
}
bool QgsFieldUIProperties::readXml( const QDomNode &node )
{
mStyles.clear();
QDomElement condel = node.firstChildElement( "conditionalstyles" );
QDomNodeList stylesList = condel.elementsByTagName( "style" );
for ( int i = 0; i < stylesList.size(); ++i )
{
QDomElement styleElm = stylesList.at( i ).toElement();
QgsConditionalStyle style = QgsConditionalStyle();
style.readXml( styleElm );
mStyles.append( style );
}
return true;
}

View File

@ -1,47 +0,0 @@
#ifndef QGSFIELDUIPROPERTIES_H
#define QGSFIELDUIPROPERTIES_H
#include <QDomDocument>
#include <QDomNode>
#include "qgsfeature.h"
#include "qgsconditionalstyle.h"
/** \class QgsFieldUIProperties
* Holds extra UI properties for a field.
*
* Currently this object holds information about conditional styles but in future will hold
* things like field widgets, etc
*
* TODO Move UI field related stuff from QgsVectorLayer here
*/
class CORE_EXPORT QgsFieldUIProperties
{
public:
QgsFieldUIProperties();
/**
* @brief Set the conditional styles for the field UI properties.
* @param styles
*/
void setConditionalStyles( QList<QgsConditionalStyle> styles );
/**
* @brief Returns the conditional styles set for the field UI properties
* @return A list of conditional styles that have been set.
*/
QList<QgsConditionalStyle> conditionalStyles();
/** Reads field ui properties specific state from Dom node.
*/
virtual bool readXml( const QDomNode& node );
/** Write field ui properties specific state from Dom node.
*/
virtual bool writeXml( QDomNode & node, QDomDocument & doc ) const;
private:
QList<QgsConditionalStyle> mStyles;
};
#endif // QGSFIELDUIPROPERTIES_H

View File

@ -38,6 +38,7 @@
#include "qgis.h" //for globals
#include "qgsapplication.h"
#include "qgsclipper.h"
#include "qgsconditionalstyle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransform.h"
#include "qgsdatasourceuri.h"
@ -45,7 +46,6 @@
#include "qgsfeature.h"
#include "qgsfeaturerequest.h"
#include "qgsfield.h"
#include "qgsfielduiproperties.h"
#include "qgsgeometrycache.h"
#include "qgsgeometry.h"
#include "qgslabel.h"
@ -148,6 +148,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
, mEditCommandActive( false )
{
mActions = new QgsAttributeAction( this );
mConditionalStyles = new QgsConditionalLayerStyles();
// if we're given a provider type, try to create and bind one to this layer
if ( ! mProviderKey.isEmpty() )
@ -188,6 +189,7 @@ QgsVectorLayer::~QgsVectorLayer()
delete mActions;
delete mRendererV2;
delete mConditionalStyles;
}
QString QgsVectorLayer::storageType() const
@ -897,6 +899,11 @@ bool QgsVectorLayer::simplifyDrawingCanbeApplied( const QgsRenderContext& render
return false;
}
QgsConditionalLayerStyles* QgsVectorLayer::conditionalStyles() const
{
return mConditionalStyles;
}
QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
{
if ( !mDataProvider )
@ -1322,18 +1329,6 @@ bool QgsVectorLayer::readXml( const QDomNode& layer_node )
readStyleManager( layer_node );
mFieldProperties.clear();
QDomNodeList nodeList = layer_node.toElement().elementsByTagName( "fielduiproperty" );
for ( int i = 0;i < nodeList.count(); i++ )
{
QDomElement propElm = nodeList.at( i ).toElement();
QString fieldName = propElm.attribute( "fieldname" );
QgsDebugMsg( "FIELDS!!" );
QgsDebugMsg( fieldName );
QgsFieldUIProperties props = QgsFieldUIProperties();
props.readXml( propElm );
setFieldUIProperties( fieldName, props );
}
setLegend( QgsMapLayerLegend::defaultVectorLegend( this ) );
@ -1528,19 +1523,6 @@ bool QgsVectorLayer::writeXml( QDomNode & layer_node,
writeStyleManager( layer_node, document );
QDomElement properties = document.createElement( "fielduiproperties" );
QHash<QString, QgsFieldUIProperties>::iterator props;
for ( props = mFieldProperties.begin(); props != mFieldProperties.end(); ++props )
{
QDomElement fielduipropel = document.createElement( "fielduiproperty" );
fielduipropel.setAttribute( "fieldname", props.key() );
QgsFieldUIProperties property = props.value();
property.writeXml( fielduipropel, document );
properties.appendChild( fielduipropel );
}
layer_node.appendChild( properties );
// renderer specific settings
QString errorMsg;
return writeSymbology( layer_node, document, errorMsg );
@ -1791,6 +1773,8 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
mAttributeEditorElements.append( attributeEditorWidget );
}
conditionalStyles()->readXml( node );
return true;
}
@ -2032,33 +2016,11 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
// add attribute actions
mActions->writeXML( node, doc );
mConditionalStyles->writeXml( node, doc );
return true;
}
QgsFieldUIProperties QgsVectorLayer::fieldUIProperties( QString fieldName )
{
if ( mFieldProperties.contains( fieldName ) )
{
return mFieldProperties[fieldName];
}
return QgsFieldUIProperties();
}
QList<QgsConditionalStyle> QgsVectorLayer::rowStyles()
{
return mRowStyles;
}
void QgsVectorLayer::setRowStyles( QList<QgsConditionalStyle> styles )
{
mRowStyles = styles;
}
void QgsVectorLayer::setFieldUIProperties( QString fieldName, QgsFieldUIProperties props )
{
mFieldProperties.insert( fieldName, props );
}
bool QgsVectorLayer::readSld( const QDomNode& node, QString& errorMessage )
{
// get the Name element

View File

@ -27,7 +27,6 @@
#include "qgis.h"
#include "qgsmaplayer.h"
#include "qgsconditionalstyle.h"
#include "qgsfeature.h"
#include "qgsfeatureiterator.h"
#include "qgseditorwidgetconfig.h"
@ -41,7 +40,7 @@ class QImage;
class QgsAbstractGeometrySimplifier;
class QgsAttributeAction;
class QgsFieldUIProperties;
class QgsConditionalLayerStyles;
class QgsCoordinateTransform;
class QgsDiagramLayerSettings;
class QgsDiagramRendererV2;
@ -1756,32 +1755,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
bool simplifyDrawingCanbeApplied( const QgsRenderContext& renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint ) const;
/**
* @brief Return the field properties that have been set for the given field.
* Field UI properties hold extra UI information for a field that can be used in the UI.
* @param fieldName The field name to get the field properties for.
* @return Return the UI properties set for the field. Returns a new QgsFieldUIProperties if
* none is currently set for the field.
* @brief Return the conditional styles that are set for this layer. Style information is
* used to render conditional formatting in the attribute table.
* @return Return a \class QgsConditionalLayerStyles object holding the conditional attribute
* style information. Style information is generic and can be used for anything.
* @note added in QGIS 2.12
*/
QgsFieldUIProperties fieldUIProperties( QString fieldName );
QList<QgsConditionalStyle> rowStyles();
/**
* @brief Set the conditional styles that apply to full rows of data in the attribute table.
* Each row will check be checked against each rule.
* @param styles The styles to assign to all the rows
* @note added in QGIS 2.12
*/
void setRowStyles( QList<QgsConditionalStyle> styles );
/**
* @brief Set the the field UI properties for a given field.
* @param fieldName The field name.
* @param props The properties to assign to a field.
* @note added in QGIS 2.12
*/
void setFieldUIProperties( QString fieldName, QgsFieldUIProperties props );
QgsConditionalLayerStyles *conditionalStyles() const;
public slots:
/**
@ -2036,8 +2016,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
private: // Private attributes
QHash<QString, QgsFieldUIProperties> mFieldProperties;
QList<QgsConditionalStyle> mRowStyles;
QgsConditionalLayerStyles * mConditionalStyles;
/** Pointer to data provider derived from the abastract base class QgsDataProvider */
QgsVectorDataProvider *mDataProvider;

View File

@ -21,7 +21,6 @@
#include "qgseditorwidgetregistry.h"
#include "qgsexpression.h"
#include "qgsconditionalstyle.h"
#include "qgsfielduiproperties.h"
#include "qgsfield.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
@ -595,39 +594,39 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
}
if ( role == Qt::BackgroundColorRole || role == Qt::TextColorRole || role == Qt::DecorationRole || role == Qt::FontRole )
{
mExpressionContext.setFeature( mFeat );
QList<QgsConditionalStyle> styles;
if ( mRowStylesMap.contains( index.row() ) )
{
mExpressionContext.setFeature( mFeat );
QList<QgsConditionalStyle> styles;
if ( mRowStylesMap.contains( index.row() ) )
{
styles = mRowStylesMap[index.row()];
}
else
{
styles = QgsConditionalStyle::matchingConditionalStyles( layer()->rowStyles(), QVariant(), &mFeat );
mRowStylesMap.insert( index.row(), styles );
}
QgsConditionalStyle rowstyle = QgsConditionalStyle::compressStyles( styles );
QgsFieldUIProperties props = layer()->fieldUIProperties( field.name() );
styles = QgsConditionalStyle::matchingConditionalStyles( props.conditionalStyles(), val, &mFeat );
styles.insert( 0, rowstyle );
QgsConditionalStyle style = QgsConditionalStyle::compressStyles( styles );
if ( style.isValid() )
{
if ( role == Qt::BackgroundColorRole && style.backgroundColor().isValid() )
return style.backgroundColor();
if ( role == Qt::TextColorRole && style.textColor().isValid() )
return style.textColor();
if ( role == Qt::DecorationRole )
return style.icon();
if ( role == Qt::FontRole )
return style.font();
}
styles = mRowStylesMap[index.row()];
}
else
{
styles = QgsConditionalStyle::matchingConditionalStyles( layer()->conditionalStyles()->rowStyles(), QVariant(), mExpressionContext );
mRowStylesMap.insert( index.row(), styles );
}
QgsConditionalStyle rowstyle = QgsConditionalStyle::compressStyles( styles );
styles = layer()->conditionalStyles()->fieldStyles( field.name() );
styles = QgsConditionalStyle::matchingConditionalStyles( styles , val, mExpressionContext );
styles.insert( 0, rowstyle );
QgsConditionalStyle style = QgsConditionalStyle::compressStyles( styles );
if ( style.isValid() )
{
if ( role == Qt::BackgroundColorRole && style.validBackgroundColor() )
return style.backgroundColor();
if ( role == Qt::TextColorRole && style.validTextColor() )
return style.textColor();
if ( role == Qt::DecorationRole )
return style.icon();
if ( role == Qt::FontRole )
return style.font();
}
}
return val;
}

View File

@ -26,6 +26,7 @@
#include "qgsvectorlayer.h" // QgsAttributeList
#include "qgsvectorlayercache.h"
#include "qgsconditionalstyle.h"
#include "qgsattributeeditorcontext.h"
class QgsMapCanvas;

View File

@ -1,7 +1,6 @@
#include "qgsfieldconditionalformatwidget.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsfielduiproperties.h"
#include "qgssymbolv2.h"
#include "qgssymbolv2selectordialog.h"
#include "qgssymbollayerv2utils.h"
@ -143,12 +142,11 @@ QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::getStyles()
QList<QgsConditionalStyle> styles;
if ( fieldRadio->isChecked() )
{
QgsFieldUIProperties props = mLayer->fieldUIProperties( mFieldCombo->currentField() );
styles = props.conditionalStyles();
styles = mLayer->conditionalStyles()->fieldStyles( mFieldCombo->currentField() );
}
if ( rowRadio->isChecked() )
{
styles = mLayer->rowStyles();
styles = mLayer->conditionalStyles()->rowStyles();
}
return styles;
}
@ -160,14 +158,12 @@ void QgsFieldConditionalFormatWidget::deleteRule()
QString fieldName;
if ( fieldRadio->isChecked() )
{
QgsFieldUIProperties props = mLayer->fieldUIProperties( mFieldCombo->currentField() );
props.setConditionalStyles( styles );
mLayer->setFieldUIProperties( mFieldCombo->currentField(), props );
fieldName = mFieldCombo->currentField();
mLayer->conditionalStyles()->setFieldStyles( fieldName, styles );
}
if ( rowRadio->isChecked() )
{
mLayer->setRowStyles( styles );
mLayer->conditionalStyles()->setRowStyles( styles );
}
pages->setCurrentIndex( 0 );
@ -204,6 +200,8 @@ void QgsFieldConditionalFormatWidget::reset()
mEditing = false;
checkIcon->setChecked( false );
btnChangeIcon->setIcon( QIcon() );
btnBackgroundColor->setToNoColor();
btnTextColor->setToNoColor();
mFontBoldBtn->setChecked( false );
mFontItalicBtn->setChecked( false );
@ -261,16 +259,7 @@ QList<QgsConditionalStyle> QgsFieldConditionalFormatWidget::defaultPresets() con
void QgsFieldConditionalFormatWidget::saveRule()
{
QList<QgsConditionalStyle> styles;
if ( fieldRadio->isChecked() )
{
QgsFieldUIProperties props = mLayer->fieldUIProperties( mFieldCombo->currentField() );
styles = props.conditionalStyles();
}
if ( rowRadio->isChecked() )
{
styles = mLayer->rowStyles();
}
QList<QgsConditionalStyle> styles = getStyles();
QgsConditionalStyle style = QgsConditionalStyle();
@ -308,14 +297,12 @@ void QgsFieldConditionalFormatWidget::saveRule()
QString fieldName;
if ( fieldRadio->isChecked() )
{
QgsFieldUIProperties props = QgsFieldUIProperties();
props.setConditionalStyles( styles );
mLayer->setFieldUIProperties( mFieldCombo->currentField(), props );
fieldName = mFieldCombo->currentField();
mLayer->conditionalStyles()->setFieldStyles( fieldName, styles );
}
if ( rowRadio->isChecked() )
{
mLayer->setRowStyles( styles );
mLayer->conditionalStyles()->setRowStyles( styles );
}
pages->setCurrentIndex( 0 );
reloadStyles();

View File

@ -634,8 +634,24 @@
<y>27</y>
</hint>
<hint type="destinationlabel">
<x>178</x>
<y>32</y>
<x>102</x>
<y>48</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkIcon</sender>
<signal>toggled(bool)</signal>
<receiver>btnChangeIcon</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>48</x>
<y>215</y>
</hint>
<hint type="destinationlabel">
<x>76</x>
<y>215</y>
</hint>
</hints>
</connection>
@ -646,6 +662,5 @@
<bool>false</bool>
</property>
</buttongroup>
<buttongroup name="mDefaultButtons"/>
</buttongroups>
</ui>