Trust is now a project option instead of a global option

This commit is contained in:
Blottiere Paul 2017-09-05 07:44:20 +01:00
parent 7ef2e7046e
commit 8a17a608e1
10 changed files with 199 additions and 89 deletions

View File

@ -785,6 +785,31 @@ Returns the number of registered layers.
:rtype: QgsCoordinateReferenceSystem
%End
void setTrust( bool trust );
%Docstring
Sets the trust option allowing to indicate if the extent has to be
read from the XML document when data source has no metadata or if the
data provider has to determine it. Moreover, when this option is
activated, primary key unicity is not checked for views and
materialized views with Postgres provider.
\param trust True to trust the project, false otherwise
.. versionadded:: 3.0
%End
bool trust() const;
%Docstring
Returns true if the trust option is activated, false otherwise. This
option allows indicateing if the extent has to be read from the XML
document when data source has no metadata or if the data provider has
to determine it. Moreover, when this option is activated, primary key
unicity is not checked for views and materialized views with Postgres
provider.
.. versionadded:: 3.0
:rtype: bool
%End
signals:
void readProject( const QDomDocument & );

View File

@ -635,7 +635,6 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
cbxAddOracleDC->setChecked( mSettings->value( QStringLiteral( "/qgis/addOracleDC" ), false ).toBool() );
cbxCompileExpressions->setChecked( mSettings->value( QStringLiteral( "/qgis/compileExpressions" ), true ).toBool() );
cbxCreateRasterLegendIcons->setChecked( mSettings->value( QStringLiteral( "/qgis/createRasterLegendIcons" ), false ).toBool() );
cbxTrustProject->setChecked( mSettings->value( QStringLiteral( "/qgis/trustProject" ), false ).toBool() );
mComboCopyFeatureFormat->addItem( tr( "Plain text, no geometry" ), QgsClipboard::AttributesOnly );
mComboCopyFeatureFormat->addItem( tr( "Plain text, WKT geometry" ), QgsClipboard::AttributesWithWKT );
@ -1226,7 +1225,6 @@ void QgsOptions::saveOptions()
mSettings->setValue( QStringLiteral( "/qgis/addPostgisDC" ), cbxAddPostgisDC->isChecked() );
mSettings->setValue( QStringLiteral( "/qgis/addOracleDC" ), cbxAddOracleDC->isChecked() );
mSettings->setValue( QStringLiteral( "/qgis/compileExpressions" ), cbxCompileExpressions->isChecked() );
mSettings->setValue( QStringLiteral( "/qgis/trustProject" ), cbxTrustProject->isChecked() );
mSettings->setValue( QStringLiteral( "/qgis/defaultLegendGraphicResolution" ), mLegendGraphicResolutionSpinBox->value() );
bool createRasterLegendIcons = mSettings->value( QStringLiteral( "/qgis/createRasterLegendIcons" ), false ).toBool();
mSettings->setValue( QStringLiteral( "/qgis/createRasterLegendIcons" ), cbxCreateRasterLegendIcons->isChecked() );

View File

@ -708,6 +708,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mAutoTransaction->setChecked( QgsProject::instance()->autoTransaction() );
mEvaluateDefaultValues->setChecked( QgsProject::instance()->evaluateDefaultValues() );
mTrustProjectCheckBox->setChecked( QgsProject::instance()->trust() );
// Variables editor
mVariableEditor->context()->appendScope( QgsExpressionContextUtils::globalScope() );
@ -764,6 +765,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->setTitle( title() );
QgsProject::instance()->setAutoTransaction( mAutoTransaction->isChecked() );
QgsProject::instance()->setEvaluateDefaultValues( mEvaluateDefaultValues->isChecked() );
QgsProject::instance()->setTrust( mTrustProjectCheckBox->isChecked() );
// set the mouse display precision method and the
// number of decimal places for the manual option

View File

@ -480,6 +480,7 @@ void QgsProject::clear()
mAutoTransaction = false;
mEvaluateDefaultValues = false;
mDirty = false;
mTrust = false;
mCustomVariables.clear();
mEmbeddedLayers.clear();
@ -719,11 +720,9 @@ bool QgsProject::addLayer( const QDomElement &layerElem, QList<QDomNode> &broken
mapLayer = new QgsVectorLayer;
// apply specific settings to vector layer
QgsSettings s;
bool trustProject = s.value( QStringLiteral( "/qgis/trustProject" ), false ).toBool();
if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mapLayer ) )
{
vl->setReadExtentFromXml( trustProject );
vl->setReadExtentFromXml( mTrust );
}
}
else if ( type == QLatin1String( "raster" ) )
@ -900,6 +899,14 @@ bool QgsProject::readProjectFile( const QString &filename )
mEvaluateDefaultValues = true;
}
nl = doc->elementsByTagName( QStringLiteral( "trust" ) );
if ( nl.count() )
{
QDomElement trustElement = nl.at( 0 ).toElement();
if ( trustElement.attribute( QStringLiteral( "active" ), QStringLiteral( "0" ) ).toInt() == 1 )
mTrust = true;
}
// read the layer tree from project file
mRootGroup->setCustomProperty( QStringLiteral( "loading" ), 1 );
@ -1304,6 +1311,10 @@ bool QgsProject::writeProjectFile( const QString &filename )
evaluateDefaultValuesNode.setAttribute( QStringLiteral( "active" ), mEvaluateDefaultValues ? "1" : "0" );
qgisNode.appendChild( evaluateDefaultValuesNode );
QDomElement trustNode = doc->createElement( QStringLiteral( "trust" ) );
trustNode.setAttribute( QStringLiteral( "active" ), mTrust ? "1" : "0" );
qgisNode.appendChild( trustNode );
QDomText titleText = doc->createTextNode( title() ); // XXX why have title TWICE?
titleNode.appendChild( titleText );
@ -2268,3 +2279,17 @@ QgsCoordinateReferenceSystem QgsProject::defaultCrsForNewLayers() const
return defaultCrs;
}
void QgsProject::setTrust( bool trust )
{
mTrust = trust;
Q_FOREACH ( QgsMapLayer *layer, mapLayers().values() )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( vl )
{
vl->setReadExtentFromXml( trust );
}
}
}

View File

@ -755,6 +755,30 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
QgsCoordinateReferenceSystem defaultCrsForNewLayers() const;
/**
* Sets the trust option allowing to indicate if the extent has to be
* read from the XML document when data source has no metadata or if the
* data provider has to determine it. Moreover, when this option is
* activated, primary key unicity is not checked for views and
* materialized views with Postgres provider.
*
* \param trust True to trust the project, false otherwise
*
* \since QGIS 3.0
*/
void setTrust( bool trust );
/**
* Returns true if the trust option is activated, false otherwise. This
* option allows indicateing if the extent has to be read from the XML
* document when data source has no metadata or if the data provider has
* to determine it. Moreover, when this option is activated, primary key
* unicity is not checked for views and materialized views with Postgres
* provider.
*
* \since QGIS 3.0
*/
bool trust() const { return mTrust; }
signals:
//! emitted when project is being read
@ -1083,6 +1107,7 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
bool mEvaluateDefaultValues; // evaluate default values immediately
QgsCoordinateReferenceSystem mCrs;
bool mDirty; // project has been modified since it has been read or saved
bool mTrust = false;
};
/** Return the version string found in the given DOM document

View File

@ -803,7 +803,8 @@ QgsRectangle QgsVectorLayer::extent() const
if ( !isSpatial() )
return rect;
if ( !mValidExtent && mDataProvider && !mDataProvider->hasMetadata() && mReadExtentFromXml && !mXmlExtent.isNull() )
if ( !mValidExtent && mLazyExtent && mDataProvider && !mDataProvider->hasMetadata() && mReadExtentFromXml && !mXmlExtent.isNull() )
{
mExtent = mXmlExtent;
mValidExtent = true;
@ -1498,12 +1499,28 @@ void QgsVectorLayer::setDataSource( const QString &dataSource, const QString &ba
bool QgsVectorLayer::setDataProvider( QString const &provider )
{
mProviderKey = provider; // XXX is this necessary? Usually already set
// primary key unicity is tested at construction time, so it has to be set
// before initializing postgres provider
QString checkUnicityKey = QStringLiteral( "checkPrimaryKeyUnicity" );
QString dataSource = mDataSource;
if ( provider.compare( QLatin1String( "postgres" ) ) == 0 )
{
QgsDataSourceUri uri( dataSource );
if ( uri.hasParam( checkUnicityKey ) )
uri.removeParam( checkUnicityKey );
uri.setParam( checkUnicityKey, mReadExtentFromXml ? "0" : "1" );
dataSource = uri.uri( false );
}
// XXX when execution gets here.
//XXX - This was a dynamic cast but that kills the Windows
// version big-time with an abnormal termination error
delete mDataProvider;
mDataProvider = ( QgsVectorDataProvider * )( QgsProviderRegistry::instance()->createProvider( provider, mDataSource ) );
mDataProvider = ( QgsVectorDataProvider * )( QgsProviderRegistry::instance()->createProvider( provider, dataSource ) );
if ( !mDataProvider )
{
QgsDebugMsg( " unable to get data provider" );
@ -1559,7 +1576,11 @@ bool QgsVectorLayer::setDataProvider( QString const &provider )
QgsDebugMsg( "Beautified layer name " + name() );
// deal with unnecessary schema qualification to make v.in.ogr happy
mDataSource = mDataProvider->dataSourceUri();
// and remove unnecessary key
QgsDataSourceUri dataProviderUri( mDataProvider->dataSourceUri() );
if ( dataProviderUri.hasParam( checkUnicityKey ) )
dataProviderUri.removeParam( checkUnicityKey );
mDataSource = dataProviderUri.uri( false );
}
else if ( mProviderKey == QLatin1String( "osm" ) )
{

View File

@ -115,6 +115,18 @@ QgsPostgresProvider::QgsPostgresProvider( QString const &uri )
mRequestedSrid = mUri.srid();
mRequestedGeomType = mUri.wkbType();
if ( mUri.hasParam( QStringLiteral( "checkPrimaryKeyUnicity" ) ) )
{
if ( mUri.param( QStringLiteral( "checkPrimaryKeyUnicity" ) ).compare( "0" ) == 0 )
{
mCheckPrimaryKeyUnicity = false;
}
else
{
mCheckPrimaryKeyUnicity = true;
}
}
if ( mSchemaName.isEmpty() && mTableName.startsWith( '(' ) && mTableName.endsWith( ')' ) )
{
mIsQuery = true;
@ -1325,9 +1337,7 @@ bool QgsPostgresProvider::determinePrimaryKey()
}
else if ( type == Relkind::View || type == Relkind::MaterializedView )
{
QgsSettings settings;
bool checkPrimaryKeyUnicity = !settings.value( QStringLiteral( "/qgis/trustProject" ), false ).toBool();
determinePrimaryKeyFromUriKeyColumn( checkPrimaryKeyUnicity );
determinePrimaryKeyFromUriKeyColumn();
}
else
{
@ -1456,7 +1466,7 @@ QStringList QgsPostgresProvider::parseUriKey( const QString &key )
return cols;
}
void QgsPostgresProvider::determinePrimaryKeyFromUriKeyColumn( bool checkPrimaryKeyUnicity )
void QgsPostgresProvider::determinePrimaryKeyFromUriKeyColumn()
{
QString primaryKey = mUri.keyColumn();
mPrimaryKeyType = PktUnknown;
@ -1489,8 +1499,10 @@ void QgsPostgresProvider::determinePrimaryKeyFromUriKeyColumn( bool checkPrimary
if ( !mPrimaryKeyAttrs.isEmpty() )
{
bool unique = true;
if ( checkPrimaryKeyUnicity )
if ( mCheckPrimaryKeyUnicity )
{
unique = uniqueData( primaryKey );
}
if ( mUseEstimatedMetadata || unique )
{

View File

@ -133,7 +133,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
* Fills mPrimaryKeyType and mPrimaryKeyAttrs
* from mUri
*/
void determinePrimaryKeyFromUriKeyColumn( bool checkPrimaryKeyUnicity = true );
void determinePrimaryKeyFromUriKeyColumn();
QgsFields fields() const override;
QString dataComment() const override;
@ -432,6 +432,8 @@ class QgsPostgresProvider : public QgsVectorDataProvider
void setTransaction( QgsTransaction *transaction ) override;
QHash<int, QString> mDefaultValues;
bool mCheckPrimaryKeyUnicity = true;
};

View File

@ -320,7 +320,7 @@
<item>
<widget class="QStackedWidget" name="mOptionsStackedWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="mOptionsPageGeneral">
<layout class="QVBoxLayout" name="verticalLayout_3">
@ -350,7 +350,7 @@
<x>0</x>
<y>0</y>
<width>857</width>
<height>680</height>
<height>678</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
@ -998,8 +998,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>843</width>
<height>1065</height>
<width>561</width>
<height>1079</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
@ -1340,10 +1340,10 @@
<property name="title">
<string>Current environment variables (read-only - bold indicates modified at startup)</string>
</property>
<property name="collapsed">
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<property name="saveCollapsedState">
<property name="saveCollapsedState" stdset="0">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
@ -1528,8 +1528,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>843</width>
<height>710</height>
<width>511</width>
<height>719</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
@ -1791,16 +1791,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbxTrustProject">
<property name="toolTip">
<string>Speed up project loading by skipping data checks. Useful in qgis server context or project with huge database views or materialized view</string>
</property>
<property name="text">
<string>Trust project when data source has no metadata</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -1906,8 +1896,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>843</width>
<height>928</height>
<width>692</width>
<height>994</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_22">
@ -2015,7 +2005,7 @@
<item>
<widget class="QgsCollapsibleGroupBox" name="mSimplifyDrawingGroupBox">
<property name="title">
<string>Enable fea&amp;ture simplification by default for newly added layers</string>
<string>Enable feature si&amp;mplification by default for newly added layers</string>
</property>
<property name="flat">
<bool>true</bool>
@ -2657,8 +2647,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>857</width>
<height>680</height>
<width>146</width>
<height>241</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_46">
@ -2808,8 +2798,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>857</width>
<height>680</height>
<width>514</width>
<height>334</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
@ -3151,8 +3141,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>857</width>
<height>680</height>
<width>625</width>
<height>612</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_30">
@ -3442,7 +3432,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<property name="value">
<number>200</number>
</property>
<property name="showClearButton">
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
@ -3595,8 +3585,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>857</width>
<height>680</height>
<width>487</width>
<height>588</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_39">
@ -3864,8 +3854,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>843</width>
<height>695</height>
<width>556</width>
<height>740</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_31">
@ -4442,8 +4432,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>857</width>
<height>680</height>
<width>427</width>
<height>380</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
@ -4581,8 +4571,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>857</width>
<height>680</height>
<width>429</width>
<height>549</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
@ -4678,7 +4668,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</widget>
</item>
<item>
<widget class="QgsProjectionSelectionWidget" name="leProjectGlobalCrs">
<widget class="QgsProjectionSelectionWidget" name="leProjectGlobalCrs" native="true">
<property name="minimumSize">
<size>
<width>0</width>
@ -4717,7 +4707,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<item row="1" column="0">
<widget class="QRadioButton" name="radPromptForProjection">
<property name="text">
<string>Promp&amp;t for CRS</string>
<string>Pro&amp;mpt for CRS</string>
</property>
</widget>
</item>
@ -4731,12 +4721,12 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<item row="3" column="0">
<widget class="QRadioButton" name="radUseGlobalProjection">
<property name="text">
<string>&amp;Use a default CRS</string>
<string>Use a default CRS</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsProjectionSelectionWidget" name="leLayerGlobalCrs">
<widget class="QgsProjectionSelectionWidget" name="leLayerGlobalCrs" native="true">
<property name="enabled">
<bool>false</bool>
</property>
@ -4794,15 +4784,15 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>857</width>
<height>680</height>
<width>282</width>
<height>234</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_32">
<item>
<widget class="QGroupBox" name="grpLocale">
<property name="title">
<string>Override s&amp;ystem locale</string>
<string>O&amp;verride system locale</string>
</property>
<property name="checkable">
<bool>true</bool>
@ -4903,8 +4893,8 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<rect>
<x>0</x>
<y>0</y>
<width>843</width>
<height>689</height>
<width>509</width>
<height>723</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">
@ -5085,10 +5075,10 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<property name="checkable">
<bool>true</bool>
</property>
<property name="collapsed">
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<property name="saveCollapsedState">
<property name="saveCollapsedState" stdset="0">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_1">
@ -5428,45 +5418,24 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsCollapsibleGroupBox</class>
<extends>QGroupBox</extends>
<header>qgscollapsiblegroupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsPasswordLineEdit</class>
<extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsScrollArea</class>
<extends>QScrollArea</extends>
<header>qgsscrollarea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsVariableEditorWidget</class>
<extends>QWidget</extends>
@ -5478,6 +5447,27 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<extends>QComboBox</extends>
<header>qgsscalecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsFilterLineEdit</class>
<extends>QLineEdit</extends>
<header>qgsfilterlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsPasswordLineEdit</class>
<extends>QLineEdit</extends>
<header>qgspasswordlineedit.h</header>
</customwidget>
<customwidget>
<class>QgsColorSchemeList</class>
<extends>QWidget</extends>

View File

@ -438,7 +438,7 @@
</property>
</spacer>
</item>
<item row="4" column="0" colspan="5">
<item row="5" column="0" colspan="5">
<widget class="QCheckBox" name="mMapTileRenderingCheckBox">
<property name="toolTip">
<string>Checking this setting avoids visible edge artifacts when rendering this project as separate map tiles. Rendering performance will be degraded.</string>
@ -486,6 +486,16 @@
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="mTrustProjectCheckBox">
<property name="toolTip">
<string>Speed up project loading by skipping data checks. Useful in qgis server context or project with huge database views or materialized views.</string>
</property>
<property name="text">
<string>Trust project when data source has no metadata</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>