Skip to content
Permalink
Browse files
Project items can be opened from gpkg from select sublayer dialog
  • Loading branch information
nyalldawson committed Jul 15, 2021
1 parent d34b9ca commit 7beccbdc0cd5c5983214f2c6d96a3dc7ce9ff1b8
Showing with 38 additions and 2 deletions.
  1. +22 −2 src/app/qgisapp.cpp
  2. +15 −0 src/app/qgsprovidersublayersdialog.cpp
  3. +1 −0 src/app/qgsprovidersublayersdialog.h
@@ -7365,7 +7365,7 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
QgsProviderSublayerModel::NonLayerItem projectItem;
projectItem.setType( QStringLiteral( "project" ) );
projectItem.setName( project );
projectItem.setUri( fileName );
projectItem.setUri( QStringLiteral( "%1://%2?projectName=%3" ).arg( ps->type(), fileName, project ) );
projectItem.setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mIconQgsProjectFile.svg" ) ) );
nonLayerItems << projectItem;
}
@@ -7392,9 +7392,15 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
dlg.setNonLayerItems( nonLayerItems );

if ( dlg.exec() )
{
sublayers = dlg.selectedLayers();
nonLayerItems = dlg.selectedNonLayerItems();
}
else
{
sublayers.clear(); // dialog was canceled, so don't add any sublayers
nonLayerItems.clear();
}
groupName = dlg.groupName();
break;
}
@@ -7435,8 +7441,22 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
}

addSublayers( sublayers, base, groupName );
activateDeactivateLayerRelatedActions( activeLayer() );
}
else if ( !nonLayerItems.empty() )
{
QgsCanvasRefreshBlocker refreshBlocker;
if ( checkTasksDependOnProject() )
return true;

// possibly save any pending work before opening a different project
if ( checkUnsavedLayerEdits() && checkMemoryLayers() && saveDirty() )
{
// error handling and reporting is in addProject() function
addProject( nonLayerItems.at( 0 ).uri() );
}
return true;
}
activateDeactivateLayerRelatedActions( activeLayer() );
}

CPLPopErrorHandler();
@@ -214,6 +214,21 @@ QList<QgsProviderSublayerDetails> QgsProviderSublayersDialog::selectedLayers() c
return selectedSublayers;
}

QList<QgsProviderSublayerModel::NonLayerItem> QgsProviderSublayersDialog::selectedNonLayerItems() const
{
const QModelIndexList selection = mLayersTree->selectionModel()->selectedRows();
QList< QgsProviderSublayerModel::NonLayerItem > selectedItems;
for ( const QModelIndex &index : selection )
{
const QModelIndex sourceIndex = mProxyModel->mapToSource( index );
if ( mModel->data( sourceIndex, static_cast< int >( QgsProviderSublayerModel::Role::IsNonLayerItem ) ).toBool() )
{
selectedItems << mModel->indexToNonLayerItem( sourceIndex );
}
}
return selectedItems;
}

QString QgsProviderSublayersDialog::groupName() const
{
if ( !mCbxAddToGroup->isChecked() )
@@ -59,6 +59,7 @@ class QgsProviderSublayersDialog : public QDialog, private Ui::QgsProviderSublay
~QgsProviderSublayersDialog() override;

QList< QgsProviderSublayerDetails > selectedLayers() const;
QList< QgsProviderSublayerModel::NonLayerItem > selectedNonLayerItems() const;
QString groupName() const;

signals:

0 comments on commit 7beccbd

Please sign in to comment.