diff --git a/data/qmls_old/line_simple.qml b/data/qmls_old/line_simple.qml index 3f6eff71..abcf242f 100644 --- a/data/qmls_old/line_simple.qml +++ b/data/qmls_old/line_simple.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/no_symbolizer.qml b/data/qmls_old/no_symbolizer.qml index 554c0244..c6d5edc1 100644 --- a/data/qmls_old/no_symbolizer.qml +++ b/data/qmls_old/no_symbolizer.qml @@ -1,4 +1,4 @@ - + diff --git a/data/qmls_old/point_external_graphic.qml b/data/qmls_old/point_external_graphic.qml index b5f29d82..ed67dc3b 100644 --- a/data/qmls_old/point_external_graphic.qml +++ b/data/qmls_old/point_external_graphic.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/point_label.qml b/data/qmls_old/point_label.qml index b2518c97..8e339b57 100644 --- a/data/qmls_old/point_label.qml +++ b/data/qmls_old/point_label.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/point_multiple_symbols.qml b/data/qmls_old/point_multiple_symbols.qml index def659e7..4f580bbc 100644 --- a/data/qmls_old/point_multiple_symbols.qml +++ b/data/qmls_old/point_multiple_symbols.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/point_ranges.qml b/data/qmls_old/point_ranges.qml index f0b7bfcc..9a2bde4e 100644 --- a/data/qmls_old/point_ranges.qml +++ b/data/qmls_old/point_ranges.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/point_rules.qml b/data/qmls_old/point_rules.qml index 015197ee..d0535c9b 100644 --- a/data/qmls_old/point_rules.qml +++ b/data/qmls_old/point_rules.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/point_simple.qml b/data/qmls_old/point_simple.qml index cdf96047..dc08a4f2 100644 --- a/data/qmls_old/point_simple.qml +++ b/data/qmls_old/point_simple.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/polygon_simple.qml b/data/qmls_old/polygon_simple.qml index 1522635f..bb94fd7c 100644 --- a/data/qmls_old/polygon_simple.qml +++ b/data/qmls_old/polygon_simple.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/polygon_simple_nostyle.qml b/data/qmls_old/polygon_simple_nostyle.qml index 1af90a75..df0c16f7 100644 --- a/data/qmls_old/polygon_simple_nostyle.qml +++ b/data/qmls_old/polygon_simple_nostyle.qml @@ -1,5 +1,5 @@ - + diff --git a/data/qmls_old/text_text_buffer.qml b/data/qmls_old/text_text_buffer.qml index f1e57608..8cc1da9e 100644 --- a/data/qmls_old/text_text_buffer.qml +++ b/data/qmls_old/text_text_buffer.qml @@ -1,5 +1,5 @@ - + diff --git a/src/QGISStyleParser.spec.ts b/src/QGISStyleParser.spec.ts index db76f9ef..eaf64f48 100644 --- a/src/QGISStyleParser.spec.ts +++ b/src/QGISStyleParser.spec.ts @@ -21,7 +21,9 @@ describe('QMLStyleParser implements StyleParser', () => { let styleParser: QGISStyleParser; beforeEach(() => { - styleParser = new QGISStyleParser(); + styleParser = (expect.getState().currentTestName.includes('>=3.28.0')) + ? new QGISStyleParser() + : new QGISStyleParser({qgisVersion: '3.22.16-Białowieża'}); }); const QML_FOLDERS = [ @@ -120,83 +122,85 @@ describe('QMLStyleParser implements StyleParser', () => { }); }); - describe('#writeStyle', () => { - it('is defined', () => { - expect(styleParser.writeStyle).toBeDefined(); - }); - describe('PointSymbolizer', () => { - it('can write a simple QML PointSymbol', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/point_simple.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(point_simple); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); - }); - it('can write a QML PointSymbolizer with an external graphic', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/point_external_graphic.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(point_external_graphic); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); - }); - it('can write a QML PointSymbolizer with multiple symbols', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/point_multiple_symbols.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(point_multiple_symbols); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); - }); - }); - describe('TextSymbolizer', () => { - it('can write some basics of the QML Labeling for Points', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/point_label.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(point_label); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); + QML_FOLDERS.forEach(qmlVersionFolder => { + const [qmlVersion, qmlFolder] = qmlVersionFolder; + describe(`#writeStyle ${qmlVersion}`, () => { + it('is defined', () => { + expect(styleParser.writeStyle).toBeDefined(); }); - it('can write QML with text-buffer', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/text_text_buffer.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(text_text_buffer); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); + describe('PointSymbolizer', () => { + it('can write a simple QML PointSymbol', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/point_simple.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(point_simple); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); + it('can write a QML PointSymbolizer with an external graphic', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/point_external_graphic.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(point_external_graphic); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); + it('can write a QML PointSymbolizer with multiple symbols', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/point_multiple_symbols.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(point_multiple_symbols); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); }); - }); - describe('LineSymbolizer', () => { - it('can write a simple QML LineSymbol', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/line_simple.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(line_simple); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); + describe('TextSymbolizer', () => { + it('can write some basics of the QML Labeling for Points', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/point_label.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(point_label); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); + it('can write QML with text-buffer', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/text_text_buffer.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(text_text_buffer); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); }); - }); - describe('FillSymbolizer', () => { - it('can write a simple QML FillSymbol', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/polygon_simple.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(polygon_simple); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); + describe('LineSymbolizer', () => { + it('can write a simple QML LineSymbol', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/line_simple.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(line_simple); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); }); - }); - describe('Filter Parsing', () => { - it('can write a rule based QML PointSymbolizer', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/point_rules.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(point_rules); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); + describe('FillSymbolizer', () => { + it('can write a simple QML FillSymbol', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/polygon_simple.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(polygon_simple); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); }); - it('can write QML with no symbolizers', async () => { - expect.assertions(2); - const qml = fs.readFileSync('./data/qmls/no_symbolizer.qml', 'utf8'); - const { output: qgisStyle } = await styleParser.writeStyle(no_symbolizer); - expect(qgisStyle).toBeDefined(); - expect(qgisStyle).toEqual(qml.trim()); + describe('Filter Parsing', () => { + it('can write a rule based QML PointSymbolizer', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/point_rules.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(point_rules); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); + it('can write QML with no symbolizers', async () => { + expect.assertions(2); + const qml = fs.readFileSync(`./data/${qmlFolder}/no_symbolizer.qml`, 'utf8'); + const { output: qgisStyle } = await styleParser.writeStyle(no_symbolizer); + expect(qgisStyle).toBeDefined(); + expect(qgisStyle).toEqual(qml.trim()); + }); }); }); }); - }); diff --git a/src/QGISStyleParser.ts b/src/QGISStyleParser.ts index 807caaf0..4efc2847 100644 --- a/src/QGISStyleParser.ts +++ b/src/QGISStyleParser.ts @@ -24,8 +24,6 @@ import { Builder } from 'xml2js'; -const OUTPUT_VERSION = '3.28.0-Firenze'; - const get = (obj: any, path: any, defaultValue = undefined) => { const travel = (regexp: RegExp) => String.prototype.split @@ -36,6 +34,10 @@ const get = (obj: any, path: any, defaultValue = undefined) => { return result === undefined || result === obj ? defaultValue : result; }; +export type ConstructorParams = { + qgisVersion?: string; +}; + type SymbolizerMap = { [key: string]: Symbolizer[]; }; @@ -130,6 +132,27 @@ export class QGISStyleParser implements StyleParser { title = 'QGIS Style Parser'; + qgisVersion: string; + + // QGIS 3.28 and later use