Skip to content

Commit

Permalink
added tags support, now lists Smart Groups in style manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Arunmozhi committed Jul 9, 2012
1 parent ca105e4 commit 64b8019
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 34 deletions.
57 changes: 55 additions & 2 deletions src/core/symbology-ng/qgsstylev2.cpp
Expand Up @@ -313,9 +313,9 @@ QgsSymbolGroupMap QgsStyleV2::groupNames( QString parent )
QgsDebugMsg( "Cannot open database for listing groups" );
return QgsSymbolGroupMap();
}
sqlite3_stmt *ppStmt;
int nError;
char *query;
int nError;
sqlite3_stmt *ppStmt;

if ( parent == "" || parent == QString() )
{
Expand Down Expand Up @@ -367,3 +367,56 @@ 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;
sqlite3 *db = openDB( mFileName );
if ( db == NULL )
{
QgsDebugMsg( "Cannot open DB to get symbols of tagid " + tagid );
return QStringList();
}
char *subquery = sqlite3_mprintf( "SELECT symbol_id FROM tagmap WHERE tag_id=%d;", tagid );
sqlite3_stmt *ppStmt;
int nErr = sqlite3_prepare_v2( db, subquery, -1, &ppStmt, NULL );
while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
int symbolId = sqlite3_column_int( ppStmt, 0 );
sqlite3_stmt *ppStmt2;
char *query = sqlite3_mprintf( "SELECT name FROM symbol WHERE id=%d;", symbolId );
int sErr = sqlite3_prepare_v2( db, query, -1, &ppStmt2, NULL );
while ( sErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
{
QString symbolName = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt2, 0 ) ) );
symbols.append( symbolName );
}
sqlite3_finalize( ppStmt2 );
}
sqlite3_finalize( ppStmt );
sqlite3_close( db );

return symbols;
}
7 changes: 7 additions & 0 deletions src/core/symbology-ng/qgsstylev2.h
Expand Up @@ -32,6 +32,7 @@ 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 };
Expand Down Expand Up @@ -83,6 +84,12 @@ class CORE_EXPORT QgsStyleV2
//! 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 );


//! add color ramp to style. takes ramp's ownership
bool addColorRamp( QString name, QgsVectorColorRampV2* colorRamp );
Expand Down
80 changes: 64 additions & 16 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -148,7 +148,7 @@ void QgsStyleV2ManagerDialog::populateList()

if ( itemType < 3 )
{
populateSymbols( itemType );
groupChanged( groupTree->selectionModel()->currentIndex() );
}
else if ( itemType == 3 )
{
Expand All @@ -160,6 +160,10 @@ void QgsStyleV2ManagerDialog::populateList()
}
}

/*
* Replaced with groupChanged() multiuse function
*
void QgsStyleV2ManagerDialog::populateSymbols( int type )
{
QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
Expand All @@ -185,6 +189,8 @@ void QgsStyleV2ManagerDialog::populateSymbols( int type )
}
*/

void QgsStyleV2ManagerDialog::populateColorRamps()
{
QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
Expand Down Expand Up @@ -570,19 +576,27 @@ void QgsStyleV2ManagerDialog::populateGroups()
{
QStandardItemModel *model = qobject_cast<QStandardItemModel*>( groupTree->model() );
model->clear();
// Add the groups
// 1. recently used
// 2. project
// 3. all symbol
// 4. group
//QStandardItem *allSymbols = new QStandardItem( "All Symbols" );

QStandardItem *allSymbols = new QStandardItem( "All Symbols" );
allSymbols->setData( QVariant( "all" ) );
model->appendRow( allSymbols );

QStandardItem *projectSymbols = new QStandardItem( "Project Symbols" );
projectSymbols->setData( "project" );
model->appendRow( projectSymbols );

QStandardItem *recent = new QStandardItem( "Recently Used" );
recent->setData( QVariant( "recent" ) );
model->appendRow( recent );

QStandardItem *group = new QStandardItem( "" ); //require empty name to get first order groups
group->setData( QVariant( "groups" ) );
buildGroupTree( group );
group->setText( "Groups" );//set title later
model->appendRow( group );

QStandardItem *tag = new QStandardItem( "Tags" );
QStandardItem *tag = new QStandardItem( "Smart Groups" );
tag->setData( QVariant( "tags" ) );
buildTagTree( tag );
model->appendRow( tag );

Expand All @@ -597,29 +611,63 @@ void QgsStyleV2ManagerDialog::buildGroupTree( QStandardItem* &parent )
QStandardItem *item = new QStandardItem( i.value() );
item->setData( QVariant( i.key() ) );
parent->appendRow( item );
QgsDebugMsg( "Added Group: " + i.value() );
buildGroupTree( item );
++i;
}

}

void QgsStyleV2ManagerDialog::buildTagTree( QStandardItem* &parent )
{
Q_UNUSED( parent );
// FIXME

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

void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
{
int groupId = index.data( Qt::UserRole + 1 ).toInt();
QStringList symbolNames;

QString category = index.data( Qt::UserRole + 1 ).toString();
if ( category == "all" || category == "groups" || category == "tags" )
{
symbolNames = mStyle->symbolNames();
}
else if ( category == "recent" )
{
// TODO add session symbols
symbolNames = QStringList();
}
else if ( category == "project" )
{
// TODO add project symbols
symbolNames = QStringList();
}
else
{
//determine groups and tags
if ( index.parent().data( Qt::UserRole + 1 ) == "tags" )
{
int tagId = index.data( Qt::UserRole + 1 ).toInt();
symbolNames = mStyle->symbolsWithTag( tagId );
}
else // then it must be a group
{
int groupId = index.data( Qt::UserRole + 1 ).toInt();
symbolNames = mStyle->symbolsOfGroup( groupId );
}
}

// Populate the symbols based upon the generated symbolNames List
int type = currentItemType();
QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
model->clear();

QStringList symbolNames = mStyle->symbolsOfGroup( groupId );

for ( int i = 0; i < symbolNames.count(); ++i )
{
QString name = symbolNames[i];
Expand Down
3 changes: 2 additions & 1 deletion src/gui/symbology-ng/qgsstylev2managerdialog.h
Expand Up @@ -65,7 +65,8 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
void buildTagTree( QStandardItem* &parent );

//! populate list view with symbols of specified type
void populateSymbols( int type );
//! @note: functionality replace with groupChanged() slot
//void populateSymbols( int type );
//! populate list view with color ramps
void populateColorRamps();

Expand Down
62 changes: 47 additions & 15 deletions src/ui/qgsstylev2managerdialogbase.ui
Expand Up @@ -13,22 +13,51 @@
<property name="windowTitle">
<string>Style Manager</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTreeView" name="groupTree">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QTreeView" name="groupTree">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="editTriggers">
<set>QAbstractItemView::DoubleClicked</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="btnAddGroup">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="btnRemoveGroup">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -160,6 +189,9 @@
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Type here to search symbols ...</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
Expand Down

0 comments on commit 64b8019

Please sign in to comment.