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!" );
151 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
158 QgsDebugMsg(
"No such symbol for deleting in database: " + name +
". Cheers." );
169 return symbol ? symbol->
clone() : 0;
190 if ( !colorRamp || name.isEmpty() )
218 QDomDocument doc(
"dummy" );
220 if ( rampEl.isNull() )
222 QgsDebugMsg(
"Couldn't convert color ramp to valid XML!" );
227 QTextStream stream( &xmlArray );
228 stream.setCodec(
"UTF-8" );
229 rampEl.save( stream, 4 );
230 char *query = sqlite3_mprintf(
"INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
231 name.toUtf8().constData(), xmlArray.constData(), groupid );
235 QgsDebugMsg(
"Couldn't insert colorramp into the database!" );
248 char *query = sqlite3_mprintf(
"DELETE FROM colorramp WHERE name='%q'", name.toUtf8().constData() );
251 QgsDebugMsg(
"Couldn't remove color ramp from the database." );
263 return ramp ? ramp->
clone() : 0;
283 int rc = sqlite3_open( filename.toUtf8(), &
mCurrentDB );
299 if ( !
openDB( filename ) )
301 mErrorString =
"Unable to open database file specified";
307 char *query = sqlite3_mprintf(
"UPDATE symbol SET groupid=0 WHERE groupid IS NULL;"
308 "UPDATE colorramp SET groupid=0 WHERE groupid IS NULL;"
309 "UPDATE symgroup SET parent=0 WHERE parent IS NULL;" );
313 query = sqlite3_mprintf(
"SELECT * FROM symbol" );
315 sqlite3_stmt *ppStmt;
316 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
317 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
320 QString symbol_name = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymbolName ) );
321 QString xmlstring = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymbolXML ) );
322 if ( !doc.setContent( xmlstring ) )
324 QgsDebugMsg(
"Cannot open symbol " + symbol_name );
328 QDomElement symElement = doc.documentElement();
330 if ( symbol != NULL )
331 mSymbols.insert( symbol_name, symbol );
334 sqlite3_finalize( ppStmt );
336 query = sqlite3_mprintf(
"SELECT * FROM colorramp" );
337 nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
338 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
341 QString ramp_name = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
ColorrampName ) );
342 QString xmlstring = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
ColorrampXML ) );
343 if ( !doc.setContent( xmlstring ) )
348 QDomElement rampElement = doc.documentElement();
364 if ( filename.isEmpty() )
370 QDomDocument doc(
"qgis_style" );
371 QDomElement root = doc.createElement(
"qgis_style" );
373 doc.appendChild( root );
377 QDomElement rampsElem = doc.createElement(
"colorramps" );
380 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
383 rampsElem.appendChild( rampEl );
386 root.appendChild( symbolsElem );
387 root.appendChild( rampsElem );
391 if ( !f.open( QFile::WriteOnly ) )
393 mErrorString =
"Couldn't open file for writing: " + filename;
396 QTextStream ts( &f );
397 ts.setCodec(
"UTF-8" );
410 QgsDebugMsg(
"Symbol of new name already exists" );
422 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
429 QgsDebugMsg(
"No such symbol for tagging in database: " + oldName );
442 QgsDebugMsg(
"Color ramp of new name already exists." );
453 sqlite3_stmt *ppStmt;
454 char *query = sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", oldName.toUtf8().constData() );
455 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
456 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
458 rampid = sqlite3_column_int( ppStmt, 0 );
460 sqlite3_finalize( ppStmt );
469 sqlite3_stmt *ppStmt;
470 const char *query =
"SELECT * FROM symgroup";
471 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
472 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
474 groupNames << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymgroupName ) );
476 sqlite3_finalize( ppStmt );
485 QgsDebugMsg(
"Cannot open database for listing groups" );
491 sqlite3_stmt *ppStmt;
494 if ( parent ==
"" || parent == QString() )
496 query = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE parent=0" );
500 char *subquery = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE name='%q'", parent.toUtf8().constData() );
501 nError = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt, NULL );
502 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
504 query = sqlite3_mprintf(
"SELECT * FROM symgroup WHERE parent=%d", sqlite3_column_int( ppStmt,
SymgroupId ) );
506 sqlite3_finalize( ppStmt );
515 nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
516 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
518 QString
group = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SymgroupName ) );
519 groupNames.insert( sqlite3_column_int( ppStmt,
SymgroupId ), group );
522 sqlite3_finalize( ppStmt );
531 QgsDebugMsg( QString(
"Cannot Open database for getting group symbols of groupid: %1" ).arg( groupid ) );
532 return QStringList();
538 query = sqlite3_mprintf(
"SELECT name FROM symbol WHERE groupid=%d", groupid );
542 query = sqlite3_mprintf(
"SELECT name FROM colorramp WHERE groupid=%d", groupid );
547 return QStringList();
550 sqlite3_stmt *ppStmt;
551 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
554 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
556 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
559 sqlite3_finalize( ppStmt );
568 QgsDebugMsg( QString(
"Cannot open database to get symbols of tagid %1" ).arg( tagid ) );
569 return QStringList();
575 subquery = sqlite3_mprintf(
"SELECT symbol_id FROM tagmap WHERE tag_id=%d", tagid );
579 subquery = sqlite3_mprintf(
"SELECT symbol_id FROM ctagmap WHERE tag_id=%d", tagid );
584 return QStringList();
587 sqlite3_stmt *ppStmt;
588 int nErr = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt, NULL );
592 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
594 int symbolId = sqlite3_column_int( ppStmt, 0 );
597 ? sqlite3_mprintf(
"SELECT name FROM symbol WHERE id=%d", symbolId )
598 : sqlite3_mprintf(
"SELECT name FROM colorramp WHERE id=%d", symbolId );
600 sqlite3_stmt *ppStmt2;
601 int sErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt2, NULL );
602 while ( sErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
604 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt2, 0 ) );
606 sqlite3_finalize( ppStmt2 );
608 sqlite3_finalize( ppStmt );
618 char *query = sqlite3_mprintf(
"INSERT INTO symgroup VALUES (NULL, '%q', %d)", groupName.toUtf8().constData(), parentid );
620 sqlite3_stmt *ppStmt;
621 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
622 if ( nErr == SQLITE_OK )
623 ( void )sqlite3_step( ppStmt );
625 sqlite3_finalize( ppStmt );
627 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
634 sqlite3_stmt *ppStmt;
636 char *query = sqlite3_mprintf(
"INSERT INTO tag VALUES (NULL, '%q')", tagname.toUtf8().constData() );
637 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
638 if ( nErr == SQLITE_OK )
639 ( void )sqlite3_step( ppStmt );
640 sqlite3_finalize( ppStmt );
642 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
651 query = sqlite3_mprintf(
"UPDATE symbol SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
654 query = sqlite3_mprintf(
"UPDATE symgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
657 query = sqlite3_mprintf(
"UPDATE tag SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
660 query = sqlite3_mprintf(
"UPDATE colorramp SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
663 query = sqlite3_mprintf(
"UPDATE smartgroup SET name='%q' WHERE id=%d", newName.toUtf8().constData(), id );
675 char *query = sqlite3_mprintf(
"SELECT parent FROM symgroup WHERE id=%d",
id );
677 sqlite3_stmt *ppStmt;
678 int err = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
681 if ( err == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
682 parentid = sqlite3_column_int( ppStmt, 0 );
684 sqlite3_finalize( ppStmt );
686 return sqlite3_mprintf(
"UPDATE symbol SET groupid=%d WHERE groupid=%d;"
687 "UPDATE symgroup SET parent=%d WHERE parent=%d;"
688 "DELETE FROM symgroup WHERE id=%d", parentid,
id, parentid,
id,
id );
697 query = sqlite3_mprintf(
"DELETE FROM symbol WHERE id=%d; DELETE FROM tagmap WHERE symbol_id=%d",
id,
id );
703 query = sqlite3_mprintf(
"DELETE FROM tag WHERE id=%d; DELETE FROM tagmap WHERE tag_id=%d",
id,
id );
706 query = sqlite3_mprintf(
"DELETE FROM colorramp WHERE id=%d",
id );
709 query = sqlite3_mprintf(
"DELETE FROM smartgroup WHERE id=%d",
id );
728 int nErr = sqlite3_exec(
mCurrentDB, query, NULL, NULL, &zErr );
732 sqlite3_free( query );
735 if ( nErr != SQLITE_OK )
740 return zErr == SQLITE_OK;
750 query = sqlite3_mprintf(
"UPDATE symbol SET groupid=%d WHERE name='%q'", groupid, name.toUtf8().constData() );
753 query = sqlite3_mprintf(
"UPDATE colorramp SET groupid=%d WHERE name='%q'", groupid, name.toUtf8().constData() );
757 QgsDebugMsg(
"Wrong entity value. cannot apply group" );
768 QgsDebugMsg(
"Sorry! Cannot open database to search" );
769 return QStringList();
772 QString item = ( type ==
SymbolEntity ) ?
"symbol" :
"colorramp";
773 char *query = sqlite3_mprintf(
"SELECT name FROM %q WHERE xml LIKE '%%%q%%'",
774 item.toUtf8().constData(), qword.toUtf8().constData() );
776 sqlite3_stmt *ppStmt;
777 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
780 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
782 symbols << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
785 sqlite3_finalize( ppStmt );
787 query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name LIKE '%%%q%%'", qword.toUtf8().constData() );
788 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
791 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
793 tagids << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
796 sqlite3_finalize( ppStmt );
799 QString dummy = tagids.join(
", " );
803 query = sqlite3_mprintf(
"SELECT symbol_id FROM tagmap WHERE tag_id IN (%q)",
804 dummy.toUtf8().constData() );
808 query = sqlite3_mprintf(
"SELECT colorramp_id FROM ctagmap WHERE tag_id IN (%q)",
809 dummy.toUtf8().constData() );
811 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
813 QStringList symbolids;
814 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
816 symbolids << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
819 sqlite3_finalize( ppStmt );
822 dummy = symbolids.join(
", " );
823 query = sqlite3_mprintf(
"SELECT name FROM %q WHERE id IN (%q)",
824 item.toUtf8().constData(), dummy.toUtf8().constData() );
825 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
826 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
828 QString symbolName = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
829 if ( !symbols.contains( symbolName ) )
830 symbols << symbolName;
833 sqlite3_finalize( ppStmt );
842 QgsDebugMsg(
"Sorry! Cannot open database to tag." );
849 QgsDebugMsg(
"No such symbol for tagging in database: " + symbol );
854 foreach (
const QString &tag, tags )
857 char *query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name='%q'", tag.toUtf8().constData() );
859 sqlite3_stmt *ppStmt;
860 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
863 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
865 tagid = sqlite3_column_int( ppStmt, 0 );
872 sqlite3_finalize( ppStmt );
876 ? sqlite3_mprintf(
"INSERT INTO tagmap VALUES (%d,%d)", tagid, symbolid )
877 : sqlite3_mprintf(
"INSERT INTO ctagmap VALUES (%d,%d)", tagid, symbolid );
880 nErr = sqlite3_exec(
mCurrentDB, query, NULL, NULL, &zErr );
894 QgsDebugMsg(
"Sorry! Cannot open database for detgging." );
899 ? sqlite3_mprintf(
"SELECT id FROM symbol WHERE name='%q'", symbol.toUtf8().constData() )
900 : sqlite3_mprintf(
"SELECT id FROM colorramp WHERE name='%q'", symbol.toUtf8().constData() );
901 sqlite3_stmt *ppStmt;
902 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
905 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
907 symbolid = sqlite3_column_int( ppStmt, 0 );
910 sqlite3_finalize( ppStmt );
912 foreach (
const QString &tag, tags )
914 query = sqlite3_mprintf(
"SELECT id FROM tag WHERE name='%q'", tag.toUtf8().constData() );
916 sqlite3_stmt *ppStmt2;
917 nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt2, NULL );
920 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
922 tagid = sqlite3_column_int( ppStmt2, 0 );
925 sqlite3_finalize( ppStmt2 );
931 ? sqlite3_mprintf(
"DELETE FROM tagmap WHERE tag_id=%d AND symbol_id=%d", tagid, symbolid )
932 : sqlite3_mprintf(
"DELETE FROM ctagmap WHERE tag_id=%d AND colorramp_id=%d", tagid, symbolid );
947 QgsDebugMsg(
"Sorry! Cannot open database for getting the tags." );
948 return QStringList();
953 return QStringList();
957 ? sqlite3_mprintf(
"SELECT tag_id FROM tagmap WHERE symbol_id=%d", symbolid )
958 : sqlite3_mprintf(
"SELECT tag_id FROM ctagmap WHERE colorramp_id=%d", symbolid );
960 sqlite3_stmt *ppStmt;
961 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
964 while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
966 char *subquery = sqlite3_mprintf(
"SELECT name FROM tag WHERE id=%d", sqlite3_column_int( ppStmt, 0 ) );
968 sqlite3_stmt *ppStmt2;
969 int pErr = sqlite3_prepare_v2(
mCurrentDB, subquery, -1, &ppStmt2, NULL );
970 if ( pErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
972 tagList << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt2, 0 ) );
974 sqlite3_finalize( ppStmt2 );
977 sqlite3_finalize( ppStmt );
984 char *query = sqlite3_mprintf(
"SELECT id FROM %q WHERE name='%q'", table.toUtf8().constData(), name.toUtf8().constData() );
986 sqlite3_stmt *ppStmt;
987 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
990 if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
992 id = sqlite3_column_int( ppStmt, 0 );
995 sqlite3_finalize( ppStmt );
1002 return getId(
"symbol", name );
1007 return getId(
"colorramp", name );
1012 return getId(
"symgroup", name );
1017 return getId(
"tag", name );
1022 return getId(
"smartgroup", name );
1027 QDomDocument doc(
"dummy" );
1028 QDomElement smartEl = doc.createElement(
"smartgroup" );
1029 smartEl.setAttribute(
"name", name );
1030 smartEl.setAttribute(
"operator", op );
1032 QStringList constraints;
1033 constraints <<
"tag" <<
"group" <<
"name" <<
"!tag" <<
"!group" <<
"!name";
1035 foreach (
const QString &constraint, constraints )
1037 QStringList parameters = conditions.values( constraint );
1038 foreach (
const QString ¶m, parameters )
1040 QDomElement condEl = doc.createElement(
"condition" );
1041 condEl.setAttribute(
"constraint", constraint );
1042 condEl.setAttribute(
"param", param );
1043 smartEl.appendChild( condEl );
1047 QByteArray xmlArray;
1048 QTextStream stream( &xmlArray );
1049 stream.setCodec(
"UTF-8" );
1050 smartEl.save( stream, 4 );
1051 char *query = sqlite3_mprintf(
"INSERT INTO smartgroup VALUES (NULL, '%q', '%q')",
1052 name.toUtf8().constData(), xmlArray.constData() );
1056 return (
int )sqlite3_last_insert_rowid(
mCurrentDB );
1060 QgsDebugMsg(
"Couldn't insert symbol into the database!" );
1069 QgsDebugMsg(
"Cannot open database for listing groups" );
1073 char *query = sqlite3_mprintf(
"SELECT * FROM smartgroup" );
1076 sqlite3_stmt *ppStmt;
1077 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1080 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1082 QString
group = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt,
SmartgroupName ) );
1083 groupNames.insert( sqlite3_column_int( ppStmt,
SmartgroupId ), group );
1086 sqlite3_finalize( ppStmt );
1095 QgsDebugMsg(
"Cannot open database for listing groups" );
1096 return QStringList();
1099 char *query = sqlite3_mprintf(
"SELECT name FROM smartgroup" );
1102 sqlite3_stmt *ppStmt;
1103 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1106 while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1108 groups << QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1111 sqlite3_finalize( ppStmt );
1118 QStringList symbols;
1120 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1122 sqlite3_stmt *ppStmt;
1123 int nErr = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1124 if ( !( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW ) )
1126 sqlite3_finalize( ppStmt );
1127 return QStringList();
1132 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1133 if ( !doc.setContent( xmlstr ) )
1135 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1137 QDomElement smartEl = doc.documentElement();
1138 QString op = smartEl.attribute(
"operator" );
1139 QDomNodeList conditionNodes = smartEl.childNodes();
1141 bool firstSet =
true;
1142 for (
int i = 0; i < conditionNodes.count(); i++ )
1144 QDomElement condEl = conditionNodes.at( i ).toElement();
1145 QString constraint = condEl.attribute(
"constraint" );
1146 QString param = condEl.attribute(
"param" );
1148 QStringList resultNames;
1150 if ( constraint ==
"tag" )
1154 else if ( constraint ==
"group" )
1160 else if ( constraint ==
"name" )
1164 resultNames =
symbolNames().filter( param, Qt::CaseInsensitive );
1168 resultNames =
colorRampNames().filter( param, Qt::CaseInsensitive );
1171 else if ( constraint ==
"!tag" )
1175 foreach ( QString name, unwanted )
1177 resultNames.removeAll( name );
1180 else if ( constraint ==
"!group" )
1184 foreach ( QString name, unwanted )
1186 resultNames.removeAll( name );
1189 else if ( constraint ==
"!name" )
1192 foreach (
const QString &str, all )
1194 if ( !str.contains( param, Qt::CaseInsensitive ) )
1202 symbols = resultNames;
1209 symbols << resultNames;
1211 else if ( op ==
"AND" )
1213 QStringList dummy = symbols;
1215 foreach (
const QString &result, resultNames )
1217 if ( dummy.contains( result ) )
1225 sqlite3_finalize( ppStmt );
1234 QgsDebugMsg(
"Cannot open database for listing groups" );
1240 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1242 sqlite3_stmt *ppStmt;
1243 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1244 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1247 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1248 if ( !doc.setContent( xmlstr ) )
1250 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1253 QDomElement smartEl = doc.documentElement();
1254 QString op = smartEl.attribute(
"operator" );
1255 QDomNodeList conditionNodes = smartEl.childNodes();
1257 for (
int i = 0; i < conditionNodes.count(); i++ )
1259 QDomElement condEl = conditionNodes.at( i ).toElement();
1260 QString constraint = condEl.attribute(
"constraint" );
1261 QString param = condEl.attribute(
"param" );
1263 condition.insert( constraint, param );
1267 sqlite3_finalize( ppStmt );
1276 QgsDebugMsg(
"Cannot open database for listing groups" );
1282 char *query = sqlite3_mprintf(
"SELECT xml FROM smartgroup WHERE id=%d",
id );
1284 sqlite3_stmt *ppStmt;
1285 int nError = sqlite3_prepare_v2(
mCurrentDB, query, -1, &ppStmt, NULL );
1286 if ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
1289 QString xmlstr = QString::fromUtf8((
const char * ) sqlite3_column_text( ppStmt, 0 ) );
1290 if ( !doc.setContent( xmlstr ) )
1292 QgsDebugMsg( QString(
"Cannot open smartgroup id: %1" ).arg(
id ) );
1294 QDomElement smartEl = doc.documentElement();
1295 op = smartEl.attribute(
"operator" );
1298 sqlite3_finalize( ppStmt );
1305 if ( filename.isEmpty() )
1307 QgsDebugMsg(
"Invalid filename for style export." );
1311 QDomDocument doc(
"qgis_style" );
1312 QDomElement root = doc.createElement(
"qgis_style" );
1314 doc.appendChild( root );
1318 QDomElement rampsElem = doc.createElement(
"colorramps" );
1321 for ( QMap<QString, QgsVectorColorRampV2*>::iterator itr =
mColorRamps.begin(); itr !=
mColorRamps.end(); ++itr )
1324 rampsElem.appendChild( rampEl );
1327 root.appendChild( symbolsElem );
1328 root.appendChild( rampsElem );
1331 QFile f( filename );
1332 if ( !f.open( QFile::WriteOnly ) )
1334 mErrorString =
"Couldn't open file for writing: " + filename;
1338 QTextStream ts( &f );
1339 ts.setCodec(
"UTF-8" );
1350 QDomDocument doc(
"style" );
1351 QFile f( filename );
1352 if ( !f.open( QFile::ReadOnly ) )
1355 QgsDebugMsg(
"Error opening the style XML file." );
1359 if ( !doc.setContent( &f ) )
1361 mErrorString = QString(
"Unable to understand the style file: %1" ).arg( filename );
1368 QDomElement docEl = doc.documentElement();
1369 if ( docEl.tagName() !=
"qgis_style" )
1371 mErrorString =
"Incorrect root tag in style: " + docEl.tagName();
1375 QString version = docEl.attribute(
"version" );
1378 mErrorString =
"Unknown style file version: " + version;
1384 QDomElement symbolsElement = docEl.firstChildElement(
"symbols" );
1385 QDomElement e = symbolsElement.firstChildElement();
1390 while ( !e.isNull() )
1392 if ( e.tagName() ==
"symbol" )
1397 symbols.insert( e.attribute(
"name" ),
symbol );
1404 e = e.nextSiblingElement();
1414 for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
1420 QDomElement rampsElement = docEl.firstChildElement(
"colorramps" );
1421 e = rampsElement.firstChildElement();
1422 while ( !e.isNull() )
1424 if ( e.tagName() ==
"colorramp" )
1436 e = e.nextSiblingElement();
1445 QDomDocument doc(
"dummy" );
1447 QByteArray xmlArray;
1448 QTextStream stream( &xmlArray );
1449 stream.setCodec(
"UTF-8" );
1458 QgsDebugMsg(
"Update request received for unavailable symbol" );
1463 if ( symEl.isNull() )
1465 QgsDebugMsg(
"Couldn't convert symbol to valid XML!" );
1468 symEl.save( stream, 4 );
1469 query = sqlite3_mprintf(
"UPDATE symbol SET xml='%q' WHERE name='%q';",
1470 xmlArray.constData(), name.toUtf8().constData() );
1476 QgsDebugMsg(
"Update requested for unavailable color ramp." );
1481 if ( symEl.isNull() )
1483 QgsDebugMsg(
"Couldn't convert color ramp to valid XML!" );
1486 symEl.save( stream, 4 );
1487 query = sqlite3_mprintf(
"UPDATE colorramp SET xml='%q' WHERE name='%q';",
1488 xmlArray.constData(), name.toUtf8().constData() );
1492 QgsDebugMsg(
"Updating the unsupported StyleEntity" );
1499 QgsDebugMsg(
"Couldn't insert symbol into the database!" );