19#include <QtConcurrentMap>
23static void getFeaturesForProvider(
const QPair< std::shared_ptr< QgsAbstractFeatureSource >,
QgsFeatureRequest > &pair )
35 constexpr int JOBS_TO_RUN = 100;
36 QList< QPair< std::shared_ptr< QgsAbstractFeatureSource >,
QgsFeatureRequest > > jobs;
37 jobs.reserve( JOBS_TO_RUN );
38 for (
int i = 0; i < JOBS_TO_RUN; ++i )
40 jobs.append( qMakePair( std::shared_ptr< QgsAbstractFeatureSource >( provider->
featureSource() ), request ) );
45 QtConcurrent::blockingMap( jobs, getFeaturesForProvider );
50bool QgsTestUtils::compareDomElements(
const QDomElement &element1,
const QDomElement &element2 )
52 QString tag1 = element1.tagName();
53 tag1.replace( QRegularExpression(
".*:" ), QString() );
54 QString tag2 = element2.tagName();
55 tag2.replace( QRegularExpression(
".*:" ), QString() );
58 qDebug(
"Different tag names: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
62 if ( element1.hasAttributes() != element2.hasAttributes() )
64 qDebug(
"Different hasAttributes: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
68 if ( element1.hasAttributes() )
70 const QDomNamedNodeMap attrs1 = element1.attributes();
71 const QDomNamedNodeMap attrs2 = element2.attributes();
73 if ( attrs1.size() != attrs2.size() )
75 qDebug(
"Different attributes size: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
79 for (
int i = 0; i < attrs1.size(); ++i )
81 const QDomNode node1 = attrs1.item( i );
82 const QDomAttr attr1 = node1.toAttr();
84 if ( !element2.hasAttribute( attr1.name() ) )
86 qDebug(
"Element2 has not attribute: %s, %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data(), attr1.name().toLatin1().data() );
90 if ( element2.attribute( attr1.name() ) != attr1.value() )
92 qDebug(
"Element2 attribute has not the same value: %s, %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data(), attr1.name().toLatin1().data() );
98 if ( element1.hasChildNodes() != element2.hasChildNodes() )
100 qDebug(
"Different childNodes: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
104 if ( element1.hasChildNodes() )
106 const QDomNodeList nodes1 = element1.childNodes();
107 const QDomNodeList nodes2 = element2.childNodes();
109 if ( nodes1.size() != nodes2.size() )
111 qDebug(
"Different childNodes size: %s, %s", tag1.toLatin1().data(), tag2.toLatin1().data() );
115 for (
int i = 0; i < nodes1.size(); ++i )
117 const QDomNode node1 = nodes1.at( i );
118 const QDomNode node2 = nodes2.at( i );
119 if ( node1.isElement() && node2.isElement() )
121 QDomElement elt1 = node1.toElement();
122 QDomElement elt2 = node2.toElement();
124 if ( !compareDomElements( elt1, elt2 ) )
127 else if ( node1.isText() && node2.isText() )
129 const QDomText txt1 = node1.toText();
130 const QDomText txt2 = node2.toText();
132 if ( txt1.data() != txt2.data() )
134 qDebug(
"Different text data: %s %s", tag1.toLatin1().data(), txt1.data().toLatin1().data() );
135 qDebug(
"Different text data: %s %s", tag2.toLatin1().data(), txt2.data().toLatin1().data() );
142 if ( element1.text() != element2.text() )
144 qDebug(
"Different text: %s %s", tag1.toLatin1().data(), element1.text().toLatin1().data() );
145 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.
This class 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...
This is the base class for vector data providers.
virtual QgsAbstractFeatureSource * featureSource() const =0
Returns feature source object that can be used for querying provider's data.