26 #include <QDomDocument>
27 #include <QDomElement>
29 #include <QDomNodeList>
31 #include <QTextStream>
36 #define STYLE_CURRENT_VERSION "1"
58 if ( !QFile::exists( styleFilename ) )
72 for ( QMap<QString, QgsSymbolV2*>::iterator its =
mSymbols.begin(); its !=
mSymbols.end(); ++its )
74 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
85 if ( !symbol || name.isEmpty() )
112 QDomDocument doc(
"dummy" );
114 if ( symEl.isNull() )
116 QgsDebugMsg(
"Couldn't convert symbol to valid XML!" );
121 QTextStream stream( &xmlArray );
122 symEl.save( stream, 4 );
123 char *query = sqlite3_mprintf(
"INSERT INTO symbol VALUES (NULL, '%q', '%q', %d);",
124 name.toUtf8().constData(), xmlArray.constData(), groupid );
128 QgsDebugMsg(
"Couldn't insert symbol into the database!" );
148 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
155 QgsDebugMsg(
"No such symbol for deleting in database: " + name +
". Cheers." );
166 return symbol ? symbol->
clone() : 0;
187 if ( !colorRamp || name.isEmpty() )
215 QDomDocument doc(
"dummy" );
217 if ( rampEl.isNull() )
219 QgsDebugMsg(
"Couldn't convert color ramp to valid XML!" );
224 QTextStream stream( &xmlArray );
225 rampEl.save( stream, 4 );
226 char *query = sqlite3_mprintf(
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
227 name.toUtf8().constData(), xmlArray.constData(), groupid );
231 QgsDebugMsg(
"Couldn't insert colorramp into the database!" );
244 char *query = sqlite3_mprintf(
"DELETE FROM colorramp WHERE name='%q'", name.toUtf8().constData() );
247 QgsDebugMsg(
"Couldn't remove color ramp from the database." );
259 return ramp ? ramp->
clone() : 0;
279 int rc = sqlite3_open( filename.toUtf8(), &
mCurrentDB );
295 if ( !
openDB( filename ) )
297 mErrorString =
"Unable to open database file specified";
303 char *query = sqlite3_mprintf(
"UPDATE symbol SET groupid=0 WHERE groupid IS NULL;"
304 "UPDATE colorramp SET groupid=0 WHERE groupid IS NULL;"
305 "UPDATE symgroup SET parent=0 WHERE parent IS NULL;" );
309 query = sqlite3_mprintf(
"SELECT * FROM symbol" );
311 sqlite3_stmt *ppStmt;
312 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
313 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
316 QString symbol_name = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymbolName ) );
317 QString xmlstring = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymbolXML ) );
318 if ( !doc.setContent( xmlstring ) )
320 QgsDebugMsg(
"Cannot open symbol " + symbol_name );
324 QDomElement symElement = doc.documentElement();
326 if ( symbol != NULL )
327 mSymbols.insert( symbol_name, symbol );
330 sqlite3_finalize( ppStmt );
332 query = sqlite3_mprintf(
"SELECT * FROM colorramp" );
333 nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
334 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
337 QString ramp_name = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
ColorrampName ) );
338 QString xmlstring = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
ColorrampXML ) );
339 if ( !doc.setContent( xmlstring ) )
344 QDomElement rampElement = doc.documentElement();
360 if ( filename.isEmpty() )
366 QDomDocument doc(
"qgis_style" );
367 QDomElement root = doc.createElement(
"qgis_style" );
369 doc.appendChild( root );
373 QDomElement rampsElem = doc.createElement(
"colorramps" );
376 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
379 rampsElem.appendChild( rampEl );
382 root.appendChild( symbolsElem );
383 root.appendChild( rampsElem );
387 if ( !f.open( QFile::WriteOnly ) )
389 mErrorString =
"Couldn't open file for writing: " + filename;
392 QTextStream ts( &f );
411 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
418 QgsDebugMsg(
"No such symbol for tagging in database: " + oldName );
436 sqlite3_stmt *ppStmt;
437 char *query = sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", oldName.toUtf8().constData() );
438 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
439 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
441 rampid = sqlite3_column_int( ppStmt, 0 );
443 sqlite3_finalize( ppStmt );
452 sqlite3_stmt *ppStmt;
453 const char *query =
"SELECT * FROM symgroup";
454 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
455 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
457 groupNames << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymgroupName ) );
459 sqlite3_finalize( ppStmt );
468 QgsDebugMsg(
"Cannot open database for listing groups" );
474 sqlite3_stmt *ppStmt;
477 if ( parent ==
"" || parent == QString() )
479 query = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE parent=0" );
483 char *subquery = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE name='%q'", parent.toUtf8().constData() );
484 nError = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt, NULL );
485 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
487 query = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE parent=%d", sqlite3_column_int( ppStmt,
SymgroupId ) );
489 sqlite3_finalize( ppStmt );
498 nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
499 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
501 QString
group = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymgroupName ) );
502 groupNames.insert( sqlite3_column_int( ppStmt,
SymgroupId ), group );
505 sqlite3_finalize( ppStmt );
514 QgsDebugMsg( QString(
"Cannot Open database for getting group symbols of groupid: %1" ).arg( groupid ) );
515 return QStringList();
521 query = sqlite3_mprintf(
"SELECT name FROM symbol WHERE groupid=%d", groupid );
525 query = sqlite3_mprintf(
"SELECT name FROM colorramp WHERE groupid=%d", groupid );
530 return QStringList();
533 sqlite3_stmt *ppStmt;
534 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
537 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
539 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
542 sqlite3_finalize( ppStmt );
551 QgsDebugMsg( QString(
"Cannot open database to get symbols of tagid %1" ).arg( tagid ) );
552 return QStringList();
558 subquery = sqlite3_mprintf(
"SELECT symbol_id FROM tagmap WHERE tag_id=%d", tagid );
562 subquery = sqlite3_mprintf(
"SELECT symbol_id FROM ctagmap WHERE tag_id=%d", tagid );
567 return QStringList();
570 sqlite3_stmt *ppStmt;
571 int nErr = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt, NULL );
575 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
577 int symbolId = sqlite3_column_int( ppStmt, 0 );
580 ? sqlite3_mprintf(
"SELECT name FROM symbol WHERE id=%d", symbolId )
581 : sqlite3_mprintf(
"SELECT name FROM colorramp WHERE id=%d", symbolId );
583 sqlite3_stmt *ppStmt2;
584 int sErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt2, NULL );
585 while ( sErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
587 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt2, 0 ) );
589 sqlite3_finalize( ppStmt2 );
591 sqlite3_finalize( ppStmt );
601 char *query = sqlite3_mprintf(
"INSERT INTO symgroup VALUES (NULL, '%q', %d)", groupName.toUtf8().constData(), parentid );
603 sqlite3_stmt *ppStmt;
604 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
605 if ( nErr == SQLITE_OK )
606 sqlite3_step( ppStmt );
608 sqlite3_finalize( ppStmt );
610 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
617 sqlite3_stmt *ppStmt;
619 char *query = sqlite3_mprintf(
"INSERT INTO tag VALUES (NULL, '%q')", tagname.toUtf8().constData() );
620 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
621 if ( nErr == SQLITE_OK )
622 sqlite3_step( ppStmt );
623 sqlite3_finalize( ppStmt );
625 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
634 query = sqlite3_mprintf(
"UPDATE symbol SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
637 query = sqlite3_mprintf(
"UPDATE symgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
640 query = sqlite3_mprintf(
"UPDATE tag SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
643 query = sqlite3_mprintf(
"UPDATE colorramp SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
646 query = sqlite3_mprintf(
"UPDATE smartgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
658 char *query = sqlite3_mprintf(
"SELECT parent FROM symgroup WHERE id=%d",
id );
660 sqlite3_stmt *ppStmt;
661 int err = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
664 if ( err == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
665 parentid = sqlite3_column_int( ppStmt, 0 );
667 sqlite3_finalize( ppStmt );
669 return sqlite3_mprintf(
"UPDATE symbol SET groupid=%d WHERE groupid=%d;"
670 "UPDATE symgroup SET parent=%d WHERE parent=%d;"
671 "DELETE FROM symgroup WHERE id=%d", parentid,
id, parentid,
id,
id );
680 query = sqlite3_mprintf(
"DELETE FROM symbol WHERE id=%d; DELETE FROM tagmap WHERE symbol_id=%d",
id,
id );
686 query = sqlite3_mprintf(
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d",
id,
id );
689 query = sqlite3_mprintf(
"DELETE FROM colorramp WHERE id=%d",
id );
692 query = sqlite3_mprintf(
"DELETE FROM smartgroup WHERE id=%d",
id );
711 int nErr = sqlite3_exec(
mCurrentDB, query, NULL, NULL, &zErr );
715 sqlite3_free( query );
718 if ( nErr != SQLITE_OK )
723 return zErr == SQLITE_OK;
733 query = sqlite3_mprintf(
"UPDATE symbol SET groupid=%d WHERE name='%q'", groupid, name.toUtf8().constData() );
736 query = sqlite3_mprintf(
"UPDATE colorramp SET groupid=%d WHERE name='%q'", groupid, name.toUtf8().constData() );
740 QgsDebugMsg(
"Wrong entity value. cannot apply group" );
751 QgsDebugMsg(
"Sorry! Cannot open database to search" );
752 return QStringList();
755 QString item = ( type ==
SymbolEntity ) ?
"symbol" :
"colorramp";
756 char *query = sqlite3_mprintf(
"SELECT name FROM %q WHERE xml LIKE '%%%q%%'",
757 item.toUtf8().constData(), qword.toUtf8().constData() );
759 sqlite3_stmt *ppStmt;
760 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
763 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
765 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
768 sqlite3_finalize( ppStmt );
770 query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.toUtf8().constData() );
771 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
774 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
776 tagids << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
779 sqlite3_finalize( ppStmt );
782 QString dummy = tagids.join(
", " );
786 query = sqlite3_mprintf(
"SELECT symbol_id FROM tagmap WHERE tag_id IN (%q)",
787 dummy.toUtf8().constData() );
791 query = sqlite3_mprintf(
"SELECT colorramp_id FROM ctagmap WHERE tag_id IN (%q)",
792 dummy.toUtf8().constData() );
794 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
796 QStringList symbolids;
797 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
799 symbolids << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
802 sqlite3_finalize( ppStmt );
805 dummy = symbolids.join(
", " );
806 query = sqlite3_mprintf(
"SELECT name FROM %q WHERE id IN (%q)",
807 item.toUtf8().constData(), dummy.toUtf8().constData() );
808 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
809 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
811 QString symbolName = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
812 if ( !symbols.contains( symbolName ) )
813 symbols << symbolName;
816 sqlite3_finalize( ppStmt );
825 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
832 QgsDebugMsg(
"No such symbol for tagging in database: " + symbol );
837 foreach (
const QString &tag, tags )
840 char *query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name='%q'", tag.toUtf8().constData() );
842 sqlite3_stmt *ppStmt;
843 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
846 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
848 tagid = sqlite3_column_int( ppStmt, 0 );
855 sqlite3_finalize( ppStmt );
859 ? sqlite3_mprintf(
"INSERT INTO tagmap VALUES (%d,%d)", tagid, symbolid )
860 : sqlite3_mprintf(
"INSERT INTO ctagmap VALUES (%d,%d)", tagid, symbolid );
863 nErr = sqlite3_exec(
mCurrentDB, query, NULL, NULL, &zErr );
877 QgsDebugMsg(
"Sorry! Cannot open database for detgging." );
882 ? sqlite3_mprintf(
"SELECT id FROM symbol WHERE name='%q'", symbol.toUtf8().constData() )
883 : sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", symbol.toUtf8().constData() );
884 sqlite3_stmt *ppStmt;
885 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
888 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
890 symbolid = sqlite3_column_int( ppStmt, 0 );
893 sqlite3_finalize( ppStmt );
895 foreach (
const QString &tag, tags )
897 query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name='%q'", tag.toUtf8().constData() );
899 sqlite3_stmt *ppStmt2;
900 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt2, NULL );
903 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
905 tagid = sqlite3_column_int( ppStmt2, 0 );
908 sqlite3_finalize( ppStmt2 );
914 ? sqlite3_mprintf(
"DELETE FROM tagmap WHERE tag_id=%d AND symbol_id=%d", tagid, symbolid )
915 : sqlite3_mprintf(
"DELETE FROM ctagmap WHERE tag_id=%d AND colorramp_id=%d", tagid, symbolid );
930 QgsDebugMsg(
"Sorry! Cannot open database for getting the tags." );
931 return QStringList();
936 return QStringList();
940 ? sqlite3_mprintf(
"SELECT tag_id FROM tagmap WHERE symbol_id=%d", symbolid )
941 : sqlite3_mprintf(
"SELECT tag_id FROM ctagmap WHERE colorramp_id=%d", symbolid );
943 sqlite3_stmt *ppStmt;
944 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
947 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
949 char *subquery = sqlite3_mprintf(
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( ppStmt, 0 ) );
951 sqlite3_stmt *ppStmt2;
952 int pErr = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt2, NULL );
953 if ( pErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
955 tagList << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt2, 0 ) );
957 sqlite3_finalize( ppStmt2 );
960 sqlite3_finalize( ppStmt );
967 char *query = sqlite3_mprintf(
"SELECT id FROM %q WHERE name='%q'", table.toUtf8().constData(), name.toUtf8().constData() );
969 sqlite3_stmt *ppStmt;
970 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
973 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
975 id = sqlite3_column_int( ppStmt, 0 );
978 sqlite3_finalize( ppStmt );
985 return getId(
"symbol", name );
990 return getId(
"colorramp", name );
995 return getId(
"symgroup", name );
1000 return getId(
"tag", name );
1005 return getId(
"smartgroup", name );
1010 QDomDocument doc(
"dummy" );
1011 QDomElement smartEl = doc.createElement(
"smartgroup" );
1012 smartEl.setAttribute(
"name", name );
1013 smartEl.setAttribute(
"operator", op );
1015 QStringList constraints;
1016 constraints <<
"tag" <<
"group" <<
"name" <<
"!tag" <<
"!group" <<
"!name";
1018 foreach (
const QString &constraint, constraints )
1020 QStringList parameters = conditions.values( constraint );
1021 foreach (
const QString ¶m, parameters )
1023 QDomElement condEl = doc.createElement(
"condition" );
1024 condEl.setAttribute(
"constraint", constraint );
1025 condEl.setAttribute(
"param", param );
1026 smartEl.appendChild( condEl );
1030 QByteArray xmlArray;
1031 QTextStream stream( &xmlArray );
1032 smartEl.save( stream, 4 );
1033 char *query = sqlite3_mprintf(
"INSERT INTO smartgroup VALUES (NULL, '%q', '%q')",
1034 name.toUtf8().constData(), xmlArray.constData() );
1038 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
1042 QgsDebugMsg(
"Couldn't insert symbol into the database!" );
1051 QgsDebugMsg(
"Cannot open database for listing groups" );
1055 char *query = sqlite3_mprintf(
"SELECT * FROM smartgroup" );
1058 sqlite3_stmt *ppStmt;
1059 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1062 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1064 QString
group = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SmartgroupName ) );
1065 groupNames.insert( sqlite3_column_int( ppStmt,
SmartgroupId ), group );
1068 sqlite3_finalize( ppStmt );
1077 QgsDebugMsg(
"Cannot open database for listing groups" );
1078 return QStringList();
1081 char *query = sqlite3_mprintf(
"SELECT name FROM smartgroup" );
1084 sqlite3_stmt *ppStmt;
1085 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1088 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1090 groups << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1093 sqlite3_finalize( ppStmt );
1100 QStringList symbols;
1102 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1104 sqlite3_stmt *ppStmt;
1105 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1106 if ( !( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW ) )
1108 sqlite3_finalize( ppStmt );
1109 return QStringList();
1114 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1115 if ( !doc.setContent( xmlstr ) )
1117 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1119 QDomElement smartEl = doc.documentElement();
1120 QString op = smartEl.attribute(
"operator" );
1121 QDomNodeList conditionNodes = smartEl.childNodes();
1123 bool firstSet =
true;
1124 for (
int i = 0; i < conditionNodes.count(); i++ )
1126 QDomElement condEl = conditionNodes.at( i ).toElement();
1127 QString constraint = condEl.attribute(
"constraint" );
1128 QString param = condEl.attribute(
"param" );
1130 QStringList resultNames;
1132 if ( constraint ==
"tag" )
1136 else if ( constraint ==
"group" )
1142 else if ( constraint ==
"name" )
1146 resultNames =
symbolNames().filter( param, Qt::CaseInsensitive );
1150 resultNames =
colorRampNames().filter( param, Qt::CaseInsensitive );
1153 else if ( constraint ==
"!tag" )
1157 foreach ( QString name, unwanted )
1159 resultNames.removeAll( name );
1162 else if ( constraint ==
"!group" )
1166 foreach ( QString name, unwanted )
1168 resultNames.removeAll( name );
1171 else if ( constraint ==
"!name" )
1174 foreach (
const QString &str, all )
1176 if ( !str.contains( param, Qt::CaseInsensitive ) )
1184 symbols = resultNames;
1191 symbols << resultNames;
1193 else if ( op ==
"AND" )
1195 QStringList dummy = symbols;
1197 foreach (
const QString &result, resultNames )
1199 if ( dummy.contains( result ) )
1207 sqlite3_finalize( ppStmt );
1216 QgsDebugMsg(
"Cannot open database for listing groups" );
1222 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1224 sqlite3_stmt *ppStmt;
1225 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1226 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1229 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1230 if ( !doc.setContent( xmlstr ) )
1232 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1235 QDomElement smartEl = doc.documentElement();
1236 QString op = smartEl.attribute(
"operator" );
1237 QDomNodeList conditionNodes = smartEl.childNodes();
1239 for (
int i = 0; i < conditionNodes.count(); i++ )
1241 QDomElement condEl = conditionNodes.at( i ).toElement();
1242 QString constraint = condEl.attribute(
"constraint" );
1243 QString param = condEl.attribute(
"param" );
1245 condition.insert( constraint, param );
1249 sqlite3_finalize( ppStmt );
1258 QgsDebugMsg(
"Cannot open database for listing groups" );
1264 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1266 sqlite3_stmt *ppStmt;
1267 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1268 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1271 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1272 if ( !doc.setContent( xmlstr ) )
1274 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1276 QDomElement smartEl = doc.documentElement();
1277 op = smartEl.attribute(
"operator" );
1280 sqlite3_finalize( ppStmt );
1287 if ( filename.isEmpty() )
1289 QgsDebugMsg(
"Invalid filename for style export." );
1293 QDomDocument doc(
"qgis_style" );
1294 QDomElement root = doc.createElement(
"qgis_style" );
1296 doc.appendChild( root );
1300 QDomElement rampsElem = doc.createElement(
"colorramps" );
1303 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
1306 rampsElem.appendChild( rampEl );
1309 root.appendChild( symbolsElem );
1310 root.appendChild( rampsElem );
1313 QFile f( filename );
1314 if ( !f.open( QFile::WriteOnly ) )
1316 mErrorString =
"Couldn't open file for writing: " + filename;
1320 QTextStream ts( &f );
1331 QDomDocument doc(
"style" );
1332 QFile f( filename );
1333 if ( !f.open( QFile::ReadOnly ) )
1336 QgsDebugMsg(
"Error opening the style XML file." );
1340 if ( !doc.setContent( &f ) )
1342 mErrorString = QString(
"Unable to understand the style file: %1" ).arg( filename );
1349 QDomElement docEl = doc.documentElement();
1350 if ( docEl.tagName() !=
"qgis_style" )
1352 mErrorString =
"Incorrect root tag in style: " + docEl.tagName();
1356 QString version = docEl.attribute(
"version" );
1359 mErrorString =
"Unknown style file version: " + version;
1365 QDomElement symbolsElement = docEl.firstChildElement(
"symbols" );
1366 QDomElement e = symbolsElement.firstChildElement();
1371 while ( !e.isNull() )
1373 if ( e.tagName() ==
"symbol" )
1378 symbols.insert( e.attribute(
"name" ),
symbol );
1385 e = e.nextSiblingElement();
1395 for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); it++ )
1401 QDomElement rampsElement = docEl.firstChildElement(
"colorramps" );
1402 e = rampsElement.firstChildElement();
1403 while ( !e.isNull() )
1405 if ( e.tagName() ==
"colorramp" )
1417 e = e.nextSiblingElement();
1426 QDomDocument doc(
"dummy" );
1428 QByteArray xmlArray;
1429 QTextStream stream( &xmlArray );
1438 QgsDebugMsg(
"Update request received for unavailable symbol" );
1443 if ( symEl.isNull() )
1445 QgsDebugMsg(
"Couldn't convert symbol to valid XML!" );
1448 symEl.save( stream, 4 );
1449 query = sqlite3_mprintf(
"UPDATE symbol SET xml='%q' WHERE name='%q';",
1450 xmlArray.constData(), name.toUtf8().constData() );
1456 QgsDebugMsg(
"Update requested for unavailable color ramp." );
1461 if ( symEl.isNull() )
1463 QgsDebugMsg(
"Couldn't convert color ramp to valid XML!" );
1466 symEl.save( stream, 4 );
1467 query = sqlite3_mprintf(
"UPDATE colorramp SET xml='%q' WHERE name='%q';",
1468 xmlArray.constData(), name.toUtf8().constData() );
1472 QgsDebugMsg(
"Updating the unsupported StyleEntity" );
1479 QgsDebugMsg(
"Couldn't insert symbol into the database!" );