Skip to content

Commit

Permalink
Add QgsVectorLayer::fields() as alias to pendingFields()
Browse files Browse the repository at this point in the history
pendingFields() is not very intuitive and leads to confusion for new developers.
  • Loading branch information
m-kuhn committed Aug 4, 2015
1 parent c27f357 commit e832b2a
Show file tree
Hide file tree
Showing 90 changed files with 304 additions and 294 deletions.
11 changes: 10 additions & 1 deletion python/core/qgsvectorlayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,16 @@ class QgsVectorLayer : QgsMapLayer
*
* @return A list of fields
*/
const QgsFields &pendingFields() const;
const QgsFields fields() const;

/**
* Returns the list of fields of this layer.
* This also includes fields which have not yet been saved to the provider.
* Alias for {@link fields()}
*
* @return A list of fields
*/
const QgsFields pendingFields() const;

/** Returns list of attributes */
QList<int> pendingAllAttributesList();
Expand Down
12 changes: 6 additions & 6 deletions src/analysis/vector/qgsgeometryanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool QgsGeometryAnalyzer::simplify( QgsVectorLayer* layer,
QGis::WkbType outputType = dp->geometryType();
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->pendingFields(), outputType, &crs );
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, &crs );
QgsFeature currentFeature;

//take only selection
Expand Down Expand Up @@ -163,7 +163,7 @@ bool QgsGeometryAnalyzer::centroids( QgsVectorLayer* layer, const QString& shape
QGis::WkbType outputType = QGis::WKBPoint;
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->pendingFields(), outputType, &crs );
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, &crs );
QgsFeature currentFeature;

//take only selection
Expand Down Expand Up @@ -622,7 +622,7 @@ bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapef
QGis::WkbType outputType = dp->geometryType();
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->pendingFields(), outputType, &crs );
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, &crs );
QgsFeature currentFeature;
QMultiMap<QString, QgsFeatureId> map;

Expand Down Expand Up @@ -775,7 +775,7 @@ bool QgsGeometryAnalyzer::buffer( QgsVectorLayer* layer, const QString& shapefil
}
const QgsCoordinateReferenceSystem crs = layer->crs();

QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->pendingFields(), outputType, &crs );
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, &crs );
QgsFeature currentFeature;
QgsGeometry *dissolveGeometry = 0; //dissolve geometry (if dissolve enabled)

Expand Down Expand Up @@ -946,14 +946,14 @@ bool QgsGeometryAnalyzer::eventLayer( QgsVectorLayer* lineLayer, QgsVectorLayer*
}
fileWriter = new QgsVectorFileWriter( outputLayer,
eventLayer->dataProvider()->encoding(),
eventLayer->pendingFields(),
eventLayer->fields(),
memoryProviderType,
&( lineLayer->crs() ),
outputFormat );
}
else
{
memoryProvider->addAttributes( eventLayer->pendingFields().toList() );
memoryProvider->addAttributes( eventLayer->fields().toList() );
}

//iterate over eventLayer and write new features to output file or layer
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/vector/qgsoverlayanalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ bool QgsOverlayAnalyzer::intersection( QgsVectorLayer* layerA, QgsVectorLayer* l

QGis::WkbType outputType = dpA->geometryType();
const QgsCoordinateReferenceSystem crs = layerA->crs();
QgsFields fieldsA = layerA->pendingFields();
QgsFields fieldsB = layerB->pendingFields();
QgsFields fieldsA = layerA->fields();
QgsFields fieldsB = layerB->fields();
combineFieldLists( fieldsA, fieldsB );

QgsVectorFileWriter vWriter( shapefileName, dpA->encoding(), fieldsA, outputType, &crs );
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgspointsample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int QgsPointSample::createRandomPoints( QProgressDialog* pd )
mNCreatedPoints = 0;

QgsFeatureIterator fIt = mInputLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes(
QStringList() << mNumberOfPointsAttribute << mMinDistanceAttribute, mInputLayer->pendingFields() ) );
QStringList() << mNumberOfPointsAttribute << mMinDistanceAttribute, mInputLayer->fields() ) );
while ( fIt.nextFeature( fet ) )
{
nPoints = fet.attribute( mNumberOfPointsAttribute ).toInt();
Expand Down
6 changes: 3 additions & 3 deletions src/analysis/vector/qgstransectsample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
QVariant::Type stratumIdType = QVariant::Int;
if ( !mStrataIdAttribute.isEmpty() )
{
stratumIdType = mStrataLayer->pendingFields().field( mStrataIdAttribute ).type();
stratumIdType = mStrataLayer->fields().field( mStrataIdAttribute ).type();
}

//create vector file writers for output
Expand Down Expand Up @@ -118,7 +118,7 @@ int QgsTransectSample::createSample( QProgressDialog* pd )
mt_srand( QTime::currentTime().msec() );

QgsFeatureRequest fr;
fr.setSubsetOfAttributes( QStringList() << mStrataIdAttribute << mMinDistanceAttribute << mNPointsAttribute, mStrataLayer->pendingFields() );
fr.setSubsetOfAttributes( QStringList() << mStrataIdAttribute << mMinDistanceAttribute << mNPointsAttribute, mStrataLayer->fields() );
QgsFeatureIterator strataIt = mStrataLayer->getFeatures( fr );

QgsFeature fet;
Expand Down Expand Up @@ -333,7 +333,7 @@ QgsGeometry* QgsTransectSample::findBaselineGeometry( QVariant strataId )
return 0;
}

QgsFeatureIterator baseLineIt = mBaselineLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QStringList( mBaselineStrataId ), mBaselineLayer->pendingFields() ) );
QgsFeatureIterator baseLineIt = mBaselineLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QStringList( mBaselineStrataId ), mBaselineLayer->fields() ) );
QgsFeature fet;

while ( baseLineIt.nextFeature( fet ) ) //todo: cache this in case there are many baslines
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6275,11 +6275,11 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
QgsFeatureList features;
if ( mMapCanvas->mapSettings().hasCrsTransformEnabled() )
{
features = clipboard()->transformedCopyOf( pasteVectorLayer->crs(), pasteVectorLayer->pendingFields() );
features = clipboard()->transformedCopyOf( pasteVectorLayer->crs(), pasteVectorLayer->fields() );
}
else
{
features = clipboard()->copyOf( pasteVectorLayer->pendingFields() );
features = clipboard()->copyOf( pasteVectorLayer->fields() );
}
int nTotalFeatures = features.count();

Expand All @@ -6295,7 +6295,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
remap.insert( idx, dst );
}

int dstAttrCount = pasteVectorLayer->pendingFields().count();
int dstAttrCount = pasteVectorLayer->fields().count();

QgsFeatureList::iterator featureIt = features.begin();
while ( featureIt != features.end() )
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void QgsAttributeTableDialog::columnBoxInit()
mFilterButton->addAction( mActionFilterColumnsMenu );
mFilterButton->addAction( mActionAdvancedFilter );

QList<QgsField> fields = mLayer->pendingFields().toList();
QList<QgsField> fields = mLayer->fields().toList();

foreach ( const QgsField field, fields )
{
Expand Down Expand Up @@ -364,7 +364,7 @@ void QgsAttributeTableDialog::runFieldCalculation( QgsVectorLayer* layer, QStrin

int rownum = 1;

const QgsField &fld = layer->pendingFields()[ fieldindex ];
const QgsField &fld = layer->fields()[ fieldindex ];

//go through all the features and change the new attributes
QgsFeatureIterator fit = layer->getFeatures( request );
Expand Down Expand Up @@ -762,7 +762,7 @@ void QgsAttributeTableDialog::setFilterExpression( QString filterString )
return;
}

if ( ! filterExpression.prepare( mLayer->pendingFields() ) )
if ( ! filterExpression.prepare( mLayer->fields() ) )
{
QgisApp::instance()->messageBar()->pushMessage( tr( "Evaluation error" ), filterExpression.evalErrorString(), QgsMessageBar::WARNING, QgisApp::instance()->messageTimeout() );
}
Expand All @@ -773,7 +773,7 @@ void QgsAttributeTableDialog::setFilterExpression( QString filterString )

filterExpression.setGeomCalculator( myDa );
QgsFeatureRequest request( mMainView->masterModel()->request() );
request.setSubsetOfAttributes( filterExpression.referencedColumns(), mLayer->pendingFields() );
request.setSubsetOfAttributes( filterExpression.referencedColumns(), mLayer->fields() );
if ( !fetchGeom )
{
request.setFlags( QgsFeatureRequest::NoGeometry );
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsattributetypedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
, mFieldIdx( fieldIdx )
{
setupUi( this );
setWindowTitle( tr( "Edit Widget Properties - %1 (%2)" ).arg( vl->pendingFields()[fieldIdx].name() ).arg( vl->name() ) );
setWindowTitle( tr( "Edit Widget Properties - %1 (%2)" ).arg( vl->fields()[fieldIdx].name() ).arg( vl->name() ) );

connect( selectionListWidget, SIGNAL( currentRowChanged( int ) ), this, SLOT( setStackPage( int ) ) );

Expand All @@ -65,8 +65,8 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
selectionListWidget->setMaximumWidth( selectionListWidget->sizeHintForColumn( 0 )
+ 2 );

if ( vl->pendingFields().fieldOrigin( fieldIdx ) == QgsFields::OriginJoin ||
vl->pendingFields().fieldOrigin( fieldIdx ) == QgsFields::OriginExpression )
if ( vl->fields().fieldOrigin( fieldIdx ) == QgsFields::OriginJoin ||
vl->fields().fieldOrigin( fieldIdx ) == QgsFields::OriginExpression )
{
isFieldEditableCheckBox->setEnabled( false );
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsclipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void QgsClipboard::replaceWithCopyOf( QgsVectorLayer *src )
return;

// Replace the QGis clipboard.
mFeatureFields = src->pendingFields();
mFeatureFields = src->fields();
mFeatureClipboard = src->selectedFeatures();
mCRS = src->crs();

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsdelattrdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ QgsDelAttrDialog::QgsDelAttrDialog( const QgsVectorLayer* vl )
{
bool canDeleteAttributes = vl->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteAttributes;
listBox2->clear();
const QgsFields& layerAttributes = vl->pendingFields();
const QgsFields& layerAttributes = vl->fields();
for ( int idx = 0; idx < layerAttributes.count(); ++idx )
{
QListWidgetItem* item = new QListWidgetItem( layerAttributes[idx].name(), listBox2 );
switch ( vl->pendingFields().fieldOrigin( idx ) )
switch ( vl->fields().fieldOrigin( idx ) )
{
case QgsFields::OriginExpression:
item->setIcon( QgsApplication::getThemeIcon( "/mIconExpression.svg" ) );
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsdiagramproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
mSizeFieldExpressionWidget->setGeomCalculator( myDa );

//insert all attributes into the combo boxes
const QgsFields& layerFields = layer->pendingFields();
const QgsFields& layerFields = layer->fields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
QTreeWidgetItem *newItem = new QTreeWidgetItem( mAttributesTreeWidget );
Expand Down Expand Up @@ -342,7 +342,7 @@ QgsDiagramProperties::QgsDiagramProperties( QgsVectorLayer* layer, QWidget* pare
}
else
{
mSizeFieldExpressionWidget->setField( mLayer->pendingFields().at( lidr->classificationAttribute() ).name() );
mSizeFieldExpressionWidget->setField( mLayer->fields().at( lidr->classificationAttribute() ).name() );
}
}
}
Expand Down Expand Up @@ -526,7 +526,7 @@ void QgsDiagramProperties::on_mFindMaximumValueButton_clicked()
if ( isExpression )
{
QgsExpression exp( sizeFieldNameOrExp );
exp.prepare( mLayer->pendingFields() );
exp.prepare( mLayer->fields() );
if ( !exp.hasEvalError() )
{
QgsFeature feature;
Expand All @@ -543,7 +543,7 @@ void QgsDiagramProperties::on_mFindMaximumValueButton_clicked()
}
else
{
int attributeNumber = mLayer->pendingFields().fieldNameIndex( sizeFieldNameOrExp );
int attributeNumber = mLayer->fields().fieldNameIndex( sizeFieldNameOrExp );
maxValue = mLayer->maximumValue( attributeNumber ).toFloat();
}

Expand Down Expand Up @@ -726,7 +726,7 @@ void QgsDiagramProperties::apply()
}
else
{
int attributeNumber = mLayer->pendingFields().fieldNameIndex( sizeFieldNameOrExp );
int attributeNumber = mLayer->fields().fieldNameIndex( sizeFieldNameOrExp );
dr->setClassificationAttribute( attributeNumber );
}
dr->setDiagram( diagram );
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsdxfexportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void FieldSelectorDelegate::setEditorData( QWidget *editor, const QModelIndex &i
return;

int idx = m->attributeIndex( vl );
if ( vl->pendingFields().exists( idx ) )
fcb->setField( vl->pendingFields()[ idx ].name() );
if ( vl->fields().exists( idx ) )
fcb->setField( vl->fields()[ idx ].name() );
}

void FieldSelectorDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
Expand Down Expand Up @@ -215,8 +215,8 @@ QVariant QgsVectorLayerAndAttributeModel::data( const QModelIndex& idx, int role

if ( role == Qt::DisplayRole )
{
if ( vl->pendingFields().exists( idx ) )
return vl->pendingFields()[ idx ].name();
if ( vl->fields().exists( idx ) )
return vl->fields()[ idx ].name();
else
return vl->name();
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfeatureaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes, boo
QgsDebugMsg( QString( "reuseLastValues: %1" ).arg( reuseLastValues ) );

// add the fields to the QgsFeature
const QgsFields& fields = mLayer->pendingFields();
const QgsFields& fields = mLayer->fields();
mFeature.initAttributes( fields.count() );
for ( int idx = 0; idx < fields.count(); ++idx )
{
Expand Down Expand Up @@ -226,7 +226,7 @@ void QgsFeatureAction::onFeatureSaved( const QgsFeature& feature )

if ( reuseLastValues )
{
QgsFields fields = mLayer->pendingFields();
QgsFields fields = mLayer->fields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
QgsAttributes newValues = feature.attributes();
Expand Down
10 changes: 5 additions & 5 deletions src/app/qgsfieldcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void QgsFieldCalculator::accept()
QgsExpression exp( calcString );
exp.setGeomCalculator( myDa );

if ( ! exp.prepare( mVectorLayer->pendingFields() ) )
if ( ! exp.prepare( mVectorLayer->fields() ) )
{
QMessageBox::critical( 0, tr( "Evaluation error" ), exp.evalErrorString() );
return;
Expand Down Expand Up @@ -198,7 +198,7 @@ void QgsFieldCalculator::accept()
}

//get index of the new field
const QgsFields& fields = mVectorLayer->pendingFields();
const QgsFields& fields = mVectorLayer->fields();

for ( int idx = 0; idx < fields.count(); ++idx )
{
Expand All @@ -209,7 +209,7 @@ void QgsFieldCalculator::accept()
}
}

if ( ! exp.prepare( mVectorLayer->pendingFields() ) )
if ( ! exp.prepare( mVectorLayer->fields() ) )
{
QApplication::restoreOverrideCursor();
QMessageBox::critical( 0, tr( "Evaluation error" ), exp.evalErrorString() );
Expand All @@ -235,7 +235,7 @@ void QgsFieldCalculator::accept()
bool useGeometry = exp.needsGeometry();
int rownum = 1;

const QgsField& field = mVectorLayer->pendingFields()[mAttributeId];
const QgsField& field = mVectorLayer->fields()[mAttributeId];

bool newField = !mUpdateExistingGroupBox->isChecked();
QVariant emptyAttribute;
Expand Down Expand Up @@ -400,7 +400,7 @@ void QgsFieldCalculator::populateFields()
if ( !mVectorLayer )
return;

const QgsFields& fields = mVectorLayer->pendingFields();
const QgsFields& fields = mVectorLayer->fields();
for ( int idx = 0; idx < fields.count(); ++idx )
{

Expand Down
Loading

0 comments on commit e832b2a

Please sign in to comment.