Skip to content

Commit

Permalink
QgsGeoNodeSourceSelect is a QgsAbstractDataSourceWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent 92a2499 commit 003bf3a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 38 deletions.
15 changes: 8 additions & 7 deletions python/gui/geonode/qgsgeonodesourceselect.sip
Expand Up @@ -29,23 +29,24 @@ class QgsGeonodeItemDelegate : QItemDelegate
explicit QgsGeonodeItemDelegate( QObject *parent = 0 );
};

class QgsGeoNodeSourceSelect: QDialog
class QgsGeoNodeSourceSelect: QgsAbstractDataSourceWidget
{

%TypeHeaderCode
#include "qgsgeonodesourceselect.h"
%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,
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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<void ( QgsGeoNodeSourceSelect::* )()>( &QgsGeoNodeSourceSelect::addRasterLayer ), this, static_cast<void ( QgisApp::* )()>( &QgisApp::addRasterLayer ) );
//connect( geonodes, static_cast<void ( QgsGeoNodeSourceSelect::* )()>( &QgsGeoNodeSourceSelect::addRasterLayer ), this, static_cast<void ( QgisApp::* )()>( &QgisApp::addRasterLayer ) );
connect( geonodes, &QgsGeoNodeSourceSelect::addWfsLayer, this, &QgisApp::addVectorLayer );
geonodes->exec();
delete geonodes;
Expand Down
30 changes: 12 additions & 18 deletions src/gui/geonode/qgsgeonodesourceselect.cpp
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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++ )
{
Expand All @@ -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;
}
}
Expand Down
19 changes: 9 additions & 10 deletions src/gui/geonode/qgsgeonodesourceselect.h
Expand Up @@ -21,6 +21,7 @@
#include <QItemDelegate>
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
#include "qgsabstractdatasourcewidget.h"
#include "ui_qgsgeonodesourceselectbase.h"
#include "qgis_gui.h"

Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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();

};

Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsdatasourcemanagerdialog.cpp
Expand Up @@ -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 )
{
Expand Down

0 comments on commit 003bf3a

Please sign in to comment.