diff --git a/app/qml/form/editors/MMFormGalleryEditor.qml b/app/qml/form/editors/MMFormGalleryEditor.qml index 37221230b..e3365d1ae 100644 --- a/app/qml/form/editors/MMFormGalleryEditor.qml +++ b/app/qml/form/editors/MMFormGalleryEditor.qml @@ -75,7 +75,7 @@ MMPrivateComponents.MMBaseInput { } } - header: __activeProject.projectRole !== "reader" ? addFeatureComponent : null + header: (__activeProject.projectRole !== "reader" && !rmodel?.layer?.readOnly) ? addFeatureComponent : null } Component { diff --git a/app/qml/form/editors/MMFormRelationEditor.qml b/app/qml/form/editors/MMFormRelationEditor.qml index 3ac0eb4c0..bcc6459ba 100644 --- a/app/qml/form/editors/MMFormRelationEditor.qml +++ b/app/qml/form/editors/MMFormRelationEditor.qml @@ -86,7 +86,7 @@ MMPrivateComponents.MMBaseInput { height: privates.itemHeight radius: 8 * __dp color: __style.lightGreenColor - visible: __activeProject.projectRole !== "reader" + visible: (__activeProject.projectRole !== "reader" && !rmodel?.layer?.readOnly) MMComponents.MMIcon { anchors.centerIn: parent diff --git a/app/relationfeaturesmodel.cpp b/app/relationfeaturesmodel.cpp index 0992ba180..b5783a401 100644 --- a/app/relationfeaturesmodel.cpp +++ b/app/relationfeaturesmodel.cpp @@ -75,12 +75,10 @@ void RelationFeaturesModel::setParentFeatureLayerPair( FeatureLayerPair pair ) if ( !InputUtils::isFeatureIdValid( pair.feature().id() ) ) { - // - // Clear the model in case parent feature has invalid id (e.g. is new) and do not populate it - // + // Parent has no valid id yet (e.g. new feature) - clear features but keep mLayer known. beginResetModel(); - reset(); + mFeatures.clear(); endResetModel(); } else @@ -96,6 +94,9 @@ void RelationFeaturesModel::setRelation( QgsRelation relation ) mRelation = relation; emit relationChanged( mRelation ); + // set layer early so it's known even before the parent feature has a valid id (e.g. new feature) + LayerFeaturesModel::setLayer( mRelation.isValid() ? mRelation.referencingLayer() : nullptr ); + setup(); } }