Skip to content
Permalink
Browse files

tagging/detagging of symbols in Style Manager done

  • Loading branch information
tecoholic committed Jul 9, 2012
1 parent 363b22e commit aeec55e008dc053635a298b44000452b7d106ccd
@@ -400,28 +400,6 @@ QStringList QgsStyleV2::symbolsOfGroup( int groupid )
return symbols;
}

QgsSymbolTagMap QgsStyleV2::symbolTags()
{
QgsSymbolTagMap tags;
sqlite3* db = openDB( mFileName );
if ( db == NULL )
{
QgsDebugMsg( "Cannot open DB to get the tags" );
return QgsSymbolTagMap();
}
sqlite3_stmt *ppStmt;
char *query = sqlite3_mprintf( "SELECT * FROM tag;" );
int nErr = sqlite3_prepare_v2( db, query, -1, &ppStmt, NULL );
while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
QString tag = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt, TagName ) ) );
tags.insert( sqlite3_column_int( ppStmt, TagId ), tag );
}
sqlite3_finalize( ppStmt );
sqlite3_close( db );
return tags;
}

QStringList QgsStyleV2::symbolsWithTag( int tagid )
{
QStringList symbols;
@@ -642,7 +620,7 @@ bool QgsStyleV2::tagSymbol( QString symbol, QStringList tags )
return false;
}

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

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

QStringList QgsStyleV2::tagsOfSymbol( QString symbol )
{
QStringList tagList;
QByteArray array = symbol.toUtf8();
char *query;
sqlite3_stmt *ppStmt;
int symbolid;
sqlite3 *db = openDB( mFileName );
if ( db == NULL )
{
QgsDebugMsg( "Sorry! Cannot open DB for getting the tags." );
return QStringList();
}
// get the symbol id
query = sqlite3_mprintf( "SELECT id FROM symbol WHERE name='%q';", array.constData() );
int nErr = sqlite3_prepare_v2( db, query, -1, &ppStmt, NULL );
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
symbolid = sqlite3_column_int( ppStmt, 0 );
}
sqlite3_finalize( ppStmt );
// get the ids of tags for the symbol
query = sqlite3_mprintf( "SELECT tag_id FROM tagmap WHERE symbol_id=%d;", symbolid );
nErr = sqlite3_prepare_v2( db, query, -1, &ppStmt, NULL );
while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
int tagid = sqlite3_column_int( ppStmt, 0 );
char *subquery;
sqlite3_stmt *ppStmt2;
subquery = sqlite3_mprintf( "SELECT name FROM tag WHERE id=%d;", tagid );
int pErr = sqlite3_prepare_v2( db, subquery, -1, &ppStmt2, NULL );
if ( pErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
{
QString tag = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt2, 0 ) ) );
tagList.append( tag );
}
sqlite3_finalize( ppStmt2 );
}
sqlite3_finalize( ppStmt );
sqlite3_close( db );

return tagList;
}
@@ -32,7 +32,6 @@ class QDomElement;

typedef QMap<QString, QgsVectorColorRampV2* > QgsVectorColorRampV2Map;
typedef QMap<int, QString> QgsSymbolGroupMap;
typedef QMap<int, QString> QgsSymbolTagMap;

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

//! return the tags associated with the symbol
QStringList tagsOfSymbol( QString symbol );

protected:

QgsSymbolV2Map mSymbols;
@@ -75,6 +75,12 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
listItems->setModel( model );

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

populateTypes();

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

connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
connect( tagBtn, SIGNAL( clicked() ), this, SLOT( tagsChanged() ) );

}

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

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

void QgsStyleV2ManagerDialog::buildTagTree( QStandardItem* &parent )
{
QgsSymbolTagMap tags = mStyle->symbolTags();
QgsSymbolTagMap::const_iterator i = tags.constBegin();
while ( i != tags.constEnd() )
{
QStandardItem *item = new QStandardItem( i.value() );
item->setData( i.key() );
parent->appendRow( item );
++i;
}
}

void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
{
QStringList symbolNames;
@@ -933,7 +927,8 @@ void QgsStyleV2ManagerDialog::regrouped( QStandardItem *item )
regrouped = mStyle->regroup( symbolName, 0 );
if ( !regrouped )
{
int er = QMessageBox::critical( this, tr( "Database Error"), tr( "There was a problem with the Symbols database while regrouping." ) );
int er = QMessageBox::critical( this, tr( "Database Error"),
tr( "There was a problem with the Symbols database while regrouping." ) );
// call the slot again to get back to normal
if ( er )
groupSymbolsAction();
@@ -961,3 +956,38 @@ void QgsStyleV2ManagerDialog::filterSymbols( QString qword )
QStringList symbols = mStyle->findSymbols( qword );
populateSymbols( symbols );
}

void QgsStyleV2ManagerDialog::tagsChanged()
{
QStringList addtags;
QStringList removetags;

QStringList oldtags = mTagList;
QStringList newtags = tagsLineEdit->text().split( ",", QString::SkipEmptyParts );

// compare old with new to find removed tags
foreach( const QString &tag, oldtags )
{
if ( !newtags.contains( tag ) )
removetags.append( tag );
}
if ( removetags.size() > 0 )
mStyle->detagSymbol( currentItemName(), removetags );

// compare new with old to find added tags
foreach( const QString &tag, newtags )
{
if( !oldtags.contains( tag ) )
addtags.append( tag );
}
if ( addtags.size() > 0 )
mStyle->tagSymbol( currentItemName(), addtags );
}

void QgsStyleV2ManagerDialog::symbolSelected( const QModelIndex& index )
{
tagsLineEdit->clear();
QStandardItem *item = static_cast<QStandardItemModel*>( listItems->model() )->itemFromIndex( index );
mTagList = mStyle->tagsOfSymbol( item->data().toString() );
tagsLineEdit->setText( mTagList.join( "," ) );
}
@@ -63,6 +63,12 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
//! filter the symbols based on input search term
void filterSymbols( QString );

//! Listen to tag changes
void tagsChanged();

//! Perform symbol specific tasks when selected
void symbolSelected( const QModelIndex& );

protected:

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

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

//! Mode to display the symbol list
bool mGrouppingMode;

//! space to store symbol tags
QStringList mTagList;
};

#endif
@@ -292,6 +292,13 @@
<item>
<widget class="QLineEdit" name="tagsLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="tagBtn">
<property name="text">
<string>Apply Tags</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>

0 comments on commit aeec55e

Please sign in to comment.
You can’t perform that action at this time.