Skip to content

Commit

Permalink
[addlayerbutton] Add embedded flag for widget-like usage
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jun 2, 2017
1 parent b2dea8e commit 3cf93bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/app/ogr/qgsopenvectorlayerdialog.cpp
Expand Up @@ -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 );
Expand All @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
8 changes: 7 additions & 1 deletion src/app/ogr/qgsopenvectorlayerdialog.h
Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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.