Skip to content

Commit aeec55e

Browse files
author
Arunmozhi
committed
tagging/detagging of symbols in Style Manager done
1 parent 363b22e commit aeec55e

5 files changed

Lines changed: 109 additions & 44 deletions

File tree

‎src/core/symbology-ng/qgsstylev2.cpp‎

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -400,28 +400,6 @@ QStringList QgsStyleV2::symbolsOfGroup( int groupid )
400400
return symbols;
401401
}
402402

403-
QgsSymbolTagMap QgsStyleV2::symbolTags()
404-
{
405-
QgsSymbolTagMap tags;
406-
sqlite3* db = openDB( mFileName );
407-
if ( db == NULL )
408-
{
409-
QgsDebugMsg( "Cannot open DB to get the tags" );
410-
return QgsSymbolTagMap();
411-
}
412-
sqlite3_stmt *ppStmt;
413-
char *query = sqlite3_mprintf( "SELECT * FROM tag;" );
414-
int nErr = sqlite3_prepare_v2( db, query, -1, &ppStmt, NULL );
415-
while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
416-
{
417-
QString tag = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt, TagName ) ) );
418-
tags.insert( sqlite3_column_int( ppStmt, TagId ), tag );
419-
}
420-
sqlite3_finalize( ppStmt );
421-
sqlite3_close( db );
422-
return tags;
423-
}
424-
425403
QStringList QgsStyleV2::symbolsWithTag( int tagid )
426404
{
427405
QStringList symbols;
@@ -642,7 +620,7 @@ bool QgsStyleV2::tagSymbol( QString symbol, QStringList tags )
642620
return false;
643621
}
644622

645-
foreach ( QString tag, tags )
623+
foreach ( const QString &tag, tags )
646624
{
647625
int tagid;
648626
char *zErr = 0;
@@ -697,7 +675,7 @@ bool QgsStyleV2::detagSymbol( QString symbol, QStringList tags )
697675
}
698676
sqlite3_finalize( ppStmt );
699677

700-
foreach ( QString tag, tags )
678+
foreach ( const QString &tag, tags )
701679
{
702680
int tagid = 0;
703681
QByteArray tagArray = tag.toUtf8();
@@ -725,3 +703,46 @@ bool QgsStyleV2::detagSymbol( QString symbol, QStringList tags )
725703
return true;
726704
}
727705

706+
QStringList QgsStyleV2::tagsOfSymbol( QString symbol )
707+
{
708+
QStringList tagList;
709+
QByteArray array = symbol.toUtf8();
710+
char *query;
711+
sqlite3_stmt *ppStmt;
712+
int symbolid;
713+
sqlite3 *db = openDB( mFileName );
714+
if ( db == NULL )
715+
{
716+
QgsDebugMsg( "Sorry! Cannot open DB for getting the tags." );
717+
return QStringList();
718+
}
719+
// get the symbol id
720+
query = sqlite3_mprintf( "SELECT id FROM symbol WHERE name='%q';", array.constData() );
721+
int nErr = sqlite3_prepare_v2( db, query, -1, &ppStmt, NULL );
722+
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
723+
{
724+
symbolid = sqlite3_column_int( ppStmt, 0 );
725+
}
726+
sqlite3_finalize( ppStmt );
727+
// get the ids of tags for the symbol
728+
query = sqlite3_mprintf( "SELECT tag_id FROM tagmap WHERE symbol_id=%d;", symbolid );
729+
nErr = sqlite3_prepare_v2( db, query, -1, &ppStmt, NULL );
730+
while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
731+
{
732+
int tagid = sqlite3_column_int( ppStmt, 0 );
733+
char *subquery;
734+
sqlite3_stmt *ppStmt2;
735+
subquery = sqlite3_mprintf( "SELECT name FROM tag WHERE id=%d;", tagid );
736+
int pErr = sqlite3_prepare_v2( db, subquery, -1, &ppStmt2, NULL );
737+
if ( pErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
738+
{
739+
QString tag = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt2, 0 ) ) );
740+
tagList.append( tag );
741+
}
742+
sqlite3_finalize( ppStmt2 );
743+
}
744+
sqlite3_finalize( ppStmt );
745+
sqlite3_close( db );
746+
747+
return tagList;
748+
}

‎src/core/symbology-ng/qgsstylev2.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class QDomElement;
3232

3333
typedef QMap<QString, QgsVectorColorRampV2* > QgsVectorColorRampV2Map;
3434
typedef QMap<int, QString> QgsSymbolGroupMap;
35-
typedef QMap<int, QString> QgsSymbolTagMap;
3635

3736
// Enumeraters representing sqlite DB columns
3837
enum SymbolTable { SymbolId, SymbolName, SymbolXML, SymbolGroupId };
@@ -84,8 +83,6 @@ class CORE_EXPORT QgsStyleV2
8483
QgsSymbolGroupMap groupNames( QString parent = "" );
8584
//! returns the symbolnames of a given groupid
8685
QStringList symbolsOfGroup( int groupid );
87-
//! returns the tags in the DB
88-
QgsSymbolTagMap symbolTags();
8986
//! returns the symbol names with which have the given tag
9087
QStringList symbolsWithTag( int tagid );
9188
//! adds a new group and returns the group's id
@@ -148,6 +145,9 @@ class CORE_EXPORT QgsStyleV2
148145
//! detags the symbol with the given list
149146
bool detagSymbol( QString symbol, QStringList tags );
150147

148+
//! return the tags associated with the symbol
149+
QStringList tagsOfSymbol( QString symbol );
150+
151151
protected:
152152

153153
QgsSymbolV2Map mSymbols;

‎src/gui/symbology-ng/qgsstylev2managerdialog.cpp‎

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
7575
listItems->setModel( model );
7676

7777
connect( model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( itemChanged( QStandardItem* ) ) );
78+
// TODO take up the selectiopn model for the symbols
79+
// connect currentChanged signal to a slot which would populate the tags for that symbol
80+
// as comma seperated values in tagLineEdit and fill the mTagList
81+
//
82+
connect( listItems->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
83+
this, SLOT( symbolSelected( const QModelIndex& ) ) );
7884

7985
populateTypes();
8086

@@ -105,6 +111,7 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
105111
populateList();
106112

107113
connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
114+
connect( tagBtn, SIGNAL( clicked() ), this, SLOT( tagsChanged() ) );
108115

109116
}
110117

@@ -622,7 +629,7 @@ void QgsStyleV2ManagerDialog::populateGroups()
622629
QStandardItem *tag = new QStandardItem( "Smart Groups" );
623630
tag->setData( "tags" );
624631
tag->setEditable( false );
625-
buildTagTree( tag );
632+
// TODO populate/build smart groups
626633
model->appendRow( tag );
627634

628635
}
@@ -641,19 +648,6 @@ void QgsStyleV2ManagerDialog::buildGroupTree( QStandardItem* &parent )
641648
}
642649
}
643650

644-
void QgsStyleV2ManagerDialog::buildTagTree( QStandardItem* &parent )
645-
{
646-
QgsSymbolTagMap tags = mStyle->symbolTags();
647-
QgsSymbolTagMap::const_iterator i = tags.constBegin();
648-
while ( i != tags.constEnd() )
649-
{
650-
QStandardItem *item = new QStandardItem( i.value() );
651-
item->setData( i.key() );
652-
parent->appendRow( item );
653-
++i;
654-
}
655-
}
656-
657651
void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
658652
{
659653
QStringList symbolNames;
@@ -933,7 +927,8 @@ void QgsStyleV2ManagerDialog::regrouped( QStandardItem *item )
933927
regrouped = mStyle->regroup( symbolName, 0 );
934928
if ( !regrouped )
935929
{
936-
int er = QMessageBox::critical( this, tr( "Database Error"), tr( "There was a problem with the Symbols database while regrouping." ) );
930+
int er = QMessageBox::critical( this, tr( "Database Error"),
931+
tr( "There was a problem with the Symbols database while regrouping." ) );
937932
// call the slot again to get back to normal
938933
if ( er )
939934
groupSymbolsAction();
@@ -961,3 +956,38 @@ void QgsStyleV2ManagerDialog::filterSymbols( QString qword )
961956
QStringList symbols = mStyle->findSymbols( qword );
962957
populateSymbols( symbols );
963958
}
959+
960+
void QgsStyleV2ManagerDialog::tagsChanged()
961+
{
962+
QStringList addtags;
963+
QStringList removetags;
964+
965+
QStringList oldtags = mTagList;
966+
QStringList newtags = tagsLineEdit->text().split( ",", QString::SkipEmptyParts );
967+
968+
// compare old with new to find removed tags
969+
foreach( const QString &tag, oldtags )
970+
{
971+
if ( !newtags.contains( tag ) )
972+
removetags.append( tag );
973+
}
974+
if ( removetags.size() > 0 )
975+
mStyle->detagSymbol( currentItemName(), removetags );
976+
977+
// compare new with old to find added tags
978+
foreach( const QString &tag, newtags )
979+
{
980+
if( !oldtags.contains( tag ) )
981+
addtags.append( tag );
982+
}
983+
if ( addtags.size() > 0 )
984+
mStyle->tagSymbol( currentItemName(), addtags );
985+
}
986+
987+
void QgsStyleV2ManagerDialog::symbolSelected( const QModelIndex& index )
988+
{
989+
tagsLineEdit->clear();
990+
QStandardItem *item = static_cast<QStandardItemModel*>( listItems->model() )->itemFromIndex( index );
991+
mTagList = mStyle->tagsOfSymbol( item->data().toString() );
992+
tagsLineEdit->setText( mTagList.join( "," ) );
993+
}

‎src/gui/symbology-ng/qgsstylev2managerdialog.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
6363
//! filter the symbols based on input search term
6464
void filterSymbols( QString );
6565

66+
//! Listen to tag changes
67+
void tagsChanged();
68+
69+
//! Perform symbol specific tasks when selected
70+
void symbolSelected( const QModelIndex& );
71+
6672
protected:
6773

6874
//! populate combo box with known style items (symbols, color ramps)
@@ -72,8 +78,6 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
7278
void populateGroups();
7379
//! build the groups tree
7480
void buildGroupTree( QStandardItem* &parent );
75-
//! build the tag tree
76-
void buildTagTree( QStandardItem* &parent );
7781
//! to set symbols checked when in editing mode
7882
void setSymbolsChecked( QStringList );
7983

@@ -105,6 +109,9 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
105109

106110
//! Mode to display the symbol list
107111
bool mGrouppingMode;
112+
113+
//! space to store symbol tags
114+
QStringList mTagList;
108115
};
109116

110117
#endif

‎src/ui/qgsstylev2managerdialogbase.ui‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@
292292
<item>
293293
<widget class="QLineEdit" name="tagsLineEdit"/>
294294
</item>
295+
<item>
296+
<widget class="QPushButton" name="tagBtn">
297+
<property name="text">
298+
<string>Apply Tags</string>
299+
</property>
300+
</widget>
301+
</item>
295302
</layout>
296303
</item>
297304
</layout>

0 commit comments

Comments
 (0)