QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
Loading...
Searching...
No Matches
qgssymbolconverterogrstyle.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssymbolconverterogrstyle.cpp
3 ----------------------
4 begin : February 2026
5 copyright : (C) 2026 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7***************************************************************************
8* *
9* This program is free software; you can redistribute it and/or modify *
10* it under the terms of the GNU General Public License as published by *
11* the Free Software Foundation; either version 2 of the License, or *
12* (at your option) any later version. *
13* *
14***************************************************************************/
15
17
18#include "qgsogrutils.h"
19#include "qgssymbol.h"
20#include "qgssymbollayerutils.h"
21
22#include <QObject>
23#include <QString>
24#include <QVariant>
25
26using namespace Qt::StringLiterals;
27
32
34{
35 return u"ogr"_s;
36}
37
39{
40 return QObject::tr( "OGR Style String" );
41}
42
44{
45 throw QgsNotSupportedException( u"This symbol converter does not support serialization of symbols"_s );
46}
47
48std::unique_ptr< QgsSymbol > QgsSymbolConverterOgrStyle::createSymbol( const QVariant &variant, QgsSymbolConverterContext &context ) const
49{
50 const QString styleString = variant.toString();
51 if ( styleString.isEmpty() )
52 return nullptr;
53
54 const Qgis::SymbolType typeHint = context.typeHint();
55 if ( typeHint == Qgis::SymbolType::Hybrid )
56 {
57 context.pushError( QObject::tr( "Hybrid symbol types are not supported by the OGR converter." ) );
58 return nullptr;
59 }
60
61 return QgsOgrUtils::symbolFromStyleString( styleString, typeHint );
62}
QFlags< SymbolConverterCapability > SymbolConverterCapabilities
Symbol converter capabilities.
Definition qgis.h:824
SymbolType
Symbol types.
Definition qgis.h:636
@ Hybrid
Hybrid symbol.
Definition qgis.h:640
@ ReadSymbol
Allows reading symbols from variants.
Definition qgis.h:813
Custom exception class which is raised when an operation is not supported.
static std::unique_ptr< QgsSymbol > symbolFromStyleString(const QString &string, Qgis::SymbolType type)
Creates a new QgsSymbol matching an OGR style string.
Represents the context in which a QgsSymbolConverter conversion occurs.
Qgis::SymbolType typeHint() const
Returns the symbol type hint, or Qgis::SymbolType::Hybrid if unknown.
void pushError(const QString &error)
Pushes a error message generated during the conversion.
Qgis::SymbolConverterCapabilities capabilities() const override
Returns the capabilities of the converter.
std::unique_ptr< QgsSymbol > createSymbol(const QVariant &variant, QgsSymbolConverterContext &context) const override
Creates a new QgsSymbol from a QVariant representation.
QString name() const override
Returns the unique name for the converter.
QVariant toVariant(const QgsSymbol *symbol, QgsSymbolConverterContext &context) const override
Converts a symbol into a QVariant representation.
QString formatName() const override
Returns a translated, user-friendly name for the converter's data format.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227