21#include <QtConcurrentMap>
26static void getFeaturesForProvider(
const QPair< std::shared_ptr< QgsAbstractFeatureSource >,
QgsFeatureRequest > &pair )
38 constexpr int JOBS_TO_RUN = 100;
39 QList< QPair< std::shared_ptr< QgsAbstractFeatureSource >,
QgsFeatureRequest > > jobs;
40 jobs.reserve( JOBS_TO_RUN );
41 for (
int i = 0; i < JOBS_TO_RUN; ++i )
43 jobs.append( qMakePair( std::shared_ptr< QgsAbstractFeatureSource >( provider->
featureSource() ), request ) );
48 QtConcurrent::blockingMap( jobs, getFeaturesForProvider );
53bool QgsTestUtils::compareDomElements(
const QDomElement &element1,
const QDomElement &element2 )
55 QString tag1 = element1.tagName();
56 tag1.replace( QRegularExpression(
".*:" ), QString() );
57 QString tag2 = element2.tagName();
58 tag2.replace( QRegularExpression(
".*:" ), QString() );
61 qDebug(
"Different tag names: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
65 if ( element1.hasAttributes() != element2.hasAttributes() )
67 qDebug(
"Different hasAttributes: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
71 if ( element1.hasAttributes() )
73 const QDomNamedNodeMap attrs1 = element1.attributes();
74 const QDomNamedNodeMap attrs2 = element2.attributes();
76 if ( attrs1.size() != attrs2.size() )
78 qDebug(
"Different attributes size: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
82 for (
int i = 0; i < attrs1.size(); ++i )
84 const QDomNode node1 = attrs1.item( i );
85 const QDomAttr attr1 = node1.toAttr();
87 if ( !element2.hasAttribute( attr1.name() ) )
89 qDebug(
"Element2 has not attribute: %s, %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data(), attr1.name().toLatin1().data() );
93 if ( element2.attribute( attr1.name() ) != attr1.value() )
95 qDebug(
"Element2 attribute has not the same value: %s, %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data(), attr1.name().toLatin1().data() );
101 if ( element1.hasChildNodes() != element2.hasChildNodes() )
103 qDebug(
"Different childNodes: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
107 if ( element1.hasChildNodes() )
109 const QDomNodeList nodes1 = element1.childNodes();
110 const QDomNodeList nodes2 = element2.childNodes();
112 if ( nodes1.size() != nodes2.size() )
114 qDebug(
"Different childNodes size: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
118 for (
int i = 0; i < nodes1.size(); ++i )
120 const QDomNode node1 = nodes1.at( i );
121 const QDomNode node2 = nodes2.at( i );
122 if ( node1.isElement() && node2.isElement() )
124 QDomElement elt1 = node1.toElement();
125 QDomElement elt2 = node2.toElement();
127 if ( !compareDomElements( elt1, elt2 ) )
130 else if ( node1.isText() && node2.isText() )
132 const QDomText txt1 = node1.toText();
133 const QDomText txt2 = node2.toText();
135 if ( txt1.data() != txt2.data() )
137 qDebug(
"Different text data: %s %s", tag1.toLatin1().data(), txt1.data().toLatin1().data() );
138 qDebug(
"Different text data: %s %s", tag2.toLatin1().data(), txt2.data().toLatin1().data() );
145 if ( element1.text() != element2.text() )
147 qDebug(
"Different text: %s %s", tag1.toLatin1().data(), element1.text().toLatin1().data() );
148 qDebug(
"Different text: %s %s", tag2.toLatin1().data(), element2.text().toLatin1().data() );
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Base class for vector data providers.
virtual QgsAbstractFeatureSource * featureSource() const =0
Returns feature source object that can be used for querying provider's data.