Skip to content

Commit

Permalink
add option to choose whether enable project macros
Browse files Browse the repository at this point in the history
  • Loading branch information
brushtyler committed Aug 31, 2012
1 parent 2910a8e commit 7a24104
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 28 deletions.
39 changes: 27 additions & 12 deletions src/app/qgisapp.cpp
Expand Up @@ -474,6 +474,11 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,

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

// a bar to warn the user with non-blocking messages
mInfoBar = new QgsMessageBar( centralWidget );
mInfoBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
centralLayout->addWidget( mInfoBar, 0, 0, 1, 1 );

//set the focus to the map canvas
mMapCanvas->setFocus();

Expand Down Expand Up @@ -502,19 +507,15 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
updateProjectFromTemplates();
activateDeactivateLayerRelatedActions( NULL );

// a bar to warn the user with non-blocking messages
mInfoBar = new QgsMessageBar( centralWidget );
mInfoBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
centralLayout->addWidget( mInfoBar, 0, 0, 1, 1 );

// create the notification widget for macros
mMacrosWarn = QgsMessageBar::createMessage( tr( "Security warning:" ),
tr( "macros have been disabled." ),
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
mInfoBar );

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

// Add the recently accessed project file paths to the File menu
mRecentProjectPaths = settings.value( "/UI/recentProjectsList" ).toStringList();

// this is a new session! reset enable macros value to "ask"
// whether set to "just for this session"
if ( settings.value( "/qgis/enableMacros", 1 ).toInt() == 2 )
{
settings.setValue( "/qgis/enableMacros", 1 );
}
}


Expand Down Expand Up @@ -3239,13 +3247,20 @@ void QgisApp::fileOpen()
// does the project have any macros?
if ( mPythonUtils && mPythonUtils->isEnabled() )
{
if ( settings.value( "/qgis/enable_macros", false ).toBool() )
{
enableProjectMacros();
}
else if ( !QgsProject::instance()->readEntry( "Macros", "/pythonCode", QString::null ).isEmpty() )
if ( !QgsProject::instance()->readEntry( "Macros", "/pythonCode", QString::null ).isEmpty() )
{
mInfoBar->pushWidget( mMacrosWarn, 1 );
int enableMacros = settings.value( "/qgis/enableMacros", 1 ).toInt();
// 0 = never, 1 = ask, 2 = just for this session, 3 = always

if ( enableMacros == 3 || enableMacros == 2 )
{
enableProjectMacros();
}
else if ( enableMacros == 1 ) // ask
{
// display the macros notification widget
mInfoBar->pushWidget( mMacrosWarn, 1 );
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -429,6 +429,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

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

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

settings.setValue( "/qgis/nullValue", leNullValue->text() );
settings.setValue( "/qgis/style", cmbStyle->currentText() );
Expand Down
86 changes: 70 additions & 16 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -66,8 +66,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>784</width>
<height>1099</height>
<width>772</width>
<height>1062</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -174,6 +174,60 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_21">
<item>
<widget class="QLabel" name="label_33">
<property name="text">
<string>Enable macros</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbEnableMacros">
<property name="currentIndex">
<number>0</number>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<item>
<property name="text">
<string>Never</string>
</property>
</item>
<item>
<property name="text">
<string>Ask</string>
</property>
</item>
<item>
<property name="text">
<string>For this session only</string>
</property>
</item>
<item>
<property name="text">
<string>Always (not recommended)</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_17">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -949,8 +1003,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1201</width>
<height>850</height>
<width>1012</width>
<height>815</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
Expand Down Expand Up @@ -1464,8 +1518,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>646</width>
<height>778</height>
<width>772</width>
<height>724</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -1834,8 +1888,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>317</width>
<height>91</height>
<width>788</width>
<height>585</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_10">
Expand Down Expand Up @@ -1915,8 +1969,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>679</width>
<height>642</height>
<width>772</width>
<height>606</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_13">
Expand Down Expand Up @@ -2291,8 +2345,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>745</width>
<height>431</height>
<width>788</width>
<height>585</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
Expand Down Expand Up @@ -2478,8 +2532,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>519</width>
<height>575</height>
<width>788</width>
<height>585</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
Expand Down Expand Up @@ -2575,8 +2629,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>589</width>
<height>582</height>
<width>788</width>
<height>585</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_20">
Expand Down

0 comments on commit 7a24104

Please sign in to comment.