mirror of
https://github.com/qgis/QGIS.git
synced 2025-05-03 00:03:15 -04:00
add checkbox to open sublayers in a group
This commit is contained in:
parent
ed1b0a2e74
commit
24e3214eda
@ -39,6 +39,18 @@ class QgsSublayersDialog : QDialog
|
|||||||
//! @note added in 2.16
|
//! @note added in 2.16
|
||||||
QgsSublayersDialog::LayerDefinitionList selection();
|
QgsSublayersDialog::LayerDefinitionList selection();
|
||||||
|
|
||||||
|
//! Set if we should display the add to group checkbox
|
||||||
|
//! @note added in 3.0
|
||||||
|
void setShowAddToGroupCheckbox( bool showAddToGroupCheckbox );
|
||||||
|
|
||||||
|
//! If we should display the add to group checkbox
|
||||||
|
//! @note added in 3.0
|
||||||
|
bool showAddToGroupCheckbox() const;
|
||||||
|
|
||||||
|
//! If we should add layers in a group
|
||||||
|
//! @note added in 3.0
|
||||||
|
bool addToGroupCheckbox() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_buttonBox_helpRequested();
|
void on_buttonBox_helpRequested();
|
||||||
int exec();
|
int exec();
|
||||||
|
@ -4061,6 +4061,7 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
|
|||||||
|
|
||||||
// We initialize a selection dialog and display it.
|
// We initialize a selection dialog and display it.
|
||||||
QgsSublayersDialog chooseSublayersDialog( QgsSublayersDialog::Gdal, QStringLiteral( "gdal" ), this );
|
QgsSublayersDialog chooseSublayersDialog( QgsSublayersDialog::Gdal, QStringLiteral( "gdal" ), this );
|
||||||
|
chooseSublayersDialog.setShowAddToGroupCheckbox( true );
|
||||||
|
|
||||||
QgsSublayersDialog::LayerDefinitionList layers;
|
QgsSublayersDialog::LayerDefinitionList layers;
|
||||||
QStringList names;
|
QStringList names;
|
||||||
@ -4112,6 +4113,13 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
|
|||||||
QRegExp rx( "\"(.*)\"" );
|
QRegExp rx( "\"(.*)\"" );
|
||||||
QString uri, name;
|
QString uri, name;
|
||||||
|
|
||||||
|
QgsLayerTreeGroup *group = nullptr;
|
||||||
|
bool addToGroup = settings.value( QStringLiteral( "/qgis/openSublayersInGroup" ), true ).toBool();
|
||||||
|
if ( addToGroup )
|
||||||
|
{
|
||||||
|
group = QgsProject::instance()->layerTreeRoot()->insertGroup( 0, layer->name() );
|
||||||
|
}
|
||||||
|
|
||||||
Q_FOREACH ( const QgsSublayersDialog::LayerDefinition &def, chooseSublayersDialog.selection() )
|
Q_FOREACH ( const QgsSublayersDialog::LayerDefinition &def, chooseSublayersDialog.selection() )
|
||||||
{
|
{
|
||||||
int i = def.layerId;
|
int i = def.layerId;
|
||||||
@ -4128,12 +4136,20 @@ void QgisApp::askUserForGDALSublayers( QgsRasterLayer *layer )
|
|||||||
|
|
||||||
QgsRasterLayer *rlayer = new QgsRasterLayer( sublayers[i], name );
|
QgsRasterLayer *rlayer = new QgsRasterLayer( sublayers[i], name );
|
||||||
if ( rlayer && rlayer->isValid() )
|
if ( rlayer && rlayer->isValid() )
|
||||||
|
{
|
||||||
|
if ( addToGroup )
|
||||||
|
{
|
||||||
|
QgsProject::instance()->addMapLayer( rlayer, false );
|
||||||
|
group->addLayer( rlayer );
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
addRasterLayer( rlayer );
|
addRasterLayer( rlayer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// should the GDAL sublayers dialog should be presented to the user?
|
// should the GDAL sublayers dialog should be presented to the user?
|
||||||
bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )
|
bool QgisApp::shouldAskUserForGDALSublayers( QgsRasterLayer *layer )
|
||||||
@ -4158,6 +4174,11 @@ void QgisApp::loadGDALSublayers( const QString &uri, const QStringList &list )
|
|||||||
{
|
{
|
||||||
QString path, name;
|
QString path, name;
|
||||||
QgsRasterLayer *subLayer = nullptr;
|
QgsRasterLayer *subLayer = nullptr;
|
||||||
|
QgsSettings settings;
|
||||||
|
QgsLayerTreeGroup *group = nullptr;
|
||||||
|
bool addToGroup = settings.value( QStringLiteral( "/qgis/openSublayersInGroup" ), true ).toBool();
|
||||||
|
if ( addToGroup )
|
||||||
|
group = QgsProject::instance()->layerTreeRoot()->insertGroup( 0, QFileInfo( uri ).completeBaseName() );
|
||||||
|
|
||||||
//add layers in reverse order so they appear in the right order in the layer dock
|
//add layers in reverse order so they appear in the right order in the layer dock
|
||||||
for ( int i = list.size() - 1; i >= 0 ; i-- )
|
for ( int i = list.size() - 1; i >= 0 ; i-- )
|
||||||
@ -4170,7 +4191,15 @@ void QgisApp::loadGDALSublayers( const QString &uri, const QStringList &list )
|
|||||||
if ( subLayer )
|
if ( subLayer )
|
||||||
{
|
{
|
||||||
if ( subLayer->isValid() )
|
if ( subLayer->isValid() )
|
||||||
|
if ( addToGroup )
|
||||||
|
{
|
||||||
|
QgsProject::instance()->addMapLayer( subLayer, false );
|
||||||
|
group->addLayer( subLayer );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
addRasterLayer( subLayer );
|
addRasterLayer( subLayer );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
delete subLayer;
|
delete subLayer;
|
||||||
}
|
}
|
||||||
@ -4224,12 +4253,14 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
|
|||||||
|
|
||||||
// We initialize a selection dialog and display it.
|
// We initialize a selection dialog and display it.
|
||||||
QgsSublayersDialog chooseSublayersDialog( QgsSublayersDialog::Ogr, QStringLiteral( "ogr" ), this );
|
QgsSublayersDialog chooseSublayersDialog( QgsSublayersDialog::Ogr, QStringLiteral( "ogr" ), this );
|
||||||
|
chooseSublayersDialog.setShowAddToGroupCheckbox( true );
|
||||||
chooseSublayersDialog.populateLayerTable( list );
|
chooseSublayersDialog.populateLayerTable( list );
|
||||||
|
|
||||||
if ( !chooseSublayersDialog.exec() )
|
if ( !chooseSublayersDialog.exec() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString uri = layer->source();
|
QString uri = layer->source();
|
||||||
|
QString name = layer->name();
|
||||||
//the separator char & was changed to | to be compatible
|
//the separator char & was changed to | to be compatible
|
||||||
//with url for protocol drivers
|
//with url for protocol drivers
|
||||||
if ( uri.contains( '|', Qt::CaseSensitive ) )
|
if ( uri.contains( '|', Qt::CaseSensitive ) )
|
||||||
@ -4276,12 +4307,19 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer )
|
|||||||
|
|
||||||
if ( ! myList.isEmpty() )
|
if ( ! myList.isEmpty() )
|
||||||
{
|
{
|
||||||
// Register layer(s) with the layers registry
|
QgsSettings settings;
|
||||||
QgsProject::instance()->addMapLayers( myList );
|
bool addToGroup = settings.value( QStringLiteral( "/qgis/openSublayersInGroup" ), true ).toBool();
|
||||||
|
QgsLayerTreeGroup *group = nullptr;
|
||||||
|
if ( addToGroup )
|
||||||
|
group = QgsProject::instance()->layerTreeRoot()->insertGroup( 0, name );
|
||||||
|
|
||||||
|
QgsProject::instance()->addMapLayers( myList, ! addToGroup );
|
||||||
Q_FOREACH ( QgsMapLayer *l, myList )
|
Q_FOREACH ( QgsMapLayer *l, myList )
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
l->loadDefaultStyle( ok );
|
l->loadDefaultStyle( ok );
|
||||||
|
if ( addToGroup )
|
||||||
|
group->addLayer( l );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,13 @@ QgsSublayersDialog::QgsSublayersDialog( ProviderType providerType, const QString
|
|||||||
|
|
||||||
QgsSettings settings;
|
QgsSettings settings;
|
||||||
restoreGeometry( settings.value( "/Windows/" + mName + "SubLayers/geometry" ).toByteArray() );
|
restoreGeometry( settings.value( "/Windows/" + mName + "SubLayers/geometry" ).toByteArray() );
|
||||||
|
|
||||||
|
// Checkbox about adding sublayers to a group
|
||||||
|
checkboxAddToGroup = new QCheckBox( tr( "Add layers to a group" ) );
|
||||||
|
bool addToGroup = settings.value( QStringLiteral( "/qgis/openSublayersInGroup" ), false ).toBool();
|
||||||
|
checkboxAddToGroup->setChecked( addToGroup );
|
||||||
|
if ( mShowAddToGroupCheckbox )
|
||||||
|
buttonBox->addButton( checkboxAddToGroup, QDialogButtonBox::ActionRole );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsSublayersDialog::~QgsSublayersDialog()
|
QgsSublayersDialog::~QgsSublayersDialog()
|
||||||
@ -177,5 +184,7 @@ int QgsSublayersDialog::exec()
|
|||||||
int ret = QDialog::exec();
|
int ret = QDialog::exec();
|
||||||
if ( overrideCursor )
|
if ( overrideCursor )
|
||||||
QApplication::setOverrideCursor( cursor );
|
QApplication::setOverrideCursor( cursor );
|
||||||
|
|
||||||
|
settings.setValue( QStringLiteral( "/qgis/openSublayersInGroup" ), checkboxAddToGroup->isChecked() );
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#define QGSSUBLAYERSDIALOG_H
|
#define QGSSUBLAYERSDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QCheckBox>
|
||||||
#include <ui_qgssublayersdialogbase.h>
|
#include <ui_qgssublayersdialogbase.h>
|
||||||
#include "qgscontexthelp.h"
|
#include "qgscontexthelp.h"
|
||||||
#include "qgis_gui.h"
|
#include "qgis_gui.h"
|
||||||
@ -63,6 +64,18 @@ class GUI_EXPORT QgsSublayersDialog : public QDialog, private Ui::QgsSublayersDi
|
|||||||
//! @note added in 2.16
|
//! @note added in 2.16
|
||||||
LayerDefinitionList selection();
|
LayerDefinitionList selection();
|
||||||
|
|
||||||
|
//! Set if we should display the add to group checkbox
|
||||||
|
//! @note added in 3.0
|
||||||
|
void setShowAddToGroupCheckbox( bool showAddToGroupCheckbox ) { mShowAddToGroupCheckbox = showAddToGroupCheckbox; }
|
||||||
|
|
||||||
|
//! If we should display the add to group checkbox
|
||||||
|
//! @note added in 3.0
|
||||||
|
bool showAddToGroupCheckbox() const { return mShowAddToGroupCheckbox; }
|
||||||
|
|
||||||
|
//! If we should add layers in a group
|
||||||
|
//! @note added in 3.0
|
||||||
|
bool addToGroupCheckbox() const { return checkboxAddToGroup->isChecked(); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
|
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
|
||||||
int exec();
|
int exec();
|
||||||
@ -72,6 +85,8 @@ class GUI_EXPORT QgsSublayersDialog : public QDialog, private Ui::QgsSublayersDi
|
|||||||
QStringList mSelectedSubLayers;
|
QStringList mSelectedSubLayers;
|
||||||
bool mShowCount; //!< Whether to show number of features in the table
|
bool mShowCount; //!< Whether to show number of features in the table
|
||||||
bool mShowType; //!< Whether to show type in the table
|
bool mShowType; //!< Whether to show type in the table
|
||||||
|
bool mShowAddToGroupCheckbox; //!< Whether to show the add to group checkbox
|
||||||
|
QCheckBox *checkboxAddToGroup = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user