Skip to content

Commit 034dd53

Browse files
author
telwertowski
committed
Remove all Qt3 classes and methods from GRASS plugin and provider (except qgsgrassshell which is now the only remaining QGIS file using Qt3).
git-svn-id: http://svn.osgeo.org/qgis/trunk@9288 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 47dbaf2 commit 034dd53

37 files changed

+1521
-2473
lines changed

src/plugins/grass/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ ADD_LIBRARY (grassplugin MODULE
9393
)
9494

9595
INCLUDE_DIRECTORIES(
96-
.
9796
..
9897
${CMAKE_CURRENT_BINARY_DIR}
9998
../../core
@@ -115,6 +114,7 @@ TARGET_LINK_LIBRARIES(grassplugin
115114
qgis_core
116115
qgis_gui
117116
qgisgrass
117+
${QT_QT3SUPPORT_LIBRARY}
118118
${GRASS_LIBRARIES}
119119
)
120120

src/plugins/grass/qgsgrassattributes.cpp

+81-104
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,21 @@
1313
* (at your option) any later version. *
1414
* *
1515
***************************************************************************/
16-
#include <qdir.h>
17-
#include <qfile.h>
18-
#include <qsettings.h>
19-
#include <qpixmap.h>
20-
#include <q3listbox.h>
21-
#include <qstringlist.h>
22-
#include <qlabel.h>
23-
#include <QComboBox>
24-
#include <qspinbox.h>
25-
#include <qmessagebox.h>
26-
#include <qinputdialog.h>
27-
#include <qsettings.h>
28-
#include <qpainter.h>
29-
#include <qpixmap.h>
30-
#include <qpen.h>
31-
#include <q3pointarray.h>
32-
#include <qcursor.h>
33-
#include <qnamespace.h>
34-
#include <qtabwidget.h>
35-
#include <q3table.h>
36-
#include <qsettings.h>
37-
#include <qevent.h>
38-
//Added by qt3to4:
39-
#include <QKeyEvent>
40-
41-
#include "qgis.h"
42-
#include "qgsmapcanvas.h"
43-
#include "qgsmaplayer.h"
44-
#include "qgsvectorlayer.h"
45-
#include "qgsdataprovider.h"
46-
#include "qgsmaptopixel.h"
4716

48-
extern "C"
49-
{
50-
#include <grass/gis.h>
51-
#include <grass/Vect.h>
52-
}
53-
54-
#include "qgsgrass.h"
55-
#include "qgsgrassprovider.h"
56-
#include "qgsgrassedit.h"
5717
#include "qgsgrassattributes.h"
18+
#include "qgsgrassedit.h"
19+
#include "qgsgrassprovider.h"
20+
5821
#include "qgslogger.h"
5922

60-
QgsGrassAttributesKeyPress::QgsGrassAttributesKeyPress( Q3Table *tab )
23+
#include <QHeaderView>
24+
#include <QKeyEvent>
25+
#include <QMessagebox>
26+
#include <QSettings>
27+
#include <QTableWidget>
28+
29+
30+
QgsGrassAttributesKeyPress::QgsGrassAttributesKeyPress( QTableWidget *tab )
6131
{
6232
mTable = tab;
6333
}
@@ -72,7 +42,7 @@ bool QgsGrassAttributesKeyPress::eventFilter( QObject *o, QEvent *e )
7242

7343
if ( k->key() == Qt::Key_Tab )
7444
{
75-
if ( mTable->currentRow() < mTable->numRows() - 1 )
45+
if ( mTable->currentRow() < mTable->rowCount() - 1 )
7646
{
7747
mTable->setCurrentCell( mTable->currentRow() + 1, mTable->currentColumn() );
7848
}
@@ -99,13 +69,13 @@ QgsGrassAttributes::QgsGrassAttributes( QgsGrassEdit *edit, QgsGrassProvider *pr
9969
// Remove old
10070
while ( tabCats->count() )
10171
{
102-
tabCats->removePage( tabCats->currentPage() );
72+
tabCats->removeTab( tabCats->currentIndex() );
10373
}
10474

10575
connect( this, SIGNAL( destroyed() ), mEdit, SLOT( attributesClosed() ) );
10676

10777
// TODO: does not work:
108-
connect( tabCats, SIGNAL( void currentChanged( QWidget * ) ), this, SLOT( tabChanged( QWidget * ) ) );
78+
connect( tabCats, SIGNAL( currentChanged( int ) ), this, SLOT( tabChanged( int ) ) );
10979

11080
resetButtons();
11181
restorePosition();
@@ -132,24 +102,27 @@ void QgsGrassAttributes::saveWindowLocation()
132102
settings.setValue( "/GRASS/windows/attributes/geometry", saveGeometry() );
133103
}
134104

105+
void QgsGrassAttributes::setRowReadOnly( QTableWidget* table, int row, bool ro )
106+
{
107+
for ( int i = 0; i < table->columnCount(); ++i )
108+
{
109+
QTableWidgetItem *item = table->item( row, i );
110+
item->setFlags( ro ? item->flags() & ~Qt::ItemIsEditable : item->flags() | Qt::ItemIsEditable );
111+
}
112+
}
113+
135114
int QgsGrassAttributes::addTab( const QString & label )
136115
{
137116
QgsDebugMsg( "entered." );
138117

139-
Q3Table *tb = new Q3Table( 2, 3 );
140-
tb->setColumnReadOnly( 0, TRUE );
141-
tb->setColumnReadOnly( 2, TRUE );
142-
tb->setRowReadOnly( 0, TRUE );
143-
tb->setRowReadOnly( 1, TRUE );
144-
145-
tb->horizontalHeader()->setLabel( 0, tr( "Column" ) );
146-
tb->horizontalHeader()->setLabel( 1, tr( "Value" ) );
147-
tb->horizontalHeader()->setLabel( 2, tr( "Type" ) ); // Internal use
118+
QTableWidget *tb = new QTableWidget( 2, 3 );
148119

149-
tb->setLeftMargin( 0 ); // hide row labels
120+
tb->setHorizontalHeaderLabels( QStringList()
121+
<< tr( "Column" )
122+
<< tr( "Value" )
123+
<< tr( "Type" ) ); // Internal use
150124

151-
tb->setText( 0, 0, tr( "Layer" ) );
152-
tb->setText( 1, 0, "Cat" );
125+
tb->verticalHeader()->hide();
153126

154127
tabCats->addTab( tb, label );
155128

@@ -164,12 +137,12 @@ int QgsGrassAttributes::addTab( const QString & label )
164137
QString path = "/GRASS/windows/attributes/columnWidth/";
165138
for ( int i = 0; i < 2; i++ )
166139
{
167-
bool ok;
168-
int cw = settings.readNumEntry( path + QString::number( i ), 30, &ok );
140+
bool ok = settings.contains( path + QString::number( i ) );
141+
int cw = settings.value( path + QString::number( i ), 30 ).toInt();
169142
if ( ok ) tb->setColumnWidth( i, cw );
170143
}
171144

172-
connect( tb->horizontalHeader(), SIGNAL( sizeChange( int, int, int ) ),
145+
connect( tb->horizontalHeader(), SIGNAL( sectionResized( int, int, int ) ),
173146
this, SLOT( columnSizeChanged( int, int, int ) ) );
174147

175148
return ( tabCats->count() - 1 );
@@ -179,45 +152,53 @@ void QgsGrassAttributes::setField( int tab, int field )
179152
{
180153
QgsDebugMsg( "entered." );
181154

182-
Q3Table *tb = ( Q3Table * ) tabCats->page( tab );
155+
QTableWidget *tb = static_cast<QTableWidget *>( tabCats->widget( tab ) );
156+
157+
tb->setItem( 0, 0, new QTableWidgetItem( tr( "Layer" ) ) );
183158

184159
QString str;
185160
str.sprintf( "%d", field );
186161

187-
tb->setText( 0, 1, str );
162+
tb->setItem( 0, 1, new QTableWidgetItem( str ) );
163+
164+
tb->setItem( 0, 2, new QTableWidgetItem() );
165+
166+
setRowReadOnly( tb, 0, TRUE );
188167
}
189168

190169
void QgsGrassAttributes::setCat( int tab, const QString & name, int cat )
191170
{
192171
QgsDebugMsg( "entered." );
193172

194-
Q3Table *tb = ( Q3Table * ) tabCats->page( tab );
173+
QTableWidget *tb = static_cast<QTableWidget *>( tabCats->widget( tab ) );
195174

196-
tb->setText( 1, 0, name );
175+
tb->setItem( 1, 0, new QTableWidgetItem( name ) );
197176

198177
QString str;
199178
str.sprintf( "%d", cat );
200179

201-
tb->setText( 1, 1, str );
180+
tb->setItem( 1, 1, new QTableWidgetItem( str ) );
181+
182+
tb->setItem( 1, 2, new QTableWidgetItem() );
183+
184+
setRowReadOnly( tb, 1, TRUE );
202185
}
203186

204187
void QgsGrassAttributes::addAttribute( int tab, const QString &name, const QString &value,
205188
const QString &type )
206189
{
207190
QgsDebugMsg( QString( "name=%1 value=%2" ).arg( name ).arg( value ) );
208191

209-
Q3Table *tb = ( Q3Table * ) tabCats->page( tab );
210-
211-
tb->setNumRows( tb->numRows() + 1 );
192+
QTableWidget *tb = static_cast<QTableWidget *>( tabCats->widget( tab ) );
212193

213-
int row = tb->numRows() - 1;
214-
tb->setText( row, 0, name );
194+
tb->setRowCount( tb->rowCount() + 1 );
215195

216-
// I have no rational explanation why fromLocal8Bit is necessary, value should be in unicode
217-
// because QgsGrassProvider::attributes is using mEncoding->toUnicode()
218-
// tb->setText ( row, 1, QString::fromLocal8Bit(value) );
219-
tb->setText( row, 1, value );
220-
tb->setText( row, 2, type );
196+
int row = tb->rowCount() - 1;
197+
tb->setItem( row, 0, new QTableWidgetItem( name ) );
198+
tb->item( row, 0 )->setFlags( tb->item( row, 0 )->flags() & ~Qt::ItemIsEditable );
199+
tb->setItem( row, 1, new QTableWidgetItem( value ) );
200+
tb->setItem( row, 2, new QTableWidgetItem( type ) );
201+
tb->item( row, 2 )->setFlags( tb->item( row, 2 )->flags() & ~Qt::ItemIsEditable );
221202

222203
resetButtons();
223204
}
@@ -226,13 +207,14 @@ void QgsGrassAttributes::addTextRow( int tab, const QString &text )
226207
{
227208
QgsDebugMsg( "entered." );
228209

229-
Q3Table *tb = ( Q3Table * ) tabCats->page( tab );
210+
QTableWidget *tb = static_cast<QTableWidget *>( tabCats->widget( tab ) );
230211

231-
tb->setNumRows( tb->numRows() + 1 );
212+
tb->setRowCount( tb->rowCount() + 1 );
232213

233-
int row = tb->numRows() - 1;
234-
tb->setText( row, 0, text );
235-
tb->item( row, 0 )->setSpan( 1, 3 ); // must be after setText() whe item exists
214+
int row = tb->rowCount() - 1;
215+
tb->setItem( row, 0, new QTableWidgetItem( text ) );
216+
tb->item( row, 0 )->setFlags( tb->item( row, 0 )->flags() & ~Qt::ItemIsEditable );
217+
tb->setSpan( row, 0, 1, 3 );
236218
}
237219

238220
void QgsGrassAttributes::updateAttributes( )
@@ -241,46 +223,43 @@ void QgsGrassAttributes::updateAttributes( )
241223

242224
if ( tabCats->count() == 0 ) return;
243225

244-
Q3Table *tb = ( Q3Table * ) tabCats->currentPage();
226+
QTableWidget *tb = static_cast<QTableWidget *>( tabCats->currentWidget() );
245227

246-
if ( tb->numRows() > 2 )
228+
if ( tb->rowCount() > 2 )
247229
{
248230

249-
// Stop editing (trick)
250-
tb->setColumnReadOnly( 1, TRUE );
251-
tb->setColumnReadOnly( 1, FALSE );
252-
tb->setRowReadOnly( 0, TRUE );
253-
tb->setRowReadOnly( 1, TRUE );
231+
// Stop editing
232+
QApplication::focusWidget()->clearFocus();
254233

255234
QString sql;
256235

257-
for ( int i = 2; i < tb->numRows(); i++ )
236+
for ( int i = 2; i < tb->rowCount(); i++ )
258237
{
259238
if ( i > 2 ) sql.append( ", " );
260239

261-
QString val = tb->text( i, 1 ).stripWhiteSpace();
240+
QString val = tb->item( i, 1 )->text().trimmed();
262241

263242
if ( val.isEmpty() )
264243
{
265-
sql.append( tb->text( i, 0 ) + " = null" );
244+
sql.append( tb->item( i, 0 )->text() + " = null" );
266245
}
267246
else
268247
{
269-
if ( tb->text( i, 2 ) == "int" || tb->text( i, 2 ) == "double" )
248+
if ( tb->item( i, 2 )->text() == "int" || tb->item( i, 2 )->text() == "double" )
270249
{
271-
sql.append( tb->text( i, 0 ) + " = " + val );
250+
sql.append( tb->item( i, 0 )->text() + " = " + val );
272251
}
273252
else
274253
{
275254
val.replace( "'", "''" );
276-
sql.append( tb->text( i, 0 ) + " = '" + val + "'" );
255+
sql.append( tb->item( i, 0 )->text() + " = '" + val + "'" );
277256
}
278257
}
279258
}
280259

281260
QgsDebugMsg( QString( "sql: %1" ).arg( sql ) );
282261

283-
QString *error = mProvider->updateAttributes( tb->text( 0, 1 ).toInt(), tb->text( 1, 1 ).toInt(), sql );
262+
QString *error = mProvider->updateAttributes( tb->item( 0, 1 )->text().toInt(), tb->item( 1, 1 )->text().toInt(), sql );
284263

285264
if ( !error->isEmpty() )
286265
{
@@ -303,7 +282,7 @@ void QgsGrassAttributes::addCat( )
303282
mEdit->addCat( mLine );
304283

305284
// Select new tab
306-
tabCats->setCurrentPage( tabCats->count() - 1 );
285+
tabCats->setCurrentIndex( tabCats->count() - 1 );
307286

308287
resetButtons();
309288
}
@@ -314,14 +293,14 @@ void QgsGrassAttributes::deleteCat( )
314293

315294
if ( tabCats->count() == 0 ) return;
316295

317-
Q3Table *tb = ( Q3Table * ) tabCats->currentPage();
296+
QTableWidget *tb = static_cast<QTableWidget *>( tabCats->currentWidget() );
318297

319-
int field = tb->text( 0, 1 ).toInt();
320-
int cat = tb->text( 1, 1 ).toInt();
298+
int field = tb->item( 0, 1 )->text().toInt();
299+
int cat = tb->item( 1, 1 )->text().toInt();
321300

322301
mEdit->deleteCat( mLine, field, cat );
323302

324-
tabCats->removePage( tb );
303+
tabCats->removeTab( tabCats->indexOf( tb ) );
325304
delete tb;
326305
resetButtons();
327306
}
@@ -332,19 +311,17 @@ void QgsGrassAttributes::clear( )
332311

333312
while ( tabCats->count() > 0 )
334313
{
335-
Q3Table *tb = ( Q3Table * ) tabCats->currentPage();
336-
tabCats->removePage( tb );
314+
QTableWidget *tb = static_cast<QTableWidget *>( tabCats->currentWidget() );
315+
tabCats->removeTab( tabCats->indexOf( tb ) );
337316
delete tb;
338317
}
339318
resetButtons();
340319
}
341320

342-
void QgsGrassAttributes::tabChanged( QWidget *widget )
321+
void QgsGrassAttributes::tabChanged( int index )
343322
{
344323
QgsDebugMsg( "entered." );
345324

346-
//Q3Table *tb = (Q3Table *) tabCats->currentPage();
347-
348325
resultLabel->setText( "" );
349326
}
350327

@@ -373,5 +350,5 @@ void QgsGrassAttributes::columnSizeChanged( int section, int oldSize, int newSiz
373350
QString path = "/GRASS/windows/attributes/columnWidth/"
374351
+ QString::number( section );
375352
QgsDebugMsg( QString( "path = %1 newSize = %2" ).arg( path ).arg( newSize ) );
376-
settings.writeEntry( path, newSize );
353+
settings.setValue( path, newSize );
377354
}

0 commit comments

Comments
 (0)