28 #include <QPainterPath>
30 #include <QProgressDialog>
80 #include "diagram/qgsdiagram.h"
82 #ifdef TESTPROVIDERLIB
88 const QString& qmlStyle,
89 const QString& sldStyle,
90 const QString& styleName,
91 const QString& styleDescription,
92 const QString& uiFileContent,
106 QStringList &descriptions,
119 bool loadDefaultStyleFlag )
120 :
QgsMapLayer( VectorLayer, baseName, vectorLayerPath )
121 , mUpdateThreshold( 0 )
122 , mDataProvider( NULL )
123 , mProviderKey( providerKey )
125 , mRendererV2( NULL )
128 , mLabelFontNotFoundNotified( false )
129 , mFeatureBlendMode( QPainter::CompositionMode_SourceOver )
130 , mLayerTransparency( 0 )
131 , mVertexMarkerOnlyForSelection( false )
132 , mFeatureFormSuppress( SuppressDefault )
136 , mDiagramRenderer( 0 )
137 , mDiagramLayerSettings( 0 )
138 , mValidExtent( false )
139 , mLazyExtent( true )
140 , mSymbolFeatureCounted( false )
141 , mCurrentRendererContext( 0 )
158 bool defaultLoadedFlag =
false;
159 if ( loadDefaultStyleFlag )
265 QString idxName =
"";
268 if ( !fldName.isEmpty() )
275 int fieldsSize = fields.
size();
277 for (
int idx = 0; idx < fields.
count(); ++idx )
279 QString fldName = fields[idx].name();
280 QgsDebugMsg(
"Checking field " + fldName +
" of " + QString::number( fieldsSize ) +
" total" );
286 if ( fldName.indexOf(
"name", 0, Qt::CaseInsensitive ) > -1 )
288 if ( idxName.isEmpty() )
293 if ( fldName.indexOf(
"descrip", 0, Qt::CaseInsensitive ) > -1 )
295 if ( idxName.isEmpty() )
300 if ( fldName.indexOf(
"id", 0, Qt::CaseInsensitive ) > -1 )
302 if ( idxId.isEmpty() )
310 if ( fieldsSize == 0 )
313 if ( idxName.length() > 0 )
319 if ( idxId.length() > 0 )
351 attributes.append( attrNum );
359 QgsDebugMsg(
"Selecting features based on view extent" );
368 .setFilterRect( rendererContext.
extent() )
369 .setSubsetOfAttributes( attributes ) );
393 QgsDebugMsg( QString(
"Total features processed %1" ).arg( featureCount ) );
412 bool vertexMarkerOnlyForSelection = settings.value(
"/qgis/digitizing/marker_only_for_selected",
false ).toBool();
426 #ifndef Q_WS_MAC //MH: disable this on Mac for now to avoid problems with resizing
435 qApp->processEvents();
437 else if ( featureCount % 1000 == 0 )
440 qApp->processEvents();
453 bool drawMarker = (
mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
480 QgsDebugMsg( QString(
"Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
481 .arg( fet.
id() ).arg( cse.
what() ) );
493 QgsDebugMsg( QString(
"Total features processed %1" ).arg( featureCount ) );
502 QHash< QgsSymbolV2*, QList<QgsFeature> > features;
505 bool vertexMarkerOnlyForSelection = settings.value(
"/qgis/digitizing/marker_only_for_selected",
false ).toBool();
532 if ( featureCount % 1000 == 0 )
534 qApp->processEvents();
543 if ( !features.contains( sym ) )
545 features.insert( sym, QList<QgsFeature>() );
547 features[sym].append( fet );
575 for (
int i = 0; i < symbols.count(); i++ )
581 if ( level < 0 || level >= 1000 )
584 while ( level >= levels.count() )
586 levels[level].append( item );
591 for (
int l = 0; l < levels.count(); l++ )
594 for (
int i = 0; i < level.count(); i++ )
597 if ( !features.contains( item.
symbol() ) )
602 int layer = item.
layer();
603 QList<QgsFeature>& lst = features[item.
symbol()];
604 QList<QgsFeature>::iterator fit;
608 for ( fit = lst.begin(); fit != lst.end(); ++fit )
616 if ( featureCount % 1000 == 0 )
618 qApp->processEvents();
623 bool drawMarker = (
mEditBuffer && ( !vertexMarkerOnlyForSelection || sel ) );
632 QgsDebugMsg( QString(
"Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
633 .arg( fet.
id() ).arg( cse.
what() ) );
691 attributes.append( attrNum );
692 QgsDebugMsg(
"attrs: " + attrName +
" - " + QString::number( attrNum ) );
695 bool labeling =
false;
704 .setSubsetOfAttributes( attributes );
709 QPainter* p = rendererContext.
painter();
710 double dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
728 QgsDebugMsg( QString(
"Simplify - SourceTransformRect=%1" ).arg( sourceRect.
toString( 16 ) ) );
729 QgsDebugMsg( QString(
"Simplify - TargetTransformRect=%1" ).arg( targetRect.toString( 16 ) ) );
731 if ( !sourceRect.
isEmpty() && sourceRect.
isFinite() && !targetRect.isEmpty() && targetRect.isFinite() )
735 QgsPoint minimumDstPoint( targetRect.xMinimum(), targetRect.yMinimum() );
736 QgsPoint maximumDstPoint( targetRect.xMaximum(), targetRect.yMaximum() );
738 double sourceHypothenuse = sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
739 double targetHypothenuse = sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
741 QgsDebugMsg( QString(
"Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ) );
742 QgsDebugMsg( QString(
"Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ) );
744 if ( targetHypothenuse != 0 )
745 map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
776 p.setPen( QColor( 50, 100, 120, 200 ) );
777 p.setBrush( QColor( 200, 200, 210, 120 ) );
778 p.drawEllipse( x - m, y - m, m * 2 + 1, m * 2 + 1 );
782 p.setPen( QColor( 255, 0, 0 ) );
783 p.drawLine( x - m, y + m, x + m, y - m );
784 p.drawLine( x - m, y - m, x + m, y + m );
827 .setFilterRect( rect )
839 if ( !addToSelection )
852 if ( intersectingIds.count() > 0 )
854 QgsDebugMsg(
"Trying to select and deselect the same item at the same time. Unsure what to do. Selecting dubious items." );
900 .setFilterRect( rect )
912 deselectIds << fet.
id();
916 selectIds << fet.
id();
995 QgsDebugMsg( QString(
"Data Provider Geometry type is not recognised, is %1" ).arg( type ) );
1007 QgsDebugMsg(
"WARNING: This code should never be reached. Problems may occur..." );
1039 .setFilterFid( fid )
1067 if ( retval.
width() == 0.0 || retval.
height() == 0.0 )
1076 retval.
set( -1.0, -1.0, 1.0, 1.0 );
1117 QgsLegendSymbolList::const_iterator symbolIt = symbolList.constBegin();
1119 for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
1125 QProgressDialog progressDialog(
tr(
"Updating feature count for layer %1" ).arg(
name() ),
tr(
"Abort" ), 0, nFeatures );
1126 progressDialog.setWindowModality( Qt::WindowModal );
1127 int featuresCounted = 0;
1140 for ( QgsSymbolV2List::iterator symbolIt = featureSymbolList.begin(); symbolIt != featureSymbolList.end(); ++symbolIt )
1148 if ( featuresCounted % 50 == 0 )
1150 if ( featuresCounted > nFeatures )
1152 progressDialog.setMaximum( 0 );
1154 progressDialog.setValue( featuresCounted );
1155 if ( progressDialog.wasCanceled() )
1165 progressDialog.setValue( nFeatures );
1226 if ( it->geometry() )
1300 if ( maximumSimplificationScale > 1 && renderContext.
rendererScale() <= maximumSimplificationScale )
1319 Q_UNUSED( alsoUpdateExtent );
1343 QgsDebugMsg( QString(
"feature %1 could not be retrieved" ).arg( f.
id() ) );
1351 QgsDebugMsg( QString(
"geometry of feature %1 could not be changed." ).arg( f.
id() ) );
1359 for (
int attr = 0; attr < fa.count(); ++attr )
1361 if ( fa[attr] != ca[attr] )
1365 QgsDebugMsg( QString(
"attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( f.
id() ) );
1381 return utils.
insertVertex( x, y, atFeatureId, beforeVertex );
1391 return utils.
moveVertex( x, y, atFeatureId, atVertex );
1481 return utils.
splitParts( splitLine, topologicalEditing );
1490 return utils.
splitFeatures( splitLine, topologicalEditing );
1498 int returnValue = 0;
1511 .setFilterRect( geomBBox )
1518 if ( ignoreFeatures.contains( f.
id() ) )
1625 QDomNode pkeyNode = layer_node.namedItem(
"provider" );
1627 if ( pkeyNode.isNull() )
1633 QDomElement pkeyElt = pkeyNode.toElement();
1657 QDomElement pkeyElem = pkeyNode.toElement();
1658 if ( !pkeyElem.isNull() )
1660 QString encodingString = pkeyElem.attribute(
"encoding" );
1661 if ( !encodingString.isEmpty() )
1677 QDomNode prevExpNode = layer_node.namedItem(
"previewExpression" );
1679 if ( prevExpNode.isNull() )
1685 QDomElement prevExpElem = prevExpNode.toElement();
1715 QgsDebugMsg(
"Instantiated the data provider plugin" );
1739 QRegExp reg(
"\"[^\"]+\"\\.\"([^\"]+)\"( \\([^)]+\\))?" );
1740 if ( reg.indexIn(
name() ) >= 0 )
1742 QStringList stuff = reg.capturedTexts();
1743 QString lName = stuff[1];
1747 QMap<QString, QgsMapLayer*>::const_iterator it;
1748 for ( it = layers.constBegin(); it != layers.constEnd() && ( *it )->name() != lName; ++it )
1751 if ( it != layers.constEnd() && stuff.size() > 2 )
1753 lName +=
"." + stuff[2].mid( 2, stuff[2].length() - 3 );
1756 if ( !lName.isEmpty() )
1770 else if ( provider ==
"ogr" )
1803 QDomDocument & document )
1807 QDomElement mapLayerNode = layer_node.toElement();
1809 if ( mapLayerNode.isNull() || (
"maplayer" != mapLayerNode.nodeName() ) )
1815 mapLayerNode.setAttribute(
"type",
"vector" );
1823 QDomElement provider = document.createElement(
"provider" );
1825 QDomText providerText = document.createTextNode(
providerType() );
1826 provider.appendChild( providerText );
1827 layer_node.appendChild( provider );
1831 QDomElement prevExpElem = document.createElement(
"previewExpression" );
1833 prevExpElem.appendChild( prevExpText );
1834 layer_node.appendChild( prevExpElem );
1846 Q_UNUSED( errorMessage );
1851 if ( !rendererElement.isNull() )
1869 QDomNode displayFieldNode = node.namedItem(
"displayfield" );
1870 if ( !displayFieldNode.isNull() )
1872 QDomElement e = displayFieldNode.toElement();
1877 QDomNode blendModeNode = node.namedItem(
"blendMode" );
1878 if ( !blendModeNode.isNull() )
1880 QDomElement e = blendModeNode.toElement();
1885 QDomNode featureBlendModeNode = node.namedItem(
"featureBlendMode" );
1886 if ( !featureBlendModeNode.isNull() )
1888 QDomElement e = featureBlendModeNode.toElement();
1893 QDomNode layerTransparencyNode = node.namedItem(
"layerTransparency" );
1894 if ( !layerTransparencyNode.isNull() )
1896 QDomElement e = layerTransparencyNode.toElement();
1901 QDomElement e = node.toElement();
1919 QDomNode labelnode = node.namedItem(
"label" );
1920 QDomElement element = labelnode.toElement();
1922 if ( hasLabelsEnabled < 1 )
1931 QDomNode labelattributesnode = node.namedItem(
"labelattributes" );
1933 if ( !labelattributesnode.isNull() &&
mLabel )
1941 QDomElement singleCatDiagramElem = node.firstChildElement(
"SingleCategoryDiagramRenderer" );
1942 if ( !singleCatDiagramElem.isNull() )
1947 QDomElement linearDiagramElem = node.firstChildElement(
"LinearlyInterpolatedDiagramRenderer" );
1948 if ( !linearDiagramElem.isNull() )
1956 QDomElement diagramSettingsElem = node.firstChildElement(
"DiagramLayerSettings" );
1957 if ( !diagramSettingsElem.isNull() )
1969 QDomNode editTypesNode = node.namedItem(
"edittypes" );
1970 if ( !editTypesNode.isNull() )
1972 QDomNodeList editTypeNodes = editTypesNode.childNodes();
1974 for (
int i = 0; i < editTypeNodes.size(); i++ )
1976 QDomNode editTypeNode = editTypeNodes.at( i );
1977 QDomElement editTypeElement = editTypeNode.toElement();
1979 QString
name = editTypeElement.attribute(
"name" );
1986 int editable = editTypeElement.attribute(
"editable" ,
"1" ).toInt();
1989 int labelOnTop = editTypeElement.attribute(
"labelontop" ,
"0" ).toInt();
1995 if ( editTypeNode.hasChildNodes() )
1997 mValueMaps.insert( name, QMap<QString, QVariant>() );
1999 QDomNodeList valueMapNodes = editTypeNode.childNodes();
2000 for (
int j = 0; j < valueMapNodes.size(); j++ )
2002 QDomElement value = valueMapNodes.at( j ).toElement();
2003 mValueMaps[
name ].insert( value.attribute(
"key" ), value.attribute(
"value" ) );
2012 QVariant
min = editTypeElement.attribute(
"min" );
2013 QVariant
max = editTypeElement.attribute(
"max" );
2014 QVariant step = editTypeElement.attribute(
"step" );
2021 mCheckedStates[
name ] = QPair<QString, QString>( editTypeElement.attribute(
"checked" ), editTypeElement.attribute(
"unchecked" ) );
2026 QString
id = editTypeElement.attribute(
"layer" );
2027 QString key = editTypeElement.attribute(
"key" );
2028 QString value = editTypeElement.attribute(
"value" );
2029 bool allowNull = editTypeElement.attribute(
"allowNull" ) ==
"true";
2030 bool orderByValue = editTypeElement.attribute(
"orderByValue" ) ==
"true";
2031 bool allowMulti = editTypeElement.attribute(
"allowMulti",
"false" ) ==
"true";
2033 QString filterExpression;
2034 if ( editTypeElement.hasAttribute(
"filterAttributeColumn" ) &&
2035 editTypeElement.hasAttribute(
"filterAttributeValue" ) )
2037 filterExpression = QString(
"\"%1\"='%2'" )
2038 .arg( editTypeElement.attribute(
"filterAttributeColumn" ) )
2039 .arg( editTypeElement.attribute(
"filterAttributeValue" ) );
2043 filterExpression = editTypeElement.attribute(
"filterExpression", QString::null );
2056 mWidgetSize[
name ] = QSize( editTypeElement.attribute(
"widgetWidth" ).toInt(), editTypeElement.attribute(
"widgetHeight" ).toInt() );
2076 QDomNode editFormNode = node.namedItem(
"editform" );
2077 if ( !editFormNode.isNull() )
2079 QDomElement e = editFormNode.toElement();
2083 QDomNode editFormInitNode = node.namedItem(
"editforminit" );
2084 if ( !editFormInitNode.isNull() )
2089 QDomNode fFSuppNode = node.namedItem(
"featformsuppress" );
2090 if ( fFSuppNode.isNull() )
2096 QDomElement e = fFSuppNode.toElement();
2100 QDomNode annotationFormNode = node.namedItem(
"annotationform" );
2101 if ( !annotationFormNode.isNull() )
2103 QDomElement e = annotationFormNode.toElement();
2108 QDomNode aliasesNode = node.namedItem(
"aliases" );
2109 if ( !aliasesNode.isNull() )
2111 QDomElement aliasElem;
2114 QDomNodeList aliasNodeList = aliasesNode.toElement().elementsByTagName(
"alias" );
2115 for (
int i = 0; i < aliasNodeList.size(); ++i )
2117 aliasElem = aliasNodeList.at( i ).toElement();
2120 if ( aliasElem.hasAttribute(
"field" ) )
2122 field = aliasElem.attribute(
"field" );
2126 int index = aliasElem.attribute(
"index" ).toInt();
2137 QDomNode editorLayoutNode = node.namedItem(
"editorlayout" );
2138 if ( editorLayoutNode.isNull() )
2144 if ( editorLayoutNode.toElement().text() ==
"uifilelayout" )
2148 else if ( editorLayoutNode.toElement().text() ==
"tablayout" )
2160 QDomNode excludeWMSNode = node.namedItem(
"excludeAttributesWMS" );
2161 if ( !excludeWMSNode.isNull() )
2163 QDomNodeList attributeNodeList = excludeWMSNode.toElement().elementsByTagName(
"attribute" );
2164 for (
int i = 0; i < attributeNodeList.size(); ++i )
2171 QDomNode excludeWFSNode = node.namedItem(
"excludeAttributesWFS" );
2172 if ( !excludeWFSNode.isNull() )
2174 QDomNodeList attributeNodeList = excludeWFSNode.toElement().elementsByTagName(
"attribute" );
2175 for (
int i = 0; i < attributeNodeList.size(); ++i )
2183 QDomNode attributeEditorFormNode = node.namedItem(
"attributeEditorForm" );
2184 QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();
2186 for (
int i = 0; i < attributeEditorFormNodeList.size(); i++ )
2188 QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();
2201 if ( elem.tagName() ==
"attributeEditorContainer" )
2205 QDomNodeList childNodeList = elem.childNodes();
2207 for (
int i = 0; i < childNodeList.size(); i++ )
2209 QDomElement childElem = childNodeList.at( i ).toElement();
2215 newElement = container;
2217 else if ( elem.tagName() ==
"attributeEditorField" )
2219 QString
name = elem.attribute(
"name" );
2223 else if ( elem.tagName() ==
"attributeEditorRelation" )
2227 QString
name = elem.attribute(
"name" );
2235 Q_UNUSED( errorMessage );
2236 QDomElement mapLayerNode = node.toElement();
2241 node.appendChild( rendererElement );
2247 mapLayerNode.setAttribute(
"minLabelScale", QString::number(
mLabel->
minScale() ) );
2248 mapLayerNode.setAttribute(
"maxLabelScale", QString::number(
mLabel->
maxScale() ) );
2261 QDomElement blendModeElem = doc.createElement(
"blendMode" );
2263 blendModeElem.appendChild( blendModeText );
2264 node.appendChild( blendModeElem );
2267 QDomElement featureBlendModeElem = doc.createElement(
"featureBlendMode" );
2269 featureBlendModeElem.appendChild( featureBlendModeText );
2270 node.appendChild( featureBlendModeElem );
2273 QDomElement layerTransparencyElem = doc.createElement(
"layerTransparency" );
2274 QDomText layerTransparencyText = doc.createTextNode( QString::number(
layerTransparency() ) );
2275 layerTransparencyElem.appendChild( layerTransparencyText );
2276 node.appendChild( layerTransparencyElem );
2279 QDomElement dField = doc.createElement(
"displayfield" );
2280 QDomText dFieldText = doc.createTextNode(
displayField() );
2281 dField.appendChild( dFieldText );
2282 node.appendChild( dField );
2285 QDomElement labelElem = doc.createElement(
"label" );
2286 QDomText labelText = doc.createTextNode(
"" );
2290 labelText.setData(
"1" );
2294 labelText.setData(
"0" );
2296 labelElem.appendChild( labelText );
2298 node.appendChild( labelElem );
2305 if ( fieldname !=
"" )
2307 dField = doc.createElement(
"labelfield" );
2308 dFieldText = doc.createTextNode( fieldname );
2309 dField.appendChild( dFieldText );
2310 node.appendChild( dField );
2327 QDomElement editTypesElement = doc.createElement(
"edittypes" );
2329 for ( QMap<QString, EditType>::const_iterator it =
mEditTypes.begin(); it !=
mEditTypes.end(); ++it )
2331 QDomElement editTypeElement = doc.createElement(
"edittype" );
2332 editTypeElement.setAttribute(
"name", it.key() );
2333 editTypeElement.setAttribute(
"type", it.value() );
2334 editTypeElement.setAttribute(
"editable",
mFieldEditables[ it.key()] ? 1 : 0 );
2335 editTypeElement.setAttribute(
"labelontop",
mLabelOnTop[ it.key()] ? 1 : 0 );
2342 const QMap<QString, QVariant> &map =
mValueMaps[ it.key()];
2344 for ( QMap<QString, QVariant>::const_iterator vmit = map.begin(); vmit != map.end(); ++vmit )
2346 QDomElement value = doc.createElement(
"valuepair" );
2347 value.setAttribute(
"key", vmit.key() );
2348 value.setAttribute(
"value", vmit.value().toString() );
2349 editTypeElement.appendChild( value );
2357 if (
mRanges.contains( it.key() ) )
2359 editTypeElement.setAttribute(
"min",
mRanges[ it.key()].mMin.toString() );
2360 editTypeElement.setAttribute(
"max",
mRanges[ it.key()].mMax.toString() );
2361 editTypeElement.setAttribute(
"step",
mRanges[ it.key()].mStep.toString() );
2368 editTypeElement.setAttribute(
"checked",
mCheckedStates[ it.key()].first );
2369 editTypeElement.setAttribute(
"unchecked",
mCheckedStates[ it.key()].second );
2377 editTypeElement.setAttribute(
"layer", data.
mLayer );
2378 editTypeElement.setAttribute(
"key", data.
mKey );
2379 editTypeElement.setAttribute(
"value", data.
mValue );
2380 editTypeElement.setAttribute(
"allowNull", data.
mAllowNull ?
"true" :
"false" );
2381 editTypeElement.setAttribute(
"orderByValue", data.
mOrderByValue ?
"true" :
"false" );
2382 editTypeElement.setAttribute(
"allowMulti", data.
mAllowMulti ?
"true" :
"false" );
2389 editTypeElement.setAttribute(
"dateFormat",
mDateFormats[ it.key()] );
2394 editTypeElement.setAttribute(
"widgetWidth",
mWidgetSize[ it.key()].width() );
2395 editTypeElement.setAttribute(
"widgetHeight",
mWidgetSize[ it.key()].height() );
2413 editTypesElement.appendChild( editTypeElement );
2416 node.appendChild( editTypesElement );
2419 QDomElement efField = doc.createElement(
"editform" );
2421 efField.appendChild( efText );
2422 node.appendChild( efField );
2424 QDomElement efiField = doc.createElement(
"editforminit" );
2426 efiField.appendChild( efiText );
2427 node.appendChild( efiField );
2429 QDomElement fFSuppElem = doc.createElement(
"featformsuppress" );
2431 fFSuppElem.appendChild( fFSuppText );
2432 node.appendChild( fFSuppElem );
2434 QDomElement afField = doc.createElement(
"annotationform" );
2436 afField.appendChild( afText );
2437 node.appendChild( afField );
2440 QDomElement editorLayoutElem = doc.createElement(
"editorlayout" );
2444 editorLayoutElem.appendChild( doc.createTextNode(
"uifilelayout" ) );
2448 editorLayoutElem.appendChild( doc.createTextNode(
"tablayout" ) );
2453 editorLayoutElem.appendChild( doc.createTextNode(
"generatedlayout" ) );
2457 node.appendChild( editorLayoutElem );
2462 QDomElement aliasElem = doc.createElement(
"aliases" );
2470 QDomElement aliasEntryElem = doc.createElement(
"alias" );
2471 aliasEntryElem.setAttribute(
"field", a_it.key() );
2472 aliasEntryElem.setAttribute(
"index", idx );
2473 aliasEntryElem.setAttribute(
"name", a_it.value() );
2474 aliasElem.appendChild( aliasEntryElem );
2476 node.appendChild( aliasElem );
2480 QDomElement excludeWMSElem = doc.createElement(
"excludeAttributesWMS" );
2484 QDomElement attrElem = doc.createElement(
"attribute" );
2485 QDomText attrText = doc.createTextNode( *attWMSIt );
2486 attrElem.appendChild( attrText );
2487 excludeWMSElem.appendChild( attrElem );
2489 node.appendChild( excludeWMSElem );
2492 QDomElement excludeWFSElem = doc.createElement(
"excludeAttributesWFS" );
2496 QDomElement attrElem = doc.createElement(
"attribute" );
2497 QDomText attrText = doc.createTextNode( *attWFSIt );
2498 attrElem.appendChild( attrText );
2499 excludeWFSElem.appendChild( attrElem );
2501 node.appendChild( excludeWFSElem );
2506 QDomElement tabsElem = doc.createElement(
"attributeEditorForm" );
2510 QDomElement attributeEditorWidgetElem = ( *it )->toDomElement( doc );
2511 tabsElem.appendChild( attributeEditorWidgetElem );
2514 node.appendChild( tabsElem );
2526 QDomElement nameElem = node.firstChildElement(
"Name" );
2527 if ( nameElem.isNull() )
2529 errorMessage =
"Warning: Name element not found within NamedLayer while it's required.";
2549 Q_UNUSED( errorMessage );
2552 QDomElement nameNode = doc.createElement(
"se:Name" );
2553 nameNode.appendChild( doc.createTextNode(
name() ) );
2554 node.appendChild( nameNode );
2579 Q_UNUSED( emitSignal );
2627 if ( attributeIndex < 0 || attributeIndex >=
pendingFields().count() )
2638 if ( displayName.isEmpty() )
2641 if ( attributeIndex >= 0 && attributeIndex < fields.
count() )
2643 displayName = fields[attributeIndex].name();
2659 bool deleted =
false;
2662 attrs = attrs.toSet().toList();
2664 qSort( attrs.begin(), attrs.end(), qGreater<int>() );
2666 foreach (
int attr, attrs )
2713 pkAttributesList << i;
2716 return pkAttributesList;
2866 for ( QgsFeatureList::iterator iter = features.begin(); iter != features.end(); ++iter )
2883 QMultiMap<double, QgsSnappingResult> snapResults;
2891 if ( snapResults.size() < 1 )
2896 QMultiMap<double, QgsSnappingResult>::const_iterator snap_it = snapResults.constBegin();
2897 point.
setX( snap_it.value().snappedVertex.x() );
2898 point.
setY( snap_it.value().snappedVertex.y() );
2904 QMultiMap<double, QgsSnappingResult>& snappingResults,
2915 QList<QgsFeature> featureList;
2916 QgsRectangle searchRect( startPoint.
x() - snappingTolerance, startPoint.
y() - snappingTolerance,
2917 startPoint.
x() + snappingTolerance, startPoint.
y() + snappingTolerance );
2918 double sqrSnappingTolerance = snappingTolerance * snappingTolerance;
2926 for ( QgsGeometryMap::iterator it = cachedGeometries.begin(); it != cachedGeometries.end() ; ++it )
2931 snapToGeometry( startPoint, it.key(), g, sqrSnappingTolerance, snappingResults, snap_to );
2941 .setFilterRect( searchRect )
2952 return n == 0 ? 2 : 0;
2958 double sqrSnappingTolerance,
2959 QMultiMap<double, QgsSnappingResult>& snappingResults,
2967 int atVertex, beforeVertex, afterVertex;
2968 double sqrDistVertexSnap, sqrDistSegmentSnap;
2975 snappedPoint = geom->
closestVertex( startPoint, atVertex, beforeVertex, afterVertex, sqrDistVertexSnap );
2976 if ( sqrDistVertexSnap < sqrSnappingTolerance )
2981 if ( beforeVertex != -1 )
2986 if ( afterVertex != -1 )
2991 snappingResultVertex.
layer =
this;
2992 snappingResults.insert( sqrt( sqrDistVertexSnap ), snappingResultVertex );
3000 sqrDistSegmentSnap = geom->
closestSegmentWithContext( startPoint, snappedPoint, afterVertex, NULL,
crs().geographicFlag() ? 1e-12 : 1e-8 );
3002 if ( sqrDistSegmentSnap < sqrSnappingTolerance )
3011 snappingResultSegment.
layer =
this;
3012 snappingResults.insert( sqrt( sqrDistSegmentSnap ), snappingResultSegment );
3028 QString markerTypeString = settings.value(
"/qgis/digitizing/marker_style",
"Cross" ).toString();
3029 if ( markerTypeString ==
"Cross" )
3033 else if ( markerTypeString ==
"SemiTransparentCircle" )
3046 return settings.value(
"/qgis/digitizing/marker_size", 3 ).toInt();
3053 QgsDebugMsg(
"----- Computing Coordinate System" );
3124 if ( idx >= 0 && idx < fields.
count() )
3178 static QMap< QString, QVariant > invalidMap;
3179 if ( idx < 0 || idx >= fields.
count() )
3181 QgsDebugMsg( QString(
"field %1 not found" ).arg( idx ) );
3184 QString fieldName = fields[idx].name();
3187 mValueMaps[fieldName] = QMap<QString, QVariant>();
3198 if ( idx < 0 || idx >= fields.
count() )
3200 QgsDebugMsg( QString(
"field %1 not found" ).arg( idx ) );
3201 return invalidRange;
3203 QString fieldName = fields[idx].name();
3205 if ( !
mRanges.contains( fieldName ) )
3215 QString fieldName = fields[idx].name();
3227 QString fieldName = fields[idx].name();
3238 if ( idx >= 0 && idx < fields.
count() )
3251 if ( idx >= 0 && idx < fields.
count() )
3252 return mLabelOnTop.value( fields[idx].name(), false );
3260 if ( idx >= 0 && idx < fields.
count() )
3267 if ( idx >= 0 && idx < fields.
count() )
3317 if ( idx >= 0 && idx < fields.
count() )
3327 return QPair<QString, QString>(
"1",
"0" );
3334 for (
int idx = 0; idx < theFields.
count(); ++idx )
3336 if ( QString::compare( theFields[idx].
name(), fieldName, Qt::CaseInsensitive ) == 0 )
3395 uniqueValues.clear();
3409 int sourceLayerIndex;
3432 .setSubsetOfAttributes( attList ) );
3435 QVariant currentValue;
3436 QHash<QString, QVariant> val;
3440 val.insert( currentValue.toString(), currentValue );
3441 if ( limit >= 0 && val.size() >= limit )
3447 uniqueValues = val.values();
3451 Q_ASSERT_X(
false,
"QgsVectorLayer::uniqueValues()",
"Unknown source of the field!" );
3469 int sourceLayerIndex;
3492 .setSubsetOfAttributes( attList ) );
3496 double currentValue = 0;
3499 currentValue = f.
attribute( index ).toDouble();
3500 if ( currentValue < minimumValue )
3502 minimumValue = currentValue;
3505 return QVariant( minimumValue );
3508 Q_ASSERT_X(
false,
"QgsVectorLayer::minimumValue()",
"Unknown source of the field!" );
3527 int sourceLayerIndex;
3553 .setSubsetOfAttributes( attList ) );
3557 double currentValue = 0;
3560 currentValue = f.
attribute( index ).toDouble();
3561 if ( currentValue > maximumValue )
3563 maximumValue = currentValue;
3566 return QVariant( maximumValue );
3569 Q_ASSERT_X(
false,
"QgsVectorLayer::maximumValue()",
"Unknown source of the field!" );
3614 QSet<int> attrIndex;
3617 QSet<int>::const_iterator attIt = attrIndex.constBegin();
3618 for ( ; attIt != attrIndex.constEnd(); ++attIt )
3620 if ( !attributes.contains( *attIt ) )
3622 attributes << *attIt;
3636 .setFilterRect( rendererContext.
extent() )
3641 int nFeatsToLabel = 0;
3664 QList<QString>::const_iterator attIt = att.constBegin();
3665 for ( ; attIt != att.constEnd(); ++attIt )
3669 QStringList::const_iterator columnsIterator = columns.constBegin();
3670 for ( ; columnsIterator != columns.constEnd(); ++columnsIterator )
3673 if ( !attributes.contains( index ) )
3675 attributes <<
index;
3681 if ( mLinearlyInterpolatedDiagramRenderer != NULL )
3687 QStringList::const_iterator columnsIterator = columns.constBegin();
3688 for ( ; columnsIterator != columns.constEnd(); ++columnsIterator )
3691 if ( !attributes.contains( index ) )
3693 attributes <<
index;
3720 QDomElement element = node.toElement();
3721 if ( element.isNull() )
3724 QDomElement userStyleElem = element.firstChildElement(
"UserStyle" );
3725 if ( userStyleElem.isNull() )
3727 QgsDebugMsg(
"Info: UserStyle element not found." );
3731 QDomElement featureTypeStyleElem = userStyleElem.firstChildElement(
"FeatureTypeStyle" );
3732 if ( featureTypeStyleElem.isNull() )
3734 QgsDebugMsg(
"Info: FeatureTypeStyle element not found." );
3739 QDomElement ruleElem = featureTypeStyleElem.lastChildElement(
"Rule" );
3740 if ( ruleElem.isNull() )
3747 QDomElement textSymbolizerElem = ruleElem.lastChildElement(
"TextSymbolizer" );
3748 if ( textSymbolizerElem.isNull() )
3750 QgsDebugMsg(
"Info: TextSymbolizer element not found." );
3756 QDomElement labelElem = textSymbolizerElem.firstChildElement(
"Label" );
3757 if ( !labelElem.isNull() )
3759 QDomElement propertyNameElem = labelElem.firstChildElement(
"PropertyName" );
3760 if ( !propertyNameElem.isNull() )
3791 QString labelAttribute = propertyNameElem.text();
3796 if ( fieldIndex == -1 )
3812 QgsDebugMsg(
"Info: PropertyName element not found." );
3823 QDomElement fontElem = textSymbolizerElem.firstChildElement(
"Font" );
3824 if ( !fontElem.isNull() )
3828 QDomElement cssElem = fontElem.firstChildElement(
"CssParameter" );
3829 while ( !cssElem.isNull() )
3831 cssName = cssElem.attribute(
"name",
"not_found" );
3832 if ( cssName !=
"not_found" )
3834 elemText = cssElem.text();
3835 if ( cssName ==
"font-family" )
3839 else if ( cssName ==
"font-style" )
3841 setCustomProperty(
"labeling/fontItalic", ( elemText ==
"italic" ) || ( elemText ==
"Italic" ) );
3843 else if ( cssName ==
"font-size" )
3846 int fontSize = elemText.toInt( &ok );
3852 else if ( cssName ==
"font-weight" )
3854 setCustomProperty(
"labeling/fontBold", ( elemText ==
"bold" ) || ( elemText ==
"Bold" ) );
3856 else if ( cssName ==
"font-underline" )
3858 setCustomProperty(
"labeling/fontUnderline", ( elemText ==
"underline" ) || ( elemText ==
"Underline" ) );
3862 cssElem = cssElem.nextSiblingElement(
"CssParameter" );
3868 if ( textColor.isValid() )
3873 setCustomProperty(
"labeling/textTransp", 100 - (
int )( 100 * textColor.alphaF() ) );
3877 QDomElement haloElem = textSymbolizerElem.firstChildElement(
"Halo" );
3878 if ( !haloElem.isNull() )
3883 QDomElement radiusElem = haloElem.firstChildElement(
"Radius" );
3884 if ( !radiusElem.isNull() )
3887 double bufferSize = radiusElem.text().toDouble( &ok );
3895 if ( bufferColor.isValid() )
3900 setCustomProperty(
"labeling/bufferTransp", 100 - (
int )( 100 * bufferColor.alphaF() ) );
3905 QDomElement labelPlacementElem = textSymbolizerElem.firstChildElement(
"LabelPlacement" );
3906 if ( !labelPlacementElem.isNull() )
3909 QDomElement pointPlacementElem = labelPlacementElem.firstChildElement(
"PointPlacement" );
3910 if ( !pointPlacementElem.isNull() )
3914 QDomElement displacementElem = pointPlacementElem.firstChildElement(
"Displacement" );
3915 if ( !displacementElem.isNull() )
3917 QDomElement displacementXElem = displacementElem.firstChildElement(
"DisplacementX" );
3918 if ( !displacementXElem.isNull() )
3921 double xOffset = displacementXElem.text().toDouble( &ok );
3927 QDomElement displacementYElem = displacementElem.firstChildElement(
"DisplacementY" );
3928 if ( !displacementYElem.isNull() )
3931 double yOffset = displacementYElem.text().toDouble( &ok );
3939 QDomElement rotationElem = pointPlacementElem.firstChildElement(
"Rotation" );
3940 if ( !rotationElem.isNull() )
3943 double rotation = rotationElem.text().toDouble( &ok );
3962 QString myMetadata =
"<html><body>";
3966 myMetadata +=
"<p class=\"subheaderglossy\">";
3967 myMetadata +=
tr(
"General" );
3968 myMetadata +=
"</p>\n";
3973 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Layer comment" ) +
"</p>\n";
3974 myMetadata +=
"<p>";
3976 myMetadata +=
"</p>\n";
3980 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Storage type of this layer" ) +
"</p>\n";
3981 myMetadata +=
"<p>";
3983 myMetadata +=
"</p>\n";
3988 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Description of this provider" ) +
"</p>\n";
3989 myMetadata +=
"<p>";
3991 myMetadata +=
"</p>\n";
3995 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Source for this layer" ) +
"</p>\n";
3996 myMetadata +=
"<p>";
3998 myMetadata +=
"</p>\n";
4012 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Geometry type of the features in this layer" ) +
"</p>\n";
4013 myMetadata +=
"<p>";
4014 myMetadata += typeString;
4015 myMetadata +=
"</p>\n";
4019 if ( !pkAttrList.isEmpty() )
4021 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Primary key attributes" ) +
"</p>\n";
4022 myMetadata +=
"<p>";
4023 foreach (
int idx, pkAttrList )
4027 myMetadata +=
"</p>\n";
4032 myMetadata +=
"<p class=\"glossy\">" +
tr(
"The number of features in this layer" ) +
"</p>\n";
4033 myMetadata +=
"<p>";
4035 myMetadata +=
"</p>\n";
4037 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Editing capabilities of this layer" ) +
"</p>\n";
4038 myMetadata +=
"<p>";
4040 myMetadata +=
"</p>\n";
4045 myMetadata +=
"<p class=\"subheaderglossy\">";
4046 myMetadata +=
tr(
"Extents" );
4047 myMetadata +=
"</p>\n";
4050 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In layer spatial reference system units" ) +
"</p>\n";
4051 myMetadata +=
"<p>";
4064 QString xMin, yMin, xMax, yMax;
4065 double changeoverValue = 99999;
4066 if ( qAbs( myExtent.
xMinimum() ) > changeoverValue )
4068 xMin = QString(
"%1" ).arg( myExtent.
xMinimum(), 0,
'f', 2 );
4072 xMin = QString(
"%1" ).arg( myExtent.
xMinimum() );
4074 if ( qAbs( myExtent.
yMinimum() ) > changeoverValue )
4076 yMin = QString(
"%1" ).arg( myExtent.
yMinimum(), 0,
'f', 2 );
4080 yMin = QString(
"%1" ).arg( myExtent.
yMinimum() );
4082 if ( qAbs( myExtent.
xMaximum() ) > changeoverValue )
4084 xMax = QString(
"%1" ).arg( myExtent.
xMaximum(), 0,
'f', 2 );
4088 xMax = QString(
"%1" ).arg( myExtent.
xMaximum() );
4090 if ( qAbs( myExtent.
yMaximum() ) > changeoverValue )
4092 yMax = QString(
"%1" ).arg( myExtent.
yMaximum(), 0,
'f', 2 );
4096 yMax = QString(
"%1" ).arg( myExtent.
yMaximum() );
4099 myMetadata +=
tr(
"xMin,yMin %1,%2 : xMax,yMax %3,%4" )
4100 .arg( xMin ).arg( yMin ).arg( xMax ).arg( yMax );
4104 myMetadata +=
tr(
"unknown extent" );
4107 myMetadata +=
"</p>\n";
4115 QgsRectangle myProjectedExtent = coordinateTransform->transformBoundingBox(
extent() );
4116 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In project spatial reference system units" ) +
"</p>\n";
4117 myMetadata +=
"<p>";
4118 myMetadata +=
tr(
"xMin,yMin %1,%2 : xMax,yMax %3,%4" )
4119 .arg( myProjectedExtent.
xMinimum() )
4120 .arg( myProjectedExtent.
yMinimum() )
4121 .arg( myProjectedExtent.
xMaximum() )
4122 .arg( myProjectedExtent.
yMaximum() );
4123 myMetadata +=
"</p>\n";
4129 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Layer Spatial Reference System" ) +
"</p>\n";
4130 myMetadata +=
"<p>";
4131 myMetadata +=
crs().
toProj4().replace( QRegExp(
"\"" ),
" \"" );
4132 myMetadata +=
"</p>\n";
4140 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Project (Output) Spatial Reference System" ) +
"</p>\n";
4141 myMetadata +=
"<p>";
4142 myMetadata += coordinateTransform->destCRS().toProj4().replace( QRegExp(
"\"" ),
" \"" );
4143 myMetadata +=
"</p>\n";
4151 myMetadata +=
"<p class=\"glossy\">" +
tr(
"In project spatial reference system units" ) +
"</p>\n";
4152 myMetadata +=
"<p>";
4153 myMetadata +=
tr(
"(Invalid transformation of layer extents)" );
4154 myMetadata +=
"</p>\n";
4162 myMetadata +=
"<p class=\"glossy\">" +
tr(
"Attribute field info" ) +
"</p>\n";
4163 myMetadata +=
"<p>";
4166 myMetadata +=
"<table width=\"100%\">";
4167 myMetadata +=
"<tr><th>";
4168 myMetadata +=
tr(
"Field" );
4169 myMetadata +=
"</th>";
4170 myMetadata +=
"<th>";
4171 myMetadata +=
tr(
"Type" );
4172 myMetadata +=
"</th>";
4173 myMetadata +=
"<th>";
4174 myMetadata +=
tr(
"Length" );
4175 myMetadata +=
"</th>";
4176 myMetadata +=
"<th>";
4177 myMetadata +=
tr(
"Precision" );
4178 myMetadata +=
"</th>";
4179 myMetadata +=
"<th>";
4180 myMetadata +=
tr(
"Comment" );
4181 myMetadata +=
"</th>";
4185 for ( QgsFieldMap::const_iterator it = myFields.begin(); it != myFields.end(); ++it )
4189 myMetadata +=
"<tr><td>";
4190 myMetadata += myField.
name();
4191 myMetadata +=
"</td>";
4192 myMetadata +=
"<td>";
4194 myMetadata +=
"</td>";
4195 myMetadata +=
"<td>";
4196 myMetadata += QString(
"%1" ).arg( myField.
length() );
4197 myMetadata +=
"</td>";
4198 myMetadata +=
"<td>";
4199 myMetadata += QString(
"%1" ).arg( myField.
precision() );
4200 myMetadata +=
"</td>";
4201 myMetadata +=
"<td>";
4202 myMetadata += QString(
"%1" ).arg( myField.
comment() );
4203 myMetadata +=
"</td></tr>";
4207 myMetadata +=
"</table>";
4210 myMetadata +=
"</body></html>";
4248 if ( idx < 0 || idx >= fields.
count() )
4250 QgsDebugMsg( QString(
"field %1 not found" ).arg( idx ) );
4253 QString fieldName = fields[idx].name();
4280 QDomElement elem = doc.createElement(
"attributeEditorContainer" );
4281 elem.setAttribute(
"name",
mName );
4297 QList<QgsAttributeEditorElement*> results;
4303 results.append( elem );
4318 QDomElement elem = doc.createElement(
"attributeEditorField" );
4319 elem.setAttribute(
"name",
mName );
4320 elem.setAttribute(
"index",
mIdx );
4335 if ( !listStylesExternalMethod )
4342 return listStylesExternalMethod(
mDataSource, ids, names, descriptions, msgError );
4356 if ( !getStyleByIdMethod )
4363 return getStyleByIdMethod(
mDataSource, styleId, msgError );
4368 bool useAsDefault, QString uiFileContent, QString &msgError )
4371 QString sldStyle, qmlStyle;
4381 if ( !saveStyleExternalMethod )
4388 QDomDocument qmlDocument, sldDocument;
4390 if ( !msgError.isNull() )
4394 qmlStyle = qmlDocument.toString();
4397 if ( !msgError.isNull() )
4401 sldStyle = sldDocument.toString();
4403 saveStyleExternalMethod(
mDataSource, qmlStyle, sldStyle, name,
4404 description, uiFileContent, useAsDefault, msgError );
4417 if ( !loadFromLocalDB && !dsUri.
database().isEmpty() )
4424 if ( loadStyleExternalMethod )
4426 QString qml, errorMsg;
4427 qml = loadStyleExternalMethod(
mDataSource, errorMsg );
4428 if ( !qml.isEmpty() )
4442 QDomDocument myDocument(
"qgis" );
4443 myDocument.setContent( namedStyle );
4445 QDomElement myRoot = myDocument.firstChildElement(
"qgis" );
4447 if ( myRoot.isNull() )
4449 errorMsg =
tr(
"Error: qgis element could not be found" );
4458 QDomNode transparencyNode = myRoot.namedItem(
"transparencyLevelInt" );
4459 if ( ! transparencyNode.isNull() )
4463 QDomElement myElement = transparencyNode.toElement();
4464 setTransparency( myElement.text().toInt() );
4474 QDomElement elem = doc.createElement(
"attributeEditorRelation" );
4475 elem.setAttribute(
"name",
mName );