Skip to content

Commit ebc1a2b

Browse files
committedJun 27, 2019
[wfs] Move GUI parts of data items to QgsDataItemGuiProvider subclass
1 parent 31420d4 commit ebc1a2b

File tree

6 files changed

+131
-70
lines changed

6 files changed

+131
-70
lines changed
 

‎src/providers/wfs/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ SET (WFS_MOC_HDRS
3333
IF (WITH_GUI)
3434
SET(WFS_SRCS ${WFS_SRCS}
3535
qgswfsprovidergui.cpp
36+
qgswfsdataitemguiprovider.cpp
3637
qgswfssourceselect.cpp
3738
qgswfsnewconnection.cpp
3839
)
3940
SET(WFS_MOC_HDRS ${WFS_MOC_HDRS}
41+
qgswfsdataitemguiprovider.h
4042
qgswfssourceselect.h
4143
qgswfsnewconnection.h
4244
)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/***************************************************************************
2+
qgswfsdataitemguiprovider.cpp
3+
--------------------------------------
4+
Date : June 2019
5+
Copyright : (C) 2019 by Martin Dobias
6+
Email : wonder dot sk at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgswfsdataitemguiprovider.h"
17+
18+
#include "qgsnewhttpconnection.h"
19+
#include "qgswfsconnection.h"
20+
#include "qgswfsconstants.h"
21+
#include "qgswfsdataitems.h"
22+
23+
24+
void QgsWfsDataItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
25+
{
26+
if ( QgsWfsRootItem *rootItem = qobject_cast< QgsWfsRootItem * >( item ) )
27+
{
28+
QAction *actionNew = new QAction( tr( "New Connection…" ), this );
29+
setItemForAction( actionNew, rootItem );
30+
connect( actionNew, &QAction::triggered, this, &QgsWfsDataItemGuiProvider::newConnection );
31+
menu->addAction( actionNew );
32+
}
33+
34+
if ( QgsWfsConnectionItem *connItem = qobject_cast< QgsWfsConnectionItem * >( item ) )
35+
{
36+
QAction *actionEdit = new QAction( tr( "Edit…" ), this );
37+
setItemForAction( actionEdit, connItem );
38+
connect( actionEdit, &QAction::triggered, this, &QgsWfsDataItemGuiProvider::editConnection );
39+
menu->addAction( actionEdit );
40+
41+
QAction *actionDelete = new QAction( tr( "Delete" ), this );
42+
setItemForAction( actionDelete, connItem );
43+
connect( actionDelete, &QAction::triggered, this, &QgsWfsDataItemGuiProvider::deleteConnection );
44+
menu->addAction( actionDelete );
45+
}
46+
}
47+
48+
void QgsWfsDataItemGuiProvider::newConnection()
49+
{
50+
QPointer< QgsDataItem > item = itemFromAction( qobject_cast<QAction *>( sender() ) );
51+
if ( !item )
52+
return;
53+
54+
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS );
55+
nc.setWindowTitle( tr( "Create a New WFS Connection" ) );
56+
57+
if ( nc.exec() )
58+
{
59+
item->refreshConnections();
60+
}
61+
}
62+
63+
void QgsWfsDataItemGuiProvider::editConnection()
64+
{
65+
QPointer< QgsDataItem > item = itemFromAction( qobject_cast<QAction *>( sender() ) );
66+
if ( !item )
67+
return;
68+
69+
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS, item->name() );
70+
nc.setWindowTitle( tr( "Modify WFS Connection" ) );
71+
72+
if ( nc.exec() )
73+
{
74+
// the parent should be updated
75+
item->parent()->refreshConnections();
76+
}
77+
}
78+
79+
void QgsWfsDataItemGuiProvider::deleteConnection()
80+
{
81+
QPointer< QgsDataItem > item = itemFromAction( qobject_cast<QAction *>( sender() ) );
82+
if ( !item )
83+
return;
84+
85+
QgsWfsConnection::deleteConnection( item->name() );
86+
// the parent should be updated
87+
item->parent()->refreshConnections();
88+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/***************************************************************************
2+
qgswfsdataitemguiprovider.h
3+
--------------------------------------
4+
Date : June 2019
5+
Copyright : (C) 2019 by Martin Dobias
6+
Email : wonder dot sk at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSWFSDATAITEMGUIPROVIDER_H
17+
#define QGSWFSDATAITEMGUIPROVIDER_H
18+
19+
#include "qgsdataitemguiprovider.h"
20+
21+
class QgsWfsDataItemGuiProvider : public QObject, public QgsDataItemGuiProvider
22+
{
23+
Q_OBJECT
24+
public:
25+
26+
QString name() override { return QStringLiteral( "WFS" ); }
27+
28+
void populateContextMenu( QgsDataItem *item, QMenu *menu,
29+
const QList<QgsDataItem *> &selectedItems, QgsDataItemGuiContext context ) override;
30+
31+
private slots:
32+
void newConnection();
33+
void editConnection();
34+
void deleteConnection();
35+
36+
};
37+
38+
#endif // QGSWFSDATAITEMGUIPROVIDER_H

‎src/providers/wfs/qgswfsdataitems.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "qgsstyle.h"
3131

3232
#ifdef HAVE_GUI
33-
#include "qgsnewhttpconnection.h"
3433
#include "qgswfssourceselect.h"
3534
#endif
3635

@@ -172,42 +171,6 @@ QVector<QgsDataItem *> QgsWfsConnectionItem::createChildren()
172171
return layers;
173172
}
174173

175-
#ifdef HAVE_GUI
176-
QList<QAction *> QgsWfsConnectionItem::actions( QWidget *parent )
177-
{
178-
QList<QAction *> lst;
179-
180-
QAction *actionEdit = new QAction( tr( "Edit…" ), parent );
181-
connect( actionEdit, &QAction::triggered, this, &QgsWfsConnectionItem::editConnection );
182-
lst.append( actionEdit );
183-
184-
QAction *actionDelete = new QAction( tr( "Delete" ), parent );
185-
connect( actionDelete, &QAction::triggered, this, &QgsWfsConnectionItem::deleteConnection );
186-
lst.append( actionDelete );
187-
188-
return lst;
189-
}
190-
191-
void QgsWfsConnectionItem::editConnection()
192-
{
193-
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS, mName );
194-
nc.setWindowTitle( tr( "Modify WFS Connection" ) );
195-
196-
if ( nc.exec() )
197-
{
198-
// the parent should be updated
199-
mParent->refreshConnections();
200-
}
201-
}
202-
203-
void QgsWfsConnectionItem::deleteConnection()
204-
{
205-
QgsWfsConnection::deleteConnection( mName );
206-
// the parent should be updated
207-
mParent->refreshConnections();
208-
}
209-
#endif
210-
211174

212175
//
213176
// QgsWfsRootItem
@@ -236,16 +199,6 @@ QVector<QgsDataItem *> QgsWfsRootItem::createChildren()
236199
}
237200

238201
#ifdef HAVE_GUI
239-
QList<QAction *> QgsWfsRootItem::actions( QWidget *parent )
240-
{
241-
QList<QAction *> lst;
242-
243-
QAction *actionNew = new QAction( tr( "New Connection…" ), parent );
244-
connect( actionNew, &QAction::triggered, this, &QgsWfsRootItem::newConnection );
245-
lst.append( actionNew );
246-
247-
return lst;
248-
}
249202

250203
QWidget *QgsWfsRootItem::paramWidget()
251204
{
@@ -259,16 +212,6 @@ void QgsWfsRootItem::onConnectionsChanged()
259212
refresh();
260213
}
261214

262-
void QgsWfsRootItem::newConnection()
263-
{
264-
QgsNewHttpConnection nc( nullptr, QgsNewHttpConnection::ConnectionWfs, QgsWFSConstants::CONNECTIONS_WFS );
265-
nc.setWindowTitle( tr( "Create a New WFS Connection" ) );
266-
267-
if ( nc.exec() )
268-
{
269-
refreshConnections();
270-
}
271-
}
272215
#endif
273216

274217

‎src/providers/wfs/qgswfsdataitems.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ class QgsWfsRootItem : public QgsDataCollectionItem
3232
QVariant sortKey() const override { return 9; }
3333

3434
#ifdef HAVE_GUI
35-
QList<QAction *> actions( QWidget *parent ) override;
3635
QWidget *paramWidget() override;
3736
#endif
3837

3938
public slots:
4039
#ifdef HAVE_GUI
4140
void onConnectionsChanged();
42-
void newConnection();
4341
#endif
4442
};
4543

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

57-
#ifdef HAVE_GUI
58-
QList<QAction *> actions( QWidget *parent ) override;
59-
#endif
60-
61-
private slots:
62-
#ifdef HAVE_GUI
63-
void editConnection();
64-
void deleteConnection();
65-
#endif
66-
6755
private:
6856
QString mUri;
6957

‎src/providers/wfs/qgswfsprovidergui.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
***************************************************************************/
1515

1616
#include "qgswfsprovider.h"
17+
#include "qgswfsdataitemguiprovider.h"
1718
#include "qgswfssourceselect.h"
1819
#include "qgssourceselectprovider.h"
1920
#include "qgsproviderguimetadata.h"
@@ -52,7 +53,8 @@ class QgsWfsProviderGuiMetadata: public QgsProviderGuiMetadata
5253

5354
QList<QgsDataItemGuiProvider *> dataItemGuiProviders() override
5455
{
55-
return QList<QgsDataItemGuiProvider *>();
56+
return QList<QgsDataItemGuiProvider *>()
57+
<< new QgsWfsDataItemGuiProvider;
5658
}
5759

5860
};

0 commit comments

Comments
 (0)
Please sign in to comment.