Skip to content

Commit

Permalink
[geonode] Move GUI related code to new files, remove legacy data item…
Browse files Browse the repository at this point in the history
…s calls
  • Loading branch information
wonder-sk committed Jun 29, 2019
1 parent 9dfb7db commit 58a01ba
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 74 deletions.
3 changes: 3 additions & 0 deletions src/providers/geonode/CMakeLists.txt
Expand Up @@ -8,11 +8,14 @@ SET(GEONODE_MOC_HDRS

IF (WITH_GUI)
SET(GEONODE_SRCS ${GEONODE_SRCS}
qgsgeonodeprovidergui.cpp
qgsgeonodedataitemguiprovider.cpp
qgsgeonodedataitems.cpp
qgsgeonodenewconnection.cpp
qgsgeonodesourceselect.cpp
)
SET(GEONODE_MOC_HDRS ${GEONODE_MOC_HDRS}
qgsgeonodedataitemguiprovider.h
qgsgeonodesourceselect.h
qgsgeonodenewconnection.h
qgsgeonodedataitems.h
Expand Down
66 changes: 66 additions & 0 deletions src/providers/geonode/qgsgeonodedataitemguiprovider.cpp
@@ -0,0 +1,66 @@
/***************************************************************************
qgsgeonodedataitemguiprovider.cpp
--------------------------------------
Date : June 2019
Copyright : (C) 2019 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsgeonodedataitemguiprovider.h"
#include "qgsgeonodedataitems.h"
#include "qgsgeonodenewconnection.h"

void QgsGeoNodeDataItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
{
if ( QgsGeoNodeRootItem *rootItem = qobject_cast< QgsGeoNodeRootItem * >( item ) )
{
QAction *actionNew = new QAction( tr( "New Connection…" ), menu );
connect( actionNew, &QAction::triggered, this, [rootItem] { newConnection( rootItem ); } );
menu->addAction( actionNew );
}
else if ( QgsGeoNodeRootItem *connItem = qobject_cast< QgsGeoNodeRootItem * >( item ) )
{
QAction *actionEdit = new QAction( tr( "Edit Connection…" ), menu );
connect( actionEdit, &QAction::triggered, this, [connItem] { editConnection( connItem ); } );
menu->addAction( actionEdit );

QAction *actionDelete = new QAction( tr( "Delete Connection" ), menu );
connect( actionDelete, &QAction::triggered, this, [connItem] { deleteConnection( connItem ); } );
menu->addAction( actionDelete );
}
}

void QgsGeoNodeDataItemGuiProvider::newConnection( QgsDataItem *item )
{
QgsGeoNodeNewConnection nc( nullptr );

if ( nc.exec() )
{
item->refresh();
}
}

void QgsGeoNodeDataItemGuiProvider::editConnection( QgsDataItem *item )
{
QgsGeoNodeNewConnection nc( nullptr, item->name() );
nc.setWindowTitle( tr( "Modify GeoNode connection" ) );

if ( nc.exec() )
{
// the parent should be updated
item->parent()->refresh();
}
}

void QgsGeoNodeDataItemGuiProvider::deleteConnection( QgsDataItem *item )
{
QgsGeoNodeConnectionUtils::deleteConnection( item->name() );
item->parent()->refresh();
}
37 changes: 37 additions & 0 deletions src/providers/geonode/qgsgeonodedataitemguiprovider.h
@@ -0,0 +1,37 @@
/***************************************************************************
qgsgeonodedataitemguiprovider.h
--------------------------------------
Date : June 2019
Copyright : (C) 2019 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGEONODEDATAITEMGUIPROVIDER_H
#define QGSGEONODEDATAITEMGUIPROVIDER_H

#include "qgsdataitemguiprovider.h"

class QgsGeoNodeDataItemGuiProvider : public QObject, public QgsDataItemGuiProvider
{
Q_OBJECT
public:

QString name() override { return QStringLiteral( "GeoNode" ); }

void populateContextMenu( QgsDataItem *item, QMenu *menu,
const QList<QgsDataItem *> &selectedItems, QgsDataItemGuiContext context ) override;

private:
static void newConnection( QgsDataItem *item );
static void editConnection( QgsDataItem *item );
static void deleteConnection( QgsDataItem *item );
};

#endif // QGSGEONODEDATAITEMGUIPROVIDER_H
38 changes: 0 additions & 38 deletions src/providers/geonode/qgsgeonodedataitems.cpp
Expand Up @@ -17,7 +17,6 @@
#include "qgsgeonodedataitems.h"
#include "qgsproviderregistry.h"
#include "qgsnewhttpconnection.h"
#include "qgsgeonodenewconnection.h"
#include "qgsgeonoderequest.h"

typedef QList<QgsDataItemProvider *> *dataItemProviders_t();
Expand Down Expand Up @@ -66,26 +65,6 @@ QVector<QgsDataItem *> QgsGeoNodeConnectionItem::createChildren()
return services;
}

QList<QAction *> QgsGeoNodeConnectionItem::actions( QWidget *parent )
{
QAction *actionEdit = new QAction( tr( "Edit Connection…" ), parent );
QAction *actionDelete = new QAction( tr( "Delete Connection" ), parent );
connect( actionEdit, &QAction::triggered, this, &QgsGeoNodeConnectionItem::editConnection );
connect( actionDelete, &QAction::triggered, this, &QgsGeoNodeConnectionItem::deleteConnection );
return QList<QAction *>() << actionEdit << actionDelete;
}

void QgsGeoNodeConnectionItem::editConnection()
{
QgsGeoNodeNewConnection nc( nullptr, mConnection->connectionName() );
nc.setWindowTitle( tr( "Modify GeoNode connection" ) );

if ( nc.exec() )
{
// the parent should be updated
mParent->refresh();
}
}

QgsGeoNodeServiceItem::QgsGeoNodeServiceItem( QgsDataItem *parent, QgsGeoNodeConnection *conn, QString serviceName, QString path )
: QgsDataCollectionItem( parent, serviceName, path )
Expand Down Expand Up @@ -231,23 +210,6 @@ QVector<QgsDataItem *> QgsGeoNodeRootItem::createChildren()
return connections;
}

QList<QAction *> QgsGeoNodeRootItem::actions( QWidget *parent )
{
QAction *actionNew = new QAction( tr( "New Connection…" ), parent );
connect( actionNew, &QAction::triggered, this, &QgsGeoNodeRootItem::newConnection );
return QList<QAction *>() << actionNew;
}

void QgsGeoNodeRootItem::newConnection()
{
QgsGeoNodeNewConnection nc( nullptr );

if ( nc.exec() )
{
refresh();
}
}


QgsDataItem *QgsGeoNodeDataItemProvider::createDataItem( const QString &path, QgsDataItem *parentItem )
{
Expand Down
11 changes: 0 additions & 11 deletions src/providers/geonode/qgsgeonodedataitems.h
Expand Up @@ -28,17 +28,10 @@ class QgsGeoNodeConnectionItem : public QgsDataCollectionItem
public:
QgsGeoNodeConnectionItem( QgsDataItem *parent, QString name, QString path, std::unique_ptr< QgsGeoNodeConnection > conn );
QVector<QgsDataItem *> createChildren() override;
QList<QAction *> actions( QWidget *parent ) override;

QString mGeoNodeName;

private:
void editConnection();
void deleteConnection()
{
QgsGeoNodeConnectionUtils::deleteConnection( name() );
mParent->refresh();
}

QString mUri;
std::unique_ptr< QgsGeoNodeConnection > mConnection = nullptr;
Expand Down Expand Up @@ -67,12 +60,8 @@ class QgsGeoNodeRootItem : public QgsDataCollectionItem

QVector<QgsDataItem *> createChildren() override;

QList<QAction *> actions( QWidget *parent ) override;

QVariant sortKey() const override { return 13; }

private slots:
void newConnection();
};

//! Provider for Geonode root data item
Expand Down
25 changes: 0 additions & 25 deletions src/providers/geonode/qgsgeonodeprovider.cpp
Expand Up @@ -20,10 +20,6 @@
#include "qgis.h"
#include "qgsprovidermetadata.h"
#include "qgsgeonodedataitems.h"
#ifdef HAVE_GUI
#include "qgsproviderguimetadata.h"
#include "qgsgeonodesourceselect.h"
#endif

static const QString PROVIDER_KEY = QStringLiteral( "geonode" );
static const QString PROVIDER_DESCRIPTION = QStringLiteral( "GeoNode provider" );
Expand All @@ -44,28 +40,7 @@ QList<QgsDataItemProvider *> QgsGeoNodeProviderMetadata::dataItemProviders() con
}


#ifdef HAVE_GUI
class QgsGeonodeProviderGuiMetadata: public QgsProviderGuiMetadata
{
public:
QgsGeonodeProviderGuiMetadata(): QgsProviderGuiMetadata( PROVIDER_KEY ) {}
QList<QgsSourceSelectProvider *> sourceSelectProviders() override
{
QList<QgsSourceSelectProvider *> providers;
providers << new QgsGeoNodeSourceSelectProvider;
return providers;
}
};
#endif

QGISEXTERN QgsProviderMetadata *providerMetadataFactory()
{
return new QgsGeoNodeProviderMetadata();
}

#ifdef HAVE_GUI
QGISEXTERN QgsProviderGuiMetadata *providerGuiMetadataFactory()
{
return new QgsGeonodeProviderGuiMetadata();
}
#endif
51 changes: 51 additions & 0 deletions src/providers/geonode/qgsgeonodeprovidergui.cpp
@@ -0,0 +1,51 @@
/***************************************************************************
qgsgeonodeprovidergui.cpp
--------------------------------------
Date : June 2019
Copyright : (C) 2019 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsproviderguimetadata.h"

#include "qgsgeonodedataitemguiprovider.h"
#include "qgsgeonodesourceselect.h"

static const QString PROVIDER_KEY = QStringLiteral( "geonode" );


class QgsGeonodeProviderGuiMetadata: public QgsProviderGuiMetadata
{
public:
QgsGeonodeProviderGuiMetadata()
: QgsProviderGuiMetadata( PROVIDER_KEY )
{
}

QList<QgsDataItemGuiProvider *> dataItemGuiProviders() override
{
QList<QgsDataItemGuiProvider *> providers;
providers << new QgsGeoNodeDataItemGuiProvider;
return providers;
}

QList<QgsSourceSelectProvider *> sourceSelectProviders() override
{
QList<QgsSourceSelectProvider *> providers;
providers << new QgsGeoNodeSourceSelectProvider;
return providers;
}
};


QGISEXTERN QgsProviderGuiMetadata *providerGuiMetadataFactory()
{
return new QgsGeonodeProviderGuiMetadata();
}

0 comments on commit 58a01ba

Please sign in to comment.