From 003bf3a76f2d53762fff9c416fd49e3847139eb0 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 6 Sep 2017 07:21:20 +1000 Subject: [PATCH] QgsGeoNodeSourceSelect is a QgsAbstractDataSourceWidget --- python/gui/geonode/qgsgeonodesourceselect.sip | 15 +++++----- src/app/qgisapp.cpp | 4 +-- src/gui/geonode/qgsgeonodesourceselect.cpp | 30 ++++++++----------- src/gui/geonode/qgsgeonodesourceselect.h | 19 ++++++------ src/gui/qgsdatasourcemanagerdialog.cpp | 2 +- 5 files changed, 32 insertions(+), 38 deletions(-) diff --git a/python/gui/geonode/qgsgeonodesourceselect.sip b/python/gui/geonode/qgsgeonodesourceselect.sip index dc27ff92c51..3dc28d8cd6f 100644 --- a/python/gui/geonode/qgsgeonodesourceselect.sip +++ b/python/gui/geonode/qgsgeonodesourceselect.sip @@ -29,7 +29,7 @@ class QgsGeonodeItemDelegate : QItemDelegate explicit QgsGeonodeItemDelegate( QObject *parent = 0 ); }; -class QgsGeoNodeSourceSelect: QDialog +class QgsGeoNodeSourceSelect: QgsAbstractDataSourceWidget { %TypeHeaderCode @@ -37,15 +37,16 @@ class QgsGeoNodeSourceSelect: QDialog %End public: - QgsGeoNodeSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode = false ); + QgsGeoNodeSourceSelect( QWidget *parent /TransferThis/ = 0, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); + ~QgsGeoNodeSourceSelect(); + public slots: + + virtual void addButtonClicked(); + + signals: - void connectionsChanged(); - void addRasterLayer( const QString &rasterLayerPath, - const QString &baseName, - const QString &providerKey ); - void addRasterLayer(); void addWfsLayer( const QString &uri, diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 3feb4534981..d566137dc60 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -4443,13 +4443,13 @@ void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer ) void QgisApp::addGeonodeLayer() { - QgsGeoNodeSourceSelect *geonodes = new QgsGeoNodeSourceSelect( this, 0, true ); + QgsGeoNodeSourceSelect *geonodes = new QgsGeoNodeSourceSelect( this, 0, QgsProviderRegistry::WidgetMode::None ); if ( !geonodes ) { QMessageBox::warning( this, tr( "Geonode" ), tr( "Cannot get Geonode select dialog." ) ); return; } - connect( geonodes, static_cast( &QgsGeoNodeSourceSelect::addRasterLayer ), this, static_cast( &QgisApp::addRasterLayer ) ); + //connect( geonodes, static_cast( &QgsGeoNodeSourceSelect::addRasterLayer ), this, static_cast( &QgisApp::addRasterLayer ) ); connect( geonodes, &QgsGeoNodeSourceSelect::addWfsLayer, this, &QgisApp::addVectorLayer ); geonodes->exec(); delete geonodes; diff --git a/src/gui/geonode/qgsgeonodesourceselect.cpp b/src/gui/geonode/qgsgeonodesourceselect.cpp index 5d569a275ef..cdd1c26d23b 100644 --- a/src/gui/geonode/qgsgeonodesourceselect.cpp +++ b/src/gui/geonode/qgsgeonodesourceselect.cpp @@ -39,26 +39,15 @@ enum MODEL_IDX_WEB_SERVICE }; -QgsGeoNodeSourceSelect::QgsGeoNodeSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode ) - : QDialog( parent, fl ) +QgsGeoNodeSourceSelect::QgsGeoNodeSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ) + : QgsAbstractDataSourceWidget( parent, fl, widgetMode ) { setupUi( this ); - - if ( embeddedMode != QgsProviderRegistry::WidgetMode::None ) - { - // For some obscure reasons hiding does not work! - // buttonBox->button( QDialogButtonBox::Close )->hide(); - buttonBox->removeButton( buttonBox->button( QDialogButtonBox::Close ) ); - } - - mAddButton = new QPushButton( tr( "&Add" ) ); - mAddButton->setEnabled( false ); - - buttonBox->addButton( mAddButton, QDialogButtonBox::ActionRole ); + setupButtons( buttonBox ); + connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsGeoNodeSourceSelect::showHelp ); populateConnectionList(); - connect( buttonBox, &QDialogButtonBox::rejected, this, &QgsGeoNodeSourceSelect::reject ); connect( btnNew, &QPushButton::clicked, this, &QgsGeoNodeSourceSelect::addConnectionsEntryList ); connect( btnEdit, &QPushButton::clicked, this, &QgsGeoNodeSourceSelect::modifyConnectionsEntryList ); connect( btnDelete, &QPushButton::clicked, this, &QgsGeoNodeSourceSelect::deleteConnectionsEntryList ); @@ -67,7 +56,6 @@ QgsGeoNodeSourceSelect::QgsGeoNodeSourceSelect( QWidget *parent, Qt::WindowFlags connect( btnLoad, &QPushButton::clicked, this, &QgsGeoNodeSourceSelect::loadGeonodeConnection ); connect( lineFilter, &QLineEdit::textChanged, this, &QgsGeoNodeSourceSelect::filterChanged ); connect( treeView, &QTreeView::clicked, this, &QgsGeoNodeSourceSelect::treeViewSelectionChanged ); - connect( mAddButton, &QPushButton::clicked, this, &QgsGeoNodeSourceSelect::addButtonClicked ); mItemDelegate = new QgsGeonodeItemDelegate( treeView ); treeView->setItemDelegate( mItemDelegate ); @@ -185,6 +173,12 @@ void QgsGeoNodeSourceSelect::setConnectionListPosition() } } +void QgsGeoNodeSourceSelect::showHelp() +{ + //TODO - correct URL + //QgsHelp::openHelp( QStringLiteral( "managing_data_source/opening_data.html#spatialite-layers" ) ); +} + void QgsGeoNodeSourceSelect::connectToGeonodeConnection() { QApplication::setOverrideCursor( Qt::BusyCursor ); @@ -366,7 +360,7 @@ void QgsGeoNodeSourceSelect::treeViewSelectionChanged() qDebug() << "Current index is invalid"; return; } - mAddButton->setEnabled( false ); + addButton()->setEnabled( false ); QModelIndexList modelIndexList = treeView->selectionModel()->selectedRows(); for ( int i = 0; i < modelIndexList.size(); i++ ) { @@ -380,7 +374,7 @@ void QgsGeoNodeSourceSelect::treeViewSelectionChanged() if ( typeItem == tr( "Layer" ) ) { // Enable if there is a layer selected - mAddButton->setEnabled( true ); + addButton()->setEnabled( true ); return; } } diff --git a/src/gui/geonode/qgsgeonodesourceselect.h b/src/gui/geonode/qgsgeonodesourceselect.h index 005b65e220f..c11ec55b2fa 100644 --- a/src/gui/geonode/qgsgeonodesourceselect.h +++ b/src/gui/geonode/qgsgeonodesourceselect.h @@ -21,6 +21,7 @@ #include #include #include +#include "qgsabstractdatasourcewidget.h" #include "ui_qgsgeonodesourceselectbase.h" #include "qgis_gui.h" @@ -32,21 +33,21 @@ class GUI_EXPORT QgsGeonodeItemDelegate : public QItemDelegate explicit QgsGeonodeItemDelegate( QObject *parent = nullptr ) : QItemDelegate( parent ) { } }; -class GUI_EXPORT QgsGeoNodeSourceSelect: public QDialog, private Ui::QgsGeonodeSourceSelectBase +class GUI_EXPORT QgsGeoNodeSourceSelect: public QgsAbstractDataSourceWidget, private Ui::QgsGeonodeSourceSelectBase { Q_OBJECT public: - QgsGeoNodeSourceSelect( QWidget *parent, Qt::WindowFlags fl, bool embeddedMode = false ); + QgsGeoNodeSourceSelect( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ); + ~QgsGeoNodeSourceSelect(); + public slots: + + void addButtonClicked() override; + signals: - void connectionsChanged(); - void addRasterLayer( const QString &rasterLayerPath, - const QString &baseName, - const QString &providerKey ); - void addRasterLayer(); void addWfsLayer( const QString &uri, @@ -65,7 +66,6 @@ class GUI_EXPORT QgsGeoNodeSourceSelect: public QDialog, private Ui::QgsGeonodeS QStandardItemModel *mModel = nullptr; QSortFilterProxyModel *mModelProxy = nullptr; QPushButton *mBuildQueryButton = nullptr; - QPushButton *mAddButton = nullptr; QModelIndex mSQLIndex; private slots: @@ -77,10 +77,9 @@ class GUI_EXPORT QgsGeoNodeSourceSelect: public QDialog, private Ui::QgsGeonodeS void loadGeonodeConnection(); void filterChanged( const QString &text ); void treeViewSelectionChanged(); - void addButtonClicked(); - void populateConnectionList(); void setConnectionListPosition(); + void showHelp(); }; diff --git a/src/gui/qgsdatasourcemanagerdialog.cpp b/src/gui/qgsdatasourcemanagerdialog.cpp index 9a492bacd29..1f7688b2b47 100644 --- a/src/gui/qgsdatasourcemanagerdialog.cpp +++ b/src/gui/qgsdatasourcemanagerdialog.cpp @@ -74,7 +74,7 @@ QgsDataSourceManagerDialog::QgsDataSourceManagerDialog( QgsBrowserModel *browser QDialog *geonodeDialog = new QgsGeoNodeSourceSelect( this, Qt::Widget, QgsProviderRegistry::WidgetMode::Embedded ); - dlg = addDialog( geonodeDialog, QStringLiteral( "geonode" ), tr( "GeoNode" ), QStringLiteral( "/mActionAddGeonodeLayer.svg" ) ); + QDialog *dlg = addDialog( geonodeDialog, QStringLiteral( "geonode" ), tr( "GeoNode" ), QStringLiteral( "/mActionAddGeonodeLayer.svg" ) ); if ( dlg ) {