Skip to content

Commit

Permalink
Renamed button slots and make ogr dialog inherit from the abstract base
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Aug 4, 2017
1 parent dc6017d commit fef3bc0
Show file tree
Hide file tree
Showing 32 changed files with 68 additions and 93 deletions.
9 changes: 5 additions & 4 deletions python/gui/qgsabstractdatasourcewidget.sip
Expand Up @@ -46,16 +46,17 @@ Destructor
The default implementation does nothing
%End

virtual void addClicked();
virtual void addButtonClicked();
%Docstring
Triggered when the add button is clicked, the add layer signal is emitted
Concrete classes should implement the right behavior depending on the layer
being added.
%End

virtual void okClicked();
virtual void okButtonClicked();
%Docstring
Triggered when the dialog is accepted, call addClicked() and emit the accepted() signal
Triggered when the dialog is accepted, call addButtonClicked() and
emit the accepted() signal
%End

signals:
Expand Down Expand Up @@ -121,7 +122,7 @@ Return the map canvas (can be null)
Connect the ok and apply/add buttons to the slots
%End

const QPushButton *addButton( );
QPushButton *addButton( ) const;
%Docstring
Return the add Button
:rtype: QPushButton
Expand Down
30 changes: 8 additions & 22 deletions src/gui/ogr/qgsopenvectorlayerdialog.cpp
Expand Up @@ -32,22 +32,10 @@
#include "qgsapplication.h"

QgsOpenVectorLayerDialog::QgsOpenVectorLayerDialog( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QDialog( parent, fl ),
mWidgetMode( widgetMode ),
mAddButton( nullptr )
: QgsAbstractDataSourceWidget( parent, fl, widgetMode )
{
setupUi( this );

if ( mWidgetMode != QgsProviderRegistry::WidgetMode::None )
{
this->layout()->setSizeConstraint( QLayout::SetNoConstraint );
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Cancel ) );
}

mAddButton = new QPushButton( tr( "&Add" ) );
// TODO: enable/disable according to valid selection
mAddButton->setEnabled( true );
buttonBox->addButton( mAddButton, QDialogButtonBox::AcceptRole );
setupButtons( buttonBox );

cmbDatabaseTypes->blockSignals( true );
cmbConnections->blockSignals( true );
Expand Down Expand Up @@ -287,7 +275,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()
if ( !selected.isEmpty() )
{
inputSrcDataset->setText( selected.join( QStringLiteral( ";" ) ) );
mAddButton->setFocus();
addButton()->setFocus();
}
}
else if ( radioSrcDirectory->isChecked() )
Expand All @@ -302,8 +290,7 @@ void QgsOpenVectorLayerDialog::on_buttonSelectSrc_clicked()



//********************auto connected slots *****************/
void QgsOpenVectorLayerDialog::accept()
void QgsOpenVectorLayerDialog::addButtonClicked()
{
QgsSettings settings;
QgsDebugMsg( "dialog button accepted" );
Expand Down Expand Up @@ -395,16 +382,15 @@ void QgsOpenVectorLayerDialog::accept()
// Save the used encoding
settings.setValue( QStringLiteral( "UI/encoding" ), encoding() );

if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
{
QDialog::accept();
}
else if ( ! mDataSources.isEmpty() )
if ( ! mDataSources.isEmpty() )
{
emit addVectorLayers( mDataSources, encoding(), dataSourceType() );
}
}


//********************auto connected slots *****************/

void QgsOpenVectorLayerDialog::on_radioSrcFile_toggled( bool checked )
{
if ( checked )
Expand Down
10 changes: 5 additions & 5 deletions src/gui/ogr/qgsopenvectorlayerdialog.h
Expand Up @@ -23,6 +23,7 @@
#include <QDialog>
#include "qgshelp.h"
#include "qgsproviderregistry.h"
#include "qgsabstractdatasourcewidget.h"
#include "qgis_gui.h"

#define SIP_NO_FILE
Expand All @@ -32,7 +33,7 @@
* file, database, directory and protocol sources.
* \note not available in Python bindings
*/
class GUI_EXPORT QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenVectorLayerDialogBase
class GUI_EXPORT QgsOpenVectorLayerDialog : public QgsAbstractDataSourceWidget, private Ui::QgsOpenVectorLayerDialogBase
{
Q_OBJECT

Expand Down Expand Up @@ -60,8 +61,9 @@ class GUI_EXPORT QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenV
QString mDataSourceType;
//! Embedded dialog (do not call parent's accept) and emit signals
QgsProviderRegistry::WidgetMode mWidgetMode = QgsProviderRegistry::WidgetMode::None;
//! Add layer button
QPushButton *mAddButton = nullptr;

public slots:
void addButtonClicked() override;

private slots:
//! Opens the create connection dialog to build a new connection
Expand All @@ -81,8 +83,6 @@ class GUI_EXPORT QgsOpenVectorLayerDialog : public QDialog, private Ui::QgsOpenV
//! Sets the selected connection
void setSelectedConnection();

void accept() override;

void on_buttonSelectSrc_clicked();
void on_radioSrcFile_toggled( bool checked );
void on_radioSrcDirectory_toggled( bool checked );
Expand Down
10 changes: 5 additions & 5 deletions src/gui/qgsabstractdatasourcewidget.cpp
Expand Up @@ -42,21 +42,21 @@ void QgsAbstractDataSourceWidget::setupButtons( QDialogButtonBox *buttonBox )
{
QPushButton *closeButton = new QPushButton( tr( "&Close" ) );
buttonBox->addButton( closeButton, QDialogButtonBox::ApplyRole );
connect( closeButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addClicked );
connect( closeButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addButtonClicked );
}

mAddButton = new QPushButton( tr( "&Add" ) );
mAddButton->setToolTip( tr( "Add selected layers to map" ) );
mAddButton->setEnabled( false );
buttonBox->addButton( mAddButton, QDialogButtonBox::ApplyRole );
connect( mAddButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addClicked );
connect( mAddButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addButtonClicked );
connect( this, &QgsAbstractDataSourceWidget::enableButtons, mAddButton, &QPushButton::setEnabled );

QPushButton *okButton = new QPushButton( tr( "&Ok" ) );
okButton->setToolTip( tr( "Add selected layers to map and close this dialog" ) );
okButton->setEnabled( false );
buttonBox->addButton( okButton, QDialogButtonBox::AcceptRole );
connect( okButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::okClicked );
connect( okButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::okButtonClicked );
connect( this, &QgsAbstractDataSourceWidget::enableButtons, okButton, &QPushButton::setEnabled );

}
Expand All @@ -67,8 +67,8 @@ void QgsAbstractDataSourceWidget::setMapCanvas( const QgsMapCanvas *mapCanvas )
mMapCanvas = mapCanvas;
}

void QgsAbstractDataSourceWidget::okClicked()
void QgsAbstractDataSourceWidget::okButtonClicked()
{
addClicked();
addButtonClicked();
emit accepted();
}
9 changes: 5 additions & 4 deletions src/gui/qgsabstractdatasourcewidget.h
Expand Up @@ -63,11 +63,12 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
* Concrete classes should implement the right behavior depending on the layer
* being added.
*/
virtual void addClicked() { }
virtual void addButtonClicked() { }

/** Triggered when the dialog is accepted, call addClicked() and emit the accepted() signal
/** Triggered when the dialog is accepted, call addButtonClicked() and
* emit the accepted() signal
*/
virtual void okClicked();
virtual void okButtonClicked();

signals:

Expand Down Expand Up @@ -110,7 +111,7 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
void setupButtons( QDialogButtonBox *buttonBox );

//! Return the add Button
const QPushButton *addButton( ) { return mAddButton; }
QPushButton *addButton( ) const { return mAddButton; }

private:
QPushButton *mAddButton = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsdatasourcemanagerdialog.cpp
Expand Up @@ -209,7 +209,7 @@ void QgsDataSourceManagerDialog::addDbProviderDialog( const QString providerKey,
connect( dlg, SIGNAL( progressMessage( QString ) ),
this, SIGNAL( showStatusMessage( QString ) ) );
connect( dlg, SIGNAL( connectionsChanged() ), this, SIGNAL( connectionsChanged() ) );
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
connect( this, SIGNAL( providerDialogsRefreshRequested() ), dlg, SLOT( refresh() ) );
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/providers/arcgisrest/qgsafssourceselect.cpp
Expand Up @@ -27,13 +27,8 @@


QgsAfsSourceSelect::QgsAfsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisFeatureServer" ), QgsArcGisServiceSourceSelect::FeatureService, parent, fl )
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisFeatureServer" ), QgsArcGisServiceSourceSelect::FeatureService, parent, fl, widgetMode )
{
if ( widgetMode == QgsProviderRegistry::WidgetMode::Embedded || widgetMode == QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}

// import/export of connections not supported yet
btnLoad->hide();
btnSave->hide();
Expand Down
6 changes: 1 addition & 5 deletions src/providers/arcgisrest/qgsamssourceselect.cpp
Expand Up @@ -26,12 +26,8 @@


QgsAmsSourceSelect::QgsAmsSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisMapServer" ), QgsArcGisServiceSourceSelect::MapService, parent, fl )
: QgsArcGisServiceSourceSelect( QStringLiteral( "ArcGisMapServer" ), QgsArcGisServiceSourceSelect::MapService, parent, fl, widgetMode )
{
if ( widgetMode == QgsProviderRegistry::WidgetMode::Embedded || widgetMode == QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}

// import/export of connections not supported yet
btnLoad->hide();
Expand Down
3 changes: 1 addition & 2 deletions src/providers/arcgisrest/qgsarcgisservicesourceselect.cpp
Expand Up @@ -57,7 +57,6 @@ QgsArcGisServiceSourceSelect::QgsArcGisServiceSourceSelect( const QString &servi
mImageEncodingGroup( 0 )
{
setupUi( this );
// Creates and connects standard ok/apply buttons
setupButtons( buttonBox );
setWindowTitle( QStringLiteral( "Add %1 Layer from a Server" ).arg( mServiceName ) );

Expand Down Expand Up @@ -306,7 +305,7 @@ void QgsArcGisServiceSourceSelect::connectToServer()
btnChangeSpatialRefSys->setEnabled( haveLayers );
}

void QgsArcGisServiceSourceSelect::addClicked()
void QgsArcGisServiceSourceSelect::addButtonClicked()
{
if ( treeView->selectionModel()->selectedRows().isEmpty() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/arcgisrest/qgsarcgisservicesourceselect.h
Expand Up @@ -104,7 +104,7 @@ class QgsArcGisServiceSourceSelect : public QgsAbstractDataSourceWidget, protect
void addEntryToServerList();
void deleteEntryOfServerList();
void modifyEntryOfServerList();
void addClicked() override;
void addButtonClicked() override;
void buildQueryButtonClicked();
void changeCrs();
void changeCrsFilter();
Expand Down
4 changes: 2 additions & 2 deletions src/providers/db2/qgsdb2sourceselect.cpp
Expand Up @@ -312,7 +312,7 @@ void QgsDb2SourceSelect::on_mTablesTreeView_doubleClicked( const QModelIndex &in
QgsSettings settings;
if ( settings.value( QStringLiteral( "qgis/addDb2DC" ), false ).toBool() )
{
addClicked();
addButtonClicked();
}
else
{
Expand Down Expand Up @@ -427,7 +427,7 @@ void QgsDb2SourceSelect::populateConnectionList()
}

// Slot for performing action when the Add button is clicked
void QgsDb2SourceSelect::addClicked()
void QgsDb2SourceSelect::addButtonClicked()
{
QgsDebugMsg( QString( "mConnInfo:%1" ).arg( mConnInfo ) );
mSelectedTables.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/db2/qgsdb2sourceselect.h
Expand Up @@ -113,7 +113,7 @@ class QgsDb2SourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDb

public slots:
//! Determines the tables the user selected and closes the dialog
void addClicked() override;
void addButtonClicked() override;
void buildQuery();
//! Triggered when the provider's connections need to be refreshed
void refresh() override;
Expand Down
Expand Up @@ -109,7 +109,7 @@ void QgsDelimitedTextSourceSelect::on_btnBrowseForFile_clicked()
getOpenFileName();
}

void QgsDelimitedTextSourceSelect::addClicked()
void QgsDelimitedTextSourceSelect::addButtonClicked()
{
// The following conditions should not be hit! OK will not be enabled...
if ( txtLayerName->text().isEmpty() )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/delimitedtext/qgsdelimitedtextsourceselect.h
Expand Up @@ -67,7 +67,7 @@ class QgsDelimitedTextSourceSelect : public QgsAbstractDataSourceWidget, private
void on_btnBrowseForFile_clicked();

public slots:
void addClicked() override;
void addButtonClicked() override;
void updateFileName();
void updateFieldsAndEnable();
void enableAccept();
Expand Down
4 changes: 2 additions & 2 deletions src/providers/mssql/qgsmssqlsourceselect.cpp
Expand Up @@ -311,7 +311,7 @@ void QgsMssqlSourceSelect::on_mTablesTreeView_doubleClicked( const QModelIndex &
QgsSettings settings;
if ( settings.value( QStringLiteral( "qgis/addMSSQLDC" ), false ).toBool() )
{
addClicked();
addButtonClicked();
}
else
{
Expand Down Expand Up @@ -426,7 +426,7 @@ void QgsMssqlSourceSelect::populateConnectionList()
}

// Slot for performing action when the Add button is clicked
void QgsMssqlSourceSelect::addClicked()
void QgsMssqlSourceSelect::addButtonClicked()
{
QgsDebugMsg( QString( "mConnInfo:%1" ).arg( mConnInfo ) );
mSelectedTables.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mssql/qgsmssqlsourceselect.h
Expand Up @@ -87,7 +87,7 @@ class QgsMssqlSourceSelect : public QgsAbstractDataSourceWidget, private Ui::Qgs
void refresh() override;

//! Determines the tables the user selected and closes the dialog
void addClicked() override;
void addButtonClicked() override;
void buildQuery();

/** Connects to the database using the stored connection parameters.
Expand Down
8 changes: 7 additions & 1 deletion src/providers/ogr/CMakeLists.txt
@@ -1,5 +1,11 @@

SET (OGR_SRCS qgsogrprovider.cpp qgsogrdataitems.cpp qgsogrfeatureiterator.cpp qgsogrconnpool.cpp qgsogrexpressioncompiler.cpp)
SET (OGR_SRCS
qgsogrprovider.cpp
qgsogrdataitems.cpp
qgsogrfeatureiterator.cpp
qgsogrconnpool.cpp
qgsogrexpressioncompiler.cpp
)

SET(OGR_MOC_HDRS qgsogrprovider.h qgsogrdataitems.h qgsogrconnpool.h)

Expand Down
14 changes: 4 additions & 10 deletions src/providers/oracle/qgsoraclesourceselect.cpp
Expand Up @@ -172,29 +172,23 @@ QgsOracleSourceSelect::QgsOracleSourceSelect( QWidget *parent, Qt::WindowFlags f
, mIsConnected( false )
{
setupUi( this );
setupButton( buttonBox );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
mHoldDialogOpen->hide();
}
else
{
setWindowTitle( tr( "Add Oracle Table(s)" ) );
}

mAddButton = new QPushButton( tr( "&Add" ) );
mAddButton->setEnabled( false );

mBuildQueryButton = new QPushButton( tr( "&Set Filter" ) );
mBuildQueryButton->setToolTip( tr( "Set Filter" ) );
mBuildQueryButton->setDisabled( true );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
{
buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole );
connect( mAddButton, &QAbstractButton::clicked, this, &QgsOracleSourceSelect::addTables );

buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsOracleSourceSelect::buildQuery );
}
Expand Down Expand Up @@ -359,7 +353,7 @@ void QgsOracleSourceSelect::on_mTablesTreeView_doubleClicked( const QModelIndex
QgsSettings settings;
if ( settings.value( QStringLiteral( "qgis/addOracleDC" ), false ).toBool() )
{
addTables();
addClicked();
}
else
{
Expand Down Expand Up @@ -470,7 +464,7 @@ void QgsOracleSourceSelect::populateConnectionList()
}

// Slot for performing action when the Add button is clicked
void QgsOracleSourceSelect::addTables()
void QgsOracleSourceSelect::addClicked()
{
mSelectedTables.clear();

Expand Down Expand Up @@ -674,5 +668,5 @@ void QgsOracleSourceSelect::loadTableFromCache()
void QgsOracleSourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
Q_UNUSED( deselected )
mAddButton->setEnabled( !selected.isEmpty() );
emit enableButtons( !selected.isEmpty() );
}

0 comments on commit fef3bc0

Please sign in to comment.