218 changes: 218 additions & 0 deletions qgis/src/qgsserversourceselect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/***************************************************************************
qgserversourceselect.cpp - selector for WMS servers, etc.
-------------------
begin : 3 April 2005
copyright : (C) 2005 by Brendan Morley
email : morb at ozemail dot com dot au
***************************************************************************/

/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/* $Id$ */

#include <iostream>
#include <cassert>
#include <qsettings.h>
#include <qpixmap.h>
#include <qlistbox.h>
#include <qlistview.h>
#include <qstringlist.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <qinputdialog.h>
#include <qgroupbox.h>

#include "xpm/point_layer.xpm"
#include "xpm/line_layer.xpm"
#include "xpm/polygon_layer.xpm"

#include "qgsserversourceselect.h"
#include "qgsnewhttpconnection.h"

#include "qgsproviderregistry.h"

#include "../providers/wms/qgswmsprovider.h"

#include "qgisapp.h"

QgsServerSourceSelect::QgsServerSourceSelect(QgisApp * app, QWidget * parent, const char *name)
: QgsServerSourceSelectBase(parent, name),
qgisApp(app)
{
btnAdd->setEnabled(false);
populateConnectionList();
// connect the double-click signal to the addSingleLayer slot in the parent

//disable the 'where clause' box for 0.4 release
// groupBox3->hide();

}

QgsServerSourceSelect::~QgsServerSourceSelect()
{

}
void QgsServerSourceSelect::populateConnectionList()
{
QSettings settings;
QStringList keys = settings.subkeyList("/Qgis/connections-wms");
QStringList::Iterator it = keys.begin();
cmbConnections->clear();
while (it != keys.end())
{
cmbConnections->insertItem(*it);
++it;
}
}
void QgsServerSourceSelect::addNewConnection()
{

QgsNewHttpConnection *nc = new QgsNewHttpConnection();

if (nc->exec())
{
populateConnectionList();
}
}

void QgsServerSourceSelect::editConnection()
{

QgsNewHttpConnection *nc = new QgsNewHttpConnection(cmbConnections->currentText());

if (nc->exec())
{
nc->saveConnection();
}
}

void QgsServerSourceSelect::deleteConnection()
{
QSettings settings;
QString key = "/Qgis/connections-wms/" + cmbConnections->currentText();
QString msg =
tr("Are you sure you want to remove the ") + cmbConnections->currentText() + tr(" connection and all associated settings?");
int result = QMessageBox::information(this, tr("Confirm Delete"), msg, tr("Yes"), tr("No"));
if (result == 0)
{
settings.removeEntry(key + "/url");
cmbConnections->removeItem(cmbConnections->currentItem()); // populateConnectionList();
}
}


void QgsServerSourceSelect::serverConnect()
{
// populate the table list
QSettings settings;

QString key = "/Qgis/connections-wms/" + cmbConnections->currentText();
QString connString = settings.readEntry(key + "/url");

#ifdef QGISDEBUG
std::cout << "QgsServerSourceSelect::serverConnect: Connection info: " << connString << std::endl;
#endif

m_connName = cmbConnections->currentText();
m_connInfo = connString; //host + " " + database + " " + username + " " + password;

// TODO: Create and bind to data provider

// load the server data provider plugin
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();

QgsWmsProvider* wmsProvider =
(QgsWmsProvider*) pReg->getProvider( "wms", connString );

std::vector<QgsWmsLayerProperty> layers;

layers = wmsProvider->supportedLayers();

lstLayers->clear();

for (std::vector<QgsWmsLayerProperty>::iterator layer = layers.begin();
layer != layers.end();
layer++)

{

// QgsWmsLayerProperty layer = *it;

#ifdef QGISDEBUG
std::cout << "QgsServerSourceSelect::serverConnect: got layer name " << layer->name << " and title '" << layer->title << "'." << std::endl;
#endif


QListViewItem *lItem = new QListViewItem(lstLayers);
lItem->setText(1,layer->name);
lItem->setText(2,layer->title);
// lItem->setPixmap(0,*p);
lstLayers->insertItem(lItem);

}


if (lstLayers->childCount() > 0)
{
btnAdd->setEnabled(true);
}


}

void QgsServerSourceSelect::addLayers()
{
//store the layer info
QListViewItemIterator it( lstLayers );
while ( it.current() )
{
QListViewItem *item = it.current();
++it;

if ( item->isSelected() )
{
m_selectedLayers += item->text(1);

#ifdef QGISDEBUG
std::cout << "QgsServerSourceSelect::addLayers: Added " << item->text(1) << std::endl;
#endif

}
}

if (m_selectedLayers.empty() == true)
{
QMessageBox::information(this, tr("Select Layer"), tr("You must select at least one layer first."));
}
else
{
// qgisApp->addRasterLayers("http://ims.cr.usgs.gov:80/servlet/com.esri.wms.Esrimap/USGS_EDC_Trans_BTS_Roads?",
// "Test WMS Layer", "wms");

accept();
}
}


QString QgsServerSourceSelect::connName()
{
return m_connName;
}

QString QgsServerSourceSelect::connInfo()
{
return m_connInfo;
}

QStringList QgsServerSourceSelect::selectedLayers()
{
return m_selectedLayers;
}

84 changes: 84 additions & 0 deletions qgis/src/qgsserversourceselect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/***************************************************************************
qgserversourceselect.h - selector for WMS servers, etc.
-------------------
begin : 3 April 2005
copyright : (C) 2005 by Brendan Morley
email : morb at ozemail dot com dot au
***************************************************************************/

/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/* $Id$ */

#ifndef QGSSERVERSOURCESELECT_H
#define QGSSERVERSOURCESELECT_H
#ifdef WIN32
#include "qgsserversourceselectbase.h"
#else
#include "qgsserversourceselectbase.uic.h"
#endif

#include <vector>
#include <utility>

class QListBoxItem;
class QgisApp;
/*!
* \brief Dialog to create connections and add layers from WMS, etc.
*
* This dialog allows the user to define and save connection information
* for WMS servers, etc.
*
* The user can then connect and add
* layers from the WMS server to the map canvas.
*/
class QgsServerSourceSelect : public QgsServerSourceSelectBase
{
Q_OBJECT

public:

//! Constructor
QgsServerSourceSelect(QgisApp *app=0, QWidget *parent = 0, const char *name = 0);
//! Destructor
~QgsServerSourceSelect();
//! Opens the create connection dialog to build a new connection
void addNewConnection();
//! Opens a dialog to edit an existing connection
void editConnection();
//! Deletes the selected connection
void deleteConnection();
//! Populate the connection list combo box
void populateConnectionList();
/*! Connects to the database using the stored connection parameters.
* Once connected, available layers are displayed.
*/
void serverConnect();

//! Determines the layers the user selected and closes the dialog
void addLayers();

//! Connection name
QString connName();
//! Connection info (uri)
QString connInfo();
//! String list containing the selected layers
QStringList selectedLayers();

private:

QString m_connName;
QString m_connInfo;
QStringList m_selectedLayers;
//! Pointer to the qgis application mainwindow
QgisApp *qgisApp;
};


#endif // QgsServerSourceSelect_H
376 changes: 376 additions & 0 deletions qgis/src/qgsserversourceselectbase.ui

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions qgis/src/qgsserversourceselectbase.ui.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename slots use Qt Designer which will
** update this file, preserving your code. Create an init() slot in place of
** a constructor, and a destroy() slot in place of a destructor.
*****************************************************************************/


void QgsServerSourceSelectBase::init()
{

}

void QgsServerSourceSelectBase::serverConnect()
{

}

void QgsServerSourceSelectBase::addLayers()
{

}

void QgsServerSourceSelectBase::addNewConnection()
{

}


void QgsServerSourceSelectBase::editConnection()
{

}

void QgsServerSourceSelectBase::deleteConnection()
{

}