Skip to content
Permalink
Browse files

added context menu grouping and regrouping

  • Loading branch information
tecoholic committed Jul 17, 2012
1 parent 3c8b4a0 commit 4a6ac283d06845a7b6be3ab08324eb6e5c88df83
@@ -406,7 +406,22 @@ bool QgsStyleV2::renameColorRamp( QString oldName, QString newName )
return true;
}

QgsSymbolGroupMap QgsStyleV2::groupNames( QString parent )
QStringList QgsStyleV2::groupNames()
{
QStringList groupNames;
sqlite3_stmt *ppStmt;
const char *query = "SELECT * FROM symgroup;";
int nError = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
while ( nError == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
QString group = QString( reinterpret_cast<const char*>( sqlite3_column_text( ppStmt, SymgroupName ) ) );
groupNames.append( group );
}
sqlite3_finalize( ppStmt );
return groupNames;
}

QgsSymbolGroupMap QgsStyleV2::childGroupNames( QString parent )
{
// get the name list from the sqlite database and return as a QStringList
if( mCurrentDB == NULL )
@@ -799,3 +814,19 @@ int QgsStyleV2::symbolId( QString name )
sqlite3_finalize( ppStmt );
return symbolid;
}

int QgsStyleV2::groupId( QString name )
{
int groupid = 0;
char *query;
sqlite3_stmt *ppStmt;
QByteArray array = name.toUtf8();
query = sqlite3_mprintf( "SELECT id FROM symgroup WHERE name='%q';", array.constData() );
int nErr = sqlite3_prepare_v2( mCurrentDB, query, -1, &ppStmt, NULL );
if ( nErr == SQLITE_OK && sqlite3_step( ppStmt ) == SQLITE_ROW )
{
groupid = sqlite3_column_int( ppStmt, 0 );
}
sqlite3_finalize( ppStmt );
return groupid;
}
@@ -82,9 +82,15 @@ class CORE_EXPORT QgsStyleV2
//! returns 0 if not found
int symbolId( QString name );

//! return a map of all groupid and names for the given parent
//! Returns the First order groups when empty QString is passed
QgsSymbolGroupMap groupNames( QString parent = "" );
//! return the id in the style database for the given group name
int groupId( QString group );

//! return the all the groups in the style
QStringList groupNames();

//! return a map of groupid and names for the given parent
QgsSymbolGroupMap childGroupNames( QString parent = "" );

//! returns the symbolnames of a given groupid
QStringList symbolsOfGroup( int groupid );
//! returns the symbol names with which have the given tag
@@ -73,6 +73,7 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa

QStandardItemModel* model = new QStandardItemModel( listItems );
listItems->setModel( model );
listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );

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

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

// Context menu for listItems
listItems->setContextMenuPolicy( Qt::CustomContextMenu );
connect( listItems, SIGNAL( customContextMenuRequested( const QPoint& ) ),
this, SLOT( listitemsContextMenu( const QPoint& ) ) );

}

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

void QgsStyleV2ManagerDialog::buildGroupTree( QStandardItem* &parent )
{
QgsSymbolGroupMap groups = mStyle->groupNames( parent->text() );
QgsSymbolGroupMap groups = mStyle->childGroupNames( parent->text() );
QgsSymbolGroupMap::const_iterator i = groups.constBegin();
while ( i != groups.constEnd() )
{
@@ -860,6 +867,8 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
this, SLOT( groupRenamed( QStandardItem* ) ) );
connect( model, SIGNAL( itemChanged( QStandardItem* ) ),
this, SLOT( itemChanged( QStandardItem* ) ) );
// Reset the selection mode
listItems->setSelectionMode( QAbstractItemView::ExtendedSelection );
}
else
{
@@ -904,6 +913,9 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
// Connect to slot which handles regrouping
connect( model, SIGNAL( itemChanged( QStandardItem* )),
this, SLOT( regrouped( QStandardItem* ) ) );

// No selection should be possible
listItems->setSelectionMode( QAbstractItemView::NoSelection );
}
}

@@ -1049,3 +1061,40 @@ void QgsStyleV2ManagerDialog::grouptreeContextMenu( const QPoint& point )
removeGroup();
}
}

void QgsStyleV2ManagerDialog::listitemsContextMenu( const QPoint& point )
{
QPoint globalPos = listItems->viewport()->mapToGlobal( point );

QMenu *groupMenu = new QMenu( this );
QMenu *groupList = new QMenu( this );
groupList->setTitle( "Apply Group" );

QStringList groups = mStyle->groupNames();
foreach( QString group, groups )
{
groupList->addAction( group );
}
groupMenu->addMenu( groupList );

groupMenu->addAction( "Un-group" );

QAction* selectedItem = groupMenu->exec( globalPos );

if ( selectedItem )
{
int groupId = 0;
if ( selectedItem->text() != "Un-group" )
{
groupId = mStyle->groupId( selectedItem->text() );
}
QModelIndexList indexes = listItems->selectionModel()->selection().indexes();
foreach( QModelIndex index, indexes )
{
mStyle->regroup( index.data().toString(), groupId );
}
populateList();

QgsDebugMsg( "Selected Action: " + selectedItem->text() );
}
}
@@ -72,6 +72,10 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
//! Context menu for the groupTree
void grouptreeContextMenu( const QPoint& );

//! Context menu for the listItems ( symbols list )
void listitemsContextMenu( const QPoint& );


protected:

//! populate combo box with known style items (symbols, color ramps)
@@ -51,7 +51,7 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* sty

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

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

0 comments on commit 4a6ac28

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