Skip to content

Commit

Permalink
Merge pull request #3351 from nyalldawson/feature_geom
Browse files Browse the repository at this point in the history
QgsFields cleanup
  • Loading branch information
nyalldawson committed Aug 4, 2016
2 parents 23909a1 + c40d6d3 commit 00a8fea
Show file tree
Hide file tree
Showing 76 changed files with 298 additions and 307 deletions.
29 changes: 29 additions & 0 deletions doc/api_break.dox
Expand Up @@ -233,6 +233,13 @@ instead.</li>
be returned in place of a null pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsDiagram QgsDiagram

<ul>
<li>The deprecated getExpression( const QString& expression, const QgsFields* fields ) method has been removed.
Use the variant which accepts an expression context instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsDiagramLayerSettings QgsDiagramLayerSettings

<ul>
Expand All @@ -255,6 +262,7 @@ a feature has a geometry is now done using the new hasGeometry() method. Any cod
None will need to be modified, as the method will return an empty geometry if the feature has no geometry.</b></li>
<li>The temporary constGeometry() method has been removed. Use geometry() instead.</li>
<li>setFields( const QgsFields*, bool ) has been removed, use setFields( const QgsFields&, bool ) instead.</li>
<li>fields() no longer returns a pointer, but instead a QgsFields value.</li>
</ul>

\subsection qgis_api_break_3_0_QgsFeatureRendererV2 QgsFeatureRendererV2
Expand All @@ -263,6 +271,12 @@ None will need to be modified, as the method will return an empty geometry if th
<li>The method capabilities() returns QgsFeatureRendererV2::Capabilities flags instead of an integer. The two are binary compatible.
</ul>

\subsection qgis_api_break_3_0_QgsFields QgsFields

<ul>
<li>All const methods which return a field from QgsFields now return a QgsField value, not a reference.</li>
</ul>

\subsection qgis_api_break_3_0_QgsGeometry QgsGeometry

<ul>
Expand Down Expand Up @@ -523,6 +537,21 @@ be returned instead of a null pointer if no transformation is required.</li>
<li>The OutputUnit enum, including QgsSymbolV2::MM, QgsSymbolV2::MapUnit, QgsSymbolV2::Mixed, QgsSymbolV2::Pixel and QgsSymbolV2::Percentage has been moved to QgsUnitTypes
and renamed to RenderUnit. QgsSymbolV2::OutputUnitList was renamed to QgsUnitTypes::RenderUnitList. All methods which previously accepted QgsSymbolV2::OutputUnit
parameters or QgsSymbolV2::OutputUnitList parameters now take QgsUnitTypes::RenderUnit or QgsUnitTypes::RenderUnitList parameters respectively.</li>
<li>startRender() now accepts a QgsFields reference, not a pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsSymbolLayerV2 QgsSymbolLayerV2

<ul>
<li>The deprecated prepareExpressions( const QgsFields* fields, double scale = -1.0 ) method has been removed. Use
the variant which takes QgsSymbolV2RenderContext instead.</li>
</ul>

\subsection qgis_api_break_3_0_QgsSymbolV2RenderContext QgsSymbolV2RenderContext

<ul>
<li>The constructor now accepts a QgsFields reference, not a pointer.</li>
<li>fields() now returns a QgsFields value, not a pointer.</li>
</ul>

\subsection qgis_api_break_3_0_QgsSymbolLayerV2Utils QgsSymbolLayerV2Utils
Expand Down
3 changes: 0 additions & 3 deletions python/core/diagram/qgsdiagram.sip
Expand Up @@ -11,9 +11,6 @@ class QgsDiagram

void clearCache();

//! @deprecated use QgsExpressionContext variant instead
QgsExpression* getExpression( const QString& expression, const QgsFields* fields ) /Deprecated/;

/** Returns a prepared expression for the specified context.
* @param expression expression string
* @param context expression context
Expand Down
3 changes: 1 addition & 2 deletions python/core/qgsfeature.sip
Expand Up @@ -361,9 +361,8 @@ class QgsFeature

/** Returns the field map associated with the feature.
* @see setFields
* TODO: QGIS 3 - return value, not pointer
*/
const QgsFields* fields() const;
QgsFields fields() const;

/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
* Field map must be associated using @link setFields @endlink before this method can be used.
Expand Down
6 changes: 3 additions & 3 deletions python/core/qgsfield.sip
Expand Up @@ -262,7 +262,7 @@ class QgsFields
%End

//! Get field at particular index (must be in range 0..N-1)
const QgsField& at( int i ) const /Factory/;
QgsField at( int i ) const /Factory/;
%MethodCode
if ( a0 < 0 || a0 >= sipCpp->count() )
{
Expand All @@ -276,7 +276,7 @@ class QgsFields
%End

//! Get field at particular index (must be in range 0..N-1)
const QgsField& field( int fieldIdx ) const /Factory/;
QgsField field( int fieldIdx ) const /Factory/;
%MethodCode
if ( a0 < 0 || a0 >= sipCpp->count() )
{
Expand All @@ -290,7 +290,7 @@ class QgsFields
%End

//! Get field at particular index (must be in range 0..N-1)
const QgsField& field( const QString& name ) const /Factory/;
QgsField field( const QString& name ) const /Factory/;
%MethodCode
int fieldIdx = sipCpp->indexFromName(*a0);
if (fieldIdx == -1)
Expand Down
8 changes: 0 additions & 8 deletions python/core/symbology-ng/qgssymbollayerv2.sip
Expand Up @@ -301,14 +301,6 @@ class QgsSymbolLayerV2
protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );

/** Prepares all data defined property expressions for evaluation. This should
* be called prior to evaluating data defined properties.
* @param fields associated layer fields
* @param scale map scale
* @deprecated use variant which takes QgsSymbolV2RenderContext instead
*/
virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 ) /Deprecated/;

/** Prepares all data defined property expressions for evaluation. This should
* be called prior to evaluating data defined properties.
* @param context symbol render context
Expand Down
23 changes: 19 additions & 4 deletions python/core/symbology-ng/qgssymbolv2.sip
Expand Up @@ -110,7 +110,21 @@ class QgsSymbolV2
//! delete layer at specified index and set a new one
bool changeSymbolLayer( int index, QgsSymbolLayerV2 *layer /Transfer/ );

void startRender( QgsRenderContext& context, const QgsFields* fields = 0 );
/** Begins the rendering process for the symbol. This must be called before renderFeature(),
* and should be followed by a call to stopRender().
* @param context render context which symbol will be drawn using
* @param fields fields for features to be rendered (usually the associated
* vector layer's fields). Required for correct calculation of data defined
* overrides.
* @see stopRender()
*/
void startRender( QgsRenderContext& context, const QgsFields& fields = QgsFields() );

/** Ends the rendering process. This should be called after rendering all desired features.
* @param context render context, must match the context specified when startRender()
* was called.
* @see startRender()
*/
void stopRender( QgsRenderContext& context );

void setColor( const QColor& color );
Expand Down Expand Up @@ -205,7 +219,8 @@ class QgsSymbolV2
const QgsVectorLayer* layer() const;

/**
* Render a feature.
* Render a feature. Before calling this the startRender() method should be called to initialise
* the rendering process. After rendering all features stopRender() must be called.
*/
void renderFeature( const QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false, int currentVertexMarkerType = 0, int currentVertexMarkerSize = 0 );

Expand Down Expand Up @@ -292,7 +307,7 @@ class QgsSymbolV2RenderContext
* @param fields
* @param mapUnitScale
*/
QgsSymbolV2RenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields* fields = 0, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
QgsSymbolV2RenderContext( QgsRenderContext& c, QgsUnitTypes::RenderUnit u, qreal alpha = 1.0, bool selected = false, int renderHints = 0, const QgsFeature* f = 0, const QgsFields& fields = QgsFields(), const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() );
~QgsSymbolV2RenderContext();

QgsRenderContext& renderContext();
Expand Down Expand Up @@ -333,7 +348,7 @@ class QgsSymbolV2RenderContext
//! to allow symbols with data-defined properties prepare the expressions
//! (other times fields() returns null)
//! @note added in 2.4
const QgsFields* fields() const;
QgsFields fields() const;

/** Part count of current geometry
* @note added in QGIS 2.16
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgsoverlayanalyzer.cpp
Expand Up @@ -192,7 +192,7 @@ void QgsOverlayAnalyzer::combineFieldLists( QgsFields& fieldListA, const QgsFiel

for ( int idx = 0; idx < fieldListB.count(); ++idx )
{
QgsField field = fieldListB[idx];
QgsField field = fieldListB.at( idx );
int count = 0;
while ( names.contains( field.name() ) )
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -271,7 +271,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx

for ( int i = 0; i < mLayer->fields().size(); ++i )
{
const QgsField &fld = mLayer->fields().at( i );
QgsField fld = mLayer->fields().at( i );
Qt::ItemFlags flags = mLayer->providerType() != "oracle" || !fld.typeName().contains( "SDO_GEOMETRY" ) ? Qt::ItemIsEnabled : Qt::NoItemFlags;
QTableWidgetItem *item;
item = new QTableWidgetItem( fld.name() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -6848,7 +6848,7 @@ void QgisApp::mergeAttributesOfSelectedFeatures()
continue;

QVariant val = merged.at( i );
const QgsField &fld( vl->fields().at( i ) );
QgsField fld( vl->fields().at( i ) );
bool isDefaultValue = vl->fields().fieldOrigin( i ) == QgsFields::OriginProvider &&
vl->dataProvider() &&
vl->dataProvider()->defaultValue( vl->fields().fieldOriginIndex( i ) ) == val;
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsdecorationgrid.cpp
Expand Up @@ -232,7 +232,7 @@ void QgsDecorationGrid::render( QPainter * p )

QgsRenderContext context = QgsRenderContext::fromMapSettings( QgisApp::instance()->mapCanvas()->mapSettings() );
context.setPainter( p );
mLineSymbol->startRender( context, nullptr );
mLineSymbol->startRender( context );

for ( ; vIt != verticalLines.constEnd(); ++vIt )
{
Expand Down Expand Up @@ -310,7 +310,7 @@ void QgsDecorationGrid::render( QPainter * p )

QgsRenderContext context = QgsRenderContext::fromMapSettings( QgisApp::instance()->mapCanvas()->mapSettings() );
context.setPainter( p );
mMarkerSymbol->startRender( context, nullptr );
mMarkerSymbol->startRender( context );

QPointF intersectionPoint;
for ( ; vIt != verticalLines.constEnd(); ++vIt )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsdelattrdialog.cpp
Expand Up @@ -34,7 +34,7 @@ QgsDelAttrDialog::QgsDelAttrDialog( const QgsVectorLayer* vl )
const QgsFields& layerAttributes = vl->fields();
for ( int idx = 0; idx < layerAttributes.count(); ++idx )
{
QListWidgetItem* item = new QListWidgetItem( layerAttributes[idx].name(), listBox2 );
QListWidgetItem* item = new QListWidgetItem( layerAttributes.at( idx ).name(), listBox2 );
switch ( vl->fields().fieldOrigin( idx ) )
{
case QgsFields::OriginExpression:
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsdiagramproperties.cpp
Expand Up @@ -184,14 +184,14 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer,
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( mAttributesTreeWidget );
QString name = QString( "\"%1\"" ).arg( layerFields[idx].name() );
QString name = QString( "\"%1\"" ).arg( layerFields.at( idx ).name() );
newItem->setText( 0, name );
newItem->setData( 0, Qt::UserRole, name );
newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );

mDataDefinedXComboBox->addItem( layerFields[idx].name(), idx );
mDataDefinedYComboBox->addItem( layerFields[idx].name(), idx );
mDataDefinedVisibilityComboBox->addItem( layerFields[idx].name(), idx );
mDataDefinedXComboBox->addItem( layerFields.at( idx ).name(), idx );
mDataDefinedYComboBox->addItem( layerFields.at( idx ).name(), idx );
mDataDefinedVisibilityComboBox->addItem( layerFields.at( idx ).name(), idx );
}

const QgsDiagramRendererV2* dr = layer->diagramRenderer();
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfieldcalculator.cpp
Expand Up @@ -234,7 +234,7 @@ void QgsFieldCalculator::accept()

for ( int idx = 0; idx < fields.count(); ++idx )
{
if ( fields[idx].name() == mOutputFieldNameLineEdit->text() )
if ( fields.at( idx ).name() == mOutputFieldNameLineEdit->text() )
{
mAttributeId = idx;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsfieldsproperties.cpp
Expand Up @@ -576,7 +576,7 @@ void QgsFieldsProperties::attributeAdded( int idx )
const QgsFields &fields = mLayer->fields();
int row = mFieldsList->rowCount();
mFieldsList->insertRow( row );
setRow( row, idx, fields[idx] );
setRow( row, idx, fields.at( idx ) );
mFieldsList->setCurrentCell( row, idx );

for ( int i = idx + 1; i < mIndexedWidgets.count(); i++ )
Expand Down
14 changes: 7 additions & 7 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -493,7 +493,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
featItem->addChild( attrItem );

attrItem->setData( 0, Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
attrItem->setData( 0, Qt::UserRole, fields[i].name() );
attrItem->setData( 0, Qt::UserRole, fields.at( i ).name() );
attrItem->setData( 0, Qt::UserRole + 1, i );

attrItem->setData( 1, Qt::UserRole, value );
Expand All @@ -515,7 +515,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
attrItem->treeWidget()->setItemWidget( attrItem, 1, nullptr );
}

if ( fields[i].name() == vlayer->displayField() )
if ( fields.at( i ).name() == vlayer->displayField() )
{
featItem->setText( 0, attrItem->text( 0 ) );
featItem->setText( 1, attrItem->text( 1 ) );
Expand Down Expand Up @@ -560,11 +560,11 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
tblResults->setItem( j, 1, item );

item = new QTableWidgetItem( QString::number( i ) );
if ( fields[i].name() == vlayer->displayField() )
if ( fields.at( i ).name() == vlayer->displayField() )
item->setData( Qt::DisplayRole, vlayer->attributeDisplayName( i ) + " *" );
else
item->setData( Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
item->setData( Qt::UserRole, fields[i].name() );
item->setData( Qt::UserRole, fields.at( i ).name() );
item->setData( Qt::UserRole + 1, i );
tblResults->setItem( j, 2, item );

Expand Down Expand Up @@ -765,7 +765,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsRasterLayer *layer,

QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << attrs.at( i ).toString() );

attrItem->setData( 0, Qt::DisplayRole, fields[i].name() );
attrItem->setData( 0, Qt::DisplayRole, fields.at( i ).name() );

QVariant value = attrs.at( i );
attrItem->setData( 1, Qt::DisplayRole, value );
Expand Down Expand Up @@ -1188,7 +1188,7 @@ void QgsIdentifyResultsDialog::doAction( QTreeWidgetItem *item, int action )
const QgsFields& fields = layer->fields();
for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx )
{
if ( fields[fldIdx].name() == fieldName )
if ( fields.at( fldIdx ).name() == fieldName )
{
idx = fldIdx;
break;
Expand Down Expand Up @@ -1741,7 +1741,7 @@ void QgsIdentifyResultsDialog::copyFeatureAttributes()
if ( attrIdx < 0 || attrIdx >= fields.count() )
continue;

text += QString( "%1: %2\n" ).arg( fields[attrIdx].name(), it.value().toString() );
text += QString( "%1: %2\n" ).arg( fields.at( attrIdx ).name(), it.value().toString() );
}
}
else if ( rlayer )
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslabelpropertydialog.cpp
Expand Up @@ -103,7 +103,7 @@ void QgsLabelPropertyDialog::init( const QString& layerId, const QString& provid
{
mLabelTextLineEdit->setText( attributeValues.at( mCurLabelField ).toString() );
const QgsFields& layerFields = vlayer->fields();
switch ( layerFields[mCurLabelField].type() )
switch ( layerFields.at( mCurLabelField ).type() )
{
case QVariant::Double:
mLabelTextLineEdit->setValidator( new QDoubleValidator( this ) );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -358,7 +358,7 @@ QVariant QgsMergeAttributesDialog::calcStatistic( int col, QgsStatisticalSummary

if ( values.isEmpty() )
{
return QVariant( mVectorLayer->fields()[col].type() );
return QVariant( mVectorLayer->fields().at( col ).type() );
}

summary.calculate( values );
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposerattributetable.cpp
Expand Up @@ -241,7 +241,7 @@ void QgsComposerAttributeTable::setDisplayAttributes( const QSet<int>& attr, boo
}
QString currentAlias = mVectorLayer->attributeDisplayName( attrIdx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[attrIdx].name() );
col->setAttribute( fields.at( attrIdx ).name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
Expand Down Expand Up @@ -652,7 +652,7 @@ bool QgsComposerAttributeTable::readXml( const QDomElement& itemElem, const QDom
//find corresponding column
Q_FOREACH ( QgsComposerTableColumn* column, mColumns )
{
if ( column->attribute() == fields[attribute].name() )
if ( column->attribute() == fields.at( attribute ).name() )
{
column->setSortByRank( i + 1 );
column->setSortOrder( order );
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposerattributetablev2.cpp
Expand Up @@ -338,7 +338,7 @@ void QgsComposerAttributeTableV2::setDisplayAttributes( const QSet<int>& attr, b
}
QString currentAlias = source->attributeDisplayName( attrIdx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[attrIdx].name() );
col->setAttribute( fields.at( attrIdx ).name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
Expand Down
13 changes: 0 additions & 13 deletions src/core/diagram/qgsdiagram.cpp
Expand Up @@ -45,19 +45,6 @@ void QgsDiagram::clearCache()
mExpressions.clear();
}

QgsExpression* QgsDiagram::getExpression( const QString& expression, const QgsFields* fields )
{
Q_NOWARN_DEPRECATED_PUSH
if ( !mExpressions.contains( expression ) )
{
QgsExpression* expr = new QgsExpression( expression );
expr->prepare( *fields );
mExpressions[expression] = expr;
}
return mExpressions[expression];
Q_NOWARN_DEPRECATED_POP
}

QgsExpression *QgsDiagram::getExpression( const QString &expression, const QgsExpressionContext &context )
{
if ( !mExpressions.contains( expression ) )
Expand Down
3 changes: 0 additions & 3 deletions src/core/diagram/qgsdiagram.h
Expand Up @@ -42,9 +42,6 @@ class CORE_EXPORT QgsDiagram

void clearCache();

//! @deprecated use QgsExpressionContext variant instead
Q_DECL_DEPRECATED QgsExpression* getExpression( const QString& expression, const QgsFields* fields );

/** Returns a prepared expression for the specified context.
* @param expression expression string
* @param context expression context
Expand Down

0 comments on commit 00a8fea

Please sign in to comment.