Skip to content
Permalink
Browse files

Move "evaluate default values" option to project properties

It was not properly placed in the application settings.
  • Loading branch information
m-kuhn committed May 28, 2016
1 parent 000eb07 commit 662bf4300d14304c47e2a59152517685e5899769
@@ -635,7 +635,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
cbxSnappingOptionsDocked->setChecked( mSettings->value( "/qgis/dockSnapping", false ).toBool() );
cbxAddPostgisDC->setChecked( mSettings->value( "/qgis/addPostgisDC", false ).toBool() );
cbxAddOracleDC->setChecked( mSettings->value( "/qgis/addOracleDC", false ).toBool() );
cbxEvaluateDefaultValues->setChecked( mSettings->value( "/qgis/evaluateDefaultValues", false ).toBool() );
cbxCompileExpressions->setChecked( mSettings->value( "/qgis/compileExpressions", true ).toBool() );
cbxCreateRasterLegendIcons->setChecked( mSettings->value( "/qgis/createRasterLegendIcons", false ).toBool() );

@@ -1192,7 +1191,6 @@ void QgsOptions::saveOptions()
mSettings->setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
mSettings->setValue( "/qgis/addOracleDC", cbxAddOracleDC->isChecked() );
mSettings->setValue( "/qgis/compileExpressions", cbxCompileExpressions->isChecked() );
mSettings->setValue( "/qgis/evaluateDefaultValues", cbxEvaluateDefaultValues->isChecked() );
mSettings->setValue( "/qgis/defaultLegendGraphicResolution", mLegendGraphicResolutionSpinBox->value() );
bool createRasterLegendIcons = mSettings->value( "/qgis/createRasterLegendIcons", false ).toBool();
mSettings->setValue( "/qgis/createRasterLegendIcons", cbxCreateRasterLegendIcons->isChecked() );
@@ -714,6 +714,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
}

mAutoTransaction->setChecked( QgsProject::instance()->autoTransaction() );
mEvaluateDefaultValues->setChecked( QgsProject::instance()->evaluateDefaultValues() );

// Variables editor
mVariableEditor->context()->appendScope( QgsExpressionContextUtils::globalScope() );
@@ -801,6 +802,7 @@ void QgsProjectProperties::apply()
// Set the project title
QgsProject::instance()->setTitle( title() );
QgsProject::instance()->setAutoTransaction( mAutoTransaction->isChecked() );
QgsProject::instance()->setEvaluateDefaultValues( mEvaluateDefaultValues->isChecked() );

// set the mouse display precision method and the
// number of decimal places for the manual option
@@ -40,6 +40,7 @@
#include "qgsunittypes.h"
#include "qgstransaction.h"
#include "qgstransactiongroup.h"
#include "qgsvectordataprovider.h"

#include <QApplication>
#include <QFileInfo>
@@ -328,11 +329,13 @@ struct QgsProject::Imp
QgsPropertyKey properties_; // property hierarchy
QString title; // project title
bool autoTransaction; // transaction grouped editing
bool evaluateDefaultValues; // evaluate default values immediately
bool dirty; // project has been modified since it has been read or saved

Imp()
: title()
, autoTransaction( false )
, evaluateDefaultValues( false )
, dirty( false )
{ // top property node is the root
// "properties" that contains all plug-in
@@ -350,6 +353,7 @@ struct QgsProject::Imp
properties_.clearKeys();
title.clear();
autoTransaction = false;
evaluateDefaultValues = false;
dirty = false;
}

@@ -370,7 +374,7 @@ QgsProject::QgsProject()
// whenever layers are added to or removed from the registry,
// layer tree will be updated
mLayerTreeRegistryBridge = new QgsLayerTreeRegistryBridge( mRootGroup, this );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( addToTransactionGroups( QList<QgsMapLayer*> ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( onMapLayersAdded( QList<QgsMapLayer*> ) ) );
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersRemoved( QStringList ) ), this, SLOT( cleanTransactionGroups() ) );
} // QgsProject ctor

@@ -902,6 +906,14 @@ bool QgsProject::read()
imp_->autoTransaction = true;
}

nl = doc->elementsByTagName( "evaluateDefaultValues" );
if ( nl.count() )
{
QDomElement evaluateDefaultValuesElement = nl.at( 0 ).toElement();
if ( evaluateDefaultValuesElement.attribute( "active", "0" ).toInt() == 1 )
imp_->evaluateDefaultValues = true;
}

// read the layer tree from project file

mRootGroup->setCustomProperty( "loading", 1 );
@@ -1010,14 +1022,14 @@ void QgsProject::loadEmbeddedNodes( QgsLayerTreeGroup *group )
}
}

void QgsProject::addToTransactionGroups( const QList<QgsMapLayer*> layers )
void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
{
if ( autoTransaction() )
Q_FOREACH ( QgsMapLayer* layer, layers )
{
Q_FOREACH ( QgsMapLayer* layer, layers )
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
if ( vlayer )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
if ( vlayer )
if ( autoTransaction() )
{
if ( QgsTransaction::supportsTransaction( vlayer ) )
{
@@ -1036,6 +1048,7 @@ void QgsProject::addToTransactionGroups( const QList<QgsMapLayer*> layers )
tg->addLayer( vlayer );
}
}
vlayer->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues() );
}
}
}
@@ -1110,6 +1123,10 @@ bool QgsProject::write()
transactionNode.setAttribute( "active", imp_->autoTransaction ? "1" : "0" );
qgisNode.appendChild( transactionNode );

QDomElement evaluateDefaultValuesNode = doc->createElement( "evaluateDefaultValues" );
evaluateDefaultValuesNode.setAttribute( "active", imp_->evaluateDefaultValues ? "1" : "0" );
qgisNode.appendChild( evaluateDefaultValuesNode );

QDomText titleText = doc->createTextNode( title() ); // XXX why have title TWICE?
titleNode.appendChild( titleText );

@@ -2119,6 +2136,25 @@ void QgsProject::snapSettings( QStringList &layerIdList, QStringList &enabledLis
avoidIntersectionList = readListEntry( "Digitizing", "/AvoidIntersectionsList" );
}

bool QgsProject::evaluateDefaultValues() const
{
return imp_->evaluateDefaultValues;
}

void QgsProject::setEvaluateDefaultValues( bool evaluateDefaultValues )
{
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers().values() )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( layer );
if ( vl )
{
vl->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues );
}
}

imp_->evaluateDefaultValues = evaluateDefaultValues;
}

void QgsProject::setTopologicalEditing( bool enabled )
{
QgsProject::instance()->writeEntry( "Digitizing", "/TopologicalEditing", ( enabled ? 1 : 0 ) );
@@ -2232,7 +2268,7 @@ void QgsProject::setAutoTransaction( bool autoTransaction )
imp_->autoTransaction = autoTransaction;

if ( autoTransaction )
addToTransactionGroups( QgsMapLayerRegistry::instance()->mapLayers().values() );
onMapLayersAdded( QgsMapLayerRegistry::instance()->mapLayers().values() );
else
cleanTransactionGroups( true );
}
@@ -389,6 +389,21 @@ class CORE_EXPORT QgsProject : public QObject
*/
QMap< QPair< QString, QString>, QgsTransactionGroup*> transactionGroups();

/**
* Should default values be evaluated on provider side when requested and not when committed.
*
* @note added in 2.16
*/
bool evaluateDefaultValues() const;


/**
* Defines if default values should be evaluated on provider side when requested and not when committed.
*
* @note added in 2.16
*/
void setEvaluateDefaultValues( bool evaluateDefaultValues );

protected:
/** Set error message from read/write operation
* @note not available in Python bindings
@@ -456,7 +471,7 @@ class CORE_EXPORT QgsProject : public QObject
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );

private slots:
void addToTransactionGroups( const QList<QgsMapLayer*> layers );
void onMapLayersAdded( const QList<QgsMapLayer*>& layers );
void cleanTransactionGroups( bool force = false );

private:
@@ -25,7 +25,6 @@
#include <qgscoordinatereferencesystem.h>

#include <QMessageBox>
#include <QSettings>

#include "qgsvectorlayerimport.h"
#include "qgsprovidercountcalcevent.h"
@@ -1655,11 +1654,9 @@ bool QgsPostgresProvider::isValid()

QVariant QgsPostgresProvider::defaultValue( int fieldId )
{
QSettings settings;

QVariant defVal = mDefaultValues.value( fieldId, QString::null );

if ( settings.value( "/qgis/evaluateDefaultValues", false ).toBool() && !defVal.isNull() )
if ( providerProperty( EvaluateDefaultValues, false ).toBool() && !defVal.isNull() )
{
const QgsField& fld = field( fieldId );

@@ -308,7 +308,7 @@
<item>
<widget class="QStackedWidget" name="mOptionsStackedWidget">
<property name="currentIndex">
<number>13</number>
<number>2</number>
</property>
<widget class="QWidget" name="mOptionsPageGeneral">
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -337,7 +337,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1230</width>
<width>662</width>
<height>682</height>
</rect>
</property>
@@ -1468,7 +1468,7 @@
<x>0</x>
<y>0</y>
<width>610</width>
<height>705</height>
<height>684</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -1720,16 +1720,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbxEvaluateDefaultValues">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;When digitizing a new feature, default values are retrieved from the database. With this option turned on, the default values will be evaluated at the time of digitizing. With this option turned off, the default values will be evaluated at the time of saving.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Evaluate default values</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -1836,7 +1826,7 @@
<x>0</x>
<y>0</y>
<width>722</width>
<height>1013</height>
<height>983</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_22">
@@ -3119,7 +3109,7 @@
<x>0</x>
<y>0</y>
<width>635</width>
<height>663</height>
<height>693</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_30">
@@ -3549,7 +3539,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1061</width>
<width>610</width>
<height>605</height>
</rect>
</property>
@@ -5383,12 +5373,6 @@
<header>qgscolorbuttonv2.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorSchemeList</class>
<extends>QWidget</extends>
@@ -5401,6 +5385,12 @@
<header location="global">qgsvariableeditorwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsScaleComboBox</class>
<extends>QComboBox</extends>
@@ -5610,7 +5600,6 @@
<tabstop>mRemoveUrlPushButton</tabstop>
<tabstop>mAdvancedSettingsEnableButton</tabstop>
<tabstop>cbxCheckVersion</tabstop>
<tabstop>cbxEvaluateDefaultValues</tabstop>
<tabstop>mOptionsScrollArea_10</tabstop>
<tabstop>mAddUrlPushButton</tabstop>
<tabstop>mExcludeUrlListWidget</tabstop>

0 comments on commit 662bf43

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