2003-12-24 02:05:43 +00:00
|
|
|
/***************************************************************************
|
|
|
|
qgsspit.cpp - description
|
|
|
|
-------------------
|
|
|
|
begin : Fri Dec 19 2003
|
|
|
|
copyright : (C) 2003 by Denis Antipov
|
|
|
|
email :
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
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>
|
2003-12-24 02:05:43 +00:00
|
|
|
#include <qprogressdialog.h>
|
2003-12-19 21:36:57 +00:00
|
|
|
#include "qgsspit.h"
|
|
|
|
#include "qgsconnectiondialog.h"
|
2003-12-24 02:05:43 +00:00
|
|
|
#include "qgsmessageviewer.h"
|
2003-12-19 21:36:57 +00:00
|
|
|
|
|
|
|
QgsSpit::QgsSpit(QWidget *parent, const char *name) : QgsSpitBase(parent, name){
|
|
|
|
populateConnectionList();
|
2003-12-20 03:42:12 +00:00
|
|
|
default_value = -1;
|
2003-12-24 02:05:43 +00:00
|
|
|
setFixedSize(QSize(579, 504));
|
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;
|
|
|
|
}
|
2003-12-22 03:28:55 +00:00
|
|
|
if(cmbConnections->count()==0) changeEditAndRemove(0);
|
2003-12-19 21:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QgsSpit::newConnection()
|
|
|
|
{
|
2003-12-22 03:28:55 +00:00
|
|
|
QgsConnectionDialog *con = new QgsConnectionDialog(this, "New Connection");
|
2003-12-19 21:36:57 +00:00
|
|
|
|
|
|
|
if (con->exec()) {
|
|
|
|
populateConnectionList();
|
|
|
|
}
|
2003-12-22 03:28:55 +00:00
|
|
|
if(cmbConnections->count()!=0) changeEditAndRemove(1);
|
2003-12-19 21:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QgsSpit::editConnection()
|
|
|
|
{
|
2003-12-22 03:28:55 +00:00
|
|
|
QgsConnectionDialog *con = new QgsConnectionDialog(this, cmbConnections->currentText());
|
2003-12-19 21:36:57 +00:00
|
|
|
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-22 03:28:55 +00:00
|
|
|
|
|
|
|
cmbConnections->removeItem(cmbConnections->currentItem());
|
|
|
|
if(cmbConnections->count()==0) changeEditAndRemove(0);
|
2003-12-19 21:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QgsSpit::addFile()
|
|
|
|
{
|
2003-12-20 03:42:12 +00:00
|
|
|
QListViewItemIterator n(lstShapefiles);
|
2003-12-24 02:05:43 +00:00
|
|
|
QString error = "";
|
2003-12-20 03:42:12 +00:00
|
|
|
bool exist;
|
2003-12-24 02:05:43 +00:00
|
|
|
bool is_error = false;
|
|
|
|
|
2003-12-19 21:36:57 +00:00
|
|
|
QStringList files = QFileDialog::getOpenFileNames(
|
|
|
|
"Shapefiles (*.shp);; All Files (*)", "", this, "add file dialog", "Add Shapefiles" );
|
2003-12-24 02:05:43 +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;
|
2003-12-24 02:05:43 +00:00
|
|
|
if(lstShapefiles->findItem(*it, 0)!=0)
|
|
|
|
exist = true;
|
2003-12-20 03:42:12 +00:00
|
|
|
if(!exist){
|
2003-12-23 05:44:06 +00:00
|
|
|
QgsShapeFile * file = new QgsShapeFile(*it);
|
2003-12-24 02:05:43 +00:00
|
|
|
if(file->is_valid()){
|
|
|
|
fileList.push_back(file);
|
|
|
|
QListViewItem *lvi = new QListViewItem(lstShapefiles, *it);
|
|
|
|
lvi->setText(1, file->getFeatureClass());
|
|
|
|
lvi->setText(2, file->getFeatureCount());
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
error += *it + "\n";
|
|
|
|
is_error = true;
|
|
|
|
}
|
2003-12-20 03:42:12 +00:00
|
|
|
}
|
2003-12-19 21:36:57 +00:00
|
|
|
}
|
2003-12-24 02:05:43 +00:00
|
|
|
|
|
|
|
if(is_error){
|
|
|
|
error = "The following Shapefile(s) could not be loaded:\n\n" + error;
|
|
|
|
QgsMessageViewer * e = new QgsMessageViewer(this, "error");
|
|
|
|
e->setMessage(error);
|
|
|
|
e->exec();
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
2003-12-22 03:28:55 +00:00
|
|
|
|
|
|
|
void QgsSpit::changeEditAndRemove(int mode){
|
|
|
|
if(mode==0){
|
|
|
|
btnEdit->setEnabled(false);
|
|
|
|
btnRemove->setEnabled(false);
|
|
|
|
}
|
|
|
|
else if(mode==1){
|
|
|
|
btnEdit->setEnabled(true);
|
|
|
|
btnRemove->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
2003-12-24 02:05:43 +00:00
|
|
|
|
|
|
|
void QgsSpit::helpInfo(){
|
|
|
|
QString message = "General Interface Help:\n\n";
|
|
|
|
QgsMessageViewer * e = new QgsMessageViewer(this, "HelpMessage");
|
|
|
|
e->setMessage(message);
|
|
|
|
e->exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QgsSpit::import(){
|
|
|
|
QProgressDialog * pro = new QProgressDialog("Importing files", "Cancel", 100, this, "Progress");
|
|
|
|
pro->setAutoClose(true);
|
|
|
|
pro->exec();
|
|
|
|
}
|