Skip to content

Commit f92a38c

Browse files
committedMay 18, 2017
Clone more members in vector layer
1 parent 30a8134 commit f92a38c

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed
 

‎python/core/qgsvectorlayer.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ Setup the coordinate system transformation for the layer
507507
:rtype: QgsActionManager
508508
%End
509509

510+
510511
int selectedFeatureCount() const;
511512
%Docstring
512513
The number of features that are selected in this layer
@@ -1429,6 +1430,11 @@ Assembles mUpdatedFields considering provider fields, joined fields and added fi
14291430
:rtype: QgsFieldConstraints.Constraints
14301431
%End
14311432

1433+
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength( int fieldIndex ) const;
1434+
%Docstring
1435+
:rtype: QMap< QgsFieldConstraints.Constraint, QgsFieldConstraints.ConstraintStrength>
1436+
%End
1437+
14321438
void setFieldConstraint( int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength = QgsFieldConstraints::ConstraintStrengthHard );
14331439
%Docstring
14341440
Sets a constraint for a specified field index. Any constraints inherited from the layer's

‎src/core/qgsvectorlayer.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ QgsVectorLayer *QgsVectorLayer::clone() const
222222
layer->setAttributeTableConfig( attributeTableConfig() );
223223
layer->setFeatureBlendMode( featureBlendMode() );
224224
layer->setLayerTransparency( layerTransparency() );
225+
layer->setEditFormConfig( editFormConfig() );
226+
227+
Q_FOREACH ( QgsAction action, actions()->actions() )
228+
{
229+
layer->actions()->addAction( action );
230+
}
225231

226232
if ( renderer() )
227233
{
@@ -248,10 +254,16 @@ QgsVectorLayer *QgsVectorLayer::clone() const
248254
for ( int i = 0; i < fields().count(); i++ )
249255
{
250256
layer->setFieldAlias( i, attributeAlias( i ) );
251-
}
257+
layer->setEditorWidgetSetup( i, editorWidgetSetup( i ) );
258+
layer->setConstraintExpression( i, constraintExpression( i ), constraintDescription( i ) );
259+
layer->setDefaultValueExpression( i, defaultValueExpression( i ) );
260+
261+
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> constraints = fieldConstraintsAndStrength( i );
262+
for ( QgsFieldConstraints::Constraint c : constraints.keys() )
263+
{
264+
layer->setFieldConstraint( i, c, constraints.value( c ) );
265+
}
252266

253-
for ( int i = 0; i < fields().count(); i++ )
254-
{
255267
if ( fields().fieldOrigin( i ) == QgsFields::OriginExpression )
256268
{
257269
layer->addExpressionField( expressionField( i ), fields().at( i ) );
@@ -4201,6 +4213,26 @@ QgsFieldConstraints::Constraints QgsVectorLayer::fieldConstraints( int fieldInde
42014213
return constraints;
42024214
}
42034215

4216+
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> QgsVectorLayer::fieldConstraintsAndStrength( int fieldIndex ) const
4217+
{
4218+
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength > m;
4219+
4220+
if ( fieldIndex < 0 || fieldIndex >= mFields.count() )
4221+
return m;
4222+
4223+
QString name = mFields.at( fieldIndex ).name();
4224+
4225+
for ( QPair< QString, QgsFieldConstraints::Constraint > p : mFieldConstraintStrength.keys() )
4226+
{
4227+
if ( p.first == name )
4228+
{
4229+
m[ p.second ] = mFieldConstraintStrength.value( p );
4230+
}
4231+
}
4232+
4233+
return m;
4234+
}
4235+
42044236
void QgsVectorLayer::setFieldConstraint( int index, QgsFieldConstraints::Constraint constraint, QgsFieldConstraints::ConstraintStrength strength )
42054237
{
42064238
if ( index < 0 || index >= mFields.count() )

‎src/core/qgsvectorlayer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
538538
*/
539539
QgsActionManager *actions() { return mActions; }
540540

541+
/**
542+
* Get all layer actions defined on this layer.
543+
*
544+
* The pointer which is returned is const.
545+
*/
546+
const QgsActionManager *actions() const SIP_SKIP { return mActions; }
547+
541548
/**
542549
* The number of features that are selected in this layer
543550
*
@@ -1340,6 +1347,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
13401347
*/
13411348
QgsFieldConstraints::Constraints fieldConstraints( int fieldIndex ) const;
13421349

1350+
QMap< QgsFieldConstraints::Constraint, QgsFieldConstraints::ConstraintStrength> fieldConstraintsAndStrength( int fieldIndex ) const;
1351+
13431352
/**
13441353
* Sets a constraint for a specified field index. Any constraints inherited from the layer's
13451354
* data provider will be kept intact and cannot be modified. Ie, calling this method only allows for new

0 commit comments

Comments
 (0)
Please sign in to comment.