From: <mh...@us...> - 2005-11-10 22:22:38
|
Update of /cvsroot/qgis/qgis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6765/src Modified Files: qgsvectorlayer.cpp Log Message: Changed definition of symbology compatibility for vector layers, some legend cleanups Index: qgsvectorlayer.cpp =================================================================== RCS file: /cvsroot/qgis/qgis/src/qgsvectorlayer.cpp,v retrieving revision 1.231 retrieving revision 1.232 diff -C2 -d -r1.231 -r1.232 *** qgsvectorlayer.cpp 9 Nov 2005 01:48:59 -0000 1.231 --- qgsvectorlayer.cpp 10 Nov 2005 22:22:25 -0000 1.232 *************** *** 2858,2899 **** bool QgsVectorLayer::isSymbologyCompatible(const QgsMapLayer& other) const { ! const QgsVectorLayer* vl = dynamic_cast<const QgsVectorLayer*>(&other); ! if(!vl) ! { ! return false; ! } ! ! //vector type must be the same ! if(vectorType() != vl->vectorType()) ! { ! return false; ! } ! //attributes must be the same ! if(dataProvider && vl->dataProvider) { ! const std::vector<QgsField> fields1 = dataProvider->fields(); ! const std::vector<QgsField> fields2 = vl->dataProvider->fields(); ! ! if(fields1.size() != fields2.size()) ! { ! return false; ! } ! //compare if equal ! std::vector<QgsField>::const_iterator it1; ! std::vector<QgsField>::const_iterator it2; ! for(it1 = fields1.begin(), it2 = fields2.begin(); (it1 != fields1.end())&&(it2 != fields2.end()); ++it1, ++it2) ! { ! if( *it1 != *it2) ! { ! return false; ! } ! } ! return true; ! } ! else ! { ! return false; } } --- 2858,2918 ---- bool QgsVectorLayer::isSymbologyCompatible(const QgsMapLayer& other) const { ! //vector layers are symbology compatible if they have the same sequence of numerical/ non numerical fields and the same field names ! ! const QgsVectorLayer* otherVectorLayer = dynamic_cast<const QgsVectorLayer*>(&other); ! if(otherVectorLayer) { ! const std::vector<QgsField> fieldsThis = dataProvider->fields(); ! const std::vector<QgsField> fieldsOther = otherVectorLayer ->dataProvider->fields(); ! if(fieldsThis.size() != fieldsOther.size()) ! { ! return false; ! } ! ! //fill two sets with the numerical types for both layers ! const std::list<QString> numAttThis = dataProvider->numericalTypes(); ! std::set<QString> numericalThis; //the set of numerical types for this vector layer ! for(std::list<QString>::const_iterator it = numAttThis.begin(); it != numAttThis.end(); ++it) ! { ! numericalThis.insert(*it); ! } ! ! const std::list<QString> numAttOther = otherVectorLayer ->dataProvider->numericalTypes(); ! std::set<QString> numericalOther; //the set of numerical types for the other vector layer ! for(std::list<QString>::const_iterator it = numAttOther.begin(); it != numAttOther.end(); ++it) ! { ! numericalOther.insert(*it); ! } ! ! std::set<QString>::const_iterator thisiter; ! std::set<QString>::const_iterator otheriter; ! ! for(int i = 0; i < fieldsThis.size(); ++i) ! { ! if(fieldsThis[i].name() != fieldsOther[i].name())//field names need to be the same ! { ! return false; ! } ! thisiter = numericalThis.find(fieldsThis[i].name()); ! otheriter = numericalOther.find(fieldsOther[i].name()); ! if(thisiter == numericalThis.end()) ! { ! if(otheriter != numericalOther.end()) ! { ! return false; ! } ! } ! else ! { ! if(otheriter == numericalOther.end()) ! { ! return false; ! } ! } ! } ! return true; //layers are symbology compatible if the code reaches this point } + return false; } |