Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions felt/core/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,26 +344,28 @@ def create_upload_file_request(self,

form_content = QByteArray()
for name, value in parameters.to_form_fields().items():
form_content.append("--QGISFormBoundary2XCkqVRLJ5XMxfw5\r\n")
form_content.append("Content-Disposition: form-data; ")
form_content.append(f"name=\"{name}\"")
form_content.append("\r\n")
form_content.append("\r\n")
form_content.append(value)
form_content.append("\r\n")

form_content.append("--QGISFormBoundary2XCkqVRLJ5XMxfw5\r\n")
form_content.append("Content-Disposition: ")
form_content.append(b"--QGISFormBoundary2XCkqVRLJ5XMxfw5\r\n")
form_content.append(b"Content-Disposition: form-data; ")
form_content.append(f"name=\"{name}\"".encode())
form_content.append(b"\r\n")
form_content.append(b"\r\n")
form_content.append(value.encode() if isinstance(value, str)
else value)
form_content.append(b"\r\n")

form_content.append(b"--QGISFormBoundary2XCkqVRLJ5XMxfw5\r\n")
form_content.append(b"Content-Disposition: ")
form_content.append(
f"form-data; name=\"file\"; filename=\"{filename}\"\r\n")
f"form-data; name=\"file\"; filename=\"{filename}\"\r\n"
.encode())
form_content.append(
"Content-Type: application/octet-stream\r\n")
form_content.append("\r\n")
b"Content-Type: application/octet-stream\r\n")
form_content.append(b"\r\n")

form_content.append(content)

form_content.append("\r\n")
form_content.append("--QGISFormBoundary2XCkqVRLJ5XMxfw5--\r\n")
form_content.append(b"\r\n")
form_content.append(b"--QGISFormBoundary2XCkqVRLJ5XMxfw5--\r\n")

content_length = form_content.length()
network_request.setRawHeader(
Expand Down Expand Up @@ -517,7 +519,7 @@ def create_layer_groups(self,
json.dumps(group_post_data).encode()
)

if reply.error() == QNetworkReply.ContentAccessDenied:
if reply.error() == QNetworkReply.NetworkError.ContentAccessDenied:
raise PaidPlanRequiredError("Upload requires a paid plan")

return [
Expand Down
2 changes: 1 addition & 1 deletion felt/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def do_GET(self):
token_body = urllib.parse.urlencode(body).encode()

network_request = QNetworkRequest(QUrl(TOKEN_URL))
network_request.setHeader(QNetworkRequest.ContentTypeHeader,
network_request.setHeader(QNetworkRequest.KnownHeaders.ContentTypeHeader,
'application/x-www-form-urlencoded')

result_code = request.post(network_request,
Expand Down
60 changes: 38 additions & 22 deletions felt/core/fsl_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
QgsRandomMarkerFillSymbolLayer,
QgsArrowSymbolLayer,
QgsRenderContext,
QgsUnitTypes,
# QgsUnitTypes removed in QGIS 4
QgsFeatureRenderer,
QgsSingleSymbolRenderer,
QgsNullSymbolRenderer,
Expand Down Expand Up @@ -71,6 +71,22 @@
from .logger import Logger
from .map_utils import MapUtils

try:
from qgis.core import QgsUnitTypes # sketchy: removed in QGIS 4
except ImportError:
from qgis.core import Qgis

class QgsUnitTypes:
"""Compatibility shim for QGIS 4"""
RenderUnit = Qgis.RenderUnit
RenderPixels = Qgis.RenderUnit.Pixels
RenderMillimeters = Qgis.RenderUnit.Millimeters
RenderPoints = Qgis.RenderUnit.Points
RenderInches = Qgis.RenderUnit.Inches
RenderPercentage = Qgis.RenderUnit.Percentage
RenderMetersInMapUnits = Qgis.RenderUnit.MetersInMapUnits
RenderMapUnits = Qgis.RenderUnit.MapUnits


class LogLevel(Enum):
"""
Expand Down Expand Up @@ -1004,9 +1020,9 @@ def convert_cap_style(style: Qt.PenCapStyle) -> str:
Convert a Qt cap style to FSL
"""
return {
Qt.RoundCap: 'round',
Qt.SquareCap: 'square',
Qt.FlatCap: 'butt',
Qt.PenCapStyle.RoundCap: 'round',
Qt.PenCapStyle.SquareCap: 'square',
Qt.PenCapStyle.FlatCap: 'butt',
}[style]

@staticmethod
Expand All @@ -1015,10 +1031,10 @@ def convert_join_style(style: Qt.PenJoinStyle) -> str:
Convert a Qt join style to FSL
"""
return {
Qt.RoundJoin: 'round',
Qt.BevelJoin: 'bevel',
Qt.MiterJoin: 'miter',
Qt.SvgMiterJoin: 'miter',
Qt.PenJoinStyle.RoundJoin: 'round',
Qt.PenJoinStyle.BevelJoin: 'bevel',
Qt.PenJoinStyle.MiterJoin: 'miter',
Qt.PenJoinStyle.SvgMiterJoin: 'miter',
}[style]

@staticmethod
Expand All @@ -1027,12 +1043,12 @@ def convert_pen_style(style: Qt.PenStyle) -> List[float]:
Converts a Qt pen style to an array of dash/space lengths
"""
return {
Qt.NoPen: [],
Qt.SolidLine: [],
Qt.DashLine: [2.5, 2],
Qt.DotLine: [0.5, 1.3],
Qt.DashDotLine: [0.5, 1.3, 2.5, 1.3],
Qt.DashDotDotLine: [0.5, 1.3, 0.5, 1.3, 2.5, 1.3]
Qt.PenStyle.NoPen: [],
Qt.PenStyle.SolidLine: [],
Qt.PenStyle.DashLine: [2.5, 2],
Qt.PenStyle.DotLine: [0.5, 1.3],
Qt.PenStyle.DashDotLine: [0.5, 1.3, 2.5, 1.3],
Qt.PenStyle.DashDotDotLine: [0.5, 1.3, 0.5, 1.3, 2.5, 1.3]
}[style]

@staticmethod
Expand All @@ -1043,7 +1059,7 @@ def simple_line_to_fsl(
"""
Converts a QGIS simple line symbol layer to FSL
"""
if (layer.penStyle() == Qt.NoPen or
if (layer.penStyle() == Qt.PenStyle.NoPen or
not layer.color().isValid() or
layer.color().alphaF() == 0):
return []
Expand All @@ -1070,7 +1086,7 @@ def simple_line_to_fsl(
part,
layer.customDashPatternUnit(), context, round_size=False) for
part in layer.customDashVector()]
elif layer.penStyle() != Qt.SolidLine:
elif layer.penStyle() != Qt.PenStyle.SolidLine:
res['dashArray'] = FslConverter.convert_pen_style(layer.penStyle())

# not supported:
Expand Down Expand Up @@ -1264,10 +1280,10 @@ def simple_fill_to_fsl(
"""
Converts a QGIS simple fill symbol layer to FSL
"""
has_invisible_fill = (layer.brushStyle() == Qt.NoBrush or
has_invisible_fill = (layer.brushStyle() == Qt.BrushStyle.NoBrush or
not layer.color().isValid() or
layer.color().alphaF() == 0)
has_invisible_stroke = (layer.strokeStyle() == Qt.NoPen or
has_invisible_stroke = (layer.strokeStyle() == Qt.PenStyle.NoPen or
not layer.strokeColor().isValid() or
layer.strokeColor().alphaF() == 0)
if has_invisible_fill and has_invisible_stroke:
Expand All @@ -1291,7 +1307,7 @@ def simple_fill_to_fsl(
res['lineJoin'] = FslConverter.convert_join_style(
layer.penJoinStyle())

if layer.strokeStyle() != Qt.SolidLine:
if layer.strokeStyle() != Qt.PenStyle.SolidLine:
res['dashArray'] = FslConverter.convert_pen_style(
layer.strokeStyle())
else:
Expand All @@ -1301,7 +1317,7 @@ def simple_fill_to_fsl(
# - fill offset
# - fill style

if layer.brushStyle() not in (Qt.SolidPattern, Qt.NoBrush):
if layer.brushStyle() not in (Qt.BrushStyle.SolidPattern, Qt.BrushStyle.NoBrush):
context.push_warning(
'Fill patterns are not supported, converting to a solid fill',
LogLevel.Warning,
Expand All @@ -1323,7 +1339,7 @@ def simple_marker_to_fsl(
"""
has_fill = layer.color().isValid() and layer.color().alphaF() > 0
has_stroke = (layer.strokeColor().alphaF() > 0 and
layer.strokeStyle() != Qt.NoPen)
layer.strokeStyle() != Qt.PenStyle.NoPen)
if not has_fill and not has_stroke:
return []

Expand Down Expand Up @@ -1378,7 +1394,7 @@ def ellipse_marker_to_fsl(
"""
has_fill = layer.color().isValid() and layer.color().alphaF() > 0
has_stroke = (layer.strokeColor().alphaF() > 0 and
layer.strokeStyle() != Qt.NoPen)
layer.strokeStyle() != Qt.PenStyle.NoPen)
if not has_fill and not has_stroke:
return []

Expand Down
46 changes: 34 additions & 12 deletions felt/core/layer_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
QgsCoordinateTransformContext,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsWkbTypes,
QgsRasterLayer,
QgsRasterFileWriter,
QgsRasterBlockFeedback,
Expand All @@ -48,6 +47,25 @@
QgsRasterRange
)

try:
from qgis.core import QgsWkbTypes # sketchy: removed in QGIS 4

def _force_multi(layer):
return QgsWkbTypes.geometryType(layer.wkbType()) in (
QgsWkbTypes.LineGeometry, QgsWkbTypes.PolygonGeometry)

def _drop_zm(layer):
return QgsWkbTypes.dropM(QgsWkbTypes.dropZ(layer.wkbType()))
except ImportError:
def _force_multi(layer):
return layer.geometryType() in (
Qgis.GeometryType.Line, Qgis.GeometryType.Polygon)

def _drop_zm(layer):
wkb = layer.wkbType()
flat = Qgis.WkbType(int(wkb) % 1000)
return flat

from .api_client import API_CLIENT
from .enums import (
LayerExportResult,
Expand Down Expand Up @@ -377,12 +395,8 @@ def export_vector_layer(
self.transform_context
)
writer_options.feedback = feedback
writer_options.forceMulti = QgsWkbTypes.geometryType(
layer.wkbType()) in (QgsWkbTypes.LineGeometry,
QgsWkbTypes.PolygonGeometry)
writer_options.overrideGeometryType = QgsWkbTypes.dropM(
QgsWkbTypes.dropZ(layer.wkbType())
)
writer_options.forceMulti = _force_multi(layer)
writer_options.overrideGeometryType = _drop_zm(layer)
writer_options.includeZ = False
writer_options.layerOptions = [
'GEOMETRY_NAME=geom',
Expand All @@ -396,11 +410,19 @@ def export_vector_layer(
writer_options.attributes = fields.allAttributesList()
if fid_index >= 0:
fid_type = fields.field(fid_index).type()
needs_rewrite = force_rewrite_fid or fid_type not in (
QVariant.Int,
QVariant.UInt,
QVariant.LongLong,
QVariant.ULongLong)
try:
int_types = (
QVariant.Type.Int,
QVariant.Type.UInt,
QVariant.Type.LongLong,
QVariant.Type.ULongLong)
except AttributeError:
int_types = (
QVariant.Int,
QVariant.UInt,
QVariant.LongLong,
QVariant.ULongLong)
needs_rewrite = force_rewrite_fid or fid_type not in int_types
if Qgis.QGIS_VERSION_INT < 32400 and needs_rewrite:
# older QGIS, can't rename attributes during export, so
# drop FID
Expand Down
8 changes: 4 additions & 4 deletions felt/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def log_message(self, message: str):
QMetaObject.invokeMethod(
self,
"_submit_usage",
Qt.QueuedConnection,
Qt.ConnectionType.QueuedConnection,
Q_ARG(str, message),
Q_ARG(str, UsageType.Info.to_string()))

Expand All @@ -137,7 +137,7 @@ def log_message_json(self, message: Dict):
QMetaObject.invokeMethod(
self,
"_submit_usage",
Qt.QueuedConnection,
Qt.ConnectionType.QueuedConnection,
Q_ARG(str, message_str),
Q_ARG(str, UsageType.Info.to_string()))

Expand All @@ -152,7 +152,7 @@ def log_error(self, error: str):
QMetaObject.invokeMethod(
self,
"_submit_usage",
Qt.QueuedConnection,
Qt.ConnectionType.QueuedConnection,
Q_ARG(str, message),
Q_ARG(str, UsageType.Error.to_string()))

Expand All @@ -167,7 +167,7 @@ def log_error_json(self, error: Dict):
QMetaObject.invokeMethod(
self,
"_submit_usage",
Qt.QueuedConnection,
Qt.ConnectionType.QueuedConnection,
Q_ARG(str, json.dumps(error)),
Q_ARG(str, UsageType.Error.to_string()))

Expand Down
2 changes: 1 addition & 1 deletion felt/core/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def from_json(jsons: Union[str, Dict]) -> 'Map':
last_visited_string = res.get('attributes', {}).get('visited_at')
if last_visited_string:
last_visited = QDateTime.fromString(
last_visited_string, Qt.ISODate
last_visited_string, Qt.DateFormat.ISODate
)
else:
last_visited = None
Expand Down
Loading
Loading