Skip to content

Commit 4a6ac28

Browse files
author
Arunmozhi
committedJul 17, 2012
added context menu grouping and regrouping
1 parent 3c8b4a0 commit 4a6ac28

File tree

5 files changed

+97
-7
lines changed

5 files changed

+97
-7
lines changed
 

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,22 @@ bool QgsStyleV2::renameColorRamp( QString oldName, QString newName )
406406
return true;
407407
}
408408

409-
QgsSymbolGroupMap QgsStyleV2::groupNames( QString parent )
409+
QStringList QgsStyleV2::groupNames()
410+
{
411+
QStringList groupNames;
412+
sqlite3_stmt *ppStmt;
413+
const char *query = "SELECT * FROM symgroup;";
414+
int nError = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
415+
while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
416+
{
417+
QString group = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt, SymgroupName ) ) );
418+
groupNames.append( group );
419+
}
420+
sqlite3_finalize( ppStmt );
421+
return groupNames;
422+
}
423+
424+
QgsSymbolGroupMap QgsStyleV2::childGroupNames( QString parent )
410425
{
411426
// get the name list from the sqlite database and return as a QStringList
412427
if( mCurrentDB == NULL )
@@ -799,3 +814,19 @@ int QgsStyleV2::symbolId( QString name )
799814
sqlite3_finalize( ppStmt );
800815
return symbolid;
801816
}
817+
818+
int QgsStyleV2::groupId( QString name )
819+
{
820+
int groupid = 0;
821+
char *query;
822+
sqlite3_stmt *ppStmt;
823+
QByteArray array = name.toUtf8();
824+
query = sqlite3_mprintf( "SELECT id FROM symgroup WHERE name='%q';", array.constData() );
825+
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
826+
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
827+
{
828+
groupid = sqlite3_column_int( ppStmt, 0 );
829+
}
830+
sqlite3_finalize( ppStmt );
831+
return groupid;
832+
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,15 @@ class CORE_EXPORT QgsStyleV2
8282
//! returns 0 if not found
8383
int symbolId( QString name );
8484

85-
//! return a map of all groupid and names for the given parent
86-
//! Returns the First order groups when empty QString is passed
87-
QgsSymbolGroupMap groupNames( QString parent = "" );
85+
//! return the id in the style database for the given group name
86+
int groupId( QString group );
87+
88+
//! return the all the groups in the style
89+
QStringList groupNames();
90+
91+
//! return a map of groupid and names for the given parent
92+
QgsSymbolGroupMap childGroupNames( QString parent = "" );
93+
8894
//! returns the symbolnames of a given groupid
8995
QStringList symbolsOfGroup( int groupid );
9096
//! returns the symbol names with which have the given tag

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
7373

7474
QStandardItemModel* model = new QStandardItemModel( listItems );
7575
listItems->setModel( model );
76+
listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
7677

7778
connect( model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( itemChanged( QStandardItem* ) ) );
7879
connect( listItems->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
@@ -91,7 +92,8 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
9192
}
9293
connect( groupTree->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
9394
this, SLOT( groupChanged( const QModelIndex& ) ) );
94-
connect( groupModel, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( groupRenamed( QStandardItem* ) ) );
95+
connect( groupModel, SIGNAL( itemChanged( QStandardItem* ) ),
96+
this, SLOT( groupRenamed( QStandardItem* ) ) );
9597

9698
QMenu *groupMenu = new QMenu( "Group Actions" );
9799
QAction *groupSymbols = groupMenu->addAction( "Group Symbols" );
@@ -114,6 +116,11 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
114116
connect( groupTree, SIGNAL( customContextMenuRequested( const QPoint& ) ),
115117
this, SLOT( grouptreeContextMenu( const QPoint& ) ) );
116118

119+
// Context menu for listItems
120+
listItems->setContextMenuPolicy( Qt::CustomContextMenu );
121+
connect( listItems, SIGNAL( customContextMenuRequested( const QPoint& ) ),
122+
this, SLOT( listitemsContextMenu( const QPoint& ) ) );
123+
117124
}
118125

119126
void QgsStyleV2ManagerDialog::onFinished()
@@ -639,7 +646,7 @@ void QgsStyleV2ManagerDialog::populateGroups()
639646

640647
void QgsStyleV2ManagerDialog::buildGroupTree( QStandardItem* &parent )
641648
{
642-
QgsSymbolGroupMap groups = mStyle->groupNames( parent->text() );
649+
QgsSymbolGroupMap groups = mStyle->childGroupNames( parent->text() );
643650
QgsSymbolGroupMap::const_iterator i = groups.constBegin();
644651
while ( i != groups.constEnd() )
645652
{
@@ -860,6 +867,8 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
860867
this, SLOT( groupRenamed( QStandardItem* ) ) );
861868
connect( model, SIGNAL( itemChanged( QStandardItem* ) ),
862869
this, SLOT( itemChanged( QStandardItem* ) ) );
870+
// Reset the selection mode
871+
listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
863872
}
864873
else
865874
{
@@ -904,6 +913,9 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
904913
// Connect to slot which handles regrouping
905914
connect( model, SIGNAL( itemChanged( QStandardItem* )),
906915
this, SLOT( regrouped( QStandardItem* ) ) );
916+
917+
// No selection should be possible
918+
listItems->setSelectionMode( QAbstractItemView::NoSelection );
907919
}
908920
}
909921

@@ -1049,3 +1061,40 @@ void QgsStyleV2ManagerDialog::grouptreeContextMenu( const QPoint& point )
10491061
removeGroup();
10501062
}
10511063
}
1064+
1065+
void QgsStyleV2ManagerDialog::listitemsContextMenu( const QPoint& point )
1066+
{
1067+
QPoint globalPos = listItems->viewport()->mapToGlobal( point );
1068+
1069+
QMenu *groupMenu = new QMenu( this );
1070+
QMenu *groupList = new QMenu( this );
1071+
groupList->setTitle( "Apply Group" );
1072+
1073+
QStringList groups = mStyle->groupNames();
1074+
foreach( QString group, groups )
1075+
{
1076+
groupList->addAction( group );
1077+
}
1078+
groupMenu->addMenu( groupList );
1079+
1080+
groupMenu->addAction( "Un-group" );
1081+
1082+
QAction* selectedItem = groupMenu->exec( globalPos );
1083+
1084+
if ( selectedItem )
1085+
{
1086+
int groupId = 0;
1087+
if ( selectedItem->text() != "Un-group" )
1088+
{
1089+
groupId = mStyle->groupId( selectedItem->text() );
1090+
}
1091+
QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
1092+
foreach( QModelIndex index, indexes )
1093+
{
1094+
mStyle->regroup( index.data().toString(), groupId );
1095+
}
1096+
populateList();
1097+
1098+
QgsDebugMsg( "Selected Action: " + selectedItem->text() );
1099+
}
1100+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
7272
//! Context menu for the groupTree
7373
void grouptreeContextMenu( const QPoint& );
7474

75+
//! Context menu for the listItems ( symbols list )
76+
void listitemsContextMenu( const QPoint& );
77+
78+
7579
protected:
7680

7781
//! populate combo box with known style items (symbols, color ramps)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* sty
5151

5252
QStandardItemModel* model = new QStandardItemModel( viewSymbols );
5353
viewSymbols->setModel( model );
54-
connect( viewSymbols, SIGNAL( clicked( const QModelIndex & ) ), this, SLOT( setSymbolFromStyle( const QModelIndex & ) ) );
54+
connect( viewSymbols->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ), this, SLOT( setSymbolFromStyle( const QModelIndex & ) ) );
5555

5656
// Set the Style Menu under btnStyle
5757
QMenu *styleMenu = new QMenu( btnStyle );

0 commit comments

Comments
 (0)
Please sign in to comment.