Skip to content

Commit 2e5506a

Browse files
author
jef
committed
various code cleanups by mloskot for GCC 4.1 (fixes #1239, #1240).
Inspired by it I also enabled pedantic mode for MSVC and cleaned up some more warnings found by GCC 4.3 and MSVC. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9133 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7703910 commit 2e5506a

File tree

107 files changed

+333
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+333
-377
lines changed

CMakeLists.txt

+15-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,21 @@ FIND_PROGRAM(QT_LRELEASE_EXECUTABLE
167167
# enable warnings
168168

169169
IF (PEDANTIC)
170-
ADD_DEFINITIONS( -Wall -Werror )
170+
MESSAGE ("Pedantic compiler settings enabled")
171+
IF(MSVC)
172+
ADD_DEFINITIONS( /W4 )
173+
174+
# disable warnings
175+
ADD_DEFINITIONS( /wd4100 ) # unused formal parameters
176+
ADD_DEFINITIONS( /wd4127 ) # constant conditional expressions (used in Qt template classes)
177+
ADD_DEFINITIONS( /wd4510 ) # default constructor could not be generated (sqlite3_index_info, QMap)
178+
ADD_DEFINITIONS( /wd4512 ) # assignment operator could not be generated (sqlite3_index_info)
179+
ADD_DEFINITIONS( /wd4610 ) # user defined constructor required (sqlite3_index_info)
180+
ELSE (MSVC)
181+
ADD_DEFINITIONS( -Wall -Werror -Wno-long-long )
182+
# Qt produces lots of warnings with strict aliasing (as of Qt 4.4.0 & GCC 4.3)
183+
# ADD_DEFINITIONS( -fstrict-aliasing -Wstrict-aliasing=1 )
184+
ENDIF (MSVC)
171185
ENDIF (PEDANTIC)
172186

173187
IF (CMAKE_BUILD_TYPE MATCHES Debug)

src/app/legend/qgslegend.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class QTreeWidgetItem;
8282

8383
class QgsLegend : public QTreeWidget
8484
{
85-
Q_OBJECT;
85+
Q_OBJECT
8686
private:
8787
// Moved here to match access of declaration later in file.
8888
// Previous location raised a warning in msvc as the forward

src/app/legend/qgslegendlayerfile.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QgsMapLayer;
3232
*/
3333
class QgsLegendLayerFile : public QgsLegendItem
3434
{
35-
Q_OBJECT;
35+
Q_OBJECT
3636

3737
public:
3838
QgsLegendLayerFile(QTreeWidgetItem * theLegendItem, QString theString, QgsMapLayer* theLayer);

src/app/main.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ int main(int argc, char *argv[])
612612
{
613613
double coords[4];
614614
int pos, posOld = 0;
615-
bool ok;
615+
bool ok = true;
616616

617617
// XXX is it necessary to switch to "C" locale?
618618

@@ -623,7 +623,8 @@ int main(int argc, char *argv[])
623623
// find comma and get coordinate
624624
pos = myInitialExtent.indexOf(',', posOld);
625625
if (pos == -1) {
626-
ok = false; break;
626+
ok = false;
627+
break;
627628
}
628629

629630
coords[i] = QString( myInitialExtent.mid(posOld, pos - posOld) ).toDouble(&ok);

src/app/qgisapp.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ QgisApp *QgisApp::smInstance = 0;
314314
QgisApp::QgisApp(QSplashScreen *splash, QWidget * parent, Qt::WFlags fl)
315315
: QMainWindow(parent,fl),
316316
mSplash(splash),
317-
mPythonUtils(NULL), mPythonConsole(NULL)
317+
mPythonConsole(NULL),
318+
mPythonUtils(NULL)
318319
{
319320
if(smInstance) {
320321
QMessageBox::critical(
@@ -1662,9 +1663,9 @@ void QgisApp::restoreSessionPlugins(QString thePluginDirString)
16621663
if (loaded)
16631664
{
16641665

1665-
name_t * myName =(name_t *) myLib->resolve("name");
1666-
description_t * myDescription = (description_t *) myLib->resolve("description");
1667-
version_t * myVersion = (version_t *) myLib->resolve("version");
1666+
name_t * myName =(name_t *) cast_to_fptr(myLib->resolve("name"));
1667+
description_t * myDescription = (description_t *) cast_to_fptr(myLib->resolve("description"));
1668+
version_t * myVersion = (version_t *) cast_to_fptr(myLib->resolve("version"));
16681669
if (myName && myDescription && myVersion )
16691670
{
16701671
//check if the plugin was active on last session
@@ -2451,7 +2452,7 @@ findLayer_( QString const & fileFilters, QDomNode const & constLayerNode )
24512452
break;
24522453
}
24532454

2454-
}; // findLayer_
2455+
} // findLayer_
24552456

24562457

24572458

@@ -2661,7 +2662,7 @@ void QgisApp::newVectorLayer()
26612662

26622663
typedef bool (*createEmptyDataSourceProc)(const QString&, const QString&, const QString&, QGis::WKBTYPE, \
26632664
const std::list<std::pair<QString, QString> >&);
2664-
createEmptyDataSourceProc createEmptyDataSource=(createEmptyDataSourceProc)myLib->resolve("createEmptyDataSource");
2665+
createEmptyDataSourceProc createEmptyDataSource=(createEmptyDataSourceProc) cast_to_fptr(myLib->resolve("createEmptyDataSource"));
26652666
if(createEmptyDataSource)
26662667
{
26672668
#if 0
@@ -3926,7 +3927,7 @@ void QgisApp::loadPythonSupport()
39263927
{
39273928
//QgsDebugMsg("Python support library loaded successfully.");
39283929
typedef QgsPythonUtils* (*inst)();
3929-
inst pythonlib_inst = (inst) pythonlib.resolve("instance");
3930+
inst pythonlib_inst = (inst) cast_to_fptr(pythonlib.resolve("instance"));
39303931
if (pythonlib_inst)
39313932
{
39323933
//QgsDebugMsg("Python support library's instance() symbol resolved.");
@@ -4009,15 +4010,15 @@ void QgisApp::loadPlugin(QString name, QString description, QString theFullPathN
40094010
{
40104011
myError += "Attempting to resolve the classFactory function " + QString (__LINE__) + " in " + QString (__FUNCTION__ ) + "\n";
40114012

4012-
type_t *pType = (type_t *) myLib->resolve("type");
4013+
type_t *pType = (type_t *) cast_to_fptr(myLib->resolve("type"));
40134014

40144015
switch (pType())
40154016
{
40164017
case QgisPlugin::RENDERER:
40174018
case QgisPlugin::UI:
40184019
{
40194020
// UI only -- doesn't use mapcanvas
4020-
create_ui *cf = (create_ui *) myLib->resolve("classFactory");
4021+
create_ui *cf = (create_ui *) cast_to_fptr(myLib->resolve("classFactory"));
40214022
if (cf)
40224023
{
40234024
QgisPlugin *pl = cf(mQgisInterface);
@@ -4049,7 +4050,7 @@ void QgisApp::loadPlugin(QString name, QString description, QString theFullPathN
40494050
case QgisPlugin::MAPLAYER:
40504051
{
40514052
// Map layer - requires interaction with the canvas
4052-
create_it *cf = (create_it *) myLib->resolve("classFactory");
4053+
create_it *cf = (create_it *) cast_to_fptr(myLib->resolve("classFactory"));
40534054
if (cf)
40544055
{
40554056
QgsMapLayerInterface *pl = cf();
@@ -4412,7 +4413,7 @@ bool QgisApp::saveDirty()
44124413
QSettings settings;
44134414
bool askThem = settings.value("qgis/askToSaveProjectChanges", true).toBool();
44144415

4415-
if (askThem && (QgsProject::instance()->isDirty() || (mMapCanvas->isDirty()) && mMapCanvas->layerCount() > 0))
4416+
if (askThem && (QgsProject::instance()->isDirty() || mMapCanvas->isDirty()) && mMapCanvas->layerCount() > 0)
44164417
{
44174418
// flag project as dirty since dirty state of canvas is reset if "dirty"
44184419
// is based on a zoom or pan

src/app/qgisapp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class QgsVectorLayer;
6868
*/
6969
class QgisApp : public QMainWindow
7070
{
71-
Q_OBJECT;
71+
Q_OBJECT
7272
public:
7373
//! Constructor
7474
QgisApp(QSplashScreen *splash, QWidget * parent = 0, Qt::WFlags fl = Qt::Window);

src/app/qgisappinterface.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QgisApp;
3232
*/
3333
class QgisAppInterface : public QgisInterface
3434
{
35-
Q_OBJECT;
35+
Q_OBJECT
3636

3737
public:
3838
/**

src/app/qgsabout.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ void QgsAbout::on_listBox1_currentItemChanged(QListWidgetItem *theItem)
215215
#ifdef QGISDEBUG
216216
printf ("Loading mug: %s\n", myString.toLocal8Bit().constData());
217217
#endif
218-
QPixmap *pixmap = new QPixmap(myString);
219-
//pixAuthorMug->setPixmap(*pixmap);
218+
220219
/* Uncomment this block to use preloaded images
221220
pixAuthorMug->setPixmap(mugs[myString]);
222221
*/

src/app/qgsattributeactiondialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void QgsAttributeActionDialog::insertRow(int row, const QString &name, const QSt
8282
attributeActionTable->setItem(row, 0, new QTableWidgetItem(name));
8383
attributeActionTable->setItem(row, 1, new QTableWidgetItem(action));
8484
QTableWidgetItem* item = new QTableWidgetItem();
85-
item->setFlags(item->flags() & ~Qt::ItemIsEditable | Qt::ItemIsUserCheckable);
85+
item->setFlags(item->flags() & ~(Qt::ItemIsEditable | Qt::ItemIsUserCheckable) );
8686
item->setCheckState(capture ? Qt::Checked : Qt::Unchecked);
8787
attributeActionTable->setItem(row, 2, item);
8888
}

src/app/qgsattributeactiondialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QgsAttributeAction;
3232

3333
class QgsAttributeActionDialog: public QWidget, private Ui::QgsAttributeActionDialogBase
3434
{
35-
Q_OBJECT;
35+
Q_OBJECT
3636

3737
public:
3838
QgsAttributeActionDialog(QgsAttributeAction* actions,

src/app/qgsattributedialog.cpp

+55-55
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
QgsAttributeDialog::QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature *thepFeature)
3939
: QDialog(),
4040
mSettingsPath("/Windows/AttributeDialog/"),
41-
mpFeature(thepFeature),
42-
mLayer(vl)
41+
mLayer(vl),
42+
mpFeature(thepFeature)
4343
{
4444
setupUi(this);
4545
if (mpFeature==NULL || vl->dataProvider()==NULL )
@@ -109,6 +109,58 @@ QgsAttributeDialog::QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature *thepFeatu
109109

110110
switch( editType )
111111
{
112+
case QgsVectorLayer::UniqueValues:
113+
{
114+
QStringList values;
115+
mLayer->dataProvider()->getUniqueValues(it.key(), values);
116+
117+
QComboBox *cb = new QComboBox();
118+
cb->setEditable(true);
119+
cb->addItems(values);
120+
121+
int idx = cb->findText( myFieldValue.toString() );
122+
if( idx>= 0 )
123+
cb->setCurrentIndex( idx );
124+
125+
myWidget = cb;
126+
}
127+
break;
128+
129+
case QgsVectorLayer::ValueMap:
130+
{
131+
const QMap<QString,QVariant> &map = vl->valueMap( it.key() );
132+
133+
QComboBox *cb = new QComboBox();
134+
135+
for(QMap<QString,QVariant>::const_iterator it=map.begin(); it!=map.end(); it++)
136+
{
137+
cb->addItem( it.key(), it.value() );
138+
}
139+
140+
int idx = cb->findData( myFieldValue );
141+
if( idx>= 0 )
142+
cb->setCurrentIndex( idx );
143+
144+
myWidget = cb;
145+
}
146+
break;
147+
148+
case QgsVectorLayer::Classification:
149+
{
150+
QComboBox *cb = new QComboBox();
151+
for(QMap<QString,QString>::const_iterator it=classes.begin(); it!=classes.end(); it++)
152+
{
153+
cb->addItem( it.value(), it.key() );
154+
}
155+
156+
int idx = cb->findData( myFieldValue );
157+
if( idx>=0 )
158+
cb->setCurrentIndex( idx );
159+
160+
myWidget = cb;
161+
}
162+
break;
163+
112164
case QgsVectorLayer::Range:
113165
{
114166
if( myFieldType==QVariant::Int )
@@ -145,9 +197,9 @@ QgsAttributeDialog::QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature *thepFeatu
145197

146198
// fall-through
147199

148-
149200
case QgsVectorLayer::LineEdit:
150201
case QgsVectorLayer::UniqueValuesEditable:
202+
default:
151203
{
152204
QLineEdit *le = new QLineEdit( myFieldValue.toString() );
153205

@@ -173,58 +225,6 @@ QgsAttributeDialog::QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature *thepFeatu
173225
myWidget = le;
174226
}
175227
break;
176-
177-
case QgsVectorLayer::UniqueValues:
178-
{
179-
QStringList values;
180-
mLayer->dataProvider()->getUniqueValues(it.key(), values);
181-
182-
QComboBox *cb = new QComboBox();
183-
cb->setEditable(true);
184-
cb->addItems(values);
185-
186-
int idx = cb->findText( myFieldValue.toString() );
187-
if( idx>= 0 )
188-
cb->setCurrentIndex( idx );
189-
190-
myWidget = cb;
191-
}
192-
break;
193-
194-
case QgsVectorLayer::ValueMap:
195-
{
196-
const QMap<QString,QVariant> &map = vl->valueMap( it.key() );
197-
198-
QComboBox *cb = new QComboBox();
199-
200-
for(QMap<QString,QVariant>::const_iterator it=map.begin(); it!=map.end(); it++)
201-
{
202-
cb->addItem( it.key(), it.value() );
203-
}
204-
205-
int idx = cb->findData( myFieldValue );
206-
if( idx>= 0 )
207-
cb->setCurrentIndex( idx );
208-
209-
myWidget = cb;
210-
}
211-
break;
212-
213-
case QgsVectorLayer::Classification:
214-
{
215-
QComboBox *cb = new QComboBox();
216-
for(QMap<QString,QString>::const_iterator it=classes.begin(); it!=classes.end(); it++)
217-
{
218-
cb->addItem( it.value(), it.key() );
219-
}
220-
221-
int idx = cb->findData( myFieldValue );
222-
if( idx>=0 )
223-
cb->setCurrentIndex( idx );
224-
225-
myWidget = cb;
226-
}
227-
break;
228228
}
229229

230230
if( myFieldType==QVariant::Int )

src/app/qgsattributedialog.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class QgsVectorLayer;
3131

3232
class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
3333
{
34-
Q_OBJECT;
34+
Q_OBJECT
3535

3636
public:
3737
QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature * thepFeature);

src/app/qgsattributetable.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
QgsAttributeTableItemDelegate::QgsAttributeTableItemDelegate(QgsAttributeTable *table, QObject *parent)
36-
: mTable(table), QItemDelegate(parent)
36+
: QItemDelegate(parent), mTable(table)
3737
{
3838
}
3939

@@ -429,8 +429,6 @@ void QgsAttributeTable::copySelectedRows()
429429

430430
void QgsAttributeTable::fillTable(QgsVectorLayer *layer)
431431
{
432-
int row = 0;
433-
434432
const QgsFieldMap &fields = layer->pendingFields();
435433

436434
// set up the column headers

src/app/qgsattributetable.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class QgsAttributeTable : public QTableWidget
5757
enum {
5858
AttributeIndex = Qt::UserRole,
5959
AttributeName = Qt::UserRole+1,
60-
AttributeType = Qt::UserRole+2,
60+
AttributeType = Qt::UserRole+2
6161
};
6262

6363
void setReadOnly(bool b);

src/app/qgsdbsourceselect.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class QgsDbSourceSelect : public QDialog, private Ui::QgsDbSourceSelectBase
103103
dbssType=0,
104104
dbssDetail,
105105
dbssSql,
106-
dbssColumns,
106+
dbssColumns
107107
};
108108

109109
typedef std::pair<QString, QString> geomPair;

src/app/qgsdbtablemodel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ schemas are the root elements that contain the individual tables as children.
2424
The tables have the following columns: Type, Schema, Tablename, Geometry Column, Sql*/
2525
class QgsDbTableModel: public QStandardItemModel
2626
{
27-
Q_OBJECT;
27+
Q_OBJECT
2828
public:
2929
QgsDbTableModel();
3030
~QgsDbTableModel();

src/app/qgsidentifyresults.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class QMenu;
3636

3737
class QgsIdentifyResults: public QDialog, private Ui::QgsIdentifyResultsBase
3838
{
39-
Q_OBJECT;
39+
Q_OBJECT
4040
public:
4141

4242
//! Constructor - takes it own copy of the QgsAttributeAction so

0 commit comments

Comments
 (0)