Skip to content

Commit 7748c57

Browse files
committed
Merge branch 'master' of https://github.com/qgis/Quantum-GIS
2 parents fbca157 + 83cb4ef commit 7748c57

File tree

13 files changed

+2554
-7
lines changed

13 files changed

+2554
-7
lines changed

src/core/raster/qgsrasterblock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ QImage::Format QgsRasterBlock::imageFormat( QgsRasterBlock::DataType theDataType
115115
{
116116
return QImage::Format_ARGB32_Premultiplied;
117117
}
118-
return QImage::QImage::Format_Invalid;
118+
return QImage::Format_Invalid;
119119
}
120120

121121
QgsRasterBlock::DataType QgsRasterBlock::dataType ( QImage::Format theFormat )
@@ -267,7 +267,7 @@ double QgsRasterBlock::value( int row, int column) const
267267

268268
QRgb QgsRasterBlock::color( size_t index) const
269269
{
270-
int row = floor ( index / mWidth );
270+
int row = floor ( (double)index / mWidth );
271271
int column = index % mWidth;
272272
return color( row, column);
273273
}

src/providers/postgres/qgspostgresconn.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
306306

307307
mLayersSupported.clear();
308308

309+
// TODO: query topology.layer too !
310+
309311
for ( int i = 0; i < 2; i++ )
310312
{
311313
QString gtableName, columnName;
@@ -413,17 +415,17 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
413415
if ( searchPublicOnly )
414416
sql += " AND pg_namespace.nspname='public'";
415417

418+
// skip columns of which we already derived information from the metadata tables
416419
if ( nColumns > 0 )
417420
{
418-
// TODO: handle this for the topogeometry case
419-
sql += " AND (pg_namespace.nspname,pg_class.relname) NOT IN (SELECT f_table_schema,f_table_name FROM geometry_columns)";
421+
sql += " AND (pg_namespace.nspname,pg_class.relname,pg_attribute.attname) NOT IN (SELECT f_table_schema,f_table_name,f_geometry_column FROM geometry_columns)";
420422

421423
if ( nGTables > 1 )
422424
{
423-
// TODO: handle this for the topogeometry case
424-
// TODO: handle this for the geometry case ?
425-
sql += " AND (pg_namespace.nspname,pg_class.relname) NOT IN (SELECT f_table_schema,f_table_name FROM geography_columns)";
425+
sql += " AND (pg_namespace.nspname,pg_class.relname,pg_attribute.attname) NOT IN (SELECT f_table_schema,f_table_name,f_geography_column FROM geography_columns)";
426426
}
427+
428+
// TODO: handle this for the topogeometry case (once we lookup topology.layer)
427429
}
428430

429431
sql += " AND pg_class.relkind IN ('v','r')"; // only from views and relations (tables)

tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ ADD_PYTHON_TEST(PyQgsSymbolLayerV2 test_qgssymbollayerv2.py)
1717
ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
1818
ADD_PYTHON_TEST(PyQgsAtlasComposition test_qgsatlascomposition.py)
1919
ADD_PYTHON_TEST(PyQgsComposerLabel test_qgscomposerlabel.py)
20+
ADD_PYTHON_TEST(PyQgsPalLabeling test_qgspallabeling.py)
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsPalLabeling
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Larry Shaffer'
10+
__date__ = '12/10/2012'
11+
__copyright__ = 'Copyright 2012, The Quantum GIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import os
16+
from PyQt4.QtCore import *
17+
from PyQt4.QtGui import *
18+
19+
from qgis.core import (QgsPalLabeling,
20+
QgsPalLayerSettings,
21+
QgsVectorLayer,
22+
QgsMapLayerRegistry,
23+
QgsMapRenderer,
24+
QgsCoordinateReferenceSystem,
25+
QgsRenderChecker,
26+
QGis)
27+
28+
from utilities import (getQgisTestApp,
29+
TestCase,
30+
unittest,
31+
expectedFailure,
32+
unitTestDataPath)
33+
34+
# Convenience instances in case you may need them
35+
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
36+
TEST_DATA_DIR = unitTestDataPath()
37+
38+
39+
class TestQgsPalLabeling(TestCase):
40+
41+
@classmethod
42+
def setUpClass(cls):
43+
"""Run before all tests"""
44+
45+
# Store/load the FreeSansQGIS labeling test font
46+
myFontDB = QFontDatabase()
47+
cls._testFontID = myFontDB.addApplicationFont(
48+
os.path.join(TEST_DATA_DIR, 'font', 'FreeSansQGIS.ttf'))
49+
myMessage = ('\nCould not store test font in font database, '
50+
'skipping test suite')
51+
assert cls._testFontID != -1, myMessage
52+
53+
cls._testFont = myFontDB.font('FreeSansQGIS', 'Medium', 12)
54+
myAppFont = QApplication.font()
55+
myMessage = ('\nCould not load test font from font database, '
56+
'skipping test suite')
57+
assert cls._testFont.toString() != myAppFont.toString(), myMessage
58+
59+
# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
60+
cls._MapRegistry = QgsMapLayerRegistry.instance()
61+
cls._Canvas = CANVAS
62+
# to match render test comparisons background
63+
cls._Canvas.setCanvasColor(QColor(152, 219, 249))
64+
cls._Map = cls._Canvas.map()
65+
cls._Map.resize(QSize(600, 400))
66+
cls._MapRenderer = cls._Canvas.mapRenderer()
67+
cls._MapRenderer.setOutputSize(QSize(600, 400), 72)
68+
69+
cls._Pal = QgsPalLabeling();
70+
cls._MapRenderer.setLabelingEngine(cls._Pal)
71+
cls._PalEngine = cls._MapRenderer.labelingEngine()
72+
myMessage = ('\nCould initialize PAL labeling engine, '
73+
'skipping test suite')
74+
assert cls._PalEngine, myMessage
75+
76+
@classmethod
77+
def tearDownClass(cls):
78+
"""Run after all tests"""
79+
# remove test font
80+
myFontDB = QFontDatabase()
81+
myResult = myFontDB.removeApplicationFont(cls._testFontID)
82+
myMessage = ('\nFailed to remove test font from font database')
83+
assert myResult, myMessage
84+
85+
def setUp(self):
86+
"""Run before each test."""
87+
pass
88+
89+
def tearDown(self):
90+
"""Run after each test."""
91+
pass
92+
93+
def test_AddPALToVectorLayer(self):
94+
"""Check if we can set a label field, verify that PAL is assigned
95+
and that output is rendered correctly"""
96+
# TODO: add UTM PAL-specific shps, with 4326 as on-the-fly cross-check
97+
# setCanvasCrs(26913)
98+
99+
myShpFile = os.path.join(TEST_DATA_DIR, 'lines.shp')
100+
myVectorLayer = QgsVectorLayer(myShpFile, 'Lines', 'ogr')
101+
102+
self._MapRegistry.addMapLayer(myVectorLayer)
103+
104+
myLayers = QStringList()
105+
myLayers.append(myVectorLayer.id())
106+
self._MapRenderer.setLayerSet(myLayers)
107+
self._MapRenderer.setExtent(myVectorLayer.extent())
108+
self._Canvas.zoomToFullExtent()
109+
110+
# check layer labeling is PAL with customProperty access
111+
# should not be activated on layer load
112+
myPalSet = myVectorLayer.customProperty( "labeling" ).toString()
113+
myMessage = '\nExpected: Empty QString\nGot: %s' % (str(myPalSet))
114+
assert str(myPalSet) == '', myMessage
115+
116+
# simulate clicking checkbox, setting label field and clicking apply
117+
self._testFont.setPointSize(20)
118+
myPalLyr = QgsPalLayerSettings()
119+
120+
myPalLyr.enabled = True
121+
myPalLyr.fieldName = 'Name'
122+
myPalLyr.placement = QgsPalLayerSettings.Line
123+
myPalLyr.placementFlags = QgsPalLayerSettings.AboveLine
124+
myPalLyr.xQuadOffset = 0
125+
myPalLyr.yQuadOffset = 0
126+
myPalLyr.xOffset = 0
127+
myPalLyr.yOffset = 0
128+
myPalLyr.angleOffset = 0
129+
myPalLyr.centroidWhole = False
130+
myPalLyr.textFont = self._testFont
131+
myPalLyr.textNamedStyle = QString("Medium")
132+
myPalLyr.textColor = Qt.black
133+
myPalLyr.textTransp = 0
134+
myPalLyr.previewBkgrdColor = Qt.white
135+
myPalLyr.priority = 5
136+
myPalLyr.obstacle = True
137+
myPalLyr.dist = 0
138+
myPalLyr.scaleMin = 0
139+
myPalLyr.scaleMax = 0
140+
myPalLyr.bufferSize = 1
141+
myPalLyr.bufferColor = Qt.white
142+
myPalLyr.bufferTransp = 0
143+
myPalLyr.bufferNoFill = False
144+
myPalLyr.bufferJoinStyle = Qt.RoundJoin
145+
myPalLyr.formatNumbers = False
146+
myPalLyr.decimals = 3
147+
myPalLyr.plusSign = False
148+
myPalLyr.labelPerPart = False
149+
myPalLyr.displayAll = True
150+
myPalLyr.mergeLines = False
151+
myPalLyr.minFeatureSize = 0.0
152+
myPalLyr.vectorScaleFactor = 1.0
153+
myPalLyr.rasterCompressFactor = 1.0
154+
myPalLyr.addDirectionSymbol = False
155+
myPalLyr.upsidedownLabels = QgsPalLayerSettings.Upright
156+
myPalLyr.fontSizeInMapUnits = False
157+
myPalLyr.bufferSizeInMapUnits = False
158+
myPalLyr.labelOffsetInMapUnits = True
159+
myPalLyr.distInMapUnits = False
160+
myPalLyr.wrapChar = ""
161+
myPalLyr.preserveRotation = True
162+
163+
myPalLyr.writeToLayer(myVectorLayer)
164+
165+
# check layer labeling is PAL with customProperty access
166+
myPalSet = myVectorLayer.customProperty( "labeling" ).toString()
167+
myMessage = '\nExpected: pal\nGot: %s' % (str(myPalSet))
168+
assert str(myPalSet) == 'pal', myMessage
169+
170+
# check layer labeling is PAL via engine interface
171+
myMessage = '\nCould not get whether PAL enabled from labelingEngine'
172+
assert self._PalEngine.willUseLayer(myVectorLayer), myMessage
173+
174+
#
175+
myChecker = QgsRenderChecker()
176+
myChecker.setControlName("expected_pal_aboveLineLabeling")
177+
myChecker.setMapRenderer(self._MapRenderer)
178+
179+
myResult = myChecker.runTest("pal_aboveLineLabeling_python");
180+
myMessage = ('\nVector layer \'above line\' label engine '
181+
'rendering test failed')
182+
assert myResult, myMessage
183+
184+
# compare against a straight rendering/save as from QgsMapCanvasMap
185+
# unnecessary? works a bit different than QgsRenderChecker, though
186+
# myImage = os.path.join(unicode(QDir.tempPath()),
187+
# 'render_pal_aboveLineLabeling.png')
188+
# self._Map.render()
189+
# self._Canvas.saveAsImage(myImage)
190+
# myChecker.setRenderedImage(myImage)
191+
# myResult = myChecker.compareImages("pal_aboveLineLabeling_python")
192+
# myMessage = ('\nVector layer \'above line\' label engine '
193+
# 'comparison to QgsMapCanvasMap.render() test failed')
194+
# assert myResult, myMessage
195+
196+
self._MapRegistry.removeMapLayer(myVectorLayer.id())
197+
198+
# @expectedFailure
199+
# def testIssue####(self):
200+
# """Test we can .
201+
# """
202+
# pass
203+
204+
if __name__ == '__main__':
205+
unittest.main()
206+
207+

0 commit comments

Comments
 (0)