Skip to content

Commit

Permalink
Move the buttons and connections into the base class
Browse files Browse the repository at this point in the history
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 dc6017d
Show file tree
Hide file tree
Showing 33 changed files with 162 additions and 181 deletions.
31 changes: 30 additions & 1 deletion python/gui/qgsabstractdatasourcewidget.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand All @@ -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

};

/************************************************************************
Expand Down
6 changes: 0 additions & 6 deletions python/gui/qgsowssourceselect.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 33 additions & 1 deletion src/gui/qgsabstractdatasourcewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 changes: 23 additions & 3 deletions src/gui/qgsabstractdatasourcewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "qgsproviderregistry.h"
#include "qgsguiutils.h"
#include <QDialog>
#include <QDialogButtonBox>

class QgsMapCanvas;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsdatasourcemanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
17 changes: 1 addition & 16 deletions src/gui/qgsowssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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
Expand All @@ -106,7 +96,6 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( const QString &service, QWidget *parent,
mTimeWidget->hide();
mFormatWidget->hide();
mCRSWidget->hide();
mAddButton->hide();
mCacheWidget->hide();
}

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

void QgsOWSSourceSelect::addClicked()
{
}

void QgsOWSSourceSelect::enableLayersForCrs( QTreeWidgetItem * )
{
}
Expand Down
5 changes: 0 additions & 5 deletions src/gui/qgsowssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 );
Expand Down
12 changes: 5 additions & 7 deletions src/providers/arcgisrest/qgsarcgisservicesourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -439,7 +437,7 @@ void QgsArcGisServiceSourceSelect::treeWidgetCurrentRowChanged( const QModelInde
{
mBuildQueryButton->setEnabled( current.isValid() );
}
mAddButton->setEnabled( current.isValid() );
emit enableButtons( current.isValid() );
}

void QgsArcGisServiceSourceSelect::buildQueryButtonClicked()
Expand Down
3 changes: 1 addition & 2 deletions src/providers/arcgisrest/qgsarcgisservicesourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
15 changes: 4 additions & 11 deletions src/providers/db2/qgsdb2sourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() );
}


Expand Down
3 changes: 1 addition & 2 deletions src/providers/db2/qgsdb2sourceselect.h
Original file line number Diff line number Diff line change
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 addTables();
void addClicked() override;
void buildQuery();
//! Triggered when the provider's connections need to be refreshed
void refresh() override;
Expand Down Expand Up @@ -179,7 +179,6 @@ class QgsDb2SourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsDb
QgsDatabaseFilterProxyModel mProxyModel;

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

void finishList();
};
Expand Down
Loading

0 comments on commit dc6017d

Please sign in to comment.