Skip to content
Permalink
Browse files

Add Replace Preset option to presets menu

  • Loading branch information
nyalldawson committed Aug 20, 2015
1 parent 415aa83 commit 0df7102d2961b461cdc2f55cd5755992859588ef
Showing with 25 additions and 0 deletions.
  1. +20 −0 src/app/qgsvisibilitypresets.cpp
  2. +5 −0 src/app/qgsvisibilitypresets.h
@@ -44,6 +44,8 @@ QgsVisibilityPresets::QgsVisibilityPresets()
mMenu->addAction( QgisApp::instance()->actionHideSelectedLayers() );
mMenu->addSeparator();

mReplaceMenu = new QMenu( tr( "Replace Preset" ) );
mMenu->addMenu( mReplaceMenu );
mActionAddPreset = mMenu->addAction( tr( "Add Preset..." ), this, SLOT( addPreset() ) );
mMenuSeparator = mMenu->addSeparator();

@@ -168,6 +170,15 @@ void QgsVisibilityPresets::presetTriggerred()
applyState( actionPreset->text() );
}

void QgsVisibilityPresets::replaceTriggerred()
{
QAction* actionPreset = qobject_cast<QAction*>( sender() );
if ( !actionPreset )
return;

//adding preset with same name is effectively a replace
addPreset( actionPreset->text() );
}

void QgsVisibilityPresets::applyStateToLayerTreeGroup( QgsLayerTreeGroup* parent, const QgsVisibilityPresetCollection::PresetRecord& rec )
{
@@ -245,6 +256,9 @@ void QgsVisibilityPresets::menuAboutToShow()
{
qDeleteAll( mMenuPresetActions );
mMenuPresetActions.clear();
mReplaceMenu->clear();
qDeleteAll( mMenuReplaceActions );
mMenuReplaceActions.clear();

QgsVisibilityPresetCollection::PresetRecord rec = currentState();
bool hasCurrent = false;
@@ -260,8 +274,14 @@ void QgsVisibilityPresets::menuAboutToShow()
}
connect( a, SIGNAL( triggered() ), this, SLOT( presetTriggerred() ) );
mMenuPresetActions.append( a );

QAction* replaceAction = new QAction( grpName, mReplaceMenu );
replaceAction->setEnabled( !a->isChecked() ); //can't replace current preset
connect( replaceAction, SIGNAL( triggered() ), this, SLOT( replaceTriggerred() ) );
mReplaceMenu->addAction( replaceAction );
}
mMenu->insertActions( mMenuSeparator, mMenuPresetActions );
mReplaceMenu->addActions( mMenuReplaceActions );

mActionAddPreset->setEnabled( !hasCurrent );
mActionRemoveCurrentPreset->setEnabled( hasCurrent );
@@ -61,6 +61,9 @@ class APP_EXPORT QgsVisibilityPresets : public QObject
//! Handles apply a preset to the map canvas
void presetTriggerred();

//! Handles replacing a preset's state
void replaceTriggerred();

//! Handles removal of current preset from the project's collection
void removeCurrentPreset();

@@ -86,10 +89,12 @@ class APP_EXPORT QgsVisibilityPresets : public QObject
static QgsVisibilityPresets* sInstance;

QMenu* mMenu;
QMenu* mReplaceMenu;
QAction* mMenuSeparator;
QAction* mActionAddPreset;
QAction* mActionRemoveCurrentPreset;
QList<QAction*> mMenuPresetActions;
QList<QAction*> mMenuReplaceActions;
};


0 comments on commit 0df7102

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