Skip to content

Commit befb5f6

Browse files
committed
WMS: add/edit/delete connection from data items
1 parent e045d34 commit befb5f6

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/providers/wms/qgswmsdataitems.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "qgswmsconnection.h"
66
#include "qgswmssourceselect.h"
77

8+
#include "qgsnewhttpconnection.h"
9+
810
// ---------------------------------------------------------------------------
911
QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path )
1012
: QgsDataCollectionItem( parent, name, path )
@@ -60,7 +62,43 @@ bool QgsWMSConnectionItem::equal( const QgsDataItem *other )
6062
const QgsWMSConnectionItem *o = dynamic_cast<const QgsWMSConnectionItem *>( other );
6163
return ( mPath == o->mPath && mName == o->mName && mConnInfo == o->mConnInfo );
6264
}
65+
66+
QList<QAction*> QgsWMSConnectionItem::actions()
67+
{
68+
QList<QAction*> lst;
69+
70+
QAction* actionEdit = new QAction( tr( "Edit..." ), this );
71+
connect( actionEdit, SIGNAL( triggered() ), this, SLOT( editConnection() ) );
72+
lst.append( actionEdit );
73+
74+
QAction* actionDelete = new QAction( tr( "Delete" ), this );
75+
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteConnection() ) );
76+
lst.append( actionDelete );
77+
78+
return lst;
79+
}
80+
81+
void QgsWMSConnectionItem::editConnection()
82+
{
83+
QgsNewHttpConnection nc( 0, "/Qgis/connections-wms/", mName );
84+
85+
if ( nc.exec() )
86+
{
87+
// the parent should be updated
88+
mParent->refresh();
89+
}
90+
}
91+
92+
void QgsWMSConnectionItem::deleteConnection()
93+
{
94+
QgsWMSConnection::deleteConnection( mName );
95+
// the parent should be updated
96+
mParent->refresh();
97+
}
98+
99+
63100
// ---------------------------------------------------------------------------
101+
64102
QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
65103
: QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, "wms" ),
66104
mCapabilitiesProperty( capabilitiesProperty ),
@@ -170,6 +208,18 @@ QVector<QgsDataItem*>QgsWMSRootItem::createChildren()
170208
return connections;
171209
}
172210

211+
QList<QAction*> QgsWMSRootItem::actions()
212+
{
213+
QList<QAction*> lst;
214+
215+
QAction* actionNew = new QAction( tr( "New..." ), this );
216+
connect( actionNew, SIGNAL( triggered() ), this, SLOT( newConnection() ) );
217+
lst.append( actionNew );
218+
219+
return lst;
220+
}
221+
222+
173223
QWidget * QgsWMSRootItem::paramWidget()
174224
{
175225
QgsWMSSourceSelect *select = new QgsWMSSourceSelect( 0, 0, true, true );
@@ -181,6 +231,17 @@ void QgsWMSRootItem::connectionsChanged()
181231
refresh();
182232
}
183233

234+
void QgsWMSRootItem::newConnection()
235+
{
236+
QgsNewHttpConnection nc( 0 );
237+
238+
if ( nc.exec() )
239+
{
240+
refresh();
241+
}
242+
}
243+
244+
184245
// ---------------------------------------------------------------------------
185246

186247
QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )

src/providers/wms/qgswmsdataitems.h

+11
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@
55

66
class QgsWMSConnectionItem : public QgsDataCollectionItem
77
{
8+
Q_OBJECT
89
public:
910
QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path );
1011
~QgsWMSConnectionItem();
1112

1213
QVector<QgsDataItem*> createChildren();
1314
virtual bool equal( const QgsDataItem *other );
1415

16+
virtual QList<QAction*> actions();
17+
1518
QgsWmsCapabilitiesProperty mCapabilitiesProperty;
1619
QString mConnInfo;
1720
QVector<QgsWmsLayerProperty> mLayerProperties;
21+
22+
public slots:
23+
void editConnection();
24+
void deleteConnection();
1825
};
1926

2027
// WMS Layers may be nested, so that they may be both QgsDataCollectionItem and QgsLayerItem
@@ -43,10 +50,14 @@ class QgsWMSRootItem : public QgsDataCollectionItem
4350

4451
QVector<QgsDataItem*> createChildren();
4552

53+
virtual QList<QAction*> actions();
54+
4655
virtual QWidget * paramWidget();
4756

4857
public slots:
4958
void connectionsChanged();
59+
60+
void newConnection();
5061
};
5162

5263
#endif // QGSWMSDATAITEMS_H

0 commit comments

Comments
 (0)