Skip to content

Commit 64b8019

Browse files
author
Arunmozhi
committed
added tags support, now lists Smart Groups in style manager
1 parent ca105e4 commit 64b8019

File tree

5 files changed

+175
-34
lines changed

5 files changed

+175
-34
lines changed

src/core/symbology-ng/qgsstylev2.cpp

+55-2
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ QgsSymbolGroupMap QgsStyleV2::groupNames( QString parent )
313313
QgsDebugMsg( "Cannot open database for listing groups" );
314314
return QgsSymbolGroupMap();
315315
}
316-
sqlite3_stmt *ppStmt;
317-
int nError;
318316
char *query;
317+
int nError;
318+
sqlite3_stmt *ppStmt;
319319

320320
if ( parent == "" || parent == QString() )
321321
{
@@ -367,3 +367,56 @@ QStringList QgsStyleV2::symbolsOfGroup( int groupid )
367367

368368
return symbols;
369369
}
370+
371+
QgsSymbolTagMap QgsStyleV2::symbolTags()
372+
{
373+
QgsSymbolTagMap tags;
374+
sqlite3* db = openDB( mFileName );
375+
if ( db == NULL )
376+
{
377+
QgsDebugMsg( "Cannot open DB to get the tags" );
378+
return QgsSymbolTagMap();
379+
}
380+
sqlite3_stmt *ppStmt;
381+
char *query = sqlite3_mprintf( "SELECT * FROM tag;" );
382+
int nErr = sqlite3_prepare_v2( db, query, -1, &ppStmt, NULL );
383+
while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
384+
{
385+
QString tag = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt, TagName ) ) );
386+
tags.insert( sqlite3_column_int( ppStmt, TagId ), tag );
387+
}
388+
sqlite3_finalize( ppStmt );
389+
sqlite3_close( db );
390+
return tags;
391+
}
392+
393+
QStringList QgsStyleV2::symbolsWithTag( int tagid )
394+
{
395+
QStringList symbols;
396+
sqlite3 *db = openDB( mFileName );
397+
if ( db == NULL )
398+
{
399+
QgsDebugMsg( "Cannot open DB to get symbols of tagid " + tagid );
400+
return QStringList();
401+
}
402+
char *subquery = sqlite3_mprintf( "SELECT symbol_id FROM tagmap WHERE tag_id=%d;", tagid );
403+
sqlite3_stmt *ppStmt;
404+
int nErr = sqlite3_prepare_v2( db, subquery, -1, &ppStmt, NULL );
405+
while ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
406+
{
407+
int symbolId = sqlite3_column_int( ppStmt, 0 );
408+
sqlite3_stmt *ppStmt2;
409+
char *query = sqlite3_mprintf( "SELECT name FROM symbol WHERE id=%d;", symbolId );
410+
int sErr = sqlite3_prepare_v2( db, query, -1, &ppStmt2, NULL );
411+
while ( sErr == SQLITE_OK && sqlite3_step( ppStmt2 ) == SQLITE_ROW )
412+
{
413+
QString symbolName = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt2, 0 ) ) );
414+
symbols.append( symbolName );
415+
}
416+
sqlite3_finalize( ppStmt2 );
417+
}
418+
sqlite3_finalize( ppStmt );
419+
sqlite3_close( db );
420+
421+
return symbols;
422+
}

src/core/symbology-ng/qgsstylev2.h

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class QDomElement;
3232

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

3637
// Enumeraters representing sqlite DB columns
3738
enum SymbolTable { SymbolId, SymbolName, SymbolXML, SymbolGroupId };
@@ -83,6 +84,12 @@ class CORE_EXPORT QgsStyleV2
8384
//! returns the symbolnames of a given groupid
8485
QStringList symbolsOfGroup( int groupid );
8586

87+
//! returns the tags in the DB
88+
QgsSymbolTagMap symbolTags();
89+
90+
//! returns the symbol names with which have the given tag
91+
QStringList symbolsWithTag( int tagid );
92+
8693

8794
//! add color ramp to style. takes ramp's ownership
8895
bool addColorRamp( QString name, QgsVectorColorRampV2* colorRamp );

src/gui/symbology-ng/qgsstylev2managerdialog.cpp

+64-16
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void QgsStyleV2ManagerDialog::populateList()
148148

149149
if ( itemType < 3 )
150150
{
151-
populateSymbols( itemType );
151+
groupChanged( groupTree->selectionModel()->currentIndex() );
152152
}
153153
else if ( itemType == 3 )
154154
{
@@ -160,6 +160,10 @@ void QgsStyleV2ManagerDialog::populateList()
160160
}
161161
}
162162

163+
/*
164+
* Replaced with groupChanged() multiuse function
165+
*
166+
163167
void QgsStyleV2ManagerDialog::populateSymbols( int type )
164168
{
165169
QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
@@ -185,6 +189,8 @@ void QgsStyleV2ManagerDialog::populateSymbols( int type )
185189
186190
}
187191
192+
*/
193+
188194
void QgsStyleV2ManagerDialog::populateColorRamps()
189195
{
190196
QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
@@ -570,19 +576,27 @@ void QgsStyleV2ManagerDialog::populateGroups()
570576
{
571577
QStandardItemModel *model = qobject_cast<QStandardItemModel*>( groupTree->model() );
572578
model->clear();
573-
// Add the groups
574-
// 1. recently used
575-
// 2. project
576-
// 3. all symbol
577-
// 4. group
578-
//QStandardItem *allSymbols = new QStandardItem( "All Symbols" );
579+
580+
QStandardItem *allSymbols = new QStandardItem( "All Symbols" );
581+
allSymbols->setData( QVariant( "all" ) );
582+
model->appendRow( allSymbols );
583+
584+
QStandardItem *projectSymbols = new QStandardItem( "Project Symbols" );
585+
projectSymbols->setData( "project" );
586+
model->appendRow( projectSymbols );
587+
588+
QStandardItem *recent = new QStandardItem( "Recently Used" );
589+
recent->setData( QVariant( "recent" ) );
590+
model->appendRow( recent );
579591

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

585-
QStandardItem *tag = new QStandardItem( "Tags" );
598+
QStandardItem *tag = new QStandardItem( "Smart Groups" );
599+
tag->setData( QVariant( "tags" ) );
586600
buildTagTree( tag );
587601
model->appendRow( tag );
588602

@@ -597,29 +611,63 @@ void QgsStyleV2ManagerDialog::buildGroupTree( QStandardItem* &parent )
597611
QStandardItem *item = new QStandardItem( i.value() );
598612
item->setData( QVariant( i.key() ) );
599613
parent->appendRow( item );
600-
QgsDebugMsg( "Added Group: " + i.value() );
601614
buildGroupTree( item );
602615
++i;
603616
}
604-
605617
}
618+
606619
void QgsStyleV2ManagerDialog::buildTagTree( QStandardItem* &parent )
607620
{
608-
Q_UNUSED( parent );
609-
// FIXME
610-
621+
QgsSymbolTagMap tags;
622+
QgsSymbolTagMap::const_iterator i = tags.constBegin();
623+
while ( i != tags.constEnd() )
624+
{
625+
QStandardItem *item = new QStandardItem( i.value() );
626+
item->setData( QVariant( i.key() ) );
627+
parent->appendRow( item );
628+
++i;
629+
}
611630
}
612631

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

636+
QString category = index.data( Qt::UserRole + 1 ).toString();
637+
if ( category == "all" || category == "groups" || category == "tags" )
638+
{
639+
symbolNames = mStyle->symbolNames();
640+
}
641+
else if ( category == "recent" )
642+
{
643+
// TODO add session symbols
644+
symbolNames = QStringList();
645+
}
646+
else if ( category == "project" )
647+
{
648+
// TODO add project symbols
649+
symbolNames = QStringList();
650+
}
651+
else
652+
{
653+
//determine groups and tags
654+
if ( index.parent().data( Qt::UserRole + 1 ) == "tags" )
655+
{
656+
int tagId = index.data( Qt::UserRole + 1 ).toInt();
657+
symbolNames = mStyle->symbolsWithTag( tagId );
658+
}
659+
else // then it must be a group
660+
{
661+
int groupId = index.data( Qt::UserRole + 1 ).toInt();
662+
symbolNames = mStyle->symbolsOfGroup( groupId );
663+
}
664+
}
665+
666+
// Populate the symbols based upon the generated symbolNames List
617667
int type = currentItemType();
618668
QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
619669
model->clear();
620670

621-
QStringList symbolNames = mStyle->symbolsOfGroup( groupId );
622-
623671
for ( int i = 0; i < symbolNames.count(); ++i )
624672
{
625673
QString name = symbolNames[i];

src/gui/symbology-ng/qgsstylev2managerdialog.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
6565
void buildTagTree( QStandardItem* &parent );
6666

6767
//! populate list view with symbols of specified type
68-
void populateSymbols( int type );
68+
//! @note: functionality replace with groupChanged() slot
69+
//void populateSymbols( int type );
6970
//! populate list view with color ramps
7071
void populateColorRamps();
7172

src/ui/qgsstylev2managerdialogbase.ui

+47-15
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,51 @@
1313
<property name="windowTitle">
1414
<string>Style Manager</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout_2">
16+
<layout class="QGridLayout" name="gridLayout_3">
1717
<item row="0" column="0">
18-
<widget class="QTreeView" name="groupTree">
19-
<property name="sizePolicy">
20-
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
21-
<horstretch>0</horstretch>
22-
<verstretch>0</verstretch>
23-
</sizepolicy>
24-
</property>
25-
<property name="maximumSize">
26-
<size>
27-
<width>16777215</width>
28-
<height>16777215</height>
29-
</size>
30-
</property>
31-
</widget>
18+
<layout class="QGridLayout" name="gridLayout_2">
19+
<item row="0" column="0" colspan="2">
20+
<widget class="QTreeView" name="groupTree">
21+
<property name="sizePolicy">
22+
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
23+
<horstretch>0</horstretch>
24+
<verstretch>0</verstretch>
25+
</sizepolicy>
26+
</property>
27+
<property name="maximumSize">
28+
<size>
29+
<width>16777215</width>
30+
<height>16777215</height>
31+
</size>
32+
</property>
33+
<property name="editTriggers">
34+
<set>QAbstractItemView::DoubleClicked</set>
35+
</property>
36+
</widget>
37+
</item>
38+
<item row="1" column="0">
39+
<widget class="QPushButton" name="btnAddGroup">
40+
<property name="text">
41+
<string/>
42+
</property>
43+
<property name="icon">
44+
<iconset resource="../../images/images.qrc">
45+
<normaloff>:/images/themes/default/symbologyAdd.png</normaloff>:/images/themes/default/symbologyAdd.png</iconset>
46+
</property>
47+
</widget>
48+
</item>
49+
<item row="1" column="1">
50+
<widget class="QPushButton" name="btnRemoveGroup">
51+
<property name="text">
52+
<string/>
53+
</property>
54+
<property name="icon">
55+
<iconset resource="../../images/images.qrc">
56+
<normaloff>:/images/themes/default/symbologyRemove.png</normaloff>:/images/themes/default/symbologyRemove.png</iconset>
57+
</property>
58+
</widget>
59+
</item>
60+
</layout>
3261
</item>
3362
<item row="0" column="1">
3463
<layout class="QGridLayout" name="gridLayout">
@@ -160,6 +189,9 @@
160189
<property name="text">
161190
<string/>
162191
</property>
192+
<property name="placeholderText">
193+
<string>Type here to search symbols ...</string>
194+
</property>
163195
</widget>
164196
</item>
165197
<item row="3" column="0" colspan="2">

0 commit comments

Comments
 (0)