qml4dart library
Pure Dart codec and object model for QGIS QML layer style files.
QML (.qml) is the native layer style format used by QGIS. This package
provides a typed Dart object model and a bidirectional codec for reading
and writing QML XML.
import 'package:qml4dart/qml4dart.dart';
const codec = Qml4DartCodec();
// Parse QML XML.
final result = codec.parseString(qmlXml);
if (result case ReadQmlSuccess(:final document)) {
print(document.renderer.type);
}
// Encode back to XML.
final writeResult = codec.encodeString(document);
if (writeResult case WriteQmlSuccess(:final xml)) {
print(xml);
}
Supported features:
- Renderers: singleSymbol, categorizedSymbol, graduatedSymbol, RuleRenderer (incl. nested rules).
- Symbol layers: SimpleMarker, SvgMarker, SimpleLine, SimpleFill, RasterFill.
- Property formats:
<Option type="Map">(QGIS >= 3.26) and legacy<prop k v>. - Scale visibility at document and rule level.
Classes
- Qml4DartCodec
-
Concrete QmlCodec implementation backed by
QmlXmlReaderandQmlXmlWriter. - QmlCategory
-
A category entry in a
categorizedSymbolrenderer. - QmlCodec
- Abstract interface for reading and writing QGIS QML layer style files.
- QmlDocument
- Root model for a QGIS QML layer style document.
- QmlRange
-
A range entry in a
graduatedSymbolrenderer. - QmlRenderer
-
Renderer definition inside a QML document (
<renderer-v2>). - QmlRule
- A rule in a QGIS rule-based renderer.
- QmlSymbol
- A QML symbol composed of one or more QmlSymbolLayers.
- QmlSymbolLayer
-
Smallest styling unit inside a QML symbol (
<layer>element). - ReadQmlFailure
- Failed parse result containing an error message and optional cause.
- ReadQmlResult
- Result of parsing QML XML input.
- ReadQmlSuccess
- Successful parse result containing the document and any non-fatal warnings (e.g. unknown renderer types, missing attributes).
- WriteQmlFailure
- Failed encode result containing an error message and optional cause.
- WriteQmlResult
- Result of encoding a QmlDocument into QML XML.
- WriteQmlSuccess
- Successful encode result containing the xml string and any non-fatal warnings.
Enums
- QmlRendererType
- High-level renderer kinds supported by QGIS QML.
- QmlSymbolLayerType
-
Symbol layer classes (
classattribute on<layer>). - QmlSymbolType
-
Symbol geometry type (
typeattribute on<symbol>).