Skip to content

Commit

Permalink
[StyleManager] have separate predefined QActions for start/finish gro…
Browse files Browse the repository at this point in the history
…uping mode
  • Loading branch information
SebDieBln committed Jan 6, 2016
1 parent a9c4179 commit 4d2d001
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -108,10 +108,13 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
this, SLOT( groupRenamed( QStandardItem* ) ) );

QMenu *groupMenu = new QMenu( tr( "Group actions" ), this );
QAction *groupSymbols = groupMenu->addAction( tr( "Group symbols" ) );
connect( actnGroupSymbols, SIGNAL( triggered() ), this, SLOT( groupSymbolsAction() ) );
groupMenu->addAction( actnGroupSymbols );
connect( actnFinishGrouping, SIGNAL( triggered() ), this, SLOT( groupSymbolsAction() ) );
actnFinishGrouping->setVisible( false );
groupMenu->addAction( actnFinishGrouping );
groupMenu->addAction( actnEditSmartGroup );
btnManageGroups->setMenu( groupMenu );
connect( groupSymbols, SIGNAL( triggered() ), this, SLOT( groupSymbolsAction() ) );

connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
tagsLineEdit->installEventFilter( this );
Expand Down Expand Up @@ -894,6 +897,7 @@ void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
if ( category == "groups" || category == "smartgroups" )
{
btnAddGroup->setEnabled( true );
actnAddGroup->setEnabled( true );
}
symbolNames = currentItemType() < 3 ? mStyle->symbolNames() : mStyle->colorRampNames();
}
Expand All @@ -903,7 +907,9 @@ void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
if ( index.parent().data( Qt::UserRole + 1 ) == "smartgroups" )
{
btnAddGroup->setEnabled( false );
actnAddGroup->setEnabled( false );
btnRemoveGroup->setEnabled( true );
actnRemoveGroup->setEnabled( true );
btnManageGroups->setEnabled( true );
int groupId = index.data( Qt::UserRole + 1 ).toInt();
symbolNames = mStyle->symbolsOfSmartgroup( type, groupId );
Expand Down Expand Up @@ -938,22 +944,26 @@ void QgsStyleV2ManagerDialog::groupChanged( const QModelIndex& index )
actnEditSmartGroup->setVisible( false );
actnAddGroup->setVisible( false );
actnRemoveGroup->setVisible( false );
actnGroupSymbols->setVisible( false );
actnFinishGrouping->setVisible( false );

if ( index.parent().isValid() && ( index.data().toString() != "Ungrouped" ) )
{
if ( index.parent().data( Qt::UserRole + 1 ).toString() == "smartgroups" )
{
actnEditSmartGroup->setVisible( true );
actnEditSmartGroup->setVisible( !mGrouppingMode );
}
else
{
actnAddGroup->setVisible( true );
actnAddGroup->setVisible( !mGrouppingMode );
actnGroupSymbols->setVisible( !mGrouppingMode );
actnFinishGrouping->setVisible( mGrouppingMode );
}
actnRemoveGroup->setVisible( true );
}
else if ( index.data( Qt::UserRole + 1 ) == "groups" || index.data( Qt::UserRole + 1 ) == "smartgroups" )
{
actnAddGroup->setVisible( true );
actnAddGroup->setVisible( !mGrouppingMode );
}
}

Expand Down Expand Up @@ -1086,12 +1096,12 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()

QStandardItemModel *treeModel = qobject_cast<QStandardItemModel*>( groupTree->model() );
QStandardItemModel *model = qobject_cast<QStandardItemModel*>( listItems->model() );
QAction *senderAction = qobject_cast<QAction*>( sender() );

if ( mGrouppingMode )
{
mGrouppingMode = false;
senderAction->setText( tr( "Group symbols" ) );
actnGroupSymbols->setVisible( true );
actnFinishGrouping->setVisible( false );
// disconnect slot which handles regrouping
disconnect( model, SIGNAL( itemChanged( QStandardItem* ) ),
this, SLOT( regrouped( QStandardItem* ) ) );
Expand Down Expand Up @@ -1127,8 +1137,9 @@ void QgsStyleV2ManagerDialog::groupSymbolsAction()
return;

mGrouppingMode = true;
// Change the text menu
senderAction->setText( tr( "Finish grouping" ) );
// Change visibility of actions
actnGroupSymbols->setVisible( false );
actnFinishGrouping->setVisible( true );
// Remove all Symbol editing functionalities
disconnect( treeModel, SIGNAL( itemChanged( QStandardItem* ) ),
this, SLOT( groupRenamed( QStandardItem* ) ) );
Expand Down Expand Up @@ -1283,7 +1294,9 @@ void QgsStyleV2ManagerDialog::enableSymbolInputs( bool enable )
{
groupTree->setEnabled( enable );
btnAddGroup->setEnabled( enable );
actnAddGroup->setEnabled( enable );
btnRemoveGroup->setEnabled( enable );
actnRemoveGroup->setEnabled( enable );
btnManageGroups->setEnabled( enable || mGrouppingMode ); // always enabled in grouping mode, as it is the only way to leave grouping mode
searchBox->setEnabled( enable );
tagsLineEdit->setEnabled( enable );
Expand All @@ -1293,6 +1306,7 @@ void QgsStyleV2ManagerDialog::enableGroupInputs( bool enable )
{
btnAddGroup->setEnabled( enable );
btnRemoveGroup->setEnabled( enable );
actnRemoveGroup->setEnabled( enable );
btnManageGroups->setEnabled( enable || mGrouppingMode ); // always enabled in grouping mode, as it is the only way to leave grouping mode
}

Expand Down Expand Up @@ -1344,7 +1358,7 @@ void QgsStyleV2ManagerDialog::grouptreeContextMenu( const QPoint& point )
QModelIndex index = groupTree->indexAt( point );
QgsDebugMsg( "Now you clicked: " + index.data().toString() );

if ( index.isValid() )
if ( index.isValid() && !mGrouppingMode )
mGroupTreeContextMenu->popup( globalPos );
}

Expand Down
16 changes: 16 additions & 0 deletions src/ui/qgsstylev2managerdialogbase.ui
Expand Up @@ -484,6 +484,22 @@ QMenu::item:selected { background-color: gray; } */
<string>Remove group</string>
</property>
</action>
<action name="actnGroupSymbols">
<property name="text">
<string>Group symbols</string>
</property>
</action>
<action name="actnFinishGrouping">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Finish grouping</string>
</property>
<property name="visible">
<bool>true</bool>
</property>
</action>
<action name="actnExportAsPNG">
<property name="enabled">
<bool>false</bool>
Expand Down

0 comments on commit 4d2d001

Please sign in to comment.