Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved conversion of MapInfo line symbols
Many MapInfo line symbols don't translate well into OGR styles, so
in order to improve the quality of the conversion this commit introduces
a new QgsMapInfoSymbolConverter class which contains utility functions
for converting MapInfo symbols by ID to their QGIS equivalent.

Implemented for line symbols only for now.
  • Loading branch information
nyalldawson committed May 6, 2021
1 parent f9014ad commit 1a4d7b0
Show file tree
Hide file tree
Showing 12 changed files with 1,292 additions and 0 deletions.
@@ -0,0 +1,74 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/symbology/qgsmapinfosymbolconverter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsMapInfoSymbolConversionContext
{
%Docstring(signature="appended")
Context for a MapInfo symbol conversion operation.

.. warning::

This is private API only, and may change in future QGIS versions

.. versionadded:: 3.20
%End

%TypeHeaderCode
#include "qgsmapinfosymbolconverter.h"
%End
public:

void pushWarning( const QString &warning );
%Docstring
Pushes a ``warning`` message generated during the conversion.
%End

QStringList warnings() const;
%Docstring
Returns a list of warning messages generated during the conversion.
%End

void clearWarnings();
%Docstring
Clears the list of warning messages.
%End

};

class QgsMapInfoSymbolConverter
{
%Docstring(signature="appended")
Handles conversion of MapInfo symbols to QGIS symbology.

.. versionadded:: 3.20
%End

%TypeHeaderCode
#include "qgsmapinfosymbolconverter.h"
%End
public:

static QgsLineSymbol *convertLineSymbol( int identifier, QgsMapInfoSymbolConversionContext &context, const QColor &foreColor, double size, QgsUnitTypes::RenderUnit sizeUnit, bool interleaved = false ) /Factory/;
%Docstring
Converts the MapInfo line symbol with the specified ``identifier`` to a :py:class:`QgsLineSymbol`.

The caller takes ownership of the returned symbol.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/symbology/qgsmapinfosymbolconverter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -571,6 +571,7 @@
%Include auto_generated/symbology/qgsinvertedpolygonrenderer.sip
%Include auto_generated/symbology/qgslegendsymbolitem.sip
%Include auto_generated/symbology/qgslinesymbollayer.sip
%Include auto_generated/symbology/qgsmapinfosymbolconverter.sip
%Include auto_generated/symbology/qgsmarkersymbollayer.sip
%Include auto_generated/symbology/qgsmergedfeaturerenderer.sip
%Include auto_generated/symbology/qgsnullsymbolrenderer.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -55,6 +55,7 @@ set(QGIS_CORE_SRCS
symbology/qgsinvertedpolygonrenderer.cpp
symbology/qgslegendsymbolitem.cpp
symbology/qgslinesymbollayer.cpp
symbology/qgsmapinfosymbolconverter.cpp
symbology/qgsmarkersymbollayer.cpp
symbology/qgsmasksymbollayer.cpp
symbology/qgsmergedfeaturerenderer.cpp
Expand Down Expand Up @@ -1530,6 +1531,7 @@ set(QGIS_CORE_HDRS
symbology/qgsinvertedpolygonrenderer.h
symbology/qgslegendsymbolitem.h
symbology/qgslinesymbollayer.h
symbology/qgsmapinfosymbolconverter.h
symbology/qgsmarkersymbollayer.h
symbology/qgsmergedfeaturerenderer.h
symbology/qgsnullsymbolrenderer.h
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsogrutils.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgslinesymbollayer.h"
#include "qgspolygon.h"
#include "qgsmultipolygon.h"
#include "qgsmapinfosymbolconverter.h"

#include <QTextCodec>
#include <QUuid>
Expand Down Expand Up @@ -1256,6 +1257,18 @@ std::unique_ptr<QgsSymbol> QgsOgrUtils::symbolFromStyleString( const QString &st
QgsUnitTypes::RenderUnit lineWidthUnit = QgsUnitTypes::RenderMillimeters;
convertSize( lineStyle.value( QStringLiteral( "w" ) ).toString(), lineWidth, lineWidthUnit );

// if the pen is a mapinfo pen, use dedicated converter for more accurate results
const thread_local QRegularExpression sMapInfoId = QRegularExpression( QStringLiteral( "mapinfo-pen-(\\d+)" ) );
const QRegularExpressionMatch match = sMapInfoId.match( string );
if ( match.hasMatch() )
{
const int penId = match.captured( 1 ).toInt();
QgsMapInfoSymbolConversionContext context;
std::unique_ptr<QgsSymbol> res( QgsMapInfoSymbolConverter::convertLineSymbol( penId, context, color, lineWidth, lineWidthUnit ) );
if ( res )
return res;
}

std::unique_ptr< QgsSimpleLineSymbolLayer > simpleLine = std::make_unique< QgsSimpleLineSymbolLayer >( color, lineWidth );
simpleLine->setWidthUnit( lineWidthUnit );

Expand Down

0 comments on commit 1a4d7b0

Please sign in to comment.