Skip to content

Commit 7a24104

Browse files
committed
add option to choose whether enable project macros
1 parent 2910a8e commit 7a24104

File tree

3 files changed

+99
-28
lines changed

3 files changed

+99
-28
lines changed

src/app/qgisapp.cpp

+27-12
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
474474

475475
centralLayout->addWidget( mMapCanvas, 0, 0, 2, 1 );
476476

477+
// a bar to warn the user with non-blocking messages
478+
mInfoBar = new QgsMessageBar( centralWidget );
479+
mInfoBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
480+
centralLayout->addWidget( mInfoBar, 0, 0, 1, 1 );
481+
477482
//set the focus to the map canvas
478483
mMapCanvas->setFocus();
479484

@@ -502,19 +507,15 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
502507
updateProjectFromTemplates();
503508
activateDeactivateLayerRelatedActions( NULL );
504509

505-
// a bar to warn the user with non-blocking messages
506-
mInfoBar = new QgsMessageBar( centralWidget );
507-
mInfoBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
508-
centralLayout->addWidget( mInfoBar, 0, 0, 1, 1 );
509-
510+
// create the notification widget for macros
510511
mMacrosWarn = QgsMessageBar::createMessage( tr( "Security warning:" ),
511512
tr( "macros have been disabled." ),
512513
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
513514
mInfoBar );
514515

515516
QToolButton *btnEnableMacros = new QToolButton( mMacrosWarn );
516517
btnEnableMacros->setText( tr( "Enable" ) );
517-
btnEnableMacros->setStyleSheet( "background-color: rgba(255, 255, 255, 0);text-decoration: underline;" );
518+
btnEnableMacros->setStyleSheet( "background-color: rgba(255, 255, 255, 0); color: black; text-decoration: underline;" );
518519
btnEnableMacros->setCursor( Qt::PointingHandCursor );
519520
connect( btnEnableMacros, SIGNAL( clicked() ), mInfoBar, SLOT( popWidget() ) );
520521
connect( btnEnableMacros, SIGNAL( clicked() ), this, SLOT( enableProjectMacros() ) );
@@ -841,6 +842,13 @@ void QgisApp::readSettings()
841842

842843
// Add the recently accessed project file paths to the File menu
843844
mRecentProjectPaths = settings.value( "/UI/recentProjectsList" ).toStringList();
845+
846+
// this is a new session! reset enable macros value to "ask"
847+
// whether set to "just for this session"
848+
if ( settings.value( "/qgis/enableMacros", 1 ).toInt() == 2 )
849+
{
850+
settings.setValue( "/qgis/enableMacros", 1 );
851+
}
844852
}
845853

846854

@@ -3239,13 +3247,20 @@ void QgisApp::fileOpen()
32393247
// does the project have any macros?
32403248
if ( mPythonUtils && mPythonUtils->isEnabled() )
32413249
{
3242-
if ( settings.value( "/qgis/enable_macros", false ).toBool() )
3243-
{
3244-
enableProjectMacros();
3245-
}
3246-
else if ( !QgsProject::instance()->readEntry( "Macros", "/pythonCode", QString::null ).isEmpty() )
3250+
if ( !QgsProject::instance()->readEntry( "Macros", "/pythonCode", QString::null ).isEmpty() )
32473251
{
3248-
mInfoBar->pushWidget( mMacrosWarn, 1 );
3252+
int enableMacros = settings.value( "/qgis/enableMacros", 1 ).toInt();
3253+
// 0 = never, 1 = ask, 2 = just for this session, 3 = always
3254+
3255+
if ( enableMacros == 3 || enableMacros == 2 )
3256+
{
3257+
enableProjectMacros();
3258+
}
3259+
else if ( enableMacros == 1 ) // ask
3260+
{
3261+
// display the macros notification widget
3262+
mInfoBar->pushWidget( mMacrosWarn, 1 );
3263+
}
32493264
}
32503265
}
32513266

src/app/qgsoptions.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
429429

430430
chbAskToSaveProjectChanges->setChecked( settings.value( "qgis/askToSaveProjectChanges", QVariant( true ) ).toBool() );
431431
chbWarnOldProjectVersion->setChecked( settings.value( "/qgis/warnOldProjectVersion", QVariant( true ) ).toBool() );
432+
cmbEnableMacros->setCurrentIndex( settings.value( "/qgis/enableMacros", 1 ).toInt() );
432433

433434
// templates
434435
cbxProjectDefaultNew->setChecked( settings.value( "/qgis/newProjectDefault", QVariant( false ) ).toBool() );
@@ -843,6 +844,7 @@ void QgsOptions::saveOptions()
843844
settings.setValue( "/qgis/projectTemplateDir", leTemplateFolder->text() );
844845
QgisApp::instance()->updateProjectFromTemplates();
845846
}
847+
settings.setValue( "/qgis/enableMacros", cmbEnableMacros->currentIndex() );
846848

847849
settings.setValue( "/qgis/nullValue", leNullValue->text() );
848850
settings.setValue( "/qgis/style", cmbStyle->currentText() );

src/ui/qgsoptionsbase.ui

+70-16
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
<rect>
6767
<x>0</x>
6868
<y>0</y>
69-
<width>784</width>
70-
<height>1099</height>
69+
<width>772</width>
70+
<height>1062</height>
7171
</rect>
7272
</property>
7373
<layout class="QGridLayout" name="gridLayout">
@@ -174,6 +174,60 @@
174174
</item>
175175
</layout>
176176
</item>
177+
<item>
178+
<layout class="QHBoxLayout" name="horizontalLayout_21">
179+
<item>
180+
<widget class="QLabel" name="label_33">
181+
<property name="text">
182+
<string>Enable macros</string>
183+
</property>
184+
</widget>
185+
</item>
186+
<item>
187+
<widget class="QComboBox" name="cmbEnableMacros">
188+
<property name="currentIndex">
189+
<number>0</number>
190+
</property>
191+
<property name="sizeAdjustPolicy">
192+
<enum>QComboBox::AdjustToContents</enum>
193+
</property>
194+
<item>
195+
<property name="text">
196+
<string>Never</string>
197+
</property>
198+
</item>
199+
<item>
200+
<property name="text">
201+
<string>Ask</string>
202+
</property>
203+
</item>
204+
<item>
205+
<property name="text">
206+
<string>For this session only</string>
207+
</property>
208+
</item>
209+
<item>
210+
<property name="text">
211+
<string>Always (not recommended)</string>
212+
</property>
213+
</item>
214+
</widget>
215+
</item>
216+
<item>
217+
<spacer name="horizontalSpacer_17">
218+
<property name="orientation">
219+
<enum>Qt::Horizontal</enum>
220+
</property>
221+
<property name="sizeHint" stdset="0">
222+
<size>
223+
<width>40</width>
224+
<height>20</height>
225+
</size>
226+
</property>
227+
</spacer>
228+
</item>
229+
</layout>
230+
</item>
177231
</layout>
178232
</widget>
179233
</item>
@@ -949,8 +1003,8 @@
9491003
<rect>
9501004
<x>0</x>
9511005
<y>0</y>
952-
<width>1201</width>
953-
<height>850</height>
1006+
<width>1012</width>
1007+
<height>815</height>
9541008
</rect>
9551009
</property>
9561010
<layout class="QGridLayout" name="gridLayout_8">
@@ -1464,8 +1518,8 @@
14641518
<rect>
14651519
<x>0</x>
14661520
<y>0</y>
1467-
<width>646</width>
1468-
<height>778</height>
1521+
<width>772</width>
1522+
<height>724</height>
14691523
</rect>
14701524
</property>
14711525
<layout class="QGridLayout" name="gridLayout_4">
@@ -1834,8 +1888,8 @@
18341888
<rect>
18351889
<x>0</x>
18361890
<y>0</y>
1837-
<width>317</width>
1838-
<height>91</height>
1891+
<width>788</width>
1892+
<height>585</height>
18391893
</rect>
18401894
</property>
18411895
<layout class="QGridLayout" name="gridLayout_10">
@@ -1915,8 +1969,8 @@
19151969
<rect>
19161970
<x>0</x>
19171971
<y>0</y>
1918-
<width>679</width>
1919-
<height>642</height>
1972+
<width>772</width>
1973+
<height>606</height>
19201974
</rect>
19211975
</property>
19221976
<layout class="QGridLayout" name="gridLayout_13">
@@ -2291,8 +2345,8 @@
22912345
<rect>
22922346
<x>0</x>
22932347
<y>0</y>
2294-
<width>745</width>
2295-
<height>431</height>
2348+
<width>788</width>
2349+
<height>585</height>
22962350
</rect>
22972351
</property>
22982352
<layout class="QGridLayout" name="gridLayout_15">
@@ -2478,8 +2532,8 @@
24782532
<rect>
24792533
<x>0</x>
24802534
<y>0</y>
2481-
<width>519</width>
2482-
<height>575</height>
2535+
<width>788</width>
2536+
<height>585</height>
24832537
</rect>
24842538
</property>
24852539
<layout class="QGridLayout" name="gridLayout_17">
@@ -2575,8 +2629,8 @@
25752629
<rect>
25762630
<x>0</x>
25772631
<y>0</y>
2578-
<width>589</width>
2579-
<height>582</height>
2632+
<width>788</width>
2633+
<height>585</height>
25802634
</rect>
25812635
</property>
25822636
<layout class="QGridLayout" name="gridLayout_20">

0 commit comments

Comments
 (0)