mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
Address review (miscellaneous): Scale parameter from long to double; use processing API to create temp files
This commit is contained in:
parent
0583b3ddb2
commit
9e67aca98f
@ -7,7 +7,7 @@ except (NameError, AttributeError):
|
||||
pass
|
||||
try:
|
||||
QgsProcessingRasterLayerDefinition.__attribute_docs__ = {'source': "Source definition. Usually a static property set to a source layer's ID or file name.", 'referenceScale': 'If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.', 'dpi': 'Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.'}
|
||||
QgsProcessingRasterLayerDefinition.__annotations__ = {'source': 'QgsProperty', 'referenceScale': int, 'dpi': int}
|
||||
QgsProcessingRasterLayerDefinition.__annotations__ = {'source': 'QgsProperty', 'referenceScale': float, 'dpi': int}
|
||||
QgsProcessingRasterLayerDefinition.__group__ = ['processing']
|
||||
except (NameError, AttributeError):
|
||||
pass
|
||||
|
@ -135,7 +135,7 @@ algorithm.
|
||||
%End
|
||||
public:
|
||||
|
||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const long referenceScale = 0, const int dpi = 96 );
|
||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const double referenceScale = 0, const int dpi = 96 );
|
||||
%Docstring
|
||||
Constructor for QgsProcessingRasterLayerDefinition, accepting a static
|
||||
string ``source``.
|
||||
@ -148,7 +148,7 @@ The optional ``dpi`` argument can be used to specify the resolution a
|
||||
raster provider (e.g., a WMS server) is using to generate the raster.
|
||||
%End
|
||||
|
||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const long referenceScale = 0, const int dpi = 96 );
|
||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const double referenceScale = 0, const int dpi = 96 );
|
||||
%Docstring
|
||||
Constructor for QgsProcessingRasterLayerDefinition, accepting a
|
||||
QgsProperty source.
|
||||
@ -163,7 +163,7 @@ raster provider (e.g., a WMS server) is using to generate the raster.
|
||||
|
||||
QgsProperty source;
|
||||
|
||||
long referenceScale;
|
||||
double referenceScale;
|
||||
|
||||
int dpi;
|
||||
|
||||
|
@ -7,7 +7,7 @@ except (NameError, AttributeError):
|
||||
pass
|
||||
try:
|
||||
QgsProcessingRasterLayerDefinition.__attribute_docs__ = {'source': "Source definition. Usually a static property set to a source layer's ID or file name.", 'referenceScale': 'If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.', 'dpi': 'Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.'}
|
||||
QgsProcessingRasterLayerDefinition.__annotations__ = {'source': 'QgsProperty', 'referenceScale': int, 'dpi': int}
|
||||
QgsProcessingRasterLayerDefinition.__annotations__ = {'source': 'QgsProperty', 'referenceScale': float, 'dpi': int}
|
||||
QgsProcessingRasterLayerDefinition.__group__ = ['processing']
|
||||
except (NameError, AttributeError):
|
||||
pass
|
||||
|
@ -135,7 +135,7 @@ algorithm.
|
||||
%End
|
||||
public:
|
||||
|
||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const long referenceScale = 0, const int dpi = 96 );
|
||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const double referenceScale = 0, const int dpi = 96 );
|
||||
%Docstring
|
||||
Constructor for QgsProcessingRasterLayerDefinition, accepting a static
|
||||
string ``source``.
|
||||
@ -148,7 +148,7 @@ The optional ``dpi`` argument can be used to specify the resolution a
|
||||
raster provider (e.g., a WMS server) is using to generate the raster.
|
||||
%End
|
||||
|
||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const long referenceScale = 0, const int dpi = 96 );
|
||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const double referenceScale = 0, const int dpi = 96 );
|
||||
%Docstring
|
||||
Constructor for QgsProcessingRasterLayerDefinition, accepting a
|
||||
QgsProperty source.
|
||||
@ -163,7 +163,7 @@ raster provider (e.g., a WMS server) is using to generate the raster.
|
||||
|
||||
QgsProperty source;
|
||||
|
||||
long referenceScale;
|
||||
double referenceScale;
|
||||
|
||||
int dpi;
|
||||
|
||||
|
@ -20,7 +20,6 @@ __date__ = "September 2013"
|
||||
__copyright__ = "(C) 2013, Alexander Bruy"
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
@ -37,6 +36,7 @@ from qgis.core import (
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterRasterDestination,
|
||||
QgsProcessingRasterLayerDefinition,
|
||||
QgsProcessingUtils,
|
||||
)
|
||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||
from processing.algs.gdal.GdalUtils import GdalConnectionDetails, GdalUtils
|
||||
@ -212,7 +212,9 @@ class ClipRasterByExtent(GdalAlgorithm):
|
||||
width, height = GdalUtils._wms_dimensions_for_scale(
|
||||
bbox, inLayer.crs(), scale, dpi, distanceArea
|
||||
)
|
||||
wms_description_file_path = tempfile.mktemp("_wms_description_file.xml")
|
||||
wms_description_file_path = QgsProcessingUtils.generateTempFilename(
|
||||
"wms_description_file.xml", context
|
||||
)
|
||||
res_xml_wms, xml_wms_error = GdalUtils.gdal_wms_xml_description_file(
|
||||
inLayer,
|
||||
GdalUtils._get_wms_version(inLayer),
|
||||
|
@ -20,7 +20,6 @@ __date__ = "September 2013"
|
||||
__copyright__ = "(C) 2013, Alexander Bruy"
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
@ -40,6 +39,7 @@ from qgis.core import (
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterRasterDestination,
|
||||
QgsProcessingRasterLayerDefinition,
|
||||
QgsProcessingUtils,
|
||||
)
|
||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||
from processing.algs.gdal.GdalUtils import GdalConnectionDetails, GdalUtils
|
||||
@ -328,7 +328,9 @@ class ClipRasterByMask(GdalAlgorithm):
|
||||
width, height = GdalUtils._wms_dimensions_for_scale(
|
||||
_bbox, inLayer.crs(), scale, dpi, distanceArea
|
||||
)
|
||||
wms_description_file_path = tempfile.mktemp("_wms_description_file.xml")
|
||||
wms_description_file_path = QgsProcessingUtils.generateTempFilename(
|
||||
"wms_description_file.xml", context
|
||||
)
|
||||
res_xml_wms, xml_wms_error = GdalUtils.gdal_wms_xml_description_file(
|
||||
inLayer,
|
||||
GdalUtils._get_wms_version(inLayer),
|
||||
|
@ -54,6 +54,7 @@ from qgis.core import (
|
||||
from qgis.PyQt.QtCore import (
|
||||
QCoreApplication,
|
||||
QFile,
|
||||
QIODevice,
|
||||
QProcess,
|
||||
QTextStream,
|
||||
)
|
||||
@ -699,7 +700,7 @@ class GdalUtils:
|
||||
xml_file = QFile(out_path)
|
||||
res = False
|
||||
error_msg = ""
|
||||
if xml_file.open(QFile.WriteOnly):
|
||||
if xml_file.open(QIODevice.OpenModeFlag.WriteOnly):
|
||||
file_stream = QTextStream(xml_file)
|
||||
doc.save(file_stream, 2)
|
||||
res = True
|
||||
|
@ -24,7 +24,7 @@ import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
from qgis.PyQt.QtCore import QFile
|
||||
from qgis.PyQt.QtCore import QFile, QIODevice
|
||||
from qgis.PyQt.QtXml import QDomDocument
|
||||
|
||||
from qgis.core import (
|
||||
@ -430,7 +430,7 @@ class TestGdalAlgorithms(QgisTestCase):
|
||||
|
||||
# Compare obtained file with and expected data
|
||||
out_file = QFile(out_path)
|
||||
self.assertTrue(out_file.open(QFile.ReadOnly))
|
||||
self.assertTrue(out_file.open(QIODevice.OpenModeFlag.ReadOnly))
|
||||
|
||||
doc = QDomDocument()
|
||||
self.assertTrue(doc.setContent(out_file))
|
||||
@ -495,7 +495,7 @@ class TestGdalAlgorithms(QgisTestCase):
|
||||
|
||||
# Compare obtained file with and expected data
|
||||
out_file = QFile(out_path)
|
||||
self.assertTrue(out_file.open(QFile.ReadOnly))
|
||||
self.assertTrue(out_file.open(QIODevice.OpenModeFlag.ReadOnly))
|
||||
|
||||
doc = QDomDocument()
|
||||
self.assertTrue(doc.setContent(out_file))
|
||||
@ -561,7 +561,7 @@ class TestGdalAlgorithms(QgisTestCase):
|
||||
|
||||
# Compare obtained file with and expected data
|
||||
out_file = QFile(out_path)
|
||||
self.assertTrue(out_file.open(QFile.ReadOnly))
|
||||
self.assertTrue(out_file.open(QIODevice.OpenModeFlag.ReadOnly))
|
||||
|
||||
doc = QDomDocument()
|
||||
self.assertTrue(doc.setContent(out_file))
|
||||
|
@ -75,7 +75,7 @@ QVariant QgsProcessingRasterLayerDefinition::toVariant() const
|
||||
{
|
||||
QVariantMap map;
|
||||
map.insert( QStringLiteral( "source" ), source.toVariant() );
|
||||
map.insert( QStringLiteral( "reference_scale" ), QVariant::fromValue( referenceScale ) );
|
||||
map.insert( QStringLiteral( "reference_scale" ), referenceScale );
|
||||
map.insert( QStringLiteral( "dpi" ), dpi );
|
||||
return map;
|
||||
}
|
||||
@ -83,7 +83,7 @@ QVariant QgsProcessingRasterLayerDefinition::toVariant() const
|
||||
bool QgsProcessingRasterLayerDefinition::loadVariant( const QVariantMap &map )
|
||||
{
|
||||
source.loadVariant( map.value( QStringLiteral( "source" ) ) );
|
||||
referenceScale = map.value( QStringLiteral( "reference_scale" ), 0 ).toLongLong();
|
||||
referenceScale = map.value( QStringLiteral( "reference_scale" ), 0 ).toDouble();
|
||||
dpi = map.value( QStringLiteral( "dpi" ), 0 ).toInt();
|
||||
return true;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ class CORE_EXPORT QgsProcessingRasterLayerDefinition
|
||||
* The optional \a dpi argument can be used to specify the resolution a raster provider
|
||||
* (e.g., a WMS server) is using to generate the raster.
|
||||
*/
|
||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const long referenceScale = 0, const int dpi = 96 )
|
||||
QgsProcessingRasterLayerDefinition( const QString &source = QString(), const double referenceScale = 0, const int dpi = 96 )
|
||||
: source( QgsProperty::fromValue( source ) )
|
||||
, referenceScale( referenceScale )
|
||||
, dpi( dpi )
|
||||
@ -227,7 +227,7 @@ class CORE_EXPORT QgsProcessingRasterLayerDefinition
|
||||
* The optional \a dpi argument can be used to specify the resolution a raster provider
|
||||
* (e.g., a WMS server) is using to generate the raster.
|
||||
*/
|
||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const long referenceScale = 0, const int dpi = 96 )
|
||||
QgsProcessingRasterLayerDefinition( const QgsProperty &source, const double referenceScale = 0, const int dpi = 96 )
|
||||
: source( source )
|
||||
, referenceScale( referenceScale )
|
||||
, dpi( dpi )
|
||||
@ -241,7 +241,7 @@ class CORE_EXPORT QgsProcessingRasterLayerDefinition
|
||||
/**
|
||||
* If set to a value > 0, sets a scale at which a raster (e.g., a WMS) should be requested or rendered.
|
||||
*/
|
||||
long referenceScale = 0;
|
||||
double referenceScale = 0;
|
||||
|
||||
/**
|
||||
* Indicates the resolution of the raster source (e.g., a WMS server). By default 96 DPI.
|
||||
|
@ -147,7 +147,7 @@ class GUI_EXPORT QgsProcessingMapLayerComboBox : public QWidget
|
||||
QString mFilterExpression;
|
||||
bool mIsOverridingDefaultGeometryCheck = false;
|
||||
Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
|
||||
long mRasterReferenceScale = 0;
|
||||
double mRasterReferenceScale = 0;
|
||||
int mRasterDpi = 0;
|
||||
QPointer<QgsMapLayer> mPrevLayer;
|
||||
int mBlockChangedSignal = 0;
|
||||
|
@ -32,9 +32,9 @@ QgsProcessingRasterSourceOptionsWidget::QgsProcessingRasterSourceOptionsWidget(
|
||||
connect( mDpiSpinBox, qOverload<int>( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
|
||||
}
|
||||
|
||||
void QgsProcessingRasterSourceOptionsWidget::setReferenceScale( long scale )
|
||||
void QgsProcessingRasterSourceOptionsWidget::setReferenceScale( double scale )
|
||||
{
|
||||
mReferenceScale->setScale( static_cast<double>( scale ) );
|
||||
mReferenceScale->setScale( scale );
|
||||
}
|
||||
|
||||
void QgsProcessingRasterSourceOptionsWidget::setDpi( int dpi )
|
||||
@ -42,9 +42,9 @@ void QgsProcessingRasterSourceOptionsWidget::setDpi( int dpi )
|
||||
mDpiSpinBox->setValue( dpi );
|
||||
}
|
||||
|
||||
long QgsProcessingRasterSourceOptionsWidget::referenceScale() const
|
||||
double QgsProcessingRasterSourceOptionsWidget::referenceScale() const
|
||||
{
|
||||
return static_cast< long >( mReferenceScale->scale() );
|
||||
return mReferenceScale->scale();
|
||||
}
|
||||
|
||||
int QgsProcessingRasterSourceOptionsWidget::dpi() const
|
||||
|
@ -47,7 +47,7 @@ class GUI_EXPORT QgsProcessingRasterSourceOptionsWidget : public QgsPanelWidget,
|
||||
*
|
||||
* \see referenceScale()
|
||||
*/
|
||||
void setReferenceScale( long scale );
|
||||
void setReferenceScale( double scale );
|
||||
|
||||
/**
|
||||
* Sets the resolution of the raster source (e.g., a WMS server).
|
||||
@ -63,7 +63,7 @@ class GUI_EXPORT QgsProcessingRasterSourceOptionsWidget : public QgsPanelWidget,
|
||||
*
|
||||
* \see setReferenceScale()
|
||||
*/
|
||||
long referenceScale() const;
|
||||
double referenceScale() const;
|
||||
|
||||
/**
|
||||
* Resolution of the raster source (e.g., a WMS server).
|
||||
|
Loading…
x
Reference in New Issue
Block a user