Skip to content

Commit

Permalink
fix #2879 photo crash on project switch
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Oct 27, 2023
1 parent a1ff0c4 commit e8cb8fd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
73 changes: 38 additions & 35 deletions app/attributes/attributecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,59 +359,59 @@ void AttributeController::clearAll()
void AttributeController::updateOnLayerChange()
{
clearAll();
QgsVectorLayer *layer = mFeatureLayerPair.layer();
if ( !layer )
return;

// 1) DATA
QgsVectorLayer *layer = mFeatureLayerPair.layer();
if ( layer )
if ( layer->editFormConfig().layout() == Qgis::AttributeFormLayout::DragAndDrop )
{
if ( layer->editFormConfig().layout() == Qgis::AttributeFormLayout::DragAndDrop )
QgsAttributeEditorContainer *root = layer->editFormConfig().invisibleRootContainer();
if ( root->columnCount() > 1 )
{
QgsAttributeEditorContainer *root = layer->editFormConfig().invisibleRootContainer();
if ( root->columnCount() > 1 )
{
qDebug() << "root tab in manual config has multiple columns. not supported on mobile devices!";
root->setColumnCount( 1 );
}
qDebug() << "root tab in manual config has multiple columns. not supported on mobile devices!";
root->setColumnCount( 1 );
}

mHasTabs = allowTabs( root );
if ( mHasTabs )
mHasTabs = allowTabs( root );
if ( mHasTabs )
{
for ( QgsAttributeEditorElement *element : root->children() )
{
for ( QgsAttributeEditorElement *element : root->children() )
if ( element->type() == Qgis::AttributeEditorType::Container )
{
if ( element->type() == Qgis::AttributeEditorType::Container )
QgsAttributeEditorContainer *container = static_cast<QgsAttributeEditorContainer *>( element );
if ( container->columnCount() > 1 )
{
QgsAttributeEditorContainer *container = static_cast<QgsAttributeEditorContainer *>( element );
if ( container->columnCount() > 1 )
{
qDebug() << "tab " << container->name() << " in manual config has multiple columns. not supported on mobile devices!";
container->setColumnCount( 1 );
}
createTab( container );
qDebug() << "tab " << container->name() << " in manual config has multiple columns. not supported on mobile devices!";
container->setColumnCount( 1 );
}
createTab( container );
}
}
else
{
createTab( root );
}
}
else
{
// Auto-Generated Layout
// We create fake root tab
QgsAttributeEditorContainer *tab = autoLayoutTabContainer();

// We need to look for relations and include them into form,
// in auto-generated layout they are not included in form config
discoverRelations( tab );

createTab( tab );
createTab( root );
}
}
else
{
// Auto-Generated Layout
// We create fake root tab
QgsAttributeEditorContainer *tab = autoLayoutTabContainer();

if ( mRememberAttributesController )
mRememberAttributesController->storeLayerFields( layer );
// We need to look for relations and include them into form,
// in auto-generated layout they are not included in form config
discoverRelations( tab );

createTab( tab );
}

if ( mRememberAttributesController )
mRememberAttributesController->storeLayerFields( layer );


// 2) MODELS
// for all other models, ownership is managed by Qt parent system
AttributeTabModel *tabModel = new AttributeTabModel( mAttributeTabProxyModel.get(), this, mTabItems.size() );
Expand Down Expand Up @@ -462,6 +462,9 @@ void AttributeController::updateOnLayerChange()

void AttributeController::updateOnFeatureChange()
{
if (!mFeatureLayerPair.layer())
return;

const QgsFeature feature = mFeatureLayerPair.feature();

QMap<QUuid, std::shared_ptr<FormItem>>::iterator formItemsIterator = mFormItems.begin();
Expand Down
14 changes: 13 additions & 1 deletion app/qml/FormsStackManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ Item {
signal createLinkedFeatureRequested( var targetLayer, var parentPair )
signal stakeoutFeature( var feature );

function openForm( pair, formState, panelState ) {
function openForm( pair, formState, panelState )
{
if ( formsStack.depth === 0 )
{
let props = {
Expand Down Expand Up @@ -137,9 +138,20 @@ Item {
}

function reload() {
// For some reason some forms could be hanging around
// for some time with dangling layer pointers even after
// formsStack.clear() is called
// https://github.com/MerginMaps/input/issues/2879
for ( let i = 0; i <= formsStack.depth; i++ ) {
let form = formsStack.get( i )
form.featureLayerPair = __inputUtils.createFeatureLayerPair(null, __inputUtils.emptyGeometry(), __variablesManager )
form.project = null
}

formsStack.clear() // removes all objects thanks to Qt parent system
}


function openLinkedFeature( linkedFeature ) {
let props = {
featureLayerPair: linkedFeature,
Expand Down
2 changes: 1 addition & 1 deletion app/qml/form/FormWrapper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Item {
property real previewHeight
property real panelHeight

property bool isReadOnly: featureLayerPair ? featureLayerPair.layer.readOnly : false
property bool isReadOnly: featureLayerPair && featureLayerPair.layer ? featureLayerPair.layer.readOnly : false

signal closed()
signal editGeometry( var pair )
Expand Down

0 comments on commit e8cb8fd

Please sign in to comment.