2003-12-19 21:36:57 +00:00
|
|
|
|
|
|
|
#include<qmessagebox.h>
|
|
|
|
|
|
|
|
#include <libpq++.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <qsettings.h>
|
|
|
|
#include <qlistbox.h>
|
|
|
|
#include <qlistview.h>
|
|
|
|
#include <qstringlist.h>
|
|
|
|
#include <qcombobox.h>
|
|
|
|
#include <qpushbutton.h>
|
|
|
|
#include <qmessagebox.h>
|
2003-12-20 03:42:12 +00:00
|
|
|
#include <qspinbox.h>
|
|
|
|
#include <qcheckbox.h>
|
2003-12-19 21:36:57 +00:00
|
|
|
#include <qinputdialog.h>
|
|
|
|
#include <qfiledialog.h>
|
|
|
|
#include "qgsspit.h"
|
|
|
|
#include "qgsconnectiondialog.h"
|
|
|
|
|
|
|
|
QgsSpit::QgsSpit(QWidget *parent, const char *name) : QgsSpitBase(parent, name){
|
|
|
|
populateConnectionList();
|
2003-12-20 03:42:12 +00:00
|
|
|
default_value = -1;
|
2003-12-19 21:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QgsSpit::~QgsSpit(){}
|
|
|
|
|
|
|
|
void QgsSpit::populateConnectionList(){
|
|
|
|
QSettings settings;
|
|
|
|
QStringList keys = settings.subkeyList("/Qgis/connections");
|
|
|
|
QStringList::Iterator it = keys.begin();
|
|
|
|
cmbConnections->clear();
|
|
|
|
while (it != keys.end()) {
|
|
|
|
cmbConnections->insertItem(*it);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QgsSpit::newConnection()
|
|
|
|
{
|
|
|
|
QgsConnectionDialog *con = new QgsConnectionDialog();
|
|
|
|
|
|
|
|
if (con->exec()) {
|
|
|
|
populateConnectionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QgsSpit::editConnection()
|
|
|
|
{
|
|
|
|
QgsConnectionDialog *con = new QgsConnectionDialog(cmbConnections->currentText());
|
|
|
|
if (con->exec()) {
|
|
|
|
con->saveConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QgsSpit::removeConnection()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
QString key = "/Qgis/connections/" + cmbConnections->currentText();
|
|
|
|
QString msg = "Are you sure you want to remove the [" + cmbConnections->currentText() + "] connection and all associated settings?";
|
|
|
|
int result = QMessageBox::information(this, "Confirm Delete", msg, "Yes", "No");
|
|
|
|
if(result == 0){
|
2003-12-20 04:04:08 +00:00
|
|
|
settings.removeEntry(key + "/host");
|
2003-12-19 21:36:57 +00:00
|
|
|
settings.removeEntry(key + "/database");
|
|
|
|
settings.removeEntry(key + "/username");
|
|
|
|
settings.removeEntry(key + "/password");
|
2003-12-20 04:04:08 +00:00
|
|
|
settings.removeEntry(key + "/save");
|
2003-12-19 21:36:57 +00:00
|
|
|
//if(!success){
|
|
|
|
// QMessageBox::information(this,"Unable to Remove","Unable to remove the connection " + cmbConnections->currentText());
|
|
|
|
//}
|
|
|
|
cmbConnections->removeItem(cmbConnections->currentItem());// populateConnectionList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QgsSpit::addFile()
|
|
|
|
{
|
2003-12-20 03:42:12 +00:00
|
|
|
QListViewItemIterator n(lstShapefiles);
|
|
|
|
bool exist;
|
2003-12-19 21:36:57 +00:00
|
|
|
QStringList files = QFileDialog::getOpenFileNames(
|
|
|
|
"Shapefiles (*.shp);; All Files (*)", "", this, "add file dialog", "Add Shapefiles" );
|
2003-12-20 03:42:12 +00:00
|
|
|
|
2003-12-19 21:36:57 +00:00
|
|
|
for ( QStringList::Iterator it = files.begin(); it != files.end(); ++it ){
|
2003-12-20 03:42:12 +00:00
|
|
|
exist = false;
|
|
|
|
for(;n.current();++n)
|
|
|
|
if(n.current()->text(0) == *it){
|
|
|
|
exist = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!exist){
|
|
|
|
QListViewItem *lvi = new QListViewItem(lstShapefiles, *it);
|
|
|
|
lvi->setText(1, "Polygon");
|
|
|
|
lvi->setText(2, "lots");
|
|
|
|
}
|
2003-12-19 21:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
2003-12-20 03:42:12 +00:00
|
|
|
|
2003-12-19 21:36:57 +00:00
|
|
|
void QgsSpit::removeFile()
|
|
|
|
{
|
2003-12-20 01:54:05 +00:00
|
|
|
QListViewItemIterator it(lstShapefiles);
|
2003-12-20 02:11:01 +00:00
|
|
|
while(it.current())
|
|
|
|
if ( it.current()->isSelected() ){
|
2003-12-20 01:54:05 +00:00
|
|
|
delete it.current();
|
2003-12-20 02:11:01 +00:00
|
|
|
it = lstShapefiles->firstChild();
|
|
|
|
}
|
|
|
|
else ++it;
|
2003-12-20 01:54:05 +00:00
|
|
|
}
|
|
|
|
void QgsSpit::removeAllFiles(){
|
|
|
|
lstShapefiles->selectAll(true);
|
|
|
|
removeFile();
|
2003-12-19 21:36:57 +00:00
|
|
|
}
|
2003-12-20 03:42:12 +00:00
|
|
|
void QgsSpit::useDefault(){
|
|
|
|
if(chkUseDefault->isChecked()) {
|
|
|
|
default_value = spinSrid->value();
|
|
|
|
spinSrid->setValue(-1);
|
|
|
|
spinSrid->setEnabled(false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
spinSrid->setEnabled(true);
|
|
|
|
spinSrid->setValue(default_value);
|
|
|
|
}
|
|
|
|
}
|