@@ -49,6 +49,8 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
49
49
#endif
50
50
51
51
QSettings settings;
52
+ QAction* a; // used as a temporary variable before passing ownership of a created action.
53
+
52
54
restoreGeometry ( settings.value ( " /Windows/StyleV2Manager/geometry" ).toByteArray () );
53
55
mSplitter ->setSizes ( QList<int >() << 170 << 540 );
54
56
mSplitter ->restoreState ( settings.value ( " /Windows/StyleV2Manager/splitter" ).toByteArray () );
@@ -67,8 +69,10 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
67
69
QMenu *shareMenu = new QMenu ( tr ( " Share menu" ), this );
68
70
QAction *exportAsPNGAction = shareMenu->addAction ( tr ( " Export selected symbols as PNG" ) );
69
71
QAction *exportAsSVGAction = shareMenu->addAction ( tr ( " Export selected symbols as SVG" ) );
70
- QAction *exportAction = shareMenu->addAction ( tr ( " Export..." ) );
71
- QAction *importAction = shareMenu->addAction ( tr ( " Import..." ) );
72
+ QAction *exportAction = new QAction ( tr ( " Export..." ), this );
73
+ shareMenu->addAction ( exportAction );
74
+ QAction *importAction = new QAction ( tr ( " Import..." ), this );
75
+ shareMenu->addAction ( importAction );
72
76
exportAsPNGAction->setIcon ( QIcon ( QgsApplication::iconPath ( " mActionSharingExport.svg" ) ) );
73
77
exportAsSVGAction->setIcon ( QIcon ( QgsApplication::iconPath ( " mActionSharingExport.svg" ) ) );
74
78
exportAction->setIcon ( QIcon ( QgsApplication::iconPath ( " mActionSharingExport.svg" ) ) );
@@ -126,6 +130,24 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
126
130
connect ( listItems, SIGNAL ( customContextMenuRequested ( const QPoint& ) ),
127
131
this , SLOT ( listitemsContextMenu ( const QPoint& ) ) );
128
132
133
+ // Menu for the "Add item" toolbutton when in colorramp mode
134
+ QStringList rampTypes;
135
+ rampTypes << tr ( " Gradient" ) << tr ( " Random" ) << tr ( " ColorBrewer" );
136
+ rampTypes << tr ( " cpt-city" ); // todo, only for rasters?
137
+ mMenuBtnAddItemColorRamp = new QMenu ( this );
138
+ Q_FOREACH ( const QString& rampType, rampTypes )
139
+ mMenuBtnAddItemColorRamp ->addAction ( new QAction ( rampType, this ) );
140
+ connect ( mMenuBtnAddItemColorRamp , SIGNAL ( triggered ( QAction* ) ),
141
+ this , SLOT ( addColorRamp ( QAction* ) ) );
142
+
143
+ // Context menu for symbols/colorramps. The menu entries for every group are created when displaying the menu.
144
+ mGroupMenu = new QMenu ( this );
145
+ mGroupListMenu = new QMenu ( mGroupMenu );
146
+ mGroupListMenu ->setTitle ( tr ( " Apply Group" ) );
147
+ mGroupMenu ->addMenu ( mGroupListMenu );
148
+ a = new QAction ( tr ( " Un-group" ), mGroupMenu );
149
+ a->setData ( 0 );
150
+ mGroupMenu ->addAction ( a );
129
151
}
130
152
131
153
void QgsStyleV2ManagerDialog::onFinished ()
@@ -183,36 +205,11 @@ void QgsStyleV2ManagerDialog::populateTypes()
183
205
184
206
void QgsStyleV2ManagerDialog::on_tabItemType_currentChanged ( int )
185
207
{
186
- // when in Color Ramp tab, add menu to add item button
187
- if ( currentItemType () == 3 )
188
- {
189
- btnShare->menu ()->actions ().at ( 0 )->setVisible ( false );
190
- btnShare->menu ()->actions ().at ( 1 )->setVisible ( false );
191
-
192
- QStringList rampTypes;
193
- rampTypes << tr ( " Gradient" ) << tr ( " Random" ) << tr ( " ColorBrewer" );
194
- rampTypes << tr ( " cpt-city" ); // todo, only for rasters?
195
- QMenu* menu = new QMenu ( btnAddItem );
196
- Q_FOREACH ( const QString& rampType, rampTypes )
197
- {
198
- menu->addAction ( rampType );
199
- }
200
- btnAddItem->setMenu ( menu );
201
- connect ( menu, SIGNAL ( triggered ( QAction* ) ),
202
- this , SLOT ( addColorRamp ( QAction* ) ) );
203
- }
204
- else
205
- {
206
- btnShare->menu ()->actions ().at ( 0 )->setVisible ( true );
207
- btnShare->menu ()->actions ().at ( 1 )->setVisible ( true );
208
-
209
- if ( btnAddItem->menu () )
210
- {
211
- disconnect ( btnAddItem->menu (), SIGNAL ( triggered ( QAction* ) ),
212
- this , SLOT ( addColorRamp ( QAction* ) ) );
213
- btnAddItem->setMenu ( nullptr );
214
- }
215
- }
208
+ // when in Color Ramp tab, add menu to add item button and hide "Export symbols as PNG/SVG"
209
+ bool flag = currentItemType () != 3 ;
210
+ btnAddItem->setMenu ( flag ? nullptr : mMenuBtnAddItemColorRamp );
211
+ btnShare->menu ()->actions ().at ( 0 )->setVisible ( flag );
212
+ btnShare->menu ()->actions ().at ( 1 )->setVisible ( flag );
216
213
217
214
// set icon and grid size, depending on type
218
215
if ( currentItemType () == 1 || currentItemType () == 3 )
@@ -1327,19 +1324,16 @@ void QgsStyleV2ManagerDialog::listitemsContextMenu( const QPoint& point )
1327
1324
{
1328
1325
QPoint globalPos = listItems->viewport ()->mapToGlobal ( point );
1329
1326
1330
- QMenu *groupMenu = new QMenu ( this );
1331
- QMenu *groupList = new QMenu ( this );
1332
- groupList->setTitle ( tr ( " Apply Group" ) );
1327
+ // Clear all actions and create new actions for every group
1328
+ mGroupListMenu ->clear ();
1333
1329
1334
1330
QStringList groups = mStyle ->groupNames ();
1335
1331
Q_FOREACH ( const QString& group, groups )
1336
1332
{
1337
- groupList ->addAction ( group );
1333
+ mGroupListMenu ->addAction ( new QAction ( group, mGroupListMenu ) );
1338
1334
}
1339
- groupMenu->addMenu ( groupList );
1340
- groupMenu->addAction ( tr ( " Un-group" ) );
1341
1335
1342
- QAction* selectedItem = groupMenu ->exec ( globalPos );
1336
+ QAction* selectedItem = mGroupMenu ->exec ( globalPos );
1343
1337
1344
1338
if ( selectedItem )
1345
1339
{
0 commit comments