Skip to content

Commit 201ffda

Browse files
author
g_j_m
committedJan 27, 2006
Completed conversion from Qt3 to Qt4 widgets
Fixed an 'EOF on connection' error (postgres connection wasn't being freed). Fixed a crash in the standalone spit when clicking close Made the standaone spit program behave like a main window rather than a dialog box (ie it has a taskbar entry now). Fixed bug with spit not putting data into non-default schema. Fixed bug with UI display after deleting selected shapefiles. Misc. code tidy ups. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4754 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

7 files changed

+224
-117
lines changed

7 files changed

+224
-117
lines changed
 

‎src/plugins/spit/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
int main( int argc, char ** argv )
55
{
66
QApplication a( argc, argv );
7-
QgsSpit w;
7+
QgsSpit w(0, Qt::Window);
88
w.show();
99

10-
// Moved get schema to constructor so plugins will work w.getSchema();
1110
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
1211

1312
return a.exec();

‎src/plugins/spit/qgsshapefile.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
***************************************************************************/
1717
/* $Id$ */
1818

19-
#include <qapplication.h>
19+
#include <QApplication>
2020
#include <ogrsf_frmts.h>
2121
#include <ogr_geometry.h>
2222
#include <string>
@@ -249,8 +249,8 @@ void QgsShapeFile::setColumnNames(QStringList columns)
249249
}
250250
}
251251

252-
bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col, QString srid, PGconn * conn, Q3ProgressDialog * pro, bool &fin){
253-
connect(pro, SIGNAL(cancelled()), this, SLOT(cancelImport()));
252+
bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col, QString srid, PGconn * conn, QProgressDialog& pro, bool &fin){
253+
connect(&pro, SIGNAL(cancelled()), this, SLOT(cancelImport()));
254254
import_cancelled = false;
255255
bool result = true;
256256
// Mangle the table name to make it PG compliant by replacing spaces with
@@ -291,7 +291,7 @@ bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col,
291291
PQclear(res);
292292
}
293293

294-
query = "SELECT AddGeometryColumn(\'" + dbname + "\', \'" + table_name + "\', \'"+geom_col+"\', " + srid +
294+
query = "SELECT AddGeometryColumn(\'" + schema + "\', \'" + table_name + "\', \'"+geom_col+"\', " + srid +
295295
", \'" + geom_type + "\', 2)";
296296
if(result) res = PQexec(conn, (const char *)query);
297297
if(PQresultStatus(res)!=PGRES_TUPLES_OK){
@@ -365,7 +365,7 @@ bool QgsShapeFile::insertLayer(QString dbname, QString schema, QString geom_col,
365365
PQclear(res);
366366
}
367367

368-
pro->setProgress(pro->progress()+1);
368+
pro.setValue(pro.value()+1);
369369
qApp->processEvents();
370370
delete[] geo_temp;
371371
}

‎src/plugins/spit/qgsshapefile.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
#define QGSSHAPEFILE_H
2121

2222
#include <vector>
23-
#include <qstring.h>
24-
#include <qstringlist.h>
25-
#include <qobject.h>
23+
#include <QString>
24+
#include <QStringList>
25+
#include <QObject>
2626
#include <ogrsf_frmts.h>
27-
#include <q3progressdialog.h>
27+
28+
class QProgressDialog;
2829

2930
class OGRLayer;
3031
class OGRDataSource;
@@ -43,7 +44,7 @@ class QgsShapeFile : public QObject
4344
~QgsShapeFile();
4445
int getFeatureCount();
4546
QString getFeatureClass();
46-
bool insertLayer(QString dbname, QString schema, QString geom_col, QString srid, PGconn * conn, Q3ProgressDialog * pro, bool &fin);
47+
bool insertLayer(QString dbname, QString schema, QString geom_col, QString srid, PGconn * conn, QProgressDialog& pro, bool &fin);
4748

4849
bool is_valid();
4950
QString getName();

‎src/plugins/spit/qgsspit.cpp

Lines changed: 160 additions & 92 deletions
Large diffs are not rendered by default.

‎src/plugins/spit/qgsspit.h

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#ifndef QGSSPIT_H
2+
#define QGSSPIT_H
13
/***************************************************************************
24
qgsspit.h - description
35
-------------------
@@ -20,9 +22,14 @@
2022
#include <algorithm>
2123

2224
#include <QStringList>
25+
#include <QString>
26+
#include <QItemDelegate>
2327

2428
#include "qgsshapefile.h"
2529
#include "ui_qgsspitbase.h"
30+
31+
class QTableWidgetItem;
32+
2633
extern "C"
2734
{
2835
#include <libpq-fe.h>
@@ -72,16 +79,25 @@ class QgsSpit : public QDialog, private Ui::QgsSpitBase
7279

7380
public slots:
7481

82+
// In porting from Qt3 to Qt4 it was easier to have these small
83+
// redirects for the widget signals rather than rename the existing
84+
// functions (which would be been connected to the widgets using the
85+
// Qt3 designer signal/slot connection mechanism), in case you were
86+
// wondering.
7587
void on_btnConnect_clicked() { dbConnect(); }
7688
void on_btnEdit_clicked() { editConnection(); }
7789
void on_btnNew_clicked() { newConnection(); }
7890
void on_btnRemove_clicked() { removeConnection(); }
7991
void on_btnImport_clicked() { import(); }
8092
void on_btnHelp_clicked() { helpInfo(); }
81-
void on_btnQuit_clicked() { close(1); }
93+
void on_btnQuit_clicked() { close(); }
8294
void on_btnAddFile_clicked() { addFile(); }
8395
void on_btnRemoveAll_clicked() { removeAllFiles(); }
8496
void on_btnRemoveFile_clicked() { removeFile(); }
97+
void on_tblShapefiles_itemClicked(QTableWidgetItem* item)
98+
{ tblShapefiles->editItem(item); }
99+
// When the user changes the selected connection, update the schema list
100+
void on_cmbConnections_activated(int) { getSchema(); }
85101

86102
private:
87103

@@ -106,3 +122,34 @@ public slots:
106122
QString defaultGeomValue;
107123
QString gl_key;
108124
};
125+
126+
// We want to provide combo boxes in the table of shape files to
127+
// load. Qt4 doesn't provide an 'out-of-the-box' way to do this
128+
// (unlike Qt3), so we have to use the Qt4 delegate technique to
129+
// provide combo boxes for the table, hence this class...
130+
131+
class ShapefileTableDelegate : public QItemDelegate
132+
{
133+
Q_OBJECT;
134+
135+
public:
136+
ShapefileTableDelegate(QObject *parent, QStringList& schema_list) :
137+
mSchemaList(schema_list) {}
138+
139+
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
140+
const QModelIndex &index) const;
141+
142+
void setEditorData(QWidget *editor, const QModelIndex &index) const;
143+
void setModelData(QWidget *editor, QAbstractItemModel *model,
144+
const QModelIndex &index) const;
145+
146+
void updateEditorGeometry(QWidget *editor,
147+
const QStyleOptionViewItem &option, const QModelIndex &index) const;
148+
void updateSchemaList(QStringList& schema_list, QString currentSchema);
149+
150+
private:
151+
QStringList mSchemaList;
152+
int mCurrentIndex;
153+
};
154+
155+
#endif

‎src/plugins/spit/qgsspitbase.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
</property>
7575
<item row="5" column="0" >
7676
<widget class="QTableWidget" name="tblShapefiles" >
77+
<property name="selectionMode" >
78+
<enum>QAbstractItemView::MultiSelection</enum>
79+
</property>
7780
<property name="selectionBehavior" >
7881
<enum>QAbstractItemView::SelectRows</enum>
7982
</property>

‎src/plugins/spit/qgsspitplugin.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@
2020
#ifndef QGSSPITPLUGIN_H
2121
#define QGSSPITPLUGIN_H
2222
#include "../qgisplugin.h"
23-
//#include <qwidget.h>
24-
//#include <q3mainwindow.h>
25-
//Added by qt3to4:
26-
//#include <Q3PopupMenu>
23+
2724
extern "C"
2825
{
2926
#include <libpq-fe.h>
3027
}
3128

32-
//class QMessageBox;
33-
//class Q3ToolBar;
34-
//class QMenuBar;
35-
//class Q3PopupMenu;
36-
37-
//#include "qgsworkerclass.h"
3829
#include "qgisapp.h"
3930

4031
/**
@@ -72,8 +63,6 @@ class QgsSpitPlugin:public QObject, public QgisPlugin
7263
int ptype;
7364
//! Id of the plugin's menu. Used for unloading
7465
int menuId;
75-
//! Pointer to our toolbar
76-
// Q3ToolBar *toolBar;
7766
//! Pionter to QGIS main application object
7867
QgisApp *qgisMainWindow;
7968
//! Pointer to the QGIS interface object

0 commit comments

Comments
 (0)
Please sign in to comment.