Skip to content

Commit

Permalink
[wfs] Move GUI parts of data items to QgsDataItemGuiProvider subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 27, 2019
1 parent 31420d4 commit ebc1a2b
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 70 deletions.
2 changes: 2 additions & 0 deletions src/providers/wfs/CMakeLists.txt
Expand Up @@ -33,10 +33,12 @@ SET (WFS_MOC_HDRS
IF (WITH_GUI)
SET(WFS_SRCS ${WFS_SRCS}
qgswfsprovidergui.cpp
qgswfsdataitemguiprovider.cpp
qgswfssourceselect.cpp
qgswfsnewconnection.cpp
)
SET(WFS_MOC_HDRS ${WFS_MOC_HDRS}
qgswfsdataitemguiprovider.h
qgswfssourceselect.h
qgswfsnewconnection.h
)
Expand Down
88 changes: 88 additions & 0 deletions src/providers/wfs/qgswfsdataitemguiprovider.cpp
@@ -0,0 +1,88 @@
/***************************************************************************
qgswfsdataitemguiprovider.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 "qgswfsdataitemguiprovider.h"

#include "qgsnewhttpconnection.h"
#include "qgswfsconnection.h"
#include "qgswfsconstants.h"
#include "qgswfsdataitems.h"


void QgsWfsDataItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
{
if ( QgsWfsRootItem *rootItem = qobject_cast< QgsWfsRootItem * >( item ) )
{
QAction *actionNew = new QAction( tr( "New Connection…" ), this );
setItemForAction( actionNew, rootItem );
connect( actionNew, &QAction::triggered, this, &QgsWfsDataItemGuiProvider::newConnection );
menu->addAction( actionNew );
}

if ( QgsWfsConnectionItem *connItem = qobject_cast< QgsWfsConnectionItem * >( item ) )
{
QAction *actionEdit = new QAction( tr( "Edit…" ), this );
setItemForAction( actionEdit, connItem );
connect( actionEdit, &QAction::triggered, this, &QgsWfsDataItemGuiProvider::editConnection );
menu->addAction( actionEdit );

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

void QgsWfsDataItemGuiProvider::newConnection()
{
QPointer< QgsDataItem > item = itemFromAction( qobject_cast<QAction *>( sender() ) );
if ( !item )
return;

QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS );
nc.setWindowTitle( tr( "Create a New WFS Connection" ) );

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

void QgsWfsDataItemGuiProvider::editConnection()
{
QPointer< QgsDataItem > item = itemFromAction( qobject_cast<QAction *>( sender() ) );
if ( !item )
return;

QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS, item->name() );
nc.setWindowTitle( tr( "Modify WFS Connection" ) );

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

void QgsWfsDataItemGuiProvider::deleteConnection()
{
QPointer< QgsDataItem > item = itemFromAction( qobject_cast<QAction *>( sender() ) );
if ( !item )
return;

QgsWfsConnection::deleteConnection( item->name() );
// the parent should be updated
item->parent()->refreshConnections();
}
38 changes: 38 additions & 0 deletions src/providers/wfs/qgswfsdataitemguiprovider.h
@@ -0,0 +1,38 @@
/***************************************************************************
qgswfsdataitemguiprovider.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 QGSWFSDATAITEMGUIPROVIDER_H
#define QGSWFSDATAITEMGUIPROVIDER_H

#include "qgsdataitemguiprovider.h"

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

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

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

private slots:
void newConnection();
void editConnection();
void deleteConnection();

};

#endif // QGSWFSDATAITEMGUIPROVIDER_H
57 changes: 0 additions & 57 deletions src/providers/wfs/qgswfsdataitems.cpp
Expand Up @@ -30,7 +30,6 @@
#include "qgsstyle.h"

#ifdef HAVE_GUI
#include "qgsnewhttpconnection.h"
#include "qgswfssourceselect.h"
#endif

Expand Down Expand Up @@ -172,42 +171,6 @@ QVector<QgsDataItem *> QgsWfsConnectionItem::createChildren()
return layers;
}

#ifdef HAVE_GUI
QList<QAction *> QgsWfsConnectionItem::actions( QWidget *parent )
{
QList<QAction *> lst;

QAction *actionEdit = new QAction( tr( "Edit…" ), parent );
connect( actionEdit, &QAction::triggered, this, &QgsWfsConnectionItem::editConnection );
lst.append( actionEdit );

QAction *actionDelete = new QAction( tr( "Delete" ), parent );
connect( actionDelete, &QAction::triggered, this, &QgsWfsConnectionItem::deleteConnection );
lst.append( actionDelete );

return lst;
}

void QgsWfsConnectionItem::editConnection()
{
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS, mName );
nc.setWindowTitle( tr( "Modify WFS Connection" ) );

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

void QgsWfsConnectionItem::deleteConnection()
{
QgsWfsConnection::deleteConnection( mName );
// the parent should be updated
mParent->refreshConnections();
}
#endif


//
// QgsWfsRootItem
Expand Down Expand Up @@ -236,16 +199,6 @@ QVector<QgsDataItem *> QgsWfsRootItem::createChildren()
}

#ifdef HAVE_GUI
QList<QAction *> QgsWfsRootItem::actions( QWidget *parent )
{
QList<QAction *> lst;

QAction *actionNew = new QAction( tr( "New Connection…" ), parent );
connect( actionNew, &QAction::triggered, this, &QgsWfsRootItem::newConnection );
lst.append( actionNew );

return lst;
}

QWidget *QgsWfsRootItem::paramWidget()
{
Expand All @@ -259,16 +212,6 @@ void QgsWfsRootItem::onConnectionsChanged()
refresh();
}

void QgsWfsRootItem::newConnection()
{
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS );
nc.setWindowTitle( tr( "Create a New WFS Connection" ) );

if ( nc.exec() )
{
refreshConnections();
}
}
#endif


Expand Down
12 changes: 0 additions & 12 deletions src/providers/wfs/qgswfsdataitems.h
Expand Up @@ -32,14 +32,12 @@ class QgsWfsRootItem : public QgsDataCollectionItem
QVariant sortKey() const override { return 9; }

#ifdef HAVE_GUI
QList<QAction *> actions( QWidget *parent ) override;
QWidget *paramWidget() override;
#endif

public slots:
#ifdef HAVE_GUI
void onConnectionsChanged();
void newConnection();
#endif
};

Expand All @@ -54,16 +52,6 @@ class QgsWfsConnectionItem : public QgsDataCollectionItem
QVector<QgsDataItem *> createChildren() override;
//virtual bool equal( const QgsDataItem *other );

#ifdef HAVE_GUI
QList<QAction *> actions( QWidget *parent ) override;
#endif

private slots:
#ifdef HAVE_GUI
void editConnection();
void deleteConnection();
#endif

private:
QString mUri;

Expand Down
4 changes: 3 additions & 1 deletion src/providers/wfs/qgswfsprovidergui.cpp
Expand Up @@ -14,6 +14,7 @@
***************************************************************************/

#include "qgswfsprovider.h"
#include "qgswfsdataitemguiprovider.h"
#include "qgswfssourceselect.h"
#include "qgssourceselectprovider.h"
#include "qgsproviderguimetadata.h"
Expand Down Expand Up @@ -52,7 +53,8 @@ class QgsWfsProviderGuiMetadata: public QgsProviderGuiMetadata

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

};
Expand Down

0 comments on commit ebc1a2b

Please sign in to comment.