Skip to content
Permalink
Browse files

* initialize pasted feature with default values (fixes #8800)

* show default values of new features in attribute table and identify
  results
  • Loading branch information
jef-n committed Jun 30, 2016
1 parent 6a93df7 commit 174d112da889e2301306bc298bfe9c4c1fc6c9a5
@@ -7379,16 +7379,26 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
QgsAttributes srcAttr = featureIt->attributes();
QgsAttributes dstAttr( dstAttrCount );

// pre-initialized with default values
for ( int dst = 0; dst < dstAttr.count(); ++dst )
{
QVariant defVal( pasteVectorLayer->dataProvider()->defaultValue( dst ) );
if( !defVal.isNull() )
{
dstAttr[ dst ] = defVal;
}
}

for ( int src = 0; src < srcAttr.count(); ++src )
{
int dst = remap.value( src, -1 );
if ( dst < 0 )
continue;

// use default value for primary key fields if it's NOT NULL
// don't overwrite default value for primary key fields if it's NOT NULL
// or for spatialite layers
if ( pkAttrList.contains( dst ) )
{
dstAttr[ dst ] = pasteVectorLayer->dataProvider()->defaultValue( dst );
if ( !dstAttr.at( dst ).isNull() )
continue;
else if ( pasteVectorLayer->providerType() == "spatialite" )
@@ -34,6 +34,7 @@
#include "qgsproject.h"
#include "qgsrasterlayer.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgswebview.h"
#include "qgswebframe.h"

@@ -470,7 +471,11 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
if ( i >= fields.count() )
continue;

QString value = fields.at( i ).displayString( attrs.at( i ) );
QString defVal;
if ( fields.fieldOrigin( i ) == QgsFields::OriginProvider && vlayer->dataProvider() )
defVal = vlayer->dataProvider()->defaultValue( fields.fieldOriginIndex( i ) ).toString();

QString value = defVal == attrs.at( i ) ? defVal : fields.at( i ).displayString( attrs.at( i ) );
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << QString::number( i ) << value );

attrItem->setData( 0, Qt::DisplayRole, vlayer->attributeDisplayName( i ) );
@@ -17,6 +17,7 @@
#include "qgsdefaultsearchwidgetwrapper.h"
#include "qgssearchwidgetwrapper.h"
#include "qgsfield.h"
#include "qgsvectordataprovider.h"

#include <QSettings>

@@ -67,7 +68,11 @@ QString QgsEditorWidgetFactory::representValue( QgsVectorLayer* vl, int fieldIdx
Q_UNUSED( cache )
Q_UNUSED( value )

return vl->fields().at( fieldIdx ).displayString( value );
QString defVal;
if ( vl->fields().fieldOrigin( fieldIdx ) == QgsFields::OriginProvider && vl->dataProvider() )
defVal = vl->dataProvider()->defaultValue( vl->fields().fieldOriginIndex( fieldIdx ) ).toString();

return value == defVal ? defVal : vl->fields().at( fieldIdx ).displayString( value );
}

Qt::AlignmentFlag QgsEditorWidgetFactory::alignmentFlag( QgsVectorLayer* vl, int fieldIdx, const QgsEditorWidgetConfig& config ) const

0 comments on commit 174d112

Please sign in to comment.
You can’t perform that action at this time.