Skip to content
Permalink
Browse files

Move the buttons and connections into the base class

This was a small refactoring to homogenize the
dialogs buttons and add an Ok/Add button bar.
  • Loading branch information
elpaso committed Aug 4, 2017
1 parent 3c58599 commit dc6017dc1db7959071abbf9c3b5d92ff6a6792bd
Showing with 162 additions and 181 deletions.
  1. +30 −1 python/gui/qgsabstractdatasourcewidget.sip
  2. +0 −6 python/gui/qgsowssourceselect.sip
  3. +33 −1 src/gui/qgsabstractdatasourcewidget.cpp
  4. +23 −3 src/gui/qgsabstractdatasourcewidget.h
  5. +1 −0 src/gui/qgsdatasourcemanagerdialog.cpp
  6. +1 −16 src/gui/qgsowssourceselect.cpp
  7. +0 −5 src/gui/qgsowssourceselect.h
  8. +5 −7 src/providers/arcgisrest/qgsarcgisservicesourceselect.cpp
  9. +1 −2 src/providers/arcgisrest/qgsarcgisservicesourceselect.h
  10. +4 −11 src/providers/db2/qgsdb2sourceselect.cpp
  11. +1 −2 src/providers/db2/qgsdb2sourceselect.h
  12. +3 −13 src/providers/delimitedtext/qgsdelimitedtextsourceselect.cpp
  13. +1 −2 src/providers/delimitedtext/qgsdelimitedtextsourceselect.h
  14. +4 −9 src/providers/mssql/qgsmssqlsourceselect.cpp
  15. +1 −2 src/providers/mssql/qgsmssqlsourceselect.h
  16. +4 −10 src/providers/postgres/qgspgsourceselect.cpp
  17. +1 −2 src/providers/postgres/qgspgsourceselect.h
  18. +3 −14 src/providers/spatialite/qgsspatialitesourceselect.cpp
  19. +1 −4 src/providers/spatialite/qgsspatialitesourceselect.h
  20. +5 −7 src/providers/virtual/qgsvirtuallayersourceselect.cpp
  21. +1 −1 src/providers/virtual/qgsvirtuallayersourceselect.h
  22. +1 −1 src/providers/virtual/qgsvirtuallayersourceselectbase.ui
  23. +3 −2 src/providers/wcs/qgswcssourceselect.cpp
  24. +5 −13 src/providers/wfs/qgswfssourceselect.cpp
  25. +1 −2 src/providers/wfs/qgswfssourceselect.h
  26. +10 −24 src/providers/wms/qgswmssourceselect.cpp
  27. +1 −3 src/providers/wms/qgswmssourceselect.h
  28. +2 −2 src/ui/qgsarcgisservicesourceselectbase.ui
  29. +1 −1 src/ui/qgsdbsourceselectbase.ui
  30. +2 −2 src/ui/qgsdelimitedtextsourceselectbase.ui
  31. +1 −1 src/ui/qgsowssourceselectbase.ui
  32. +10 −10 src/ui/qgswfssourceselectbase.ui
  33. +2 −2 src/ui/qgswmssourceselectbase.ui
@@ -46,6 +46,18 @@ Destructor
The default implementation does nothing
%End

virtual void addClicked();
%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();
%Docstring
Triggered when the dialog is accepted, call addClicked() and emit the accepted() signal
%End

signals:

void connectionsChanged();
@@ -79,6 +91,12 @@ Emitted when a progress dialog is shown by the provider dialog
Emitted when a progress dialog is shown by the provider dialog
%End

void enableButtons( bool enable );
%Docstring
Emitted when the ok/add buttons should be enabled/disabled
%End


protected:

QgsAbstractDataSourceWidget( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
@@ -94,10 +112,21 @@ Return the widget mode

const QgsMapCanvas *mapCanvas() const;
%Docstring
Return the map canvas (can be null)
Return the map canvas (can be null)
:rtype: QgsMapCanvas
%End

void setupButtons( QDialogButtonBox *buttonBox );
%Docstring
Connect the ok and apply/add buttons to the slots
%End

const QPushButton *addButton( );
%Docstring
Return the add Button
:rtype: QPushButton
%End

};

/************************************************************************
@@ -75,11 +75,6 @@ Loads connections from the file
Once connected, available layers are displayed.
%End

virtual void addClicked();
%Docstring
Determines the layers the user selected
%End

void searchFinished();

void on_mChangeCRSButton_clicked();
@@ -214,7 +209,6 @@ Returns a textual description for the authority id




void addWmsListRow( const QDomElement &item, int row );
%Docstring
layer name derived from latest layer selection (updated as long it's not edited manually)
@@ -17,12 +17,12 @@
***************************************************************************/

#include "qgsabstractdatasourcewidget.h"
#include <QPushButton>

QgsAbstractDataSourceWidget::QgsAbstractDataSourceWidget( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
QDialog( parent, fl ),
mWidgetMode( widgetMode )
{

}

QgsProviderRegistry::WidgetMode QgsAbstractDataSourceWidget::widgetMode() const
@@ -35,8 +35,40 @@ const QgsMapCanvas *QgsAbstractDataSourceWidget::mapCanvas() const
return mMapCanvas;
}

void QgsAbstractDataSourceWidget::setupButtons( QDialogButtonBox *buttonBox )
{

if ( mWidgetMode == QgsProviderRegistry::WidgetMode::None )
{
QPushButton *closeButton = new QPushButton( tr( "&Close" ) );
buttonBox->addButton( closeButton, QDialogButtonBox::ApplyRole );
connect( closeButton, &QPushButton::clicked, this, &QgsAbstractDataSourceWidget::addClicked );
}

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( 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( this, &QgsAbstractDataSourceWidget::enableButtons, okButton, &QPushButton::setEnabled );

}


void QgsAbstractDataSourceWidget::setMapCanvas( const QgsMapCanvas *mapCanvas )
{
mMapCanvas = mapCanvas;
}

void QgsAbstractDataSourceWidget::okClicked()
{
addClicked();
emit accepted();
}
@@ -26,6 +26,7 @@
#include "qgsproviderregistry.h"
#include "qgsguiutils.h"
#include <QDialog>
#include <QDialogButtonBox>

class QgsMapCanvas;

@@ -58,6 +59,16 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
*/
virtual void refresh() {}

/** 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.
*/
virtual void addClicked() { }

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

signals:

/** Emitted when the provider's connections have changed
@@ -80,6 +91,10 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
//! Emitted when a progress dialog is shown by the provider dialog
void progressMessage( QString message );

//! Emitted when the ok/add buttons should be enabled/disabled
void enableButtons( bool enable );


protected:

//! Constructor
@@ -88,12 +103,17 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
//! Return the widget mode
QgsProviderRegistry::WidgetMode widgetMode() const;

/** Return the map canvas (can be null)
*/
//! Return the map canvas (can be null)
const QgsMapCanvas *mapCanvas() const;

private:
//! Connect the ok and apply/add buttons to the slots
void setupButtons( QDialogButtonBox *buttonBox );

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

private:
QPushButton *mAddButton = nullptr;
QgsProviderRegistry::WidgetMode mWidgetMode;
QgsMapCanvas const *mMapCanvas = nullptr;

@@ -192,6 +192,7 @@ QgsAbstractDataSourceWidget *QgsDataSourceManagerDialog::providerDialog( const Q
dlg->setMapCanvas( mMapCanvas );
}
connect( dlg, &QgsAbstractDataSourceWidget::rejected, this, &QgsDataSourceManagerDialog::reject );
connect( dlg, &QgsAbstractDataSourceWidget::accepted, this, &QgsDataSourceManagerDialog::accept );
return dlg;
}
}
@@ -60,20 +60,11 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
, mCurrentTileset( nullptr )
{
setupUi( this );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
}
setupButtons( buttonBox );


setWindowTitle( tr( "Add Layer(s) from a %1 Server" ).arg( service ) );

mAddButton = buttonBox->button( QDialogButtonBox::Apply );
mAddButton->setText( tr( "&Add" ) );
mAddButton->setToolTip( tr( "Add selected layers to map" ) );
mAddButton->setEnabled( false );

clearCrs();

mTileWidthLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
@@ -90,7 +81,6 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,

if ( widgetMode() != QgsProviderRegistry::WidgetMode::Manager )
{
connect( mAddButton, &QAbstractButton::clicked, this, &QgsOWSSourceSelect::addClicked );
//set the current project CRS if available
QgsCoordinateReferenceSystem currentRefSys = QgsProject::instance()->crs();
//convert CRS id to epsg
@@ -106,7 +96,6 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
mTimeWidget->hide();
mFormatWidget->hide();
mCRSWidget->hide();
mAddButton->hide();
mCacheWidget->hide();
}

@@ -361,10 +350,6 @@ void QgsOWSSourceSelect::on_mConnectButton_clicked()
QApplication::restoreOverrideCursor();
}

void QgsOWSSourceSelect::addClicked()
{
}

void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
{
}
@@ -87,9 +87,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QgsAbstractDataSourceWidget, protec
*/
void on_mConnectButton_clicked();

//! Determines the layers the user selected
virtual void addClicked();

void searchFinished();

//! Opens the Spatial Reference System dialog.
@@ -187,8 +184,6 @@ class GUI_EXPORT QgsOWSSourceSelect : public QgsAbstractDataSourceWidget, protec
//! layer name derived from latest layer selection (updated as long it's not edited manually)
QString mLastLayerName;

QPushButton *mAddButton = nullptr;

QMap<QString, QString> mCrsNames;

void addWmsListRow( const QDomElement &item, int row );
@@ -57,12 +57,10 @@ 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 ) );

mAddButton = buttonBox->addButton( tr( "&Add" ), QDialogButtonBox::ActionRole );
mAddButton->setEnabled( false );
connect( mAddButton, &QAbstractButton::clicked, this, &QgsArcGisServiceSourceSelect::addButtonClicked );

if ( mServiceType == FeatureService )
{
mBuildQueryButton = buttonBox->addButton( tr( "&Build query" ), QDialogButtonBox::ActionRole );
@@ -300,15 +298,15 @@ void QgsArcGisServiceSourceSelect::connectToServer()
}

btnConnect->setEnabled( true );
mAddButton->setEnabled( haveLayers );
emit enableButtons( haveLayers );
if ( mServiceType == FeatureService )
{
mBuildQueryButton->setEnabled( haveLayers );
}
btnChangeSpatialRefSys->setEnabled( haveLayers );
}

void QgsArcGisServiceSourceSelect::addButtonClicked()
void QgsArcGisServiceSourceSelect::addClicked()
{
if ( treeView->selectionModel()->selectedRows().isEmpty() )
{
@@ -439,7 +437,7 @@ void QgsArcGisServiceSourceSelect::treeWidgetCurrentRowChanged( const QModelInde
{
mBuildQueryButton->setEnabled( current.isValid() );
}
mAddButton->setEnabled( current.isValid() );
emit enableButtons( current.isValid() );
}

void QgsArcGisServiceSourceSelect::buildQueryButtonClicked()
@@ -59,7 +59,6 @@ class QgsArcGisServiceSourceSelect : public QgsAbstractDataSourceWidget, protect
QStandardItemModel *mModel = nullptr;
QSortFilterProxyModel *mModelProxy = nullptr;
QPushButton *mBuildQueryButton = nullptr;
QPushButton *mAddButton = nullptr;
QButtonGroup *mImageEncodingGroup = nullptr;
QgsRectangle mCanvasExtent;
QgsCoordinateReferenceSystem mCanvasCrs;
@@ -105,7 +104,7 @@ class QgsArcGisServiceSourceSelect : public QgsAbstractDataSourceWidget, protect
void addEntryToServerList();
void deleteEntryOfServerList();
void modifyEntryOfServerList();
void addButtonClicked();
void addClicked() override;
void buildQueryButtonClicked();
void changeCrs();
void changeCrsFilter();
@@ -122,27 +122,20 @@ QgsDb2SourceSelect::QgsDb2SourceSelect( QWidget *parent, Qt::WindowFlags fl, Qgs
, mUseEstimatedMetadata( false )
{
setupUi( this );

setupButtons( buttonBox );
setWindowTitle( tr( "Add Db2 Table(s)" ) );

if ( widgetMode() != QgsProviderRegistry::WidgetMode::None )
{
buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) );
mHoldDialogOpen->hide();
}

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, &QgsDb2SourceSelect::addTables );

buttonBox->addButton( mBuildQueryButton, QDialogButtonBox::ActionRole );
connect( mBuildQueryButton, &QAbstractButton::clicked, this, &QgsDb2SourceSelect::buildQuery );
}
@@ -319,7 +312,7 @@ void QgsDb2SourceSelect::on_mTablesTreeView_doubleClicked( const QModelIndex &in
QgsSettings settings;
if ( settings.value( QStringLiteral( "qgis/addDb2DC" ), false ).toBool() )
{
addTables();
addClicked();
}
else
{
@@ -434,7 +427,7 @@ void QgsDb2SourceSelect::populateConnectionList()
}

// Slot for performing action when the Add button is clicked
void QgsDb2SourceSelect::addTables()
void QgsDb2SourceSelect::addClicked()
{
QgsDebugMsg( QString( "mConnInfo:%1" ).arg( mConnInfo ) );
mSelectedTables.clear();
@@ -664,7 +657,7 @@ void QgsDb2SourceSelect::setSearchExpression( const QString &regexp )
void QgsDb2SourceSelect::treeWidgetSelectionChanged( const QItemSelection &selected, const QItemSelection &deselected )
{
Q_UNUSED( deselected )
mAddButton->setEnabled( !selected.isEmpty() );
emit enableButtons( !selected.isEmpty() );
}


@@ -113,7 +113,7 @@ class QgsDb2SourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDb

public slots:
//! Determines the tables the user selected and closes the dialog
void addTables();
void addClicked() override;
void buildQuery();
//! Triggered when the provider's connections need to be refreshed
void refresh() override;
@@ -179,7 +179,6 @@ class QgsDb2SourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDb
QgsDatabaseFilterProxyModel mProxyModel;

QPushButton *mBuildQueryButton = nullptr;
QPushButton *mAddButton = nullptr;

void finishList();
};

0 comments on commit dc6017d

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