Skip to content
Permalink
Browse files

[addlayerbutton] Add embedded flag for widget-like usage

  • Loading branch information
elpaso committed Jun 2, 2017
1 parent b2dea8e commit 3cf93bc40263977d5721e238e0923ea6f0e2953d
Showing with 23 additions and 5 deletions.
  1. +16 −4 src/app/ogr/qgsopenvectorlayerdialog.cpp
  2. +7 −1 src/app/ogr/qgsopenvectorlayerdialog.h
@@ -31,11 +31,16 @@
#include "qgscontexthelp.h"
#include "qgsapplication.h"

QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode )
: QDialog( parent, fl ),
mEmbeddedMode( embeddedMode )
{
setupUi( this );

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

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

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

QDialog::accept();
if ( ! mEmbeddedMode )
{
QDialog::accept();
}
else if ( ! mDataSources.isEmpty( ) )
{
emit addVectorLayers( mDataSources, encoding(), dataSourceType( ) );
}
}

void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )
@@ -32,7 +32,7 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
Q_OBJECT

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

private slots:
//! Opens the create connection dialog to build a new connection
@@ -85,6 +87,10 @@ class QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerD
void on_cmbDatabaseTypes_currentIndexChanged( const QString &text );
void on_cmbConnections_currentIndexChanged( const QString &text );
void on_buttonBox_helpRequested() { QgsHelp::openHelp( QStringLiteral( "working_with_vector/supported_data.html#loading-a-layer-from-a-file" ) ); }

signals:
//! Emitted when in embedded mode
void addVectorLayers( const QStringList &layerQStringList, const QString &enc, const QString &dataSourceType );
};

#endif // QGSOPENVECTORDIALOG_H

0 comments on commit 3cf93bc

Please sign in to comment.
You can’t perform that action at this time.