35 #include <QApplication> 38 #include <QFontMetrics> 59 #include <QMessageBox> 81 : upsidedownLabels( Upright )
88 , mFeaturesToLabel( 0 )
89 , mFeatsSendingToPal( 0 )
103 blendMode = QPainter::CompositionMode_SourceOver;
212 mDataDefinedNames.insert(
Size, QPair<QString, int>(
"Size", 0 ) );
213 mDataDefinedNames.insert(
Bold, QPair<QString, int>(
"Bold", 1 ) );
214 mDataDefinedNames.insert(
Italic, QPair<QString, int>(
"Italic", 2 ) );
215 mDataDefinedNames.insert(
Underline, QPair<QString, int>(
"Underline", 3 ) );
216 mDataDefinedNames.insert(
Color, QPair<QString, int>(
"Color", 4 ) );
217 mDataDefinedNames.insert(
Strikeout, QPair<QString, int>(
"Strikeout", 5 ) );
218 mDataDefinedNames.insert(
Family, QPair<QString, int>(
"Family", 6 ) );
219 mDataDefinedNames.insert(
FontStyle, QPair<QString, int>(
"FontStyle", -1 ) );
220 mDataDefinedNames.insert(
FontSizeUnit, QPair<QString, int>(
"FontSizeUnit", -1 ) );
221 mDataDefinedNames.insert(
FontTransp, QPair<QString, int>(
"FontTransp", 18 ) );
222 mDataDefinedNames.insert(
FontCase, QPair<QString, int>(
"FontCase", -1 ) );
223 mDataDefinedNames.insert(
FontLetterSpacing, QPair<QString, int>(
"FontLetterSpacing", -1 ) );
224 mDataDefinedNames.insert(
FontWordSpacing, QPair<QString, int>(
"FontWordSpacing", -1 ) );
225 mDataDefinedNames.insert(
FontBlendMode, QPair<QString, int>(
"FontBlendMode", -1 ) );
228 mDataDefinedNames.insert(
MultiLineWrapChar, QPair<QString, int>(
"MultiLineWrapChar", -1 ) );
229 mDataDefinedNames.insert(
MultiLineHeight, QPair<QString, int>(
"MultiLineHeight", -1 ) );
230 mDataDefinedNames.insert(
MultiLineAlignment, QPair<QString, int>(
"MultiLineAlignment", -1 ) );
231 mDataDefinedNames.insert(
DirSymbDraw, QPair<QString, int>(
"DirSymbDraw", -1 ) );
232 mDataDefinedNames.insert(
DirSymbLeft, QPair<QString, int>(
"DirSymbLeft", -1 ) );
233 mDataDefinedNames.insert(
DirSymbRight, QPair<QString, int>(
"DirSymbRight", -1 ) );
234 mDataDefinedNames.insert(
DirSymbPlacement, QPair<QString, int>(
"DirSymbPlacement", -1 ) );
235 mDataDefinedNames.insert(
DirSymbReverse, QPair<QString, int>(
"DirSymbReverse", -1 ) );
236 mDataDefinedNames.insert(
NumFormat, QPair<QString, int>(
"NumFormat", -1 ) );
237 mDataDefinedNames.insert(
NumDecimals, QPair<QString, int>(
"NumDecimals", -1 ) );
238 mDataDefinedNames.insert(
NumPlusSign, QPair<QString, int>(
"NumPlusSign", -1 ) );
241 mDataDefinedNames.insert(
BufferDraw, QPair<QString, int>(
"BufferDraw", -1 ) );
242 mDataDefinedNames.insert(
BufferSize, QPair<QString, int>(
"BufferSize", 7 ) );
243 mDataDefinedNames.insert(
BufferUnit, QPair<QString, int>(
"BufferUnit", -1 ) );
244 mDataDefinedNames.insert(
BufferColor, QPair<QString, int>(
"BufferColor", 8 ) );
245 mDataDefinedNames.insert(
BufferTransp, QPair<QString, int>(
"BufferTransp", 19 ) );
246 mDataDefinedNames.insert(
BufferJoinStyle, QPair<QString, int>(
"BufferJoinStyle", -1 ) );
247 mDataDefinedNames.insert(
BufferBlendMode, QPair<QString, int>(
"BufferBlendMode", -1 ) );
250 mDataDefinedNames.insert(
ShapeDraw, QPair<QString, int>(
"ShapeDraw", -1 ) );
251 mDataDefinedNames.insert(
ShapeKind, QPair<QString, int>(
"ShapeKind", -1 ) );
252 mDataDefinedNames.insert(
ShapeSVGFile, QPair<QString, int>(
"ShapeSVGFile", -1 ) );
253 mDataDefinedNames.insert(
ShapeSizeType, QPair<QString, int>(
"ShapeSizeType", -1 ) );
254 mDataDefinedNames.insert(
ShapeSizeX, QPair<QString, int>(
"ShapeSizeX", -1 ) );
255 mDataDefinedNames.insert(
ShapeSizeY, QPair<QString, int>(
"ShapeSizeY", -1 ) );
256 mDataDefinedNames.insert(
ShapeSizeUnits, QPair<QString, int>(
"ShapeSizeUnits", -1 ) );
257 mDataDefinedNames.insert(
ShapeRotationType, QPair<QString, int>(
"ShapeRotationType", -1 ) );
258 mDataDefinedNames.insert(
ShapeRotation, QPair<QString, int>(
"ShapeRotation", -1 ) );
259 mDataDefinedNames.insert(
ShapeOffset, QPair<QString, int>(
"ShapeOffset", -1 ) );
260 mDataDefinedNames.insert(
ShapeOffsetUnits, QPair<QString, int>(
"ShapeOffsetUnits", -1 ) );
261 mDataDefinedNames.insert(
ShapeRadii, QPair<QString, int>(
"ShapeRadii", -1 ) );
262 mDataDefinedNames.insert(
ShapeRadiiUnits, QPair<QString, int>(
"ShapeRadiiUnits", -1 ) );
263 mDataDefinedNames.insert(
ShapeTransparency, QPair<QString, int>(
"ShapeTransparency", -1 ) );
264 mDataDefinedNames.insert(
ShapeBlendMode, QPair<QString, int>(
"ShapeBlendMode", -1 ) );
265 mDataDefinedNames.insert(
ShapeFillColor, QPair<QString, int>(
"ShapeFillColor", -1 ) );
266 mDataDefinedNames.insert(
ShapeBorderColor, QPair<QString, int>(
"ShapeBorderColor", -1 ) );
267 mDataDefinedNames.insert(
ShapeBorderWidth, QPair<QString, int>(
"ShapeBorderWidth", -1 ) );
268 mDataDefinedNames.insert(
ShapeBorderWidthUnits, QPair<QString, int>(
"ShapeBorderWidthUnits", -1 ) );
269 mDataDefinedNames.insert(
ShapeJoinStyle, QPair<QString, int>(
"ShapeJoinStyle", -1 ) );
272 mDataDefinedNames.insert(
ShadowDraw, QPair<QString, int>(
"ShadowDraw", -1 ) );
273 mDataDefinedNames.insert(
ShadowUnder, QPair<QString, int>(
"ShadowUnder", -1 ) );
274 mDataDefinedNames.insert(
ShadowOffsetAngle, QPair<QString, int>(
"ShadowOffsetAngle", -1 ) );
275 mDataDefinedNames.insert(
ShadowOffsetDist, QPair<QString, int>(
"ShadowOffsetDist", -1 ) );
276 mDataDefinedNames.insert(
ShadowOffsetUnits, QPair<QString, int>(
"ShadowOffsetUnits", -1 ) );
277 mDataDefinedNames.insert(
ShadowRadius, QPair<QString, int>(
"ShadowRadius", -1 ) );
278 mDataDefinedNames.insert(
ShadowRadiusUnits, QPair<QString, int>(
"ShadowRadiusUnits", -1 ) );
279 mDataDefinedNames.insert(
ShadowTransparency, QPair<QString, int>(
"ShadowTransparency", -1 ) );
280 mDataDefinedNames.insert(
ShadowScale, QPair<QString, int>(
"ShadowScale", -1 ) );
281 mDataDefinedNames.insert(
ShadowColor, QPair<QString, int>(
"ShadowColor", -1 ) );
282 mDataDefinedNames.insert(
ShadowBlendMode, QPair<QString, int>(
"ShadowBlendMode", -1 ) );
285 mDataDefinedNames.insert(
CentroidWhole, QPair<QString, int>(
"CentroidWhole", -1 ) );
286 mDataDefinedNames.insert(
OffsetQuad, QPair<QString, int>(
"OffsetQuad", -1 ) );
287 mDataDefinedNames.insert(
OffsetXY, QPair<QString, int>(
"OffsetXY", -1 ) );
288 mDataDefinedNames.insert(
OffsetUnits, QPair<QString, int>(
"OffsetUnits", -1 ) );
289 mDataDefinedNames.insert(
LabelDistance, QPair<QString, int>(
"LabelDistance", 13 ) );
290 mDataDefinedNames.insert(
DistanceUnits, QPair<QString, int>(
"DistanceUnits", -1 ) );
291 mDataDefinedNames.insert(
OffsetRotation, QPair<QString, int>(
"OffsetRotation", -1 ) );
292 mDataDefinedNames.insert(
CurvedCharAngleInOut, QPair<QString, int>(
"CurvedCharAngleInOut", -1 ) );
293 mDataDefinedNames.insert(
RepeatDistance, QPair<QString, int>(
"RepeatDistance", -1 ) );
294 mDataDefinedNames.insert(
RepeatDistanceUnit, QPair<QString, int>(
"RepeatDistanceUnit", -1 ) );
296 mDataDefinedNames.insert(
PositionX, QPair<QString, int>(
"PositionX", 9 ) );
297 mDataDefinedNames.insert(
PositionY, QPair<QString, int>(
"PositionY", 10 ) );
298 mDataDefinedNames.insert(
Hali, QPair<QString, int>(
"Hali", 11 ) );
299 mDataDefinedNames.insert(
Vali, QPair<QString, int>(
"Vali", 12 ) );
300 mDataDefinedNames.insert(
Rotation, QPair<QString, int>(
"Rotation", 14 ) );
303 mDataDefinedNames.insert(
ScaleVisibility, QPair<QString, int>(
"ScaleVisibility", -1 ) );
304 mDataDefinedNames.insert(
MinScale, QPair<QString, int>(
"MinScale", 16 ) );
305 mDataDefinedNames.insert(
MaxScale, QPair<QString, int>(
"MaxScale", 17 ) );
306 mDataDefinedNames.insert(
FontLimitPixel, QPair<QString, int>(
"FontLimitPixel", -1 ) );
307 mDataDefinedNames.insert(
FontMinPixel, QPair<QString, int>(
"FontMinPixel", -1 ) );
308 mDataDefinedNames.insert(
FontMaxPixel, QPair<QString, int>(
"FontMaxPixel", -1 ) );
310 mDataDefinedNames.insert(
Show, QPair<QString, int>(
"Show", 15 ) );
311 mDataDefinedNames.insert(
AlwaysShow, QPair<QString, int>(
"AlwaysShow", 20 ) );
457 mDataDefinedNames = s.mDataDefinedNames;
488 if ( expression == NULL )
497 int r = layer->
customProperty( property +
"R", QVariant( defaultColor.red() ) ).toInt();
498 int g = layer->
customProperty( property +
"G", QVariant( defaultColor.green() ) ).toInt();
499 int b = layer->
customProperty( property +
"B", QVariant( defaultColor.blue() ) ).toInt();
500 int a = withAlpha ? layer->
customProperty( property +
"A", QVariant( defaultColor.alpha() ) ).toInt() : 255;
501 return QColor( r, g, b, a );
515 if ( str.compare(
"Point", Qt::CaseInsensitive ) == 0
517 if ( str.compare(
"MapUnit", Qt::CaseInsensitive ) == 0
525 if ( str.compare(
"Miter", Qt::CaseInsensitive ) == 0 )
return Qt::MiterJoin;
526 if ( str.compare(
"Round", Qt::CaseInsensitive ) == 0 )
return Qt::RoundJoin;
527 return Qt::BevelJoin;
530 void QgsPalLayerSettings::readDataDefinedPropertyMap(
QgsVectorLayer* layer,
531 QMap < QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > & propertyMap )
538 QMapIterator<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > i( mDataDefinedNames );
539 while ( i.hasNext() )
542 readDataDefinedProperty( layer, i.key(), propertyMap );
546 void QgsPalLayerSettings::writeDataDefinedPropertyMap(
QgsVectorLayer* layer,
547 const QMap < QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > & propertyMap )
554 QMapIterator<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > i( mDataDefinedNames );
555 while ( i.hasNext() )
558 QString newPropertyName =
"labeling/dataDefined/" + i.value().first;
559 QVariant propertyValue = QVariant();
561 QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* >::const_iterator it = propertyMap.find( i.key() );
562 if ( it != propertyMap.constEnd() )
570 QString field = dd->
field();
572 bool defaultVals = ( !active && !useExpr && expr.isEmpty() && field.isEmpty() );
578 values << ( active ?
"1" :
"0" );
579 values << ( useExpr ?
"1" :
"0" );
582 if ( !values.isEmpty() )
584 propertyValue = QVariant( values.join(
"~~" ) );
590 if ( propertyValue.isValid() )
600 if ( layer->
customProperty( newPropertyName, QVariant() ).isValid() && i.value().second > -1 )
603 layer->
removeCustomProperty( QString(
"labeling/dataDefinedProperty" ) + QString::number( i.value().second ) );
608 void QgsPalLayerSettings::readDataDefinedProperty(
QgsVectorLayer* layer,
610 QMap < QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > & propertyMap )
612 QString newPropertyName =
"labeling/dataDefined/" + mDataDefinedNames.value( p ).first;
613 QVariant newPropertyField = layer->
customProperty( newPropertyName, QVariant() );
615 QString ddString = QString();
616 if ( newPropertyField.isValid() )
618 ddString = newPropertyField.toString();
622 int oldIndx = mDataDefinedNames.value( p ).second;
629 QString oldPropertyName =
"labeling/dataDefinedProperty" + QString::number( oldIndx );
630 QVariant oldPropertyField = layer->
customProperty( oldPropertyName, QVariant() );
632 if ( !oldPropertyField.isValid() )
639 int indx = oldPropertyField.toInt( &conversionOk );
649 if ( !oldIndicesToNames.isEmpty() )
651 ddString = oldIndicesToNames.value( indx );
656 if ( indx < fields.
size() )
658 ddString = fields.
at( indx ).
name();
663 if ( !ddString.isEmpty() )
676 if ( oldIndx == 16 || oldIndx == 17 )
687 if ( !ddString.isEmpty() && ddString != QString(
"0~~0~~~~" ) )
691 QStringList ddv = newStyleString.split(
"~~" );
694 propertyMap.insert( p, dd );
705 if ( layer->
customProperty(
"labeling" ).toString() != QString(
"pal" ) )
722 QFont appFont = QApplication::font();
734 fontFamily = appFont.family();
737 double fontSize = layer->
customProperty(
"labeling/fontSize" ).toDouble();
741 int fontWeight = layer->
customProperty(
"labeling/fontWeight" ).toInt();
742 bool fontItalic = layer->
customProperty(
"labeling/fontItalic" ).toBool();
743 textFont = QFont( fontFamily, fontSize, fontWeight, fontItalic );
747 textFont.setCapitalization(( QFont::Capitalization )layer->
customProperty(
"labeling/fontCapitals", QVariant( 0 ) ).toUInt() );
750 textFont.setLetterSpacing( QFont::AbsoluteSpacing, layer->
customProperty(
"labeling/fontLetterSpacing", QVariant( 0.0 ) ).toDouble() );
751 textFont.setWordSpacing( layer->
customProperty(
"labeling/fontWordSpacing", QVariant( 0.0 ) ).toDouble() );
773 double bufSize = layer->
customProperty(
"labeling/bufferSize", QVariant( 0.0 ) ).toDouble();
776 QVariant drawBuffer = layer->
customProperty(
"labeling/bufferDraw", QVariant() );
777 if ( drawBuffer.isValid() )
782 else if ( bufSize != 0.0 )
809 layer->
customProperty(
"labeling/shapeSizeY", QVariant( 0.0 ) ).toDouble() );
816 layer->
customProperty(
"labeling/shapeOffsetY", QVariant( 0.0 ) ).toDouble() );
821 layer->
customProperty(
"labeling/shapeRadiiY", QVariant( 0.0 ) ).toDouble() );
882 int scalemn = layer->
customProperty(
"labeling/scaleMin", QVariant( 0 ) ).toInt();
883 int scalemx = layer->
customProperty(
"labeling/scaleMax", QVariant( 0 ) ).toInt();
886 QVariant scalevis = layer->
customProperty(
"labeling/scaleVisibility", QVariant() );
887 if ( scalevis.isValid() )
893 else if ( scalemn > 0 || scalemx > 0 )
1073 bool active,
bool useExpr,
const QString& expr,
const QString& field )
1075 bool defaultVals = ( !active && !useExpr && expr.isEmpty() && field.isEmpty() );
1079 QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* >::const_iterator it =
dataDefinedProperties.find( p );
1089 else if ( !defaultVals )
1101 delete( it.value() );
1109 QString newValue = value;
1110 if ( !value.isEmpty() && !value.contains(
"~~" ) )
1117 newValue = values.join(
"~~" );
1125 QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* >::const_iterator it =
dataDefinedProperties.find( p );
1135 QMap<QString, QString> map;
1136 QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* >::const_iterator it =
dataDefinedProperties.find( p );
1139 return it.value()->toMap();
1152 QMap< DataDefinedProperties, QgsDataDefined* >::const_iterator it =
dataDefinedProperties.find( p );
1168 QVariant result = QVariant();
1170 QString field = dd->
field();
1189 else if ( !useExpression && !field.isEmpty() )
1208 if ( result.isValid() && !result.isNull() )
1221 bool isActive =
false;
1222 QMap< DataDefinedProperties, QgsDataDefined* >::const_iterator it =
dataDefinedProperties.find( p );
1225 isActive = it.value()->isActive();
1233 bool useExpression =
false;
1234 QMap< DataDefinedProperties, QgsDataDefined* >::const_iterator it =
dataDefinedProperties.find( p );
1237 useExpression = it.value()->useExpression();
1240 return useExpression;
1264 double length = geom->
length();
1265 if ( length >= 0.0 )
1267 return ( length >= ( minSize * mapUnitsPerMM ) );
1272 double area = geom->
area();
1275 return ( sqrt( area ) >= ( minSize * mapUnitsPerMM ) );
1336 if ( exprVal.isValid() )
1338 wrapchr = exprVal.toString();
1342 if ( exprVal.isValid() )
1345 double size = exprVal.toDouble( &ok );
1354 if ( exprVal.isValid() )
1356 addDirSymb = exprVal.toBool();
1363 if ( exprVal.isValid() )
1365 leftDirSymb = exprVal.toString();
1369 if ( exprVal.isValid() )
1371 rightDirSymb = exprVal.toString();
1375 if ( exprVal.isValid() )
1378 int enmint = exprVal.toInt( &ok );
1388 if ( wrapchr.isEmpty() )
1390 wrapchr = QString(
"\n" );
1395 && ( !leftDirSymb.isEmpty() || !rightDirSymb.isEmpty() ) )
1397 QString dirSym = leftDirSymb;
1399 if ( fm->width( rightDirSymb ) > fm->width( dirSym ) )
1400 dirSym = rightDirSymb;
1404 text.append( dirSym );
1408 text.prepend( dirSym + QString(
"\n" ) );
1412 double w = 0.0, h = 0.0;
1414 int lines = multiLineSplit.size();
1416 double labelHeight = fm->ascent() + fm->descent();
1418 h += fm->height() + ( double )(( lines - 1 ) * labelHeight * multilineH );
1421 for (
int i = 0; i < lines; ++i )
1423 double width = fm->width( multiLineSplit.at( i ) );
1433 labelX = qAbs( ptSize.
x() -
ptZero.
x() );
1434 labelY = qAbs( ptSize.
y() -
ptZero.
y() );
1449 dataDefinedValues.clear();
1455 showLabel = exprVal.toBool();
1456 QgsDebugMsgLevel( QString(
"exprVal Show:%1" ).arg( showLabel ?
"true" :
"false" ), 4 );
1467 QgsDebugMsgLevel( QString(
"exprVal ScaleVisibility:%1" ).arg( exprVal.toBool() ?
"true" :
"false" ), 4 );
1468 useScaleVisibility = exprVal.toBool();
1471 if ( useScaleVisibility )
1477 QgsDebugMsgLevel( QString(
"exprVal MinScale:%1" ).arg( exprVal.toDouble() ), 4 );
1479 double mins = exprVal.toDouble( &conversionOk );
1489 minScale = 1 / qAbs( minScale );
1501 QgsDebugMsgLevel( QString(
"exprVal MaxScale:%1" ).arg( exprVal.toDouble() ), 4 );
1503 double maxs = exprVal.toDouble( &conversionOk );
1513 maxScale = 1 / qAbs( maxScale );
1529 QString units = exprVal.toString().trimmed();
1531 if ( !units.isEmpty() )
1538 double fontSize = labelFont.pointSizeF();
1541 QgsDebugMsgLevel( QString(
"exprVal Size:%1" ).arg( exprVal.toDouble() ), 4 );
1543 double size = exprVal.toDouble( &ok );
1549 if ( fontSize <= 0.0 )
1556 if ( fontPixelSize < 1 )
1560 labelFont.setPixelSize( fontPixelSize );
1570 QgsDebugMsgLevel( QString(
"exprVal FontLimitPixel:%1" ).arg( exprVal.toBool() ?
"true" :
"false" ), 4 );
1571 useFontLimitPixelSize = exprVal.toBool();
1574 if ( useFontLimitPixelSize )
1580 int sizeInt = exprVal.toInt( &ok );
1581 QgsDebugMsgLevel( QString(
"exprVal FontMinPixel:%1" ).arg( sizeInt ), 4 );
1584 fontMinPixel = sizeInt;
1592 int sizeInt = exprVal.toInt( &ok );
1593 QgsDebugMsgLevel( QString(
"exprVal FontMaxPixel:%1" ).arg( sizeInt ), 4 );
1596 fontMaxPixel = sizeInt;
1600 if ( fontMinPixel > labelFont.pixelSize() || labelFont.pixelSize() > fontMaxPixel )
1612 parseTextStyle( labelFont, fontunits, context );
1613 parseTextFormatting();
1615 parseShapeBackground();
1631 QVariant result = exp->
evaluate( &f );
1637 labelText = result.isNull() ?
"" : result.toString();
1642 labelText = v.isNull() ?
"" : v.toString();
1649 formatnum = exprVal.toBool();
1650 QgsDebugMsgLevel( QString(
"exprVal NumFormat:%1" ).arg( formatnum ?
"true" :
"false" ), 4 );
1661 int dInt = exprVal.toInt( &ok );
1663 if ( ok && dInt > 0 )
1665 decimalPlaces = dInt;
1673 signPlus = exprVal.toBool();
1674 QgsDebugMsgLevel( QString(
"exprVal NumPlusSign:%1" ).arg( signPlus ?
"true" :
"false" ), 4 );
1677 QVariant textV( labelText );
1679 double d = textV.toDouble( &ok );
1682 QString numberFormat;
1683 if ( d > 0 && signPlus )
1685 numberFormat.append(
"+" );
1687 numberFormat.append(
"%1" );
1688 labelText = numberFormat.arg( d, 0,
'f', decimalPlaces );
1694 QFontMetricsF* labelFontMetrics =
new QFontMetricsF( labelFont );
1695 double labelX, labelY;
1701 double maxcharanglein = 20.0;
1702 double maxcharangleout = -20.0;
1712 QString ptstr = exprVal.toString().trimmed();
1713 QgsDebugMsgLevel( QString(
"exprVal CurvedCharAngleInOut:%1" ).arg( ptstr ), 4 );
1715 if ( !ptstr.isEmpty() )
1718 maxcharanglein = qBound( 20.0, (
double )maxcharanglePt.x(), 60.0 );
1719 maxcharangleout = qBound( 20.0, (
double )maxcharanglePt.y(), 95.0 );
1723 maxcharangleout = -( qAbs( maxcharangleout ) );
1734 QScopedPointer<QgsGeometry> clonedGeometry;
1738 clonedGeometry.reset( geom );
1747 QgsDebugMsgLevel( QString(
"Ignoring feature %1 due transformation exception" ).arg( f.
id() ), 4 );
1766 QString str = exprVal.toString().trimmed();
1769 if ( !str.isEmpty() )
1771 if ( str.compare(
"Visible", Qt::CaseInsensitive ) == 0 )
1773 wholeCentroid =
false;
1775 else if ( str.compare(
"Whole", Qt::CaseInsensitive ) == 0 )
1777 wholeCentroid =
true;
1794 clonedGeometry.reset( geom );
1810 bool do_clip =
false;
1811 if ( !centroidPoly || ( centroidPoly && !wholeCentroid ) )
1822 clonedGeometry.reset( geom );
1826 const GEOSGeometry* geos_geom = geom->
asGeos();
1828 if ( geos_geom == NULL )
1857 GEOSGeometry* geos_geom_clone;
1868 bool dataDefinedPosition =
false;
1869 bool labelIsPinned =
false;
1870 bool layerDefinedRotation =
false;
1871 bool dataDefinedRotation =
false;
1872 double xPos = 0.0, yPos = 0.0,
angle = 0.0;
1873 bool ddXPos =
false, ddYPos =
false;
1874 double quadOffsetX = 0.0, quadOffsetY = 0.0;
1875 double offsetX = 0.0, offsetY = 0.0;
1882 int quadInt = exprVal.toInt( &ok );
1884 if ( ok && 0 <= quadInt && quadInt <= 8 )
1935 QString ptstr = exprVal.toString().trimmed();
1938 if ( !ptstr.isEmpty() )
1950 QString units = exprVal.toString().trimmed();
1952 if ( !units.isEmpty() )
1964 if ( !offinmapunits )
1966 offsetX *= mapUntsPerMM;
1972 if ( !offinmapunits )
1974 offsetY *= mapUntsPerMM;
1982 layerDefinedRotation =
true;
1990 double rotD = exprVal.toDouble( &ok );
1994 dataDefinedRotation =
true;
2004 if ( !exprVal.isNull() )
2005 xPos = exprVal.toDouble( &ddXPos );
2011 if ( !exprVal.isNull() )
2012 yPos = exprVal.toDouble( &ddYPos );
2015 if ( ddXPos && ddYPos )
2017 dataDefinedPosition =
true;
2018 labelIsPinned =
true;
2020 if ( layerDefinedRotation && !dataDefinedRotation )
2032 QString haliString = exprVal.toString();
2034 if ( haliString.compare(
"Center", Qt::CaseInsensitive ) == 0 )
2036 xdiff -= labelX / 2.0;
2038 else if ( haliString.compare(
"Right", Qt::CaseInsensitive ) == 0 )
2047 QString valiString = exprVal.toString();
2050 if ( valiString.compare(
"Bottom", Qt::CaseInsensitive ) != 0 )
2052 if ( valiString.compare(
"Top", Qt::CaseInsensitive ) == 0 )
2058 double descentRatio = labelFontMetrics->descent() / labelFontMetrics->height();
2059 if ( valiString.compare(
"Base", Qt::CaseInsensitive ) == 0 )
2061 ydiff -= labelY * descentRatio;
2065 double capHeightRatio = ( labelFontMetrics->boundingRect(
'H' ).height() + 1 + labelFontMetrics->descent() ) / labelFontMetrics->height();
2066 ydiff -= labelY * capHeightRatio;
2067 if ( valiString.compare(
"Half", Qt::CaseInsensitive ) == 0 )
2069 ydiff += labelY * ( capHeightRatio - descentRatio ) / 2.0;
2076 if ( dataDefinedRotation )
2079 double xd = xdiff * cos(
angle ) - ydiff * sin(
angle );
2080 double yd = xdiff * sin(
angle ) + ydiff * cos(
angle );
2091 ct->transformInPlace( xPos, yPos, z );
2096 QgsDebugMsgLevel( QString(
"Ignoring feature %1 due transformation exception on data-defined position" ).arg( f.
id() ), 4 );
2105 QTransform t = QTransform::fromTranslate( center.
x(), center.
y() );
2107 t.translate( -center.
x(), -center.
y() );
2109 t.map( xPos, yPos, &xPosR, &yPosR );
2110 xPos = xPosR; yPos = yPosR;
2128 bool alwaysShow =
false;
2131 alwaysShow = exprVal.toBool();
2138 labelFont.letterSpacing(),
2139 labelFont.wordSpacing(),
2148 #if QT_VERSION >= 0x040800 2149 QgsDebugMsgLevel( QString(
"PAL font stored definedFont: %1, Style: %2" ).arg( labelFont.toString() ).arg( labelFont.styleName() ), 4 );
2159 double distD = exprVal.toDouble( &ok );
2170 QString units = exprVal.toString().trimmed();
2171 QgsDebugMsgLevel( QString(
"exprVal RepeatDistanceUnits:%1" ).arg( units ), 4 );
2172 if ( !units.isEmpty() )
2180 if ( !repeatdistinmapunit )
2182 repeatDist *= mapUntsPerMM;
2190 xPos, yPos, dataDefinedPosition,
angle, dataDefinedRotation,
2191 quadOffsetX, quadOffsetY, offsetX, offsetY, alwaysShow, repeatDist ) )
2194 catch ( std::exception &e )
2197 QgsDebugMsgLevel( QString(
"Ignoring feature %1 due PAL exception:" ).arg( f.
id() ) + QString::fromLatin1( e.what() ), 4 );
2205 delete labelFontMetrics;
2210 double distance =
dist;
2214 double distD = exprVal.toDouble( &ok );
2225 QString units = exprVal.toString().trimmed();
2227 if ( !units.isEmpty() )
2233 if ( distance != 0 )
2235 if ( distinmapunit )
2248 QMap< DataDefinedProperties, QVariant >::const_iterator dIt = dataDefinedValues.constBegin();
2249 for ( ; dIt != dataDefinedValues.constEnd(); ++dIt )
2258 bool QgsPalLayerSettings::dataDefinedValEval(
const QString& valType,
2264 QString dbgStr = QString(
"exprVal %1:" ).arg( mDataDefinedNames.value( p ).first ) +
"%1";
2266 if ( valType == QString(
"bool" ) )
2268 bool bol = exprVal.toBool();
2270 dataDefinedValues.insert( p, QVariant( bol ) );
2273 if ( valType == QString(
"int" ) )
2276 int size = exprVal.toInt( &ok );
2281 dataDefinedValues.insert( p, QVariant( size ) );
2285 if ( valType == QString(
"intpos" ) )
2288 int size = exprVal.toInt( &ok );
2291 if ( ok && size > 0 )
2293 dataDefinedValues.insert( p, QVariant( size ) );
2297 if ( valType == QString(
"double" ) )
2300 double size = exprVal.toDouble( &ok );
2305 dataDefinedValues.insert( p, QVariant( size ) );
2309 if ( valType == QString(
"doublepos" ) )
2312 double size = exprVal.toDouble( &ok );
2315 if ( ok && size > 0.0 )
2317 dataDefinedValues.insert( p, QVariant( size ) );
2321 if ( valType == QString(
"rotation180" ) )
2324 double rot = exprVal.toDouble( &ok );
2328 if ( rot < -180.0 && rot >= -360 )
2332 if ( rot > 180.0 && rot <= 360 )
2336 if ( rot >= -180 && rot <= 180 )
2338 dataDefinedValues.insert( p, QVariant( rot ) );
2343 if ( valType == QString(
"transp" ) )
2346 int size = exprVal.toInt( &ok );
2348 if ( ok && size >= 0 && size <= 100 )
2350 dataDefinedValues.insert( p, QVariant( size ) );
2354 if ( valType == QString(
"string" ) )
2356 QString str = exprVal.toString();
2359 dataDefinedValues.insert( p, QVariant( str ) );
2362 if ( valType == QString(
"units" ) )
2364 QString unitstr = exprVal.toString().trimmed();
2367 if ( !unitstr.isEmpty() )
2369 dataDefinedValues.insert( p, QVariant((
int )
_decodeUnits( unitstr ) ) );
2373 if ( valType == QString(
"color" ) )
2375 QString colorstr = exprVal.toString().trimmed();
2379 if ( color.isValid() )
2381 dataDefinedValues.insert( p, QVariant( color ) );
2385 if ( valType == QString(
"joinstyle" ) )
2387 QString joinstr = exprVal.toString().trimmed();
2390 if ( !joinstr.isEmpty() )
2396 if ( valType == QString(
"blendmode" ) )
2398 QString blendstr = exprVal.toString().trimmed();
2401 if ( !blendstr.isEmpty() )
2407 if ( valType == QString(
"pointf" ) )
2409 QString ptstr = exprVal.toString().trimmed();
2412 if ( !ptstr.isEmpty() )
2422 void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
2435 QString ddFontFamily(
"" );
2438 QString family = exprVal.toString().trimmed();
2441 if ( labelFont.family() != family )
2447 ddFontFamily = family;
2453 QString ddFontStyle(
"" );
2456 QString fontstyle = exprVal.toString().trimmed();
2457 QgsDebugMsgLevel( QString(
"exprVal Font style:%1" ).arg( fontstyle ), 4 );
2458 ddFontStyle = fontstyle;
2462 bool ddBold =
false;
2465 bool bold = exprVal.toBool();
2466 QgsDebugMsgLevel( QString(
"exprVal Font bold:%1" ).arg( bold ?
"true" :
"false" ), 4 );
2471 bool ddItalic =
false;
2474 bool italic = exprVal.toBool();
2475 QgsDebugMsgLevel( QString(
"exprVal Font italic:%1" ).arg( italic ?
"true" :
"false" ), 4 );
2482 QFont appFont = QApplication::font();
2483 bool newFontBuilt =
false;
2484 if ( ddBold || ddItalic )
2487 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : labelFont.family() );
2488 newFontBuilt =
true;
2489 newFont.setBold( ddBold );
2490 newFont.setItalic( ddItalic );
2492 else if ( !ddFontStyle.isEmpty()
2493 && ddFontStyle.compare(
"Ignore", Qt::CaseInsensitive ) != 0 )
2495 if ( !ddFontFamily.isEmpty() )
2498 QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
2499 if ( appFont != styledfont )
2501 newFont = styledfont;
2502 newFontBuilt =
true;
2509 else if ( !ddFontFamily.isEmpty() )
2511 if ( ddFontStyle.compare(
"Ignore", Qt::CaseInsensitive ) != 0 )
2514 QFont styledfont = mFontDB.font( ddFontFamily,
textNamedStyle, appFont.pointSize() );
2515 if ( appFont != styledfont )
2517 newFont = styledfont;
2518 newFontBuilt =
true;
2523 newFont = QFont( ddFontFamily );
2524 newFontBuilt =
true;
2532 newFont.setPixelSize( labelFont.pixelSize() );
2533 newFont.setCapitalization( labelFont.capitalization() );
2534 newFont.setUnderline( labelFont.underline() );
2535 newFont.setStrikeOut( labelFont.strikeOut() );
2536 newFont.setWordSpacing( labelFont.wordSpacing() );
2537 newFont.setLetterSpacing( QFont::AbsoluteSpacing, labelFont.letterSpacing() );
2539 labelFont = newFont;
2543 double wordspace = labelFont.wordSpacing();
2547 double wspacing = exprVal.toDouble( &ok );
2548 QgsDebugMsgLevel( QString(
"exprVal FontWordSpacing:%1" ).arg( wspacing ), 4 );
2551 wordspace = wspacing;
2557 double letterspace = labelFont.letterSpacing();
2561 double lspacing = exprVal.toDouble( &ok );
2562 QgsDebugMsgLevel( QString(
"exprVal FontLetterSpacing:%1" ).arg( lspacing ), 4 );
2565 letterspace = lspacing;
2571 QFont::Capitalization fontcaps = labelFont.capitalization();
2574 QString fcase = exprVal.toString().trimmed();
2577 if ( !fcase.isEmpty() )
2579 if ( fcase.compare(
"NoChange", Qt::CaseInsensitive ) == 0 )
2581 fontcaps = QFont::MixedCase;
2583 else if ( fcase.compare(
"Upper", Qt::CaseInsensitive ) == 0 )
2585 fontcaps = QFont::AllUppercase;
2587 else if ( fcase.compare(
"Lower", Qt::CaseInsensitive ) == 0 )
2589 fontcaps = QFont::AllLowercase;
2591 else if ( fcase.compare(
"Capitalize", Qt::CaseInsensitive ) == 0 )
2593 fontcaps = QFont::Capitalize;
2596 if ( fontcaps != labelFont.capitalization() )
2598 labelFont.setCapitalization( fontcaps );
2606 bool strikeout = exprVal.toBool();
2607 QgsDebugMsgLevel( QString(
"exprVal Font strikeout:%1" ).arg( strikeout ?
"true" :
"false" ), 4 );
2608 labelFont.setStrikeOut( strikeout );
2614 bool underline = exprVal.toBool();
2615 QgsDebugMsgLevel( QString(
"exprVal Font underline:%1" ).arg( underline ?
"true" :
"false" ), 4 );
2616 labelFont.setUnderline( underline );
2632 void QgsPalLayerSettings::parseTextBuffer()
2640 drawBuffer = exprVal.toBool();
2652 bufrSize = exprVal.toDouble();
2659 bufTransp = exprVal.toInt();
2662 drawBuffer = ( drawBuffer && bufrSize > 0.0 && bufTransp < 100 );
2685 void QgsPalLayerSettings::parseTextFormatting()
2693 wrapchr = exprVal.toString();
2702 QString str = exprVal.toString().trimmed();
2703 QgsDebugMsgLevel( QString(
"exprVal MultiLineAlignment:%1" ).arg( str ), 4 );
2705 if ( !str.isEmpty() )
2710 if ( str.compare(
"Center", Qt::CaseInsensitive ) == 0 )
2714 else if ( str.compare(
"Right", Qt::CaseInsensitive ) == 0 )
2726 drawDirSymb = exprVal.toBool();
2740 QString str = exprVal.toString().trimmed();
2741 QgsDebugMsgLevel( QString(
"exprVal DirSymbPlacement:%1" ).arg( str ), 4 );
2743 if ( !str.isEmpty() )
2748 if ( str.compare(
"Above", Qt::CaseInsensitive ) == 0 )
2752 else if ( str.compare(
"Below", Qt::CaseInsensitive ) == 0 )
2767 void QgsPalLayerSettings::parseShapeBackground()
2775 drawShape = exprVal.toBool();
2787 shapeTransp = exprVal.toInt();
2790 drawShape = ( drawShape && shapeTransp < 100 );
2803 QString skind = exprVal.toString().trimmed();
2806 if ( !skind.isEmpty() )
2811 if ( skind.compare(
"Square", Qt::CaseInsensitive ) == 0 )
2815 else if ( skind.compare(
"Ellipse", Qt::CaseInsensitive ) == 0 )
2819 else if ( skind.compare(
"Circle", Qt::CaseInsensitive ) == 0 )
2823 else if ( skind.compare(
"SVG", Qt::CaseInsensitive ) == 0 )
2827 shapeKind = shpkind;
2836 QString svgfile = exprVal.toString().trimmed();
2837 QgsDebugMsgLevel( QString(
"exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
2848 QString stype = exprVal.toString().trimmed();
2851 if ( !stype.isEmpty() )
2856 if ( stype.compare(
"Fixed", Qt::CaseInsensitive ) == 0 )
2860 shpSizeType = sizType;
2869 ddShpSizeX = exprVal.toDouble();
2876 ddShpSizeY = exprVal.toDouble();
2882 && ( svgPath.isEmpty()
2883 || ( !svgPath.isEmpty()
2885 && ddShpSizeX == 0.0 ) ) )
2891 && ( ddShpSizeX == 0.0 || ddShpSizeY == 0.0 ) )
2913 QString rotstr = exprVal.toString().trimmed();
2914 QgsDebugMsgLevel( QString(
"exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
2916 if ( !rotstr.isEmpty() )
2921 if ( rotstr.compare(
"Offset", Qt::CaseInsensitive ) == 0 )
2925 else if ( rotstr.compare(
"Fixed", Qt::CaseInsensitive ) == 0 )
2968 void QgsPalLayerSettings::parseDropShadow()
2976 drawShadow = exprVal.toBool();
2988 shadowTransp = exprVal.toInt();
2995 shadowOffDist = exprVal.toDouble();
3002 shadowRad = exprVal.toDouble();
3005 drawShadow = ( drawShadow && shadowTransp < 100 && !( shadowOffDist == 0.0 && shadowRad == 0.0 ) );
3019 QString str = exprVal.toString().trimmed();
3022 if ( !str.isEmpty() )
3027 if ( str.compare(
"Text", Qt::CaseInsensitive ) == 0 )
3031 else if ( str.compare(
"Buffer", Qt::CaseInsensitive ) == 0 )
3035 else if ( str.compare(
"Background", Qt::CaseInsensitive ) == 0 )
3075 if ( unit ==
MapUnits && mapUnitsPerPixel > 0.0 )
3081 double ptsTomm = ( unit ==
Points ? 0.352778 : 1 );
3090 : mMapSettings( NULL ), mPal( NULL )
3144 bool enabled =
false;
3145 if ( layer->
customProperty(
"labeling" ).toString() == QString(
"pal" ) )
3146 enabled = layer->
customProperty(
"labeling/enabled", QVariant(
false ) ).toBool();
3154 QHash<QString, QgsPalLayerSettings>::iterator lit;
3167 QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* >::iterator it = lyr.
dataDefinedProperties.begin();
3170 delete( it.value() );
3191 if ( lyrTmp.fieldName.isEmpty() )
3196 if ( lyrTmp.isExpression )
3234 attrNames.append( name );
3243 QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* >::const_iterator dIt = lyr.
dataDefinedProperties.constBegin();
3255 QMap<QString, QVariant> exprParams;
3264 foreach ( QString name, cols )
3266 attrNames.append( name );
3280 default: Q_ASSERT(
"unsupported placement" && 0 );
return 0;
3284 double priority = 1 - lyr.
priority / 10.0;
3285 double min_scale = -1, max_scale = -1;
3295 min_scale, max_scale, arrangement,
3319 default: Q_ASSERT(
"unsupported upside-down label setting" && 0 );
return 0;
3380 double priority = 1 - s->
priority / 10.0;
3410 QStringList multiLineSplit;
3411 if ( !wrapCharacter.isEmpty() && wrapCharacter != QString(
"\n" ) )
3414 foreach ( QString line, text.split( wrapCharacter ) )
3416 multiLineSplit.append( line.split( QString(
"\n" ) ) );
3421 multiLineSplit = text.split(
"\n" );
3424 return multiLineSplit;
3430 QHash<QString, QgsDiagramLayerSettings>::iterator layerIt =
mActiveDiagramLayers.find( layerID );
3440 if ( settingList.size() > 0 )
3442 double minScale = settingList.at( 0 ).minScaleDenominator;
3448 double maxScale = settingList.at( 0 ).maxScaleDenominator;
3461 QScopedPointer<QgsGeometry> clonedGeometry;
3462 if ( layerIt.value().ct )
3465 clonedGeometry.reset( geom );
3469 geom->
transform( *( layerIt.value().ct ) );
3474 QgsDebugMsgLevel( QString(
"Ignoring feature %1 due transformation exception" ).arg( feat.
id() ), 4 );
3479 const GEOSGeometry* geos_geom = geom->
asGeos();
3480 if ( geos_geom == 0 )
3490 layerIt.value().geometries.append( lbl );
3492 double diagramWidth = 0;
3493 double diagramHeight = 0;
3497 if ( diagSize.isValid() )
3499 diagramWidth = diagSize.width();
3500 diagramHeight = diagSize.height();
3508 int ddColX = layerIt.value().xPosColumn;
3509 int ddColY = layerIt.value().yPosColumn;
3510 double ddPosX = 0.0;
3511 double ddPosY = 0.0;
3512 bool ddPos = ( ddColX >= 0 && ddColY >= 0 );
3515 bool posXOk, posYOk;
3517 ddPosX = feat.
attribute( ddColX ).toDouble( &posXOk ) - diagramWidth / 2.0;
3518 ddPosY = feat.
attribute( ddColY ).toDouble( &posYOk ) - diagramHeight / 2.0;
3519 if ( !posXOk || !posYOk )
3536 if ( !layerIt.value().palLayer->registerFeature( lbl->
strId(), lbl, diagramWidth, diagramHeight,
"", ddPosX, ddPosY, ddPos ) )
3541 catch ( std::exception &e )
3544 QgsDebugMsgLevel( QString(
"Ignoring feature %1 due PAL exception:" ).arg( feat.
id() ) + QString::fromLatin1( e.what() ), 4 );
3549 QgsPoint ptZero = layerIt.value().xform->toMapCoordinates( 0, 0 );
3550 QgsPoint ptOne = layerIt.value().xform->toMapCoordinates( 1, 0 );
3551 palFeat->
setDistLabel( qAbs( ptOne.
x() - ptZero.
x() ) * layerIt.value().dist );
3602 QHash<QString, QgsPalLayerSettings>::iterator lit;
3605 if ( lit.key() == layerName )
3614 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues )
3620 tmpLyr.
textColor = ddColor.value<QColor>();
3639 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues )
3692 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues )
3749 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues )
3860 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues )
3935 QPainter* painter = context.
painter();
3951 std::list<LabelPosition*>* labels;
3957 catch ( std::exception& e )
3960 QgsDebugMsgLevel(
"PAL EXCEPTION :-( " + QString::fromLatin1( e.what() ), 4 );
3985 painter->setPen( QColor( 0, 0, 0, 64 ) );
3986 painter->setBrush( Qt::NoBrush );
4001 QgsDebugMsgLevel( QString(
"LABELING work: %1 ms ... labels# %2" ).arg( t.elapsed() ).arg( labels->size() ), 4 );
4012 painter->setRenderHint( QPainter::Antialiasing );
4015 std::list<LabelPosition*>::iterator it = labels->begin();
4016 for ( ; it != labels->end(); ++it )
4028 QString layerName = QString::fromUtf8(( *it )->getLayerName() );
4036 if ( QString( dit.key() +
"d" ) == layerName )
4038 feature.
setFields( &dit.value().fields );
4039 palGeometry->
feature( feature );
4041 dit.value().renderer->renderDiagram( feature, context, outPt.
toQPointF() );
4049 QString layerId = layerName;
4051 mResults->mLabelSearchTree->
insertLabel( *it, QString( palGeometry->
strId() ).toInt(), QString(
"" ), layerId, QFont(),
true, false );
4064 const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues = palGeometry->
dataDefinedValues();
4069 #if QT_VERSION >= 0x040800 4071 QgsDebugMsgLevel( QString(
"PAL font definedFont: %1, Style: %2" ).arg( dFont.toString() ).arg( dFont.styleName() ), 4 );
4126 QString labeltext = ((
QgsPalGeometry* )( *it )->getFeaturePart()->getUserGeometry() )->text();
4132 painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
4134 QgsDebugMsgLevel( QString(
"LABELING draw: %1 ms" ).arg( t.elapsed() ), 4 );
4144 QHash<QString, QgsPalLayerSettings>::iterator lit;
4148 for ( QList<QgsPalGeometry*>::iterator git = lyr.
geometries.begin(); git != lyr.
geometries.end(); ++git )
4165 for ( QList<QgsPalGeometry*>::iterator git = dls.
geometries.begin(); git != dls.
geometries.end(); ++git )
4225 #if 0 // TODO: generalize some of this 4228 double cx = lp->
getX() + w / 2.0;
4229 double cy = lp->
getY() + h / 2.0;
4232 double sw = w * scale;
4233 double sh = h * scale;
4234 QRectF rect( -sw / 2, -sh / 2, sw, sh );
4244 painter->rotate( rotation );
4247 painter->translate( rect.bottomLeft() );
4249 painter->translate( -rect.bottomLeft() );
4252 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
4253 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
4257 painter->drawRect( rect );
4261 rect.moveTo( outPt.
x(), outPt.
y() );
4272 QPainter* painter = context.
painter();
4301 double xc = outPt2.
x() - outPt.
x();
4302 double yc = outPt2.
y() - outPt.
y();
4305 double xd = xc * cos( angle ) - yc * sin( angle );
4306 double yd = xc * sin( angle ) + yc * cos( angle );
4308 centerPt.
setX( centerPt.
x() + xd );
4309 centerPt.
setY( centerPt.
y() + yd );
4329 bool prependSymb =
false;
4347 prependSymb =
false;
4355 symb = symb + QString(
"\n" );
4359 prependSymb =
false;
4360 symb = QString(
"\n" ) + symb;
4365 txt.prepend( symb );
4375 int lines = multiLineList.size();
4377 double labelWidest = 0.0;
4378 for (
int i = 0; i < lines; ++i )
4380 double labelWidth = labelfm->width( multiLineList.at( i ) );
4381 if ( labelWidth > labelWidest )
4383 labelWidest = labelWidth;
4387 double labelHeight = labelfm->ascent() + labelfm->descent();
4391 double ascentOffset = 0.25 * labelfm->ascent();
4393 for (
int i = 0; i < lines; ++i )
4396 #if 0 // TODO: generalize some of this 4400 double cx = lp->
getX() + w / 2.0;
4401 double cy = lp->
getY() + h / 2.0;
4404 double sw = w * scale;
4405 double sh = h * scale;
4406 QRectF rect( -sw / 2, -sh / 2, sw, sh );
4415 painter->rotate( rotation );
4418 painter->translate( rect.bottomLeft() );
4421 painter->translate( QPointF( outPt.
x(), outPt.
y() ) );
4430 double xMultiLineOffset = 0.0;
4431 double labelWidth = labelfm->width( multiLineList.at( i ) );
4434 double labelWidthDiff = labelWidest - labelWidth;
4437 labelWidthDiff /= 2;
4439 xMultiLineOffset = labelWidthDiff;
4443 double yMultiLineOffset = ( lines - 1 - i ) * labelHeight * tmpLyr.
multilineHeight;
4444 painter->translate( QPointF( xMultiLineOffset, - ascentOffset - yMultiLineOffset ) );
4446 component.
setText( multiLineList.at( i ) );
4461 path.setFillRule( Qt::WindingFill );
4462 path.addText( 0, 0, tmpLyr.
textFont, component.
text() );
4467 textp.begin( &textPict );
4468 textp.setPen( Qt::NoPen );
4470 textp.drawPath( path );
4490 painter->setCompositionMode( tmpLyr.
blendMode );
4500 painter->drawPicture( 0, 0, textPict );
4505 painter->setFont( tmpLyr.
textFont );
4507 painter->setRenderHint( QPainter::TextAntialiasing );
4508 painter->drawText( 0, 0, component.
text() );
4524 QPainter* p = context.
painter();
4530 path.setFillRule( Qt::WindingFill );
4531 path.addText( 0, 0, tmpLyr.
textFont, component.
text() );
4533 pen.setWidthF( penSize );
4539 tmpColor.setAlpha( 0 );
4545 buffp.begin( &buffPict );
4546 buffp.setPen( pen );
4547 buffp.setBrush( tmpColor );
4548 buffp.drawPath( path );
4572 p->drawPicture( 0, 0, buffPict );
4580 QPainter* p = context.
painter();
4581 double labelWidth = component.
size().
x(), labelHeight = component.
size().
y();
4611 double sizeOut = 0.0;
4620 if ( labelWidth >= labelHeight )
4621 sizeOut = labelWidth;
4622 else if ( labelHeight > labelWidth )
4623 sizeOut = labelHeight;
4628 sizeOut /= mmToMapUnits;
4642 map[
"size"] = QString::number( sizeOut );
4645 map[
"angle"] = QString::number( 0.0 );
4673 svgp.begin( &svgPict );
4692 svgShdwM->
renderPoint( QPointF( svgSize / 2, -svgSize / 2 ), svgShdwContext );
4709 p->translate( QPointF( xoff, yoff ) );
4711 p->translate( -svgSize / 2, svgSize / 2 );
4735 p->translate( QPointF( xoff, yoff ) );
4738 p->setCompositionMode( QPainter::CompositionMode_SourceOver );
4772 h = sqrt( pow( w, 2 ) + pow( h, 2 ) );
4778 h = h / sqrt( 2.0 ) * 2;
4779 w = w / sqrt( 2.0 ) * 2;
4791 QRectF rect( -w / 2.0, - h / 2.0, w, h );
4793 if ( rect.isNull() )
4797 p->translate( QPointF( component.
center().
x(), component.
center().
y() ) );
4801 p->translate( QPointF( xoff, yoff ) );
4810 pen.setWidthF( penSize );
4822 shapep.begin( &shapePict );
4823 shapep.setPen( pen );
4831 shapep.drawRoundedRect( rect, tmpLyr.
shapeRadii.x(), tmpLyr.
shapeRadii.y(), Qt::RelativeSize );
4837 shapep.drawRoundedRect( rect, xRadius, yRadius );
4843 shapep.drawEllipse( rect );
4868 p->drawPicture( 0, 0, shapePict );
4881 QPainter* p = context.
painter();
4882 double componentWidth = component.
size().
x(), componentHeight = component.
size().
y();
4883 double xOffset = component.
offset().
x(), yOffset = component.
offset().
y();
4890 radius = ( int )( radius + 0.5 );
4894 double blurBufferClippingScale = 3.75;
4895 int blurbuffer = ( radius > 17 ? 16 : radius ) * blurBufferClippingScale;
4897 QImage blurImg( componentWidth + ( pictbuffer * 2.0 ) + ( blurbuffer * 2.0 ),
4898 componentHeight + ( pictbuffer * 2.0 ) + ( blurbuffer * 2.0 ),
4899 QImage::Format_ARGB32_Premultiplied );
4903 int minBlurImgSize = 1;
4907 int maxBlurImgSize = 40000;
4908 if ( blurImg.isNull()
4909 || ( blurImg.width() < minBlurImgSize || blurImg.height() < minBlurImgSize )
4910 || ( blurImg.width() > maxBlurImgSize || blurImg.height() > maxBlurImgSize ) )
4913 blurImg.fill( QColor( Qt::transparent ).rgba() );
4915 if ( !pictp.begin( &blurImg ) )
4917 pictp.setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
4918 QPointF imgOffset( blurbuffer + pictbuffer + xOffset,
4919 blurbuffer + pictbuffer + componentHeight + yOffset );
4921 pictp.drawPicture( imgOffset,
4925 pictp.setCompositionMode( QPainter::CompositionMode_SourceIn );
4926 pictp.fillRect( blurImg.rect(), tmpLyr.
shadowColor );
4939 picti.begin( &blurImg );
4940 picti.setBrush( Qt::Dense7Pattern );
4941 QPen imgPen( QColor( 0, 0, 255, 255 ) );
4942 imgPen.setWidth( 1 );
4943 picti.setPen( imgPen );
4944 picti.setOpacity( 0.1 );
4945 picti.drawRect( 0, 0, blurImg.width(), blurImg.height() );
4961 QPointF transPt( -offsetDist * cos( angleRad +
M_PI / 2 ),
4962 -offsetDist * sin( angleRad +
M_PI / 2 ) );
4965 p->setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
4972 double scale = ( double )tmpLyr.
shadowScale / 100.0;
4974 p->scale( scale, scale );
4979 p->translate( transPt );
4980 p->translate( -imgOffset.x(),
4982 p->drawImage( 0, 0, blurImg );
4990 p->setBrush( Qt::NoBrush );
4991 QPen imgPen( QColor( 255, 0, 0, 10 ) );
4992 imgPen.setWidth( 2 );
4993 imgPen.setStyle( Qt::DashLine );
4994 p->setPen( imgPen );
4995 p->scale( scale, scale );
5000 p->translate( transPt );
5001 p->translate( -imgOffset.x(),
5003 p->drawRect( 0, 0, blurImg.width(), blurImg.height() );
5008 p->setBrush( Qt::NoBrush );
5009 QPen componentRectPen( QColor( 0, 255, 0, 70 ) );
5010 componentRectPen.setWidth( 1 );
5015 p->setPen( componentRectPen );
5016 p->drawRect( QRect( -xOffset, -componentHeight - yOffset, componentWidth, componentHeight ) );
5027 "PAL",
"/SearchMethod", (
int )p.
getSearch(), &saved ) );
5029 "PAL",
"/CandidatesPoint", p.
getPointP(), &saved );
5031 "PAL",
"/CandidatesLine", p.
getLineP(), &saved );
5033 "PAL",
"/CandidatesPolygon", p.
getPolyP(), &saved );
5035 "PAL",
"/ShowingCandidates",
false, &saved );
5037 "PAL",
"/ShowingShadowRects",
false, &saved );
5039 "PAL",
"/ShowingAllLabels",
false, &saved );
5043 "PAL",
"/DrawOutlineLabels",
true, &saved );
5091 delete mLabelSearchTree;
5092 mLabelSearchTree = NULL;
5097 QList<QgsLabelPosition> positions;
5099 QList<QgsLabelPosition*> positionPointers;
5100 if ( mLabelSearchTree )
5102 mLabelSearchTree->label( p, positionPointers );
5103 QList<QgsLabelPosition*>::const_iterator pointerIt = positionPointers.constBegin();
5104 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
5115 QList<QgsLabelPosition> positions;
5117 QList<QgsLabelPosition*> positionPointers;
5118 if ( mLabelSearchTree )
5120 mLabelSearchTree->labelsInRect( r, positionPointers );
5121 QList<QgsLabelPosition*>::const_iterator pointerIt = positionPointers.constBegin();
5122 for ( ; pointerIt != positionPointers.constEnd(); ++pointerIt )
const QgsMapSettings & mapSettings()
bridge to QgsMapSettings
QgsFeatureId id() const
Get the feature id for this feature.
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
static void _fixQPictureDPI(QPainter *p)
void calculateLabelSize(const QFontMetricsF *fm, QString text, double &labelX, double &labelY, QgsFeature *f=0)
Class for parsing and evaluation of expressions (formerly called "search strings").
const QString & name() const
Gets the name of the field.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
void setActive(bool active)
FeaturePart * getFeaturePart()
return the feature corresponding to this labelposition
A rectangle specified with double values.
double maxCurvedCharAngleOut
double getCost() const
get the position geographical cost
QString leftDirectionSymbol
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
void dataDefinedShapeBackground(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)
std::list< LabelPosition * > * solveProblem(Problem *prob, bool displayAll)
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
bool dataDefinedIsActive(QgsPalLayerSettings::DataDefinedProperties p) const
Whether data definition is active.
QStringList referencedColumns() const
Get list of columns referenced by the expression.
QgsMapUnitScale shapeSizeMapUnitScale
void dataDefinedTextStyle(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)
A container class for data source field mapping or expression.
QgsMapUnitScale shadowRadiusMapUnitScale
virtual void drawLabel(pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, DrawLabelType drawType, double dpiRatio=1.0)
drawLabel
double scale() const
Return the calculated scale of the map.
void setOrigin(const QgsPoint &point)
double length()
get length of geometry using GEOS
SizeUnit repeatDistanceUnit
virtual bool willUseLayer(QgsVectorLayer *layer) override
called to find out whether the layer is used for labeling
const QgsMapSettings * mMapSettings
void addDataDefinedValue(QgsPalLayerSettings::DataDefinedProperties p, QVariant v)
int getFeatureCandidateCount(int i)
void setNumCandidatePositions(int candPoint, int candLine, int candPolygon)
const QString expression() const
Alias for dump()
void registerFeature(QgsFeature &f, const QgsRenderContext &context, QString dxfLayer)
void setDxfLayer(QString dxfLayer)
QgsExpression * expression()
const QString & text() const
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
QgsLabelingResults * takeResults()
Return pointer to recently computed results (in drawLabeling()) and pass the ownership of results to ...
A class to query the labeling structure at a given point (small wraper around pal RTree class) ...
bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
double yMaximum() const
Get the y maximum value (top side of rectangle)
void setSearchMethod(Search s)
void loadEngineSettings()
load/save engine settings to project file
virtual void registerFeature(const QString &layerID, QgsFeature &feat, const QgsRenderContext &context=QgsRenderContext(), QString dxfLayer=QString::null) override
hook called when drawing for every feature in a layer
QPainter::CompositionMode bufferBlendMode
A layer of spacial entites.
double rendererScale() const
double rotationOffset() const
QgsMapUnitScale shadowOffsetMapUnitScale
const QgsPoint & size() const
void setPointP(int point_p)
set # candidates to generate for points features Higher the value is, longer Pal::labeller will spend...
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
double computeMapUnitsPerPixel(const QgsRenderContext &c) const
Computes a map units per pixel scaling factor, respecting the minimum and maximum scales set for the ...
QgsPoint transform(const QgsPoint &p) const
void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
static QgsMapLayerRegistry * instance()
void setPolyP(int poly_p)
set maximum # candidates to generate for polygon features Higher the value is, longer Pal::labeller w...
bool mShowingPartialsLabels
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QuadrantPosition quadOffset
static void drawLabelBuffer(QgsRenderContext &context, const QgsLabelComponent &component, const QgsPalLayerSettings &tmpLyr)
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
QGis::GeometryType type() const
Returns type of the vector.
virtual int addDiagramLayer(QgsVectorLayer *layer, const QgsDiagramLayerSettings *s) override
adds a diagram layer to the labeling engine
void numCandidatePositions(int &candPoint, int &candLine, int &candPolygon)
static bool _palIsCancelled(void *ctx)
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
static QPointF decodePoint(QString str)
Container of fields for a vector layer.
static QgsPalLayerSettings fromLayer(QgsVectorLayer *layer)
void saveEngineSettings()
void readFromLayer(QgsVectorLayer *layer)
void setUpsidedownLabels(UpsideDownLabels ud)
static QColor decodeColor(QString str)
QString expressionString() const
const QgsRectangle & extent() const
const QgsMapToPixel & mapToPixel() const
void dataDefinedDropShadow(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)
QVariant dataDefinedValue(QgsPalLayerSettings::DataDefinedProperties p, QgsFeature &f, const QgsFields &fields) const
Get data defined property value from expression string or attribute field name.
void setIsDiagram(bool d)
QgsMapUnitScale repeatDistanceMapUnitScale
MultiLineAlign multilineAlign
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Layer * getLayer()
return the layer that feature belongs to
void removeDataDefinedProperty(QgsPalLayerSettings::DataDefinedProperties p)
Set a property to static instead data defined.
double scaleFactor() const
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsPoint & origin() const
double area()
get area of geometry using GEOS
A non GUI class for rendering a map layer set onto a QPainter.
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=0) const
Problem * extractProblem(double scale, double bbox[4])
static QStringList splitToLines(const QString &text, const QString &wrapCharacter)
Splits a text string to a list of seperate lines, using a specified wrap character.
const QgsPoint & center() const
QMap< QString, QString > QgsStringMap
Feature * getFeature(const char *geom_id)
return pointer to feature or NULL if doesn't exist
double mapRotation() const
Return current map rotation in degrees.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=0) const
PalGeometry * getUserGeometry()
double maxCurvedCharAngleIn
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
int getLineP()
get maximum # candidates to generate for line features
bool reverseDirectionSymbol
double maxScale
The maximum scale, or 0.0 if unset.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
void setRotationOffset(const double rotation)
int getNbFeatures()
get the number of features into layer
void setDistLabel(double dist)
const GEOSGeometry * asGeos() const
Returns a geos geometry.
void setCentroidInside(bool forceInside)
static void drawLabelBackground(QgsRenderContext &context, QgsLabelComponent component, const QgsPalLayerSettings &tmpLyr)
Qt::PenJoinStyle bufferJoinStyle
arranges candidates around a point (centroid for polygon)
Returns diagram settings for a feature.
QgsMapUnitScale fontSizeMapUnitScale
bool dataDefinedEvaluate(QgsPalLayerSettings::DataDefinedProperties p, QVariant &exprVal) const
Get data defined property value from expression string or attribute field name.
const QgsPoint & offset() const
The QgsMapSettings class contains configuration for rendering of the map.
QgsMapUnitScale shapeBorderWidthMapUnitScale
virtual Q_DECL_DEPRECATED void init(QgsMapRenderer *mr) override
called when we're going to start with rendering
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
bool dataDefinedUseExpression(QgsPalLayerSettings::DataDefinedProperties p) const
Whether data definition is set to use an expression.
static bool staticWillUseLayer(QgsVectorLayer *layer)
called to find out whether the layer is used for labeling
bool isGeosValid()
check validity using GEOS
virtual void clearActiveLayer(const QString &layerID) override
clears data defined objects from PAL layer settings for a registered layer
Perform transforms between map coordinates and device coordinates.
QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) const
return infos about labels within a given (map) rectangle
void setUseExpression(bool use)
bool writeEntry(const QString &scope, const QString &key, bool value)
bool contains(const QgsPoint *p) const
Test for containment of a point (uses GEOS)
static QPainter::CompositionMode decodeBlendMode(const QString &s)
void setRotation(const double rotation)
const QgsMapToPixel * xform
void dataDefinedTextBuffer(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > & dataDefinedValues() const
void setScaleFactor(double factor)
QList< QgsPalGeometry * > geometries
const QgsCoordinateTransform * ct
QgsGeometry * buffer(double distance, int segments)
Returns a buffer region around this geometry having the given width and with a specified number of se...
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
QgsMapUnitScale shapeRadiiMapUnitScale
void setSearch(SearchMethod method)
Select the search method to use.
const QPicture * picture() const
double rasterCompressFactor
double getY(int i=0) const
get the down-left y coordinate
double xMaximum() const
Get the x maximum value (right side of rectangle)
virtual QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c)
Returns size of the diagram for a feature in map units.
#define QgsDebugMsgLevel(str, level)
bool bufferSizeInMapUnits
double getAlpha() const
get alpha
QgsPalLayerSettings mInvalidLayerSettings
SizeUnit shapeBorderWidthUnits
bool renderingStopped() const
QPainter::CompositionMode blendMode
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
QHash< QString, QgsDiagramLayerSettings > mActiveDiagramLayers
QList< QgsLabelPosition > labelsAtPosition(const QgsPoint &p) const
return infos about labels at a given (map) position
Layer * addLayer(const char *lyrName, double min_scale, double max_scale, Arrangement arrangement, Units label_unit, double defaultPriority, bool obstacle, bool active, bool toLabel, bool displayAll=false)
add a new layer
void setField(const QString &field)
QString updateDataDefinedString(const QString &value)
Convert old property value to new one as delimited values.
virtual QgsLabelingEngineInterface * clone() override
called when passing engine among map renderers
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
virtual void drawLabeling(QgsRenderContext &context) override
called when the map is drawn and labels should be placed
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const
Return list of indexes to names for QgsPalLabeling fix.
QgsPalLayerSettings & layer(const QString &layerName) override
returns PAL layer settings for a registered layer
void setCenter(const QgsPoint &point)
void setExpressionParams(QMap< QString, QVariant > params)
static QString symbolNameToPath(QString name)
Get symbol's path from its name.
int getPointP()
get # candidates to generate for point features
void setLabelInfo(LabelInfo *info)
const QgsMapToPixel * xform
QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined * > dataDefinedProperties
Map of current data defined properties.
arranges candidates over a point (centroid for polygon)
const QgsAttributes & attributes() const
void setPainter(QPainter *p)
double rasterScaleFactor() const
Only for lines, labels along the line.
void setText(const QString &text)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
bool removeEntry(const QString &scope, const QString &key)
remove the given key
void deleteTemporaryData()
QgsMapUnitScale bufferSizeMapUnitScale
double mapUnitsPerPixel() const
Return current map units per pixel.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
LabelPosition * getNextPart() const
QgsDiagramRendererV2 * renderer
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
QPainter::CompositionMode shapeBlendMode
double scaleToPixelContext(double size, const QgsRenderContext &c, SizeUnit unit, bool rasterfactor=false, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale()) const
Calculates size (considering output size should be in pixel or map units, scale factors and optionall...
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsDataDefined * dataDefinedProperty(QgsPalLayerSettings::DataDefinedProperties p)
Get a data defined property pointer.
SizeUnit shadowOffsetUnits
SizeUnit
Units used for option sizes, before being converted to rendered sizes.
Search searchMethod() const
QgsGeometry * intersection(QgsGeometry *geometry)
Returns a geometry representing the points shared by this geometry and other.
QMap< QString, QString > dataDefinedMap(QgsPalLayerSettings::DataDefinedProperties p) const
Get property value as separate values split into Qmap.
const QgsDiagramRendererV2 * diagramRenderer() const
A class to represent a point.
QHash< QString, QgsPalLayerSettings > mActiveLayers
void setFields(const QgsFields *fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
void setDiagramAttributes(const QgsAttributes &attrs)
static Qt::PenJoinStyle _decodePenJoinStyle(const QString &str)
Qt::PenJoinStyle shapeJoinStyle
unsigned int upsidedownLabels
bool useExpression() const
int indexFromName(const QString &name) const
Look up field's index from name. Returns -1 on error.
bool insertLabel(LabelPosition *labelPos, int featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram=false, bool pinned=false)
Inserts label position.
Arrangement getArrangement()
get arrangement policy
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void setDpiRatio(const double ratio)
enum _searchMethod SearchMethod
Typedef for _Units enumeration.
void setShowPartial(bool show)
Set flag show partial label.
bool registerFeature(const char *geom_id, PalGeometry *userGeom, double label_x=-1, double label_y=-1, const char *labelText=NULL, double labelPosX=0.0, double labelPosY=0.0, bool fixedPos=false, double angle=0.0, bool fixedAngle=false, int xQuadOffset=0, int yQuadOffset=0, double xOffset=0.0, double yOffset=0.0, bool alwaysShow=false, double repeatDistance=0)
register a feature in the layer
is slower and best than TABU, worse and faster than TABU_CHAIN
Q_GUI_EXPORT int qt_defaultDpiX()
bool getShowPartial()
Get flag show partial label.
static void _writeColor(QgsVectorLayer *layer, QString property, QColor color, bool withAlpha=true)
QgsPoint toMapCoordinatesF(double x, double y) const
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
unsigned int placementFlags
QgsPoint toMapCoordinates(int x, int y) const
enum _arrangement Arrangement
typedef for _arrangement enumeration
QString rightDirectionSymbol
Q_GUI_EXPORT int qt_defaultDpiY()
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
Contains information about the context of a rendering operation.
void clearEngineSettings()
void setPicture(QPicture *picture)
virtual const QgsFields & fields() const =0
Return a map of indexes with field names for this layer.
void setDataDefinedProperty(QgsPalLayerSettings::DataDefinedProperties p, bool active, bool useExpr, const QString &expr, const QString &field)
Set a property as data defined.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
void setDefinedFont(QFont f)
void drawLabelCandidateRect(pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform)
void setOffset(const QgsPoint &point)
static QgsPalLayerSettings::SizeUnit _decodeUnits(const QString &str)
static GEOSContextHandle_t getGEOSHandler()
return GEOS context handle
QgsMapUnitScale distMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
virtual Q_DECL_DEPRECATED QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r) override
return infos about labels within a given (map) rectangle
bool expressionIsPrepared() const
bool shadowRadiusAlphaOnly
int rotate(double rotation, const QgsPoint ¢er)
Rotate this geometry around the Z axis.
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
int sizeToPixel(double size, const QgsRenderContext &c, SizeUnit unit, bool rasterfactor=false, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale()) const
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
void setMergeConnectedLines(bool m)
static QgsProject * instance()
access to canonical QgsProject instance
virtual void clearActiveLayers() override
clears all PAL layer settings for registered layers
void setMapToPixel(const QgsMapToPixel &mtp)
int size() const
Return number of items.
SizeUnit shadowRadiusUnits
void setArrangementFlags(unsigned long flags)
Only for polygon, arranges candidates with respect of polygon orientation.
virtual QgsDiagramRendererV2 * clone() const =0
Returns new instance that is equivalent to this one.
static QgsGeometry * fromRect(const QgsRectangle &rect)
construct geometry from a rectangle
LabelPositon is a candidate feature label position.
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
const QgsMapToPixel & mapToPixel() const
SearchMethod getSearch()
get the search method in use
void writeToLayer(QgsVectorLayer *layer)
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
virtual void registerDiagramFeature(const QString &layerID, QgsFeature &feat, const QgsRenderContext &context=QgsRenderContext()) override
called for every diagram feature
virtual int prepareLayer(QgsVectorLayer *layer, QStringList &attrNames, QgsRenderContext &ctx) override
hook called when drawing layer before issuing select()
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
bool labelOffsetInMapUnits
void setLineP(int line_p)
set maximum # candidates to generate for lines features Higher the value is, longer Pal::labeller wil...
double getX(int i=0) const
get the down-left x coordinate
double pictureBuffer() const
QPainter::CompositionMode shadowBlendMode
bool isExpression
Is this label made from a expression string eg FieldName || 'mm'.
LabelPosition * getFeatureCandidate(int fi, int ci)
virtual Q_DECL_DEPRECATED QList< QgsLabelPosition > labelsAtPosition(const QgsPoint &p) override
return infos about labels at a given (map) position
void setSize(const QgsPoint &point)
QList< QgsPalGeometry * > geometries
Class that stores computed placement from labeling engine.
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode &blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Custom exception class for Coordinate Reference System related exceptions.
int getPolyP()
get maximum # candidates to generate for polygon features
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QgsMapUnitScale shapeOffsetMapUnitScale
QList< QgsLabelCandidate > mCandidates
Labeling engine interface.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
void setPictureBuffer(const double buffer)
SizeUnit shapeOffsetUnits
void setScale(double scale)
is a little bit better than CHAIN but slower
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
double minScale
The minimum scale, or 0.0 if unset.
void feature(QgsFeature &feature)
QString parserErrorString() const
Returns parser error.
double xMinimum() const
Get the x minimum value (left side of rectangle)
QgsPoint center() const
Center point of the rectangle.
is the worst but fastest method
const QgsCoordinateTransform * ct
QString evalErrorString() const
Returns evaluation error.
void setExpressionString(const QString &expr)
QString exportToWkt(const int &precision=17) const
Exports the geometry to WKT.
QHash< int, QString > QgsAttrPalIndexNameHash
static void blurImageInPlace(QImage &image, const QRect &rect, int radius, bool alphaOnly)
Blurs an image in place, e.g.
Maintains current state of more grainular and temporal values when creating/painting component parts ...
static bool fontFamilyMatchOnSystem(const QString &family, QString *chosen=0, bool *match=0)
Check whether font family is on system.
void setLabelMode(LabelMode m)
pal::LabelInfo * info(QFontMetricsF *fm, const QgsMapToPixel *xform, double fontScale, double maxinangle, double maxoutangle)
QStringList referencedColumns(QgsVectorLayer *layer)
RotationType shapeRotationType
QgsMapUnitScale labelOffsetMapUnitScale
void registerCancellationCallback(FnIsCancelled fnCancelled, void *context)
Register a function that returns whether this job has been cancelled - PAL calls it during the comput...
void renderPoint(const QPointF &point, QgsSymbolV2RenderContext &context) override
virtual void exit() override
called when we're done with rendering
static QColor _readColor(QgsVectorLayer *layer, QString property, QColor defaultColor=Qt::black, bool withAlpha=true)
QgsLabelingResults * mResults
LinePlacementFlags placementFlags
const QgsFields * mCurFields
DirectionSymbols placeDirectionSymbol
QPointF toQPointF() const
Converts a point to a QPointF.
static void drawLabelShadow(QgsRenderContext &context, const QgsLabelComponent &component, const QgsPalLayerSettings &tmpLyr)
void dataDefinedTextFormatting(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)