Skip to content

Commit

Permalink
WMS: add/edit/delete connection from data items
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Oct 14, 2011
1 parent e045d34 commit befb5f6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/providers/wms/qgswmsdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "qgswmsconnection.h"
#include "qgswmssourceselect.h"

#include "qgsnewhttpconnection.h"

// ---------------------------------------------------------------------------
QgsWMSConnectionItem::QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path )
: QgsDataCollectionItem( parent, name, path )
Expand Down Expand Up @@ -60,7 +62,43 @@ bool QgsWMSConnectionItem::equal( const QgsDataItem *other )
const QgsWMSConnectionItem *o = dynamic_cast<const QgsWMSConnectionItem *>( other );
return ( mPath == o->mPath && mName == o->mName && mConnInfo == o->mConnInfo );
}

QList<QAction*> QgsWMSConnectionItem::actions()
{
QList<QAction*> lst;

QAction* actionEdit = new QAction( tr( "Edit..." ), this );
connect( actionEdit, SIGNAL( triggered() ), this, SLOT( editConnection() ) );
lst.append( actionEdit );

QAction* actionDelete = new QAction( tr( "Delete" ), this );
connect( actionDelete, SIGNAL( triggered() ), this, SLOT( deleteConnection() ) );
lst.append( actionDelete );

return lst;
}

void QgsWMSConnectionItem::editConnection()
{
QgsNewHttpConnection nc( 0, "/Qgis/connections-wms/", mName );

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

void QgsWMSConnectionItem::deleteConnection()
{
QgsWMSConnection::deleteConnection( mName );
// the parent should be updated
mParent->refresh();
}


// ---------------------------------------------------------------------------

QgsWMSLayerItem::QgsWMSLayerItem( QgsDataItem* parent, QString name, QString path, QgsWmsCapabilitiesProperty capabilitiesProperty, QString connInfo, QgsWmsLayerProperty layerProperty )
: QgsLayerItem( parent, name, path, QString(), QgsLayerItem::Raster, "wms" ),
mCapabilitiesProperty( capabilitiesProperty ),
Expand Down Expand Up @@ -170,6 +208,18 @@ QVector<QgsDataItem*>QgsWMSRootItem::createChildren()
return connections;
}

QList<QAction*> QgsWMSRootItem::actions()
{
QList<QAction*> lst;

QAction* actionNew = new QAction( tr( "New..." ), this );
connect( actionNew, SIGNAL( triggered() ), this, SLOT( newConnection() ) );
lst.append( actionNew );

return lst;
}


QWidget * QgsWMSRootItem::paramWidget()
{
QgsWMSSourceSelect *select = new QgsWMSSourceSelect( 0, 0, true, true );
Expand All @@ -181,6 +231,17 @@ void QgsWMSRootItem::connectionsChanged()
refresh();
}

void QgsWMSRootItem::newConnection()
{
QgsNewHttpConnection nc( 0 );

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


// ---------------------------------------------------------------------------

QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
Expand Down
11 changes: 11 additions & 0 deletions src/providers/wms/qgswmsdataitems.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@

class QgsWMSConnectionItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsWMSConnectionItem( QgsDataItem* parent, QString name, QString path );
~QgsWMSConnectionItem();

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

virtual QList<QAction*> actions();

QgsWmsCapabilitiesProperty mCapabilitiesProperty;
QString mConnInfo;
QVector<QgsWmsLayerProperty> mLayerProperties;

public slots:
void editConnection();
void deleteConnection();
};

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

QVector<QgsDataItem*> createChildren();

virtual QList<QAction*> actions();

virtual QWidget * paramWidget();

public slots:
void connectionsChanged();

void newConnection();
};

#endif // QGSWMSDATAITEMS_H

0 comments on commit befb5f6

Please sign in to comment.