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 stream.setCodec(
"UTF-8" );
123 symEl.save( stream, 4 );
124 char *query = sqlite3_mprintf(
"INSERT INTO symbol VALUES (NULL, '%q', '%q', %d);",
125 name.toUtf8().constData(), xmlArray.constData(), groupid );
129 QgsDebugMsg(
"Couldn't insert symbol into the database!" );
149 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
156 QgsDebugMsg(
"No such symbol for deleting in database: " + name +
". Cheers." );
167 return symbol ? symbol->
clone() : 0;
188 if ( !colorRamp || name.isEmpty() )
216 QDomDocument doc(
"dummy" );
218 if ( rampEl.isNull() )
220 QgsDebugMsg(
"Couldn't convert color ramp to valid XML!" );
225 QTextStream stream( &xmlArray );
226 stream.setCodec(
"UTF-8" );
227 rampEl.save( stream, 4 );
228 char *query = sqlite3_mprintf(
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
229 name.toUtf8().constData(), xmlArray.constData(), groupid );
233 QgsDebugMsg(
"Couldn't insert colorramp into the database!" );
246 char *query = sqlite3_mprintf(
"DELETE FROM colorramp WHERE name='%q'", name.toUtf8().constData() );
249 QgsDebugMsg(
"Couldn't remove color ramp from the database." );
261 return ramp ? ramp->
clone() : 0;
281 int rc = sqlite3_open( filename.toUtf8(), &
mCurrentDB );
297 if ( !
openDB( filename ) )
299 mErrorString =
"Unable to open database file specified";
305 char *query = sqlite3_mprintf(
"UPDATE symbol SET groupid=0 WHERE groupid IS NULL;"
306 "UPDATE colorramp SET groupid=0 WHERE groupid IS NULL;"
307 "UPDATE symgroup SET parent=0 WHERE parent IS NULL;" );
311 query = sqlite3_mprintf(
"SELECT * FROM symbol" );
313 sqlite3_stmt *ppStmt;
314 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
315 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
318 QString symbol_name = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymbolName ) );
319 QString xmlstring = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymbolXML ) );
320 if ( !doc.setContent( xmlstring ) )
322 QgsDebugMsg(
"Cannot open symbol " + symbol_name );
326 QDomElement symElement = doc.documentElement();
328 if ( symbol != NULL )
329 mSymbols.insert( symbol_name, symbol );
332 sqlite3_finalize( ppStmt );
334 query = sqlite3_mprintf(
"SELECT * FROM colorramp" );
335 nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
336 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
339 QString ramp_name = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
ColorrampName ) );
340 QString xmlstring = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
ColorrampXML ) );
341 if ( !doc.setContent( xmlstring ) )
346 QDomElement rampElement = doc.documentElement();
362 if ( filename.isEmpty() )
368 QDomDocument doc(
"qgis_style" );
369 QDomElement root = doc.createElement(
"qgis_style" );
371 doc.appendChild( root );
375 QDomElement rampsElem = doc.createElement(
"colorramps" );
378 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
381 rampsElem.appendChild( rampEl );
384 root.appendChild( symbolsElem );
385 root.appendChild( rampsElem );
389 if ( !f.open( QFile::WriteOnly ) )
391 mErrorString =
"Couldn't open file for writing: " + filename;
394 QTextStream ts( &f );
395 ts.setCodec(
"UTF-8" );
414 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
421 QgsDebugMsg(
"No such symbol for tagging in database: " + oldName );
439 sqlite3_stmt *ppStmt;
440 char *query = sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", oldName.toUtf8().constData() );
441 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
442 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
444 rampid = sqlite3_column_int( ppStmt, 0 );
446 sqlite3_finalize( ppStmt );
455 sqlite3_stmt *ppStmt;
456 const char *query =
"SELECT * FROM symgroup";
457 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
458 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
460 groupNames << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymgroupName ) );
462 sqlite3_finalize( ppStmt );
471 QgsDebugMsg(
"Cannot open database for listing groups" );
477 sqlite3_stmt *ppStmt;
480 if ( parent ==
"" || parent == QString() )
482 query = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE parent=0" );
486 char *subquery = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE name='%q'", parent.toUtf8().constData() );
487 nError = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt, NULL );
488 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
490 query = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE parent=%d", sqlite3_column_int( ppStmt,
SymgroupId ) );
492 sqlite3_finalize( ppStmt );
501 nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
502 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
504 QString
group = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymgroupName ) );
505 groupNames.insert( sqlite3_column_int( ppStmt,
SymgroupId ), group );
508 sqlite3_finalize( ppStmt );
517 QgsDebugMsg( QString(
"Cannot Open database for getting group symbols of groupid: %1" ).arg( groupid ) );
518 return QStringList();
524 query = sqlite3_mprintf(
"SELECT name FROM symbol WHERE groupid=%d", groupid );
528 query = sqlite3_mprintf(
"SELECT name FROM colorramp WHERE groupid=%d", groupid );
533 return QStringList();
536 sqlite3_stmt *ppStmt;
537 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
540 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
542 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
545 sqlite3_finalize( ppStmt );
554 QgsDebugMsg( QString(
"Cannot open database to get symbols of tagid %1" ).arg( tagid ) );
555 return QStringList();
561 subquery = sqlite3_mprintf(
"SELECT symbol_id FROM tagmap WHERE tag_id=%d", tagid );
565 subquery = sqlite3_mprintf(
"SELECT symbol_id FROM ctagmap WHERE tag_id=%d", tagid );
570 return QStringList();
573 sqlite3_stmt *ppStmt;
574 int nErr = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt, NULL );
578 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
580 int symbolId = sqlite3_column_int( ppStmt, 0 );
583 ? sqlite3_mprintf(
"SELECT name FROM symbol WHERE id=%d", symbolId )
584 : sqlite3_mprintf(
"SELECT name FROM colorramp WHERE id=%d", symbolId );
586 sqlite3_stmt *ppStmt2;
587 int sErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt2, NULL );
588 while ( sErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
590 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt2, 0 ) );
592 sqlite3_finalize( ppStmt2 );
594 sqlite3_finalize( ppStmt );
604 char *query = sqlite3_mprintf(
"INSERT INTO symgroup VALUES (NULL, '%q', %d)", groupName.toUtf8().constData(), parentid );
606 sqlite3_stmt *ppStmt;
607 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
608 if ( nErr == SQLITE_OK )
609 sqlite3_step( ppStmt );
611 sqlite3_finalize( ppStmt );
613 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
620 sqlite3_stmt *ppStmt;
622 char *query = sqlite3_mprintf(
"INSERT INTO tag VALUES (NULL, '%q')", tagname.toUtf8().constData() );
623 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
624 if ( nErr == SQLITE_OK )
625 sqlite3_step( ppStmt );
626 sqlite3_finalize( ppStmt );
628 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
637 query = sqlite3_mprintf(
"UPDATE symbol SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
640 query = sqlite3_mprintf(
"UPDATE symgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
643 query = sqlite3_mprintf(
"UPDATE tag SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
646 query = sqlite3_mprintf(
"UPDATE colorramp SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
649 query = sqlite3_mprintf(
"UPDATE smartgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
661 char *query = sqlite3_mprintf(
"SELECT parent FROM symgroup WHERE id=%d",
id );
663 sqlite3_stmt *ppStmt;
664 int err = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
667 if ( err == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
668 parentid = sqlite3_column_int( ppStmt, 0 );
670 sqlite3_finalize( ppStmt );
672 return sqlite3_mprintf(
"UPDATE symbol SET groupid=%d WHERE groupid=%d;"
673 "UPDATE symgroup SET parent=%d WHERE parent=%d;"
674 "DELETE FROM symgroup WHERE id=%d", parentid,
id, parentid,
id,
id );
683 query = sqlite3_mprintf(
"DELETE FROM symbol WHERE id=%d; DELETE FROM tagmap WHERE symbol_id=%d",
id,
id );
689 query = sqlite3_mprintf(
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d",
id,
id );
692 query = sqlite3_mprintf(
"DELETE FROM colorramp WHERE id=%d",
id );
695 query = sqlite3_mprintf(
"DELETE FROM smartgroup WHERE id=%d",
id );
714 int nErr = sqlite3_exec(
mCurrentDB, query, NULL, NULL, &zErr );
718 sqlite3_free( query );
721 if ( nErr != SQLITE_OK )
726 return zErr == SQLITE_OK;
736 query = sqlite3_mprintf(
"UPDATE symbol SET groupid=%d WHERE name='%q'", groupid, name.toUtf8().constData() );
739 query = sqlite3_mprintf(
"UPDATE colorramp SET groupid=%d WHERE name='%q'", groupid, name.toUtf8().constData() );
743 QgsDebugMsg(
"Wrong entity value. cannot apply group" );
754 QgsDebugMsg(
"Sorry! Cannot open database to search" );
755 return QStringList();
758 QString item = ( type ==
SymbolEntity ) ?
"symbol" :
"colorramp";
759 char *query = sqlite3_mprintf(
"SELECT name FROM %q WHERE xml LIKE '%%%q%%'",
760 item.toUtf8().constData(), qword.toUtf8().constData() );
762 sqlite3_stmt *ppStmt;
763 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
766 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
768 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
771 sqlite3_finalize( ppStmt );
773 query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.toUtf8().constData() );
774 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
777 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
779 tagids << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
782 sqlite3_finalize( ppStmt );
785 QString dummy = tagids.join(
", " );
789 query = sqlite3_mprintf(
"SELECT symbol_id FROM tagmap WHERE tag_id IN (%q)",
790 dummy.toUtf8().constData() );
794 query = sqlite3_mprintf(
"SELECT colorramp_id FROM ctagmap WHERE tag_id IN (%q)",
795 dummy.toUtf8().constData() );
797 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
799 QStringList symbolids;
800 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
802 symbolids << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
805 sqlite3_finalize( ppStmt );
808 dummy = symbolids.join(
", " );
809 query = sqlite3_mprintf(
"SELECT name FROM %q WHERE id IN (%q)",
810 item.toUtf8().constData(), dummy.toUtf8().constData() );
811 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
812 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
814 QString symbolName = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
815 if ( !symbols.contains( symbolName ) )
816 symbols << symbolName;
819 sqlite3_finalize( ppStmt );
828 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
835 QgsDebugMsg(
"No such symbol for tagging in database: " + symbol );
840 foreach (
const QString &tag, tags )
843 char *query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name='%q'", tag.toUtf8().constData() );
845 sqlite3_stmt *ppStmt;
846 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
849 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
851 tagid = sqlite3_column_int( ppStmt, 0 );
858 sqlite3_finalize( ppStmt );
862 ? sqlite3_mprintf(
"INSERT INTO tagmap VALUES (%d,%d)", tagid, symbolid )
863 : sqlite3_mprintf(
"INSERT INTO ctagmap VALUES (%d,%d)", tagid, symbolid );
866 nErr = sqlite3_exec(
mCurrentDB, query, NULL, NULL, &zErr );
880 QgsDebugMsg(
"Sorry! Cannot open database for detgging." );
885 ? sqlite3_mprintf(
"SELECT id FROM symbol WHERE name='%q'", symbol.toUtf8().constData() )
886 : sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", symbol.toUtf8().constData() );
887 sqlite3_stmt *ppStmt;
888 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
891 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
893 symbolid = sqlite3_column_int( ppStmt, 0 );
896 sqlite3_finalize( ppStmt );
898 foreach (
const QString &tag, tags )
900 query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name='%q'", tag.toUtf8().constData() );
902 sqlite3_stmt *ppStmt2;
903 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt2, NULL );
906 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
908 tagid = sqlite3_column_int( ppStmt2, 0 );
911 sqlite3_finalize( ppStmt2 );
917 ? sqlite3_mprintf(
"DELETE FROM tagmap WHERE tag_id=%d AND symbol_id=%d", tagid, symbolid )
918 : sqlite3_mprintf(
"DELETE FROM ctagmap WHERE tag_id=%d AND colorramp_id=%d", tagid, symbolid );
933 QgsDebugMsg(
"Sorry! Cannot open database for getting the tags." );
934 return QStringList();
939 return QStringList();
943 ? sqlite3_mprintf(
"SELECT tag_id FROM tagmap WHERE symbol_id=%d", symbolid )
944 : sqlite3_mprintf(
"SELECT tag_id FROM ctagmap WHERE colorramp_id=%d", symbolid );
946 sqlite3_stmt *ppStmt;
947 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
950 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
952 char *subquery = sqlite3_mprintf(
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( ppStmt, 0 ) );
954 sqlite3_stmt *ppStmt2;
955 int pErr = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt2, NULL );
956 if ( pErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
958 tagList << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt2, 0 ) );
960 sqlite3_finalize( ppStmt2 );
963 sqlite3_finalize( ppStmt );
970 char *query = sqlite3_mprintf(
"SELECT id FROM %q WHERE name='%q'", table.toUtf8().constData(), name.toUtf8().constData() );
972 sqlite3_stmt *ppStmt;
973 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
976 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
978 id = sqlite3_column_int( ppStmt, 0 );
981 sqlite3_finalize( ppStmt );
988 return getId(
"symbol", name );
993 return getId(
"colorramp", name );
998 return getId(
"symgroup", name );
1003 return getId(
"tag", name );
1008 return getId(
"smartgroup", name );
1013 QDomDocument doc(
"dummy" );
1014 QDomElement smartEl = doc.createElement(
"smartgroup" );
1015 smartEl.setAttribute(
"name", name );
1016 smartEl.setAttribute(
"operator", op );
1018 QStringList constraints;
1019 constraints <<
"tag" <<
"group" <<
"name" <<
"!tag" <<
"!group" <<
"!name";
1021 foreach (
const QString &constraint, constraints )
1023 QStringList parameters = conditions.values( constraint );
1024 foreach (
const QString ¶m, parameters )
1026 QDomElement condEl = doc.createElement(
"condition" );
1027 condEl.setAttribute(
"constraint", constraint );
1028 condEl.setAttribute(
"param", param );
1029 smartEl.appendChild( condEl );
1033 QByteArray xmlArray;
1034 QTextStream stream( &xmlArray );
1035 stream.setCodec(
"UTF-8" );
1036 smartEl.save( stream, 4 );
1037 char *query = sqlite3_mprintf(
"INSERT INTO smartgroup VALUES (NULL, '%q', '%q')",
1038 name.toUtf8().constData(), xmlArray.constData() );
1042 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
1046 QgsDebugMsg(
"Couldn't insert symbol into the database!" );
1055 QgsDebugMsg(
"Cannot open database for listing groups" );
1059 char *query = sqlite3_mprintf(
"SELECT * FROM smartgroup" );
1062 sqlite3_stmt *ppStmt;
1063 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1066 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1068 QString
group = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SmartgroupName ) );
1069 groupNames.insert( sqlite3_column_int( ppStmt,
SmartgroupId ), group );
1072 sqlite3_finalize( ppStmt );
1081 QgsDebugMsg(
"Cannot open database for listing groups" );
1082 return QStringList();
1085 char *query = sqlite3_mprintf(
"SELECT name FROM smartgroup" );
1088 sqlite3_stmt *ppStmt;
1089 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1092 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1094 groups << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1097 sqlite3_finalize( ppStmt );
1104 QStringList symbols;
1106 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1108 sqlite3_stmt *ppStmt;
1109 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1110 if ( !( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW ) )
1112 sqlite3_finalize( ppStmt );
1113 return QStringList();
1118 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1119 if ( !doc.setContent( xmlstr ) )
1121 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1123 QDomElement smartEl = doc.documentElement();
1124 QString op = smartEl.attribute(
"operator" );
1125 QDomNodeList conditionNodes = smartEl.childNodes();
1127 bool firstSet =
true;
1128 for (
int i = 0; i < conditionNodes.count(); i++ )
1130 QDomElement condEl = conditionNodes.at( i ).toElement();
1131 QString constraint = condEl.attribute(
"constraint" );
1132 QString param = condEl.attribute(
"param" );
1134 QStringList resultNames;
1136 if ( constraint ==
"tag" )
1140 else if ( constraint ==
"group" )
1146 else if ( constraint ==
"name" )
1150 resultNames =
symbolNames().filter( param, Qt::CaseInsensitive );
1154 resultNames =
colorRampNames().filter( param, Qt::CaseInsensitive );
1157 else if ( constraint ==
"!tag" )
1161 foreach ( QString name, unwanted )
1163 resultNames.removeAll( name );
1166 else if ( constraint ==
"!group" )
1170 foreach ( QString name, unwanted )
1172 resultNames.removeAll( name );
1175 else if ( constraint ==
"!name" )
1178 foreach (
const QString &str, all )
1180 if ( !str.contains( param, Qt::CaseInsensitive ) )
1188 symbols = resultNames;
1195 symbols << resultNames;
1197 else if ( op ==
"AND" )
1199 QStringList dummy = symbols;
1201 foreach (
const QString &result, resultNames )
1203 if ( dummy.contains( result ) )
1211 sqlite3_finalize( ppStmt );
1220 QgsDebugMsg(
"Cannot open database for listing groups" );
1226 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1228 sqlite3_stmt *ppStmt;
1229 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1230 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1233 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1234 if ( !doc.setContent( xmlstr ) )
1236 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1239 QDomElement smartEl = doc.documentElement();
1240 QString op = smartEl.attribute(
"operator" );
1241 QDomNodeList conditionNodes = smartEl.childNodes();
1243 for (
int i = 0; i < conditionNodes.count(); i++ )
1245 QDomElement condEl = conditionNodes.at( i ).toElement();
1246 QString constraint = condEl.attribute(
"constraint" );
1247 QString param = condEl.attribute(
"param" );
1249 condition.insert( constraint, param );
1253 sqlite3_finalize( ppStmt );
1262 QgsDebugMsg(
"Cannot open database for listing groups" );
1268 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1270 sqlite3_stmt *ppStmt;
1271 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1272 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1275 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1276 if ( !doc.setContent( xmlstr ) )
1278 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1280 QDomElement smartEl = doc.documentElement();
1281 op = smartEl.attribute(
"operator" );
1284 sqlite3_finalize( ppStmt );
1291 if ( filename.isEmpty() )
1293 QgsDebugMsg(
"Invalid filename for style export." );
1297 QDomDocument doc(
"qgis_style" );
1298 QDomElement root = doc.createElement(
"qgis_style" );
1300 doc.appendChild( root );
1304 QDomElement rampsElem = doc.createElement(
"colorramps" );
1307 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
1310 rampsElem.appendChild( rampEl );
1313 root.appendChild( symbolsElem );
1314 root.appendChild( rampsElem );
1317 QFile f( filename );
1318 if ( !f.open( QFile::WriteOnly ) )
1320 mErrorString =
"Couldn't open file for writing: " + filename;
1324 QTextStream ts( &f );
1325 ts.setCodec(
"UTF-8" );
1336 QDomDocument doc(
"style" );
1337 QFile f( filename );
1338 if ( !f.open( QFile::ReadOnly ) )
1341 QgsDebugMsg(
"Error opening the style XML file." );
1345 if ( !doc.setContent( &f ) )
1347 mErrorString = QString(
"Unable to understand the style file: %1" ).arg( filename );
1354 QDomElement docEl = doc.documentElement();
1355 if ( docEl.tagName() !=
"qgis_style" )
1357 mErrorString =
"Incorrect root tag in style: " + docEl.tagName();
1361 QString version = docEl.attribute(
"version" );
1364 mErrorString =
"Unknown style file version: " + version;
1370 QDomElement symbolsElement = docEl.firstChildElement(
"symbols" );
1371 QDomElement e = symbolsElement.firstChildElement();
1376 while ( !e.isNull() )
1378 if ( e.tagName() ==
"symbol" )
1383 symbols.insert( e.attribute(
"name" ),
symbol );
1390 e = e.nextSiblingElement();
1400 for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
1406 QDomElement rampsElement = docEl.firstChildElement(
"colorramps" );
1407 e = rampsElement.firstChildElement();
1408 while ( !e.isNull() )
1410 if ( e.tagName() ==
"colorramp" )
1422 e = e.nextSiblingElement();
1431 QDomDocument doc(
"dummy" );
1433 QByteArray xmlArray;
1434 QTextStream stream( &xmlArray );
1435 stream.setCodec(
"UTF-8" );
1444 QgsDebugMsg(
"Update request received for unavailable symbol" );
1449 if ( symEl.isNull() )
1451 QgsDebugMsg(
"Couldn't convert symbol to valid XML!" );
1454 symEl.save( stream, 4 );
1455 query = sqlite3_mprintf(
"UPDATE symbol SET xml='%q' WHERE name='%q';",
1456 xmlArray.constData(), name.toUtf8().constData() );
1462 QgsDebugMsg(
"Update requested for unavailable color ramp." );
1467 if ( symEl.isNull() )
1469 QgsDebugMsg(
"Couldn't convert color ramp to valid XML!" );
1472 symEl.save( stream, 4 );
1473 query = sqlite3_mprintf(
"UPDATE colorramp SET xml='%q' WHERE name='%q';",
1474 xmlArray.constData(), name.toUtf8().constData() );
1478 QgsDebugMsg(
"Updating the unsupported StyleEntity" );
1485 QgsDebugMsg(
"Couldn't insert symbol into the database!" );