Skip to content

Commit 3cf93bc

Browse files
committed
[addlayerbutton] Add embedded flag for widget-like usage
1 parent b2dea8e commit 3cf93bc

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/app/ogr/qgsopenvectorlayerdialog.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@
3131
#include "qgscontexthelp.h"
3232
#include "qgsapplication.h"
3333

34-
QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl )
35-
: QDialog( parent, fl )
34+
QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
35+
: QDialog( parent, fl ),
36+
mEmbeddedMode( embeddedMode )
3637
{
3738
setupUi( this );
3839

40+
if ( mEmbeddedMode )
41+
{
42+
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
43+
}
3944
cmbDatabaseTypes->blockSignals( true );
4045
cmbConnections->blockSignals( true );
4146
radioSrcFile->setChecked( true );
@@ -49,7 +54,7 @@ QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowF
4954

5055
restoreGeometry( settings.value( QStringLiteral( "Windows/OpenVectorLayer/geometry" ) ).toByteArray() );
5156

52-
// The specified decoding is added if not existing alread, and then set current.
57+
// The specified decoding is added if not existing already, and then set current.
5358
// This should select it.
5459
int encindex = cmbEncodings->findText( enc );
5560
if ( encindex < 0 )
@@ -382,7 +387,14 @@ void QgsOpenVectorLayerDialog::accept()
382387
// Save the used encoding
383388
settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );
384389

385-
QDialog::accept();
390+
if ( ! mEmbeddedMode )
391+
{
392+
QDialog::accept();
393+
}
394+
else if ( ! mDataSources.isEmpty( ) )
395+
{
396+
emit addVectorLayers( mDataSources, encoding(), dataSourceType( ) );
397+
}
386398
}
387399

388400
void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )

src/app/ogr/qgsopenvectorlayerdialog.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
3232
Q_OBJECT
3333

3434
public:
35-
QgsOpenVectorLayerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = 0 );
35+
QgsOpenVectorLayerDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = 0, bool embeddedMode = false );
3636
~QgsOpenVectorLayerDialog();
3737
//! Opens a dialog to select a file datasource*/
3838
QStringList openFile();
@@ -53,6 +53,8 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
5353
QString mEnc;
5454
//! Stores the datasource type
5555
QString mDataSourceType;
56+
//! Embedded dialog (do not call parent's accept) and emit signals
57+
bool mEmbeddedMode;
5658

5759
private slots:
5860
//! Opens the create connection dialog to build a new connection
@@ -85,6 +87,10 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
8587
void on_cmbDatabaseTypes_currentIndexChanged( const QString &text );
8688
void on_cmbConnections_currentIndexChanged( const QString &text );
8789
void on_buttonBox_helpRequested() { QgsHelp::openHelp( QStringLiteral( "working_with_vector/supported_data.html#loading-a-layer-from-a-file" ) ); }
90+
91+
signals:
92+
//! Emitted when in embedded mode
93+
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
8894
};
8995

9096
#endif // QGSOPENVECTORDIALOG_H

0 commit comments

Comments
 (0)