Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Oct 14, 2012
2 parents fbca157 + 83cb4ef commit 7748c57
Show file tree
Hide file tree
Showing 13 changed files with 2,554 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterblock.cpp
Expand Up @@ -115,7 +115,7 @@ QImage::Format QgsRasterBlock::imageFormat( QgsRasterBlock::DataType theDataType
{
return QImage::Format_ARGB32_Premultiplied;
}
return QImage::QImage::Format_Invalid;
return QImage::Format_Invalid;
}

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

QRgb QgsRasterBlock::color( size_t index) const
{
int row = floor ( index / mWidth );
int row = floor ( (double)index / mWidth );
int column = index % mWidth;
return color( row, column);
}
Expand Down
12 changes: 7 additions & 5 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -306,6 +306,8 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP

mLayersSupported.clear();

// TODO: query topology.layer too !

for ( int i = 0; i < 2; i++ )
{
QString gtableName, columnName;
Expand Down Expand Up @@ -413,17 +415,17 @@ bool QgsPostgresConn::getTableInfo( bool searchGeometryColumnsOnly, bool searchP
if ( searchPublicOnly )
sql += " AND pg_namespace.nspname='public'";

// skip columns of which we already derived information from the metadata tables
if ( nColumns > 0 )
{
// TODO: handle this for the topogeometry case
sql += " AND (pg_namespace.nspname,pg_class.relname) NOT IN (SELECT f_table_schema,f_table_name FROM geometry_columns)";
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)";

if ( nGTables > 1 )
{
// TODO: handle this for the topogeometry case
// TODO: handle this for the geometry case ?
sql += " AND (pg_namespace.nspname,pg_class.relname) NOT IN (SELECT f_table_schema,f_table_name FROM geography_columns)";
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)";
}

// TODO: handle this for the topogeometry case (once we lookup topology.layer)
}

sql += " AND pg_class.relkind IN ('v','r')"; // only from views and relations (tables)
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -17,3 +17,4 @@ ADD_PYTHON_TEST(PyQgsSymbolLayerV2 test_qgssymbollayerv2.py)
ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
ADD_PYTHON_TEST(PyQgsAtlasComposition test_qgsatlascomposition.py)
ADD_PYTHON_TEST(PyQgsComposerLabel test_qgscomposerlabel.py)
ADD_PYTHON_TEST(PyQgsPalLabeling test_qgspallabeling.py)
207 changes: 207 additions & 0 deletions tests/src/python/test_qgspallabeling.py
@@ -0,0 +1,207 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsPalLabeling
.. note:: 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.
"""
__author__ = 'Larry Shaffer'
__date__ = '12/10/2012'
__copyright__ = 'Copyright 2012, The Quantum GIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import (QgsPalLabeling,
QgsPalLayerSettings,
QgsVectorLayer,
QgsMapLayerRegistry,
QgsMapRenderer,
QgsCoordinateReferenceSystem,
QgsRenderChecker,
QGis)

from utilities import (getQgisTestApp,
TestCase,
unittest,
expectedFailure,
unitTestDataPath)

# Convenience instances in case you may need them
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()


class TestQgsPalLabeling(TestCase):

@classmethod
def setUpClass(cls):
"""Run before all tests"""

# Store/load the FreeSansQGIS labeling test font
myFontDB = QFontDatabase()
cls._testFontID = myFontDB.addApplicationFont(
os.path.join(TEST_DATA_DIR, 'font', 'FreeSansQGIS.ttf'))
myMessage = ('\nCould not store test font in font database, '
'skipping test suite')
assert cls._testFontID != -1, myMessage

cls._testFont = myFontDB.font('FreeSansQGIS', 'Medium', 12)
myAppFont = QApplication.font()
myMessage = ('\nCould not load test font from font database, '
'skipping test suite')
assert cls._testFont.toString() != myAppFont.toString(), myMessage

# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
cls._MapRegistry = QgsMapLayerRegistry.instance()
cls._Canvas = CANVAS
# to match render test comparisons background
cls._Canvas.setCanvasColor(QColor(152, 219, 249))
cls._Map = cls._Canvas.map()
cls._Map.resize(QSize(600, 400))
cls._MapRenderer = cls._Canvas.mapRenderer()
cls._MapRenderer.setOutputSize(QSize(600, 400), 72)

cls._Pal = QgsPalLabeling();
cls._MapRenderer.setLabelingEngine(cls._Pal)
cls._PalEngine = cls._MapRenderer.labelingEngine()
myMessage = ('\nCould initialize PAL labeling engine, '
'skipping test suite')
assert cls._PalEngine, myMessage

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
# remove test font
myFontDB = QFontDatabase()
myResult = myFontDB.removeApplicationFont(cls._testFontID)
myMessage = ('\nFailed to remove test font from font database')
assert myResult, myMessage

def setUp(self):
"""Run before each test."""
pass

def tearDown(self):
"""Run after each test."""
pass

def test_AddPALToVectorLayer(self):
"""Check if we can set a label field, verify that PAL is assigned
and that output is rendered correctly"""
# TODO: add UTM PAL-specific shps, with 4326 as on-the-fly cross-check
# setCanvasCrs(26913)

myShpFile = os.path.join(TEST_DATA_DIR, 'lines.shp')
myVectorLayer = QgsVectorLayer(myShpFile, 'Lines', 'ogr')

self._MapRegistry.addMapLayer(myVectorLayer)

myLayers = QStringList()
myLayers.append(myVectorLayer.id())
self._MapRenderer.setLayerSet(myLayers)
self._MapRenderer.setExtent(myVectorLayer.extent())
self._Canvas.zoomToFullExtent()

# check layer labeling is PAL with customProperty access
# should not be activated on layer load
myPalSet = myVectorLayer.customProperty( "labeling" ).toString()
myMessage = '\nExpected: Empty QString\nGot: %s' % (str(myPalSet))
assert str(myPalSet) == '', myMessage

# simulate clicking checkbox, setting label field and clicking apply
self._testFont.setPointSize(20)
myPalLyr = QgsPalLayerSettings()

myPalLyr.enabled = True
myPalLyr.fieldName = 'Name'
myPalLyr.placement = QgsPalLayerSettings.Line
myPalLyr.placementFlags = QgsPalLayerSettings.AboveLine
myPalLyr.xQuadOffset = 0
myPalLyr.yQuadOffset = 0
myPalLyr.xOffset = 0
myPalLyr.yOffset = 0
myPalLyr.angleOffset = 0
myPalLyr.centroidWhole = False
myPalLyr.textFont = self._testFont
myPalLyr.textNamedStyle = QString("Medium")
myPalLyr.textColor = Qt.black
myPalLyr.textTransp = 0
myPalLyr.previewBkgrdColor = Qt.white
myPalLyr.priority = 5
myPalLyr.obstacle = True
myPalLyr.dist = 0
myPalLyr.scaleMin = 0
myPalLyr.scaleMax = 0
myPalLyr.bufferSize = 1
myPalLyr.bufferColor = Qt.white
myPalLyr.bufferTransp = 0
myPalLyr.bufferNoFill = False
myPalLyr.bufferJoinStyle = Qt.RoundJoin
myPalLyr.formatNumbers = False
myPalLyr.decimals = 3
myPalLyr.plusSign = False
myPalLyr.labelPerPart = False
myPalLyr.displayAll = True
myPalLyr.mergeLines = False
myPalLyr.minFeatureSize = 0.0
myPalLyr.vectorScaleFactor = 1.0
myPalLyr.rasterCompressFactor = 1.0
myPalLyr.addDirectionSymbol = False
myPalLyr.upsidedownLabels = QgsPalLayerSettings.Upright
myPalLyr.fontSizeInMapUnits = False
myPalLyr.bufferSizeInMapUnits = False
myPalLyr.labelOffsetInMapUnits = True
myPalLyr.distInMapUnits = False
myPalLyr.wrapChar = ""
myPalLyr.preserveRotation = True

myPalLyr.writeToLayer(myVectorLayer)

# check layer labeling is PAL with customProperty access
myPalSet = myVectorLayer.customProperty( "labeling" ).toString()
myMessage = '\nExpected: pal\nGot: %s' % (str(myPalSet))
assert str(myPalSet) == 'pal', myMessage

# check layer labeling is PAL via engine interface
myMessage = '\nCould not get whether PAL enabled from labelingEngine'
assert self._PalEngine.willUseLayer(myVectorLayer), myMessage

#
myChecker = QgsRenderChecker()
myChecker.setControlName("expected_pal_aboveLineLabeling")
myChecker.setMapRenderer(self._MapRenderer)

myResult = myChecker.runTest("pal_aboveLineLabeling_python");
myMessage = ('\nVector layer \'above line\' label engine '
'rendering test failed')
assert myResult, myMessage

# compare against a straight rendering/save as from QgsMapCanvasMap
# unnecessary? works a bit different than QgsRenderChecker, though
# myImage = os.path.join(unicode(QDir.tempPath()),
# 'render_pal_aboveLineLabeling.png')
# self._Map.render()
# self._Canvas.saveAsImage(myImage)
# myChecker.setRenderedImage(myImage)
# myResult = myChecker.compareImages("pal_aboveLineLabeling_python")
# myMessage = ('\nVector layer \'above line\' label engine '
# 'comparison to QgsMapCanvasMap.render() test failed')
# assert myResult, myMessage

self._MapRegistry.removeMapLayer(myVectorLayer.id())

# @expectedFailure
# def testIssue####(self):
# """Test we can .
# """
# pass

if __name__ == '__main__':
unittest.main()


Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7748c57

Please sign in to comment.