Skip to content

Commit 662bf43

Browse files
committed
Move "evaluate default values" option to project properties
It was not properly placed in the application settings.
1 parent 000eb07 commit 662bf43

File tree

7 files changed

+98
-48
lines changed

7 files changed

+98
-48
lines changed

src/app/qgsoptions.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl )
635635
cbxSnappingOptionsDocked->setChecked( mSettings->value( "/qgis/dockSnapping", false ).toBool() );
636636
cbxAddPostgisDC->setChecked( mSettings->value( "/qgis/addPostgisDC", false ).toBool() );
637637
cbxAddOracleDC->setChecked( mSettings->value( "/qgis/addOracleDC", false ).toBool() );
638-
cbxEvaluateDefaultValues->setChecked( mSettings->value( "/qgis/evaluateDefaultValues", false ).toBool() );
639638
cbxCompileExpressions->setChecked( mSettings->value( "/qgis/compileExpressions", true ).toBool() );
640639
cbxCreateRasterLegendIcons->setChecked( mSettings->value( "/qgis/createRasterLegendIcons", false ).toBool() );
641640

@@ -1192,7 +1191,6 @@ void QgsOptions::saveOptions()
11921191
mSettings->setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
11931192
mSettings->setValue( "/qgis/addOracleDC", cbxAddOracleDC->isChecked() );
11941193
mSettings->setValue( "/qgis/compileExpressions", cbxCompileExpressions->isChecked() );
1195-
mSettings->setValue( "/qgis/evaluateDefaultValues", cbxEvaluateDefaultValues->isChecked() );
11961194
mSettings->setValue( "/qgis/defaultLegendGraphicResolution", mLegendGraphicResolutionSpinBox->value() );
11971195
bool createRasterLegendIcons = mSettings->value( "/qgis/createRasterLegendIcons", false ).toBool();
11981196
mSettings->setValue( "/qgis/createRasterLegendIcons", cbxCreateRasterLegendIcons->isChecked() );

src/app/qgsprojectproperties.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
714714
}
715715

716716
mAutoTransaction->setChecked( QgsProject::instance()->autoTransaction() );
717+
mEvaluateDefaultValues->setChecked( QgsProject::instance()->evaluateDefaultValues() );
717718

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

805807
// set the mouse display precision method and the
806808
// number of decimal places for the manual option

src/core/qgsproject.cpp

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "qgsunittypes.h"
4141
#include "qgstransaction.h"
4242
#include "qgstransactiongroup.h"
43+
#include "qgsvectordataprovider.h"
4344

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

333335
Imp()
334336
: title()
335337
, autoTransaction( false )
338+
, evaluateDefaultValues( false )
336339
, dirty( false )
337340
{ // top property node is the root
338341
// "properties" that contains all plug-in
@@ -350,6 +353,7 @@ struct QgsProject::Imp
350353
properties_.clearKeys();
351354
title.clear();
352355
autoTransaction = false;
356+
evaluateDefaultValues = false;
353357
dirty = false;
354358
}
355359

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

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

909+
nl = doc->elementsByTagName( "evaluateDefaultValues" );
910+
if ( nl.count() )
911+
{
912+
QDomElement evaluateDefaultValuesElement = nl.at( 0 ).toElement();
913+
if ( evaluateDefaultValuesElement.attribute( "active", "0" ).toInt() == 1 )
914+
imp_->evaluateDefaultValues = true;
915+
}
916+
905917
// read the layer tree from project file
906918

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

1013-
void QgsProject::addToTransactionGroups( const QList<QgsMapLayer*> layers )
1025+
void QgsProject::onMapLayersAdded( const QList<QgsMapLayer*>& layers )
10141026
{
1015-
if ( autoTransaction() )
1027+
Q_FOREACH ( QgsMapLayer* layer, layers )
10161028
{
1017-
Q_FOREACH ( QgsMapLayer* layer, layers )
1029+
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
1030+
if ( vlayer )
10181031
{
1019-
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( layer );
1020-
if ( vlayer )
1032+
if ( autoTransaction() )
10211033
{
10221034
if ( QgsTransaction::supportsTransaction( vlayer ) )
10231035
{
@@ -1036,6 +1048,7 @@ void QgsProject::addToTransactionGroups( const QList<QgsMapLayer*> layers )
10361048
tg->addLayer( vlayer );
10371049
}
10381050
}
1051+
vlayer->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues() );
10391052
}
10401053
}
10411054
}
@@ -1110,6 +1123,10 @@ bool QgsProject::write()
11101123
transactionNode.setAttribute( "active", imp_->autoTransaction ? "1" : "0" );
11111124
qgisNode.appendChild( transactionNode );
11121125

1126+
QDomElement evaluateDefaultValuesNode = doc->createElement( "evaluateDefaultValues" );
1127+
evaluateDefaultValuesNode.setAttribute( "active", imp_->evaluateDefaultValues ? "1" : "0" );
1128+
qgisNode.appendChild( evaluateDefaultValuesNode );
1129+
11131130
QDomText titleText = doc->createTextNode( title() ); // XXX why have title TWICE?
11141131
titleNode.appendChild( titleText );
11151132

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

2139+
bool QgsProject::evaluateDefaultValues() const
2140+
{
2141+
return imp_->evaluateDefaultValues;
2142+
}
2143+
2144+
void QgsProject::setEvaluateDefaultValues( bool evaluateDefaultValues )
2145+
{
2146+
Q_FOREACH ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers().values() )
2147+
{
2148+
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( layer );
2149+
if ( vl )
2150+
{
2151+
vl->dataProvider()->setProviderProperty( QgsVectorDataProvider::EvaluateDefaultValues, evaluateDefaultValues );
2152+
}
2153+
}
2154+
2155+
imp_->evaluateDefaultValues = evaluateDefaultValues;
2156+
}
2157+
21222158
void QgsProject::setTopologicalEditing( bool enabled )
21232159
{
21242160
QgsProject::instance()->writeEntry( "Digitizing", "/TopologicalEditing", ( enabled ? 1 : 0 ) );
@@ -2232,7 +2268,7 @@ void QgsProject::setAutoTransaction( bool autoTransaction )
22322268
imp_->autoTransaction = autoTransaction;
22332269

22342270
if ( autoTransaction )
2235-
addToTransactionGroups( QgsMapLayerRegistry::instance()->mapLayers().values() );
2271+
onMapLayersAdded( QgsMapLayerRegistry::instance()->mapLayers().values() );
22362272
else
22372273
cleanTransactionGroups( true );
22382274
}

src/core/qgsproject.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,21 @@ class CORE_EXPORT QgsProject : public QObject
389389
*/
390390
QMap< QPair< QString, QString>, QgsTransactionGroup*> transactionGroups();
391391

392+
/**
393+
* Should default values be evaluated on provider side when requested and not when committed.
394+
*
395+
* @note added in 2.16
396+
*/
397+
bool evaluateDefaultValues() const;
398+
399+
400+
/**
401+
* Defines if default values should be evaluated on provider side when requested and not when committed.
402+
*
403+
* @note added in 2.16
404+
*/
405+
void setEvaluateDefaultValues( bool evaluateDefaultValues );
406+
392407
protected:
393408
/** Set error message from read/write operation
394409
* @note not available in Python bindings
@@ -456,7 +471,7 @@ class CORE_EXPORT QgsProject : public QObject
456471
void nonIdentifiableLayersChanged( QStringList nonIdentifiableLayers );
457472

458473
private slots:
459-
void addToTransactionGroups( const QList<QgsMapLayer*> layers );
474+
void onMapLayersAdded( const QList<QgsMapLayer*>& layers );
460475
void cleanTransactionGroups( bool force = false );
461476

462477
private:

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <qgscoordinatereferencesystem.h>
2626

2727
#include <QMessageBox>
28-
#include <QSettings>
2928

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

16561655
QVariant QgsPostgresProvider::defaultValue( int fieldId )
16571656
{
1658-
QSettings settings;
1659-
16601657
QVariant defVal = mDefaultValues.value( fieldId, QString::null );
16611658

1662-
if ( settings.value( "/qgis/evaluateDefaultValues", false ).toBool() && !defVal.isNull() )
1659+
if ( providerProperty( EvaluateDefaultValues, false ).toBool() && !defVal.isNull() )
16631660
{
16641661
const QgsField& fld = field( fieldId );
16651662

src/ui/qgsoptionsbase.ui

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
<item>
309309
<widget class="QStackedWidget" name="mOptionsStackedWidget">
310310
<property name="currentIndex">
311-
<number>13</number>
311+
<number>2</number>
312312
</property>
313313
<widget class="QWidget" name="mOptionsPageGeneral">
314314
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -337,7 +337,7 @@
337337
<rect>
338338
<x>0</x>
339339
<y>0</y>
340-
<width>1230</width>
340+
<width>662</width>
341341
<height>682</height>
342342
</rect>
343343
</property>
@@ -1468,7 +1468,7 @@
14681468
<x>0</x>
14691469
<y>0</y>
14701470
<width>610</width>
1471-
<height>705</height>
1471+
<height>684</height>
14721472
</rect>
14731473
</property>
14741474
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -1720,16 +1720,6 @@
17201720
</property>
17211721
</widget>
17221722
</item>
1723-
<item>
1724-
<widget class="QCheckBox" name="cbxEvaluateDefaultValues">
1725-
<property name="toolTip">
1726-
<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>
1727-
</property>
1728-
<property name="text">
1729-
<string>Evaluate default values</string>
1730-
</property>
1731-
</widget>
1732-
</item>
17331723
</layout>
17341724
</widget>
17351725
</item>
@@ -1836,7 +1826,7 @@
18361826
<x>0</x>
18371827
<y>0</y>
18381828
<width>722</width>
1839-
<height>1013</height>
1829+
<height>983</height>
18401830
</rect>
18411831
</property>
18421832
<layout class="QGridLayout" name="gridLayout_22">
@@ -3119,7 +3109,7 @@
31193109
<x>0</x>
31203110
<y>0</y>
31213111
<width>635</width>
3122-
<height>663</height>
3112+
<height>693</height>
31233113
</rect>
31243114
</property>
31253115
<layout class="QVBoxLayout" name="verticalLayout_30">
@@ -3549,7 +3539,7 @@
35493539
<rect>
35503540
<x>0</x>
35513541
<y>0</y>
3552-
<width>1061</width>
3542+
<width>610</width>
35533543
<height>605</height>
35543544
</rect>
35553545
</property>
@@ -5383,12 +5373,6 @@
53835373
<header>qgscolorbuttonv2.h</header>
53845374
<container>1</container>
53855375
</customwidget>
5386-
<customwidget>
5387-
<class>QgsProjectionSelectionWidget</class>
5388-
<extends>QWidget</extends>
5389-
<header>qgsprojectionselectionwidget.h</header>
5390-
<container>1</container>
5391-
</customwidget>
53925376
<customwidget>
53935377
<class>QgsColorSchemeList</class>
53945378
<extends>QWidget</extends>
@@ -5401,6 +5385,12 @@
54015385
<header location="global">qgsvariableeditorwidget.h</header>
54025386
<container>1</container>
54035387
</customwidget>
5388+
<customwidget>
5389+
<class>QgsProjectionSelectionWidget</class>
5390+
<extends>QWidget</extends>
5391+
<header>qgsprojectionselectionwidget.h</header>
5392+
<container>1</container>
5393+
</customwidget>
54045394
<customwidget>
54055395
<class>QgsScaleComboBox</class>
54065396
<extends>QComboBox</extends>
@@ -5610,7 +5600,6 @@
56105600
<tabstop>mRemoveUrlPushButton</tabstop>
56115601
<tabstop>mAdvancedSettingsEnableButton</tabstop>
56125602
<tabstop>cbxCheckVersion</tabstop>
5613-
<tabstop>cbxEvaluateDefaultValues</tabstop>
56145603
<tabstop>mOptionsScrollArea_10</tabstop>
56155604
<tabstop>mAddUrlPushButton</tabstop>
56165605
<tabstop>mExcludeUrlListWidget</tabstop>

0 commit comments

Comments
 (0)