@vectoriahq/quac 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +35 -2
- package/dist/generate/arcgisStacCatalogue.d.ts +46 -0
- package/dist/generate/arcgisStacCatalogue.js +189 -0
- package/dist/generate/externalStacCatalogue.d.ts +53 -0
- package/dist/generate/externalStacCatalogue.js +145 -0
- package/dist/generate/fileLayerCollection.d.ts +44 -0
- package/dist/generate/fileLayerCollection.js +72 -0
- package/dist/generate/folderStacCatalogue.d.ts +48 -0
- package/dist/generate/folderStacCatalogue.js +69 -0
- package/dist/generate/normalizedProject.d.ts +451 -0
- package/dist/generate/normalizedProject.js +925 -0
- package/dist/generate/ogcFeaturesStacCatalogue.d.ts +49 -0
- package/dist/generate/ogcFeaturesStacCatalogue.js +207 -0
- package/dist/generate/qmlForLayer.d.ts +17 -0
- package/dist/generate/qmlForLayer.js +36 -0
- package/dist/generate/serverLayerTree.d.ts +44 -0
- package/dist/generate/serverLayerTree.js +50 -0
- package/dist/generate/serverStacCatalogue.d.ts +84 -0
- package/dist/generate/serverStacCatalogue.js +327 -0
- package/dist/generate/stacCatalogue.d.ts +110 -0
- package/dist/generate/stacCatalogue.js +882 -0
- package/dist/generate/wfsStacCatalogue.d.ts +37 -0
- package/dist/generate/wfsStacCatalogue.js +127 -0
- package/dist/generate/wmsStacCatalogue.d.ts +46 -0
- package/dist/generate/wmsStacCatalogue.js +228 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +52 -0
- package/dist/model/QgsProject.d.ts +722 -0
- package/dist/model/QgsProject.js +15 -0
- package/dist/model/Stac.d.ts +320 -0
- package/dist/model/Stac.js +16 -0
- package/dist/model/WmsProject.d.ts +105 -0
- package/dist/model/WmsProject.js +1 -0
- package/dist/model/arcgis.d.ts +134 -0
- package/dist/model/arcgis.js +1 -0
- package/dist/model/delimitedText.d.ts +38 -0
- package/dist/model/delimitedText.js +46 -0
- package/dist/model/featureFilter.d.ts +41 -0
- package/dist/model/featureFilter.js +24 -0
- package/dist/model/fieldIconAddress.d.ts +27 -0
- package/dist/model/fieldIconAddress.js +93 -0
- package/dist/model/ogcFeatures.d.ts +40 -0
- package/dist/model/ogcFeatures.js +6 -0
- package/dist/model/quacExtension.d.ts +28 -0
- package/dist/model/quacExtension.js +75 -0
- package/dist/model/stacAssetRoles.d.ts +33 -0
- package/dist/model/stacAssetRoles.js +44 -0
- package/dist/model/stacCollectionNotes.d.ts +21 -0
- package/dist/model/stacCollectionNotes.js +44 -0
- package/dist/model/stacHref.d.ts +56 -0
- package/dist/model/stacHref.js +93 -0
- package/dist/model/stacPmtiles.d.ts +38 -0
- package/dist/model/stacPmtiles.js +69 -0
- package/dist/model/stacSizeAndCount.d.ts +14 -0
- package/dist/model/stacSizeAndCount.js +20 -0
- package/dist/model/stacStyles.d.ts +93 -0
- package/dist/model/stacStyles.js +87 -0
- package/dist/model/stacTreeWalk.d.ts +36 -0
- package/dist/model/stacTreeWalk.js +76 -0
- package/dist/model/stacWms.d.ts +18 -0
- package/dist/model/stacWms.js +73 -0
- package/dist/model/stacWmts.d.ts +34 -0
- package/dist/model/stacWmts.js +90 -0
- package/dist/model/stacXyz.d.ts +24 -0
- package/dist/model/stacXyz.js +46 -0
- package/dist/model/wfs.d.ts +136 -0
- package/dist/model/wfs.js +1 -0
- package/dist/parse/collectLayerVisibility.d.ts +10 -0
- package/dist/parse/collectLayerVisibility.js +22 -0
- package/dist/parse/customProperties.d.ts +18 -0
- package/dist/parse/customProperties.js +43 -0
- package/dist/parse/geometrySiblings.d.ts +25 -0
- package/dist/parse/geometrySiblings.js +83 -0
- package/dist/parse/parseBrandColour.d.ts +14 -0
- package/dist/parse/parseBrandColour.js +25 -0
- package/dist/parse/parseDataDefinedEditable.d.ts +38 -0
- package/dist/parse/parseDataDefinedEditable.js +76 -0
- package/dist/parse/parseDataSource.d.ts +53 -0
- package/dist/parse/parseDataSource.js +484 -0
- package/dist/parse/parseExtent.d.ts +17 -0
- package/dist/parse/parseExtent.js +49 -0
- package/dist/parse/parseFormLayout.d.ts +26 -0
- package/dist/parse/parseFormLayout.js +60 -0
- package/dist/parse/parseGetProjectSettings.d.ts +15 -0
- package/dist/parse/parseGetProjectSettings.js +172 -0
- package/dist/parse/parseLayers.d.ts +23 -0
- package/dist/parse/parseLayers.js +1122 -0
- package/dist/parse/parseLegendTree.d.ts +20 -0
- package/dist/parse/parseLegendTree.js +66 -0
- package/dist/parse/parseMeasurement.d.ts +21 -0
- package/dist/parse/parseMeasurement.js +67 -0
- package/dist/parse/parseMergin.d.ts +19 -0
- package/dist/parse/parseMergin.js +51 -0
- package/dist/parse/parseProjectVariables.d.ts +9 -0
- package/dist/parse/parseProjectVariables.js +19 -0
- package/dist/parse/parseQfieldSync.d.ts +47 -0
- package/dist/parse/parseQfieldSync.js +95 -0
- package/dist/parse/parseQgsXml.d.ts +15 -0
- package/dist/parse/parseQgsXml.js +100 -0
- package/dist/parse/parseRelations.d.ts +19 -0
- package/dist/parse/parseRelations.js +64 -0
- package/dist/parse/parseStyle.d.ts +33 -0
- package/dist/parse/parseStyle.js +128 -0
- package/dist/parse/parseWmsPublishing.d.ts +21 -0
- package/dist/parse/parseWmsPublishing.js +38 -0
- package/dist/parse/projectProperties.d.ts +15 -0
- package/dist/parse/projectProperties.js +27 -0
- package/dist/parse/qgisExpression.d.ts +194 -0
- package/dist/parse/qgisExpression.js +859 -0
- package/dist/parse/qtDateFormat.d.ts +74 -0
- package/dist/parse/qtDateFormat.js +324 -0
- package/dist/parse/qtRegex.d.ts +67 -0
- package/dist/parse/qtRegex.js +397 -0
- package/dist/parse/readProjectFile.d.ts +7 -0
- package/dist/parse/readProjectFile.js +27 -0
- package/dist/sources/qgisServerUrl.d.ts +6 -0
- package/dist/sources/qgisServerUrl.js +17 -0
- package/dist/sources/stacDocuments.d.ts +40 -0
- package/dist/sources/stacDocuments.js +85 -0
- package/dist/sources/stacItems.d.ts +109 -0
- package/dist/sources/stacItems.js +287 -0
- package/dist/util/catalogueFileFormats.d.ts +58 -0
- package/dist/util/catalogueFileFormats.js +64 -0
- package/dist/util/devLog.d.ts +11 -0
- package/dist/util/devLog.js +23 -0
- package/dist/util/fileName.d.ts +18 -0
- package/dist/util/fileName.js +45 -0
- package/dist/util/wfsVersions.d.ts +9 -0
- package/dist/util/wfsVersions.js +13 -0
- package/package.json +47 -4
- package/src/schema/quac.schema.json +935 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LayerGroup } from '../model/QgsProject.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Parses the <layer-tree-group> root into a tree of groups + layer leaves.
|
|
4
|
+
*
|
|
5
|
+
* Structure:
|
|
6
|
+
* <layer-tree-group>
|
|
7
|
+
* <layer-tree-group name="Subgroup" checked="Qt::Checked" mutually-exclusive="1">
|
|
8
|
+
* <layer-tree-layer name="..." id="..." checked="Qt::Checked"/>
|
|
9
|
+
* </layer-tree-group>
|
|
10
|
+
* <layer-tree-layer name="..." id="..." checked="Qt::Checked"/>
|
|
11
|
+
* <custom-order .../> ← ignored
|
|
12
|
+
* <customproperties.../> ← ignored
|
|
13
|
+
* </layer-tree-group>
|
|
14
|
+
*
|
|
15
|
+
* The root group has no name attribute — we represent it with name = "".
|
|
16
|
+
*
|
|
17
|
+
* Returns an empty root group if parsing fails so the rest of the project
|
|
18
|
+
* still loads.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseLegendTree(qgisRoot: Element): LayerGroup;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { devLog } from "../util/devLog.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parses the <layer-tree-group> root into a tree of groups + layer leaves.
|
|
4
|
+
*
|
|
5
|
+
* Structure:
|
|
6
|
+
* <layer-tree-group>
|
|
7
|
+
* <layer-tree-group name="Subgroup" checked="Qt::Checked" mutually-exclusive="1">
|
|
8
|
+
* <layer-tree-layer name="..." id="..." checked="Qt::Checked"/>
|
|
9
|
+
* </layer-tree-group>
|
|
10
|
+
* <layer-tree-layer name="..." id="..." checked="Qt::Checked"/>
|
|
11
|
+
* <custom-order .../> ← ignored
|
|
12
|
+
* <customproperties.../> ← ignored
|
|
13
|
+
* </layer-tree-group>
|
|
14
|
+
*
|
|
15
|
+
* The root group has no name attribute — we represent it with name = "".
|
|
16
|
+
*
|
|
17
|
+
* Returns an empty root group if parsing fails so the rest of the project
|
|
18
|
+
* still loads.
|
|
19
|
+
*/
|
|
20
|
+
export function parseLegendTree(qgisRoot) {
|
|
21
|
+
const empty = { kind: 'group', name: '', checked: true, children: [] };
|
|
22
|
+
try {
|
|
23
|
+
// The first layer-tree-group is the root.
|
|
24
|
+
const root = qgisRoot.querySelector('layer-tree-group');
|
|
25
|
+
if (!root)
|
|
26
|
+
return empty;
|
|
27
|
+
return readGroup(root, /* isRoot */ true);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
devLog('qgs/parseLegendTree', 'failed to parse layer tree', { error: String(err) });
|
|
31
|
+
return empty;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function readGroup(node, isRoot) {
|
|
35
|
+
const name = isRoot ? '' : node.getAttribute('name') ?? '';
|
|
36
|
+
const checked = parseChecked(node.getAttribute('checked'));
|
|
37
|
+
const children = [];
|
|
38
|
+
for (const child of Array.from(node.children)) {
|
|
39
|
+
if (child.tagName === 'layer-tree-group') {
|
|
40
|
+
children.push(readGroup(child, false));
|
|
41
|
+
}
|
|
42
|
+
else if (child.tagName === 'layer-tree-layer') {
|
|
43
|
+
const layerId = child.getAttribute('id') ?? '';
|
|
44
|
+
if (!layerId)
|
|
45
|
+
continue;
|
|
46
|
+
children.push({
|
|
47
|
+
kind: 'layer',
|
|
48
|
+
layerId,
|
|
49
|
+
name: child.getAttribute('name') ?? '',
|
|
50
|
+
checked: parseChecked(child.getAttribute('checked'))
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// <custom-order> and <customproperties> intentionally skipped
|
|
54
|
+
}
|
|
55
|
+
// QGIS saves a mutually exclusive group with `mutually-exclusive="1"`
|
|
56
|
+
// (`src/core/layertree/qgslayertreegroup.cpp`).
|
|
57
|
+
const mutuallyExclusive = !isRoot && node.getAttribute('mutually-exclusive') === '1';
|
|
58
|
+
return { kind: 'group', name, checked, ...(mutuallyExclusive ? { mutuallyExclusive } : {}), children };
|
|
59
|
+
}
|
|
60
|
+
function parseChecked(attr) {
|
|
61
|
+
// QGIS uses Qt's tri-state strings: "Qt::Checked", "Qt::Unchecked", "Qt::PartiallyChecked".
|
|
62
|
+
// We treat PartiallyChecked as checked since at least one child is on.
|
|
63
|
+
if (!attr)
|
|
64
|
+
return true; // default visible
|
|
65
|
+
return attr === 'Qt::Checked' || attr === 'Qt::PartiallyChecked';
|
|
66
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ProjectMeasurement } from '../model/QgsProject.ts';
|
|
2
|
+
/** QGIS's own defaults for a project that saves no units (`QgsProject::clear`, `src/core/project/qgsproject.cpp`). */
|
|
3
|
+
export declare const DEFAULT_MEASUREMENT: ProjectMeasurement;
|
|
4
|
+
/**
|
|
5
|
+
* The factors that turn the metres and square metres Groundwork measures into
|
|
6
|
+
* the project's units, or null for a unit it does not convert. An expression
|
|
7
|
+
* that measures in a unit with no factor is unreadable.
|
|
8
|
+
*/
|
|
9
|
+
export interface MeasureFactors {
|
|
10
|
+
area: number | null;
|
|
11
|
+
distance: number | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function measureFactorsOf(measurement: ProjectMeasurement | null | undefined): MeasureFactors;
|
|
14
|
+
/**
|
|
15
|
+
* The project's area and distance units from `<properties><Measurement>`, as
|
|
16
|
+
* QGIS writes them (`QgsProject::writeProject`, `src/core/project/qgsproject.cpp`).
|
|
17
|
+
* Null where the project saves neither, which QGIS reads as square metres and
|
|
18
|
+
* metres. The project's ellipsoid (`<Measure><Ellipsoid>`) is not read:
|
|
19
|
+
* Groundwork measures on WGS 84 whatever the project says.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseProjectMeasurement(qgisRoot: Element): ProjectMeasurement | null;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { propertyText, readPropertyBlock } from "./projectProperties.js";
|
|
2
|
+
/**
|
|
3
|
+
* How many of a unit make up one square metre, for the area units QGIS saves
|
|
4
|
+
* as `<Measurement><AreaUnits>` that Groundwork converts. The saved names are
|
|
5
|
+
* `QgsUnitTypes::encodeUnit( Qgis::AreaUnit )` (`src/core/qgsunittypes.cpp`,
|
|
6
|
+
* `qgis/QGIS@master`, read 2026-10-25). `deg2` is saved too and is left out: a
|
|
7
|
+
* square degree is no fixed area.
|
|
8
|
+
*/
|
|
9
|
+
const AREA_UNITS_PER_SQUARE_METRE = {
|
|
10
|
+
m2: 1,
|
|
11
|
+
km2: 1e-6,
|
|
12
|
+
ft2: 1 / 0.09290304,
|
|
13
|
+
y2: 1 / 0.83612736,
|
|
14
|
+
mi2: 1 / 2589988.110336,
|
|
15
|
+
ha: 1e-4,
|
|
16
|
+
ac: 1 / 4046.8564224,
|
|
17
|
+
nm2: 1 / 3429904,
|
|
18
|
+
cm2: 1e4,
|
|
19
|
+
mm2: 1e6,
|
|
20
|
+
in2: 1 / 0.00064516
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* How many of a unit make up one metre, for the distance units QGIS saves as
|
|
24
|
+
* `<Measurement><DistanceUnits>` that Groundwork converts. The saved names are
|
|
25
|
+
* `QgsUnitTypes::encodeUnit( Qgis::DistanceUnit )`, same file. `degrees` and
|
|
26
|
+
* the survey chains are left out.
|
|
27
|
+
*/
|
|
28
|
+
const DISTANCE_UNITS_PER_METRE = {
|
|
29
|
+
meters: 1,
|
|
30
|
+
km: 1e-3,
|
|
31
|
+
feet: 1 / 0.3048,
|
|
32
|
+
yd: 1 / 0.9144,
|
|
33
|
+
mi: 1 / 1609.344,
|
|
34
|
+
'nautical miles': 1 / 1852,
|
|
35
|
+
cm: 100,
|
|
36
|
+
mm: 1000,
|
|
37
|
+
in: 1 / 0.0254
|
|
38
|
+
};
|
|
39
|
+
/** QGIS's own defaults for a project that saves no units (`QgsProject::clear`, `src/core/project/qgsproject.cpp`). */
|
|
40
|
+
export const DEFAULT_MEASUREMENT = { areaUnit: 'm2', distanceUnit: 'meters' };
|
|
41
|
+
export function measureFactorsOf(measurement) {
|
|
42
|
+
const { areaUnit, distanceUnit } = measurement ?? DEFAULT_MEASUREMENT;
|
|
43
|
+
return {
|
|
44
|
+
area: Object.hasOwn(AREA_UNITS_PER_SQUARE_METRE, areaUnit) ? AREA_UNITS_PER_SQUARE_METRE[areaUnit] : null,
|
|
45
|
+
distance: Object.hasOwn(DISTANCE_UNITS_PER_METRE, distanceUnit) ? DISTANCE_UNITS_PER_METRE[distanceUnit] : null
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The project's area and distance units from `<properties><Measurement>`, as
|
|
50
|
+
* QGIS writes them (`QgsProject::writeProject`, `src/core/project/qgsproject.cpp`).
|
|
51
|
+
* Null where the project saves neither, which QGIS reads as square metres and
|
|
52
|
+
* metres. The project's ellipsoid (`<Measure><Ellipsoid>`) is not read:
|
|
53
|
+
* Groundwork measures on WGS 84 whatever the project says.
|
|
54
|
+
*/
|
|
55
|
+
export function parseProjectMeasurement(qgisRoot) {
|
|
56
|
+
const block = readPropertyBlock(qgisRoot, 'Measurement');
|
|
57
|
+
if (!block)
|
|
58
|
+
return null;
|
|
59
|
+
const areaUnit = propertyText(block, 'AreaUnits');
|
|
60
|
+
const distanceUnit = propertyText(block, 'DistanceUnits');
|
|
61
|
+
if (!areaUnit && !distanceUnit)
|
|
62
|
+
return null;
|
|
63
|
+
return {
|
|
64
|
+
areaUnit: areaUnit ?? DEFAULT_MEASUREMENT.areaUnit,
|
|
65
|
+
distanceUnit: distanceUnit ?? DEFAULT_MEASUREMENT.distanceUnit
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PresetFilter } from '../model/QgsProject.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The filters the Mergin Maps plugin sets up, on its **Mergin Maps** tab of
|
|
4
|
+
* Project Properties: the project entries `Mergin/Filtering/Enabled` and
|
|
5
|
+
* `Mergin/Filtering/Filters`, saved as `<properties><Mergin><Filtering>`
|
|
6
|
+
* (`ProjectSettingsWidget.apply`, `Mergin/project_settings_widget.py`,
|
|
7
|
+
* `MerginMaps/qgis-plugin@eb2c52a`). The second is a JSON list of filters, each
|
|
8
|
+
* with `filter_name`, `layer_id`, `field_name`, `filter_type` and
|
|
9
|
+
* `sql_expression` (`FieldFilter`, `Mergin/field_filtering.py`, same commit).
|
|
10
|
+
*
|
|
11
|
+
* The app offers them only while `Enabled` is true, and skips a filter that
|
|
12
|
+
* lacks `layer_id`, `field_name` or `sql_expression` (`FilterController`,
|
|
13
|
+
* `app/filter/filtercontroller.cpp`, `MerginMaps/mobile@779434d`), as this
|
|
14
|
+
* does. `sql_expression`, a template for the data source's own SQL, is not
|
|
15
|
+
* read beyond that: the filter row filters the field itself. A `Text` filter
|
|
16
|
+
* is left out. Empty where the project sets none, or the list does not read
|
|
17
|
+
* as JSON.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseMerginFilters(qgisRoot: Element): PresetFilter[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { isTrueValue } from "./customProperties.js";
|
|
2
|
+
import { propertyChild, propertyText, readPropertyBlock } from "./projectProperties.js";
|
|
3
|
+
/** The Mergin Maps filter types the filter row has a control for; `Text`, a "contains" search, is not one. */
|
|
4
|
+
const READ_FILTER_TYPES = new Set(['Number', 'Date', 'Checkbox', 'Single select', 'Multi select']);
|
|
5
|
+
/**
|
|
6
|
+
* The filters the Mergin Maps plugin sets up, on its **Mergin Maps** tab of
|
|
7
|
+
* Project Properties: the project entries `Mergin/Filtering/Enabled` and
|
|
8
|
+
* `Mergin/Filtering/Filters`, saved as `<properties><Mergin><Filtering>`
|
|
9
|
+
* (`ProjectSettingsWidget.apply`, `Mergin/project_settings_widget.py`,
|
|
10
|
+
* `MerginMaps/qgis-plugin@eb2c52a`). The second is a JSON list of filters, each
|
|
11
|
+
* with `filter_name`, `layer_id`, `field_name`, `filter_type` and
|
|
12
|
+
* `sql_expression` (`FieldFilter`, `Mergin/field_filtering.py`, same commit).
|
|
13
|
+
*
|
|
14
|
+
* The app offers them only while `Enabled` is true, and skips a filter that
|
|
15
|
+
* lacks `layer_id`, `field_name` or `sql_expression` (`FilterController`,
|
|
16
|
+
* `app/filter/filtercontroller.cpp`, `MerginMaps/mobile@779434d`), as this
|
|
17
|
+
* does. `sql_expression`, a template for the data source's own SQL, is not
|
|
18
|
+
* read beyond that: the filter row filters the field itself. A `Text` filter
|
|
19
|
+
* is left out. Empty where the project sets none, or the list does not read
|
|
20
|
+
* as JSON.
|
|
21
|
+
*/
|
|
22
|
+
export function parseMerginFilters(qgisRoot) {
|
|
23
|
+
const block = readPropertyBlock(qgisRoot, 'Mergin');
|
|
24
|
+
const filtering = block ? propertyChild(block, 'Filtering') : null;
|
|
25
|
+
if (!filtering || !isTrueValue(propertyText(filtering, 'Enabled')))
|
|
26
|
+
return [];
|
|
27
|
+
let entries;
|
|
28
|
+
try {
|
|
29
|
+
entries = JSON.parse(propertyText(filtering, 'Filters') ?? '[]');
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
if (!Array.isArray(entries))
|
|
35
|
+
return [];
|
|
36
|
+
const text = (entry, key) => {
|
|
37
|
+
const value = entry[key];
|
|
38
|
+
return typeof value === 'string' && value.trim() !== '' ? value : null;
|
|
39
|
+
};
|
|
40
|
+
return entries.flatMap((entry) => {
|
|
41
|
+
if (!entry || typeof entry !== 'object')
|
|
42
|
+
return [];
|
|
43
|
+
const filter = entry;
|
|
44
|
+
const layerId = text(filter, 'layer_id');
|
|
45
|
+
const field = text(filter, 'field_name');
|
|
46
|
+
const type = text(filter, 'filter_type');
|
|
47
|
+
if (!layerId || !field || !text(filter, 'sql_expression') || !type || !READ_FILTER_TYPES.has(type))
|
|
48
|
+
return [];
|
|
49
|
+
return [{ layerId, field, name: text(filter, 'filter_name')?.trim() ?? null }];
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project's own variables (Project Properties > Variables), by name. QGIS
|
|
3
|
+
* saves them as two parallel lists, `<Variables><variableNames>` and
|
|
4
|
+
* `<Variables><variableValues>` (`QgsProject::setCustomVariables`,
|
|
5
|
+
* `src/core/project/qgsproject.cpp`, `qgis/QGIS@master`, read 2026-10-25),
|
|
6
|
+
* and reads none when the two differ in length, as this does. The global
|
|
7
|
+
* variables QGIS lists beside them are not saved in the project.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseProjectVariables(qgisRoot: Element): Record<string, string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { propertyList, readPropertyBlock } from "./projectProperties.js";
|
|
2
|
+
/**
|
|
3
|
+
* The project's own variables (Project Properties > Variables), by name. QGIS
|
|
4
|
+
* saves them as two parallel lists, `<Variables><variableNames>` and
|
|
5
|
+
* `<Variables><variableValues>` (`QgsProject::setCustomVariables`,
|
|
6
|
+
* `src/core/project/qgsproject.cpp`, `qgis/QGIS@master`, read 2026-10-25),
|
|
7
|
+
* and reads none when the two differ in length, as this does. The global
|
|
8
|
+
* variables QGIS lists beside them are not saved in the project.
|
|
9
|
+
*/
|
|
10
|
+
export function parseProjectVariables(qgisRoot) {
|
|
11
|
+
const block = readPropertyBlock(qgisRoot, 'Variables');
|
|
12
|
+
if (!block)
|
|
13
|
+
return {};
|
|
14
|
+
const names = propertyList(block, 'variableNames');
|
|
15
|
+
const values = propertyList(block, 'variableValues');
|
|
16
|
+
if (names.length !== values.length)
|
|
17
|
+
return {};
|
|
18
|
+
return Object.fromEntries(names.map((name, i) => [name, values[i]]));
|
|
19
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { LayerLocks, WfsTransactionLayers } from '../model/QgsProject.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The layer the QFieldSync plugin names as the one a project opens with as
|
|
4
|
+
* the active layer: **Initial active layer** on the QField tab of Project
|
|
5
|
+
* Properties, saved as `<properties><qfieldsync><initialActiveLayer>`, a layer
|
|
6
|
+
* id (`ProjectConfig.initial_active_layer`, `libqfieldsync/project.py`,
|
|
7
|
+
* `opengisch/libqfieldsync@aad2ea6`).
|
|
8
|
+
*
|
|
9
|
+
* QFieldSync writes the key on every OK of Project Properties, but writes it
|
|
10
|
+
* blank until an author picks a layer: the list offers no empty choice, and
|
|
11
|
+
* opens on none where none is saved (`ProjectConfigurationWidget`,
|
|
12
|
+
* `qfieldsync/gui/project_configuration_widget.py`,
|
|
13
|
+
* `opengisch/qfieldsync@c8abedb`; `QgsMapLayerComboBox::setLayer`,
|
|
14
|
+
* `src/gui/qgsmaplayercombobox.cpp`, `qgis/QGIS@16eddb2`). So a saved id is
|
|
15
|
+
* an author's choice. Null where the project names none.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseInitialActiveLayerId(qgisRoot: Element): string | null;
|
|
18
|
+
/**
|
|
19
|
+
* The edits QFieldSync locks on a layer: **Disable feature addition**,
|
|
20
|
+
* **Disable attribute editing**, **Disable geometry editing** and **Disable
|
|
21
|
+
* feature deletion**, under Permissions on the QField tab of Layer Properties.
|
|
22
|
+
* Each is three custom properties: the box, `QFieldSync/is_<edit>_locked`; the
|
|
23
|
+
* switch of its data-defined button, `QFieldSync/is_<edit>_locked_expression_active`;
|
|
24
|
+
* and the button's expression, `QFieldSync/<edit>_locked_expression`
|
|
25
|
+
* (`LayerSource.apply`, `libqfieldsync/layer.py`, `opengisch/libqfieldsync@aad2ea6`).
|
|
26
|
+
*
|
|
27
|
+
* With the switch on and an expression that is not blank, the expression
|
|
28
|
+
* decides in place of the box, and a true result locks the feature it is
|
|
29
|
+
* evaluated for; otherwise the box decides (`QfFeatureModel`,
|
|
30
|
+
* `src/core/qffeaturemodel.cpp`, `opengisch/QField@2cd8695`). The expression is
|
|
31
|
+
* kept as QFieldSync saved it. A layer QFieldSync saved before 4.15 holds one
|
|
32
|
+
* lock, `QFieldSync/is_geometry_locked` and its two companions, which QField
|
|
33
|
+
* reads as adding, geometry editing and deleting locked, and attributes free.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseQfieldSyncLocks(maplayer: Element): LayerLocks;
|
|
36
|
+
/**
|
|
37
|
+
* The layers a project publishes for WFS, and the WFS-T operations each takes:
|
|
38
|
+
* **Published**, **Update**, **Insert** and **Delete** in Project Properties →
|
|
39
|
+
* QGIS Server → WFS capabilities. QGIS saves them as lists of layer ids,
|
|
40
|
+
* `<properties><WFSLayers>` and `<WFSTLayers><Update>`, `<Insert>` and
|
|
41
|
+
* `<Delete>`, writing a layer to the last three only while it is published
|
|
42
|
+
* (`QgsProjectProperties::apply`, `src/app/qgsprojectproperties.cpp`; read back
|
|
43
|
+
* by `QgsServerProjectUtils::wfstUpdateLayerIds` and its siblings,
|
|
44
|
+
* `src/server/qgsserverprojectutils.cpp`; `qgis/QGIS@16eddb2`). Null where the
|
|
45
|
+
* project saves no `WFSLayers`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseWfsTransactionLayers(qgisRoot: Element): WfsTransactionLayers | null;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { isTrueValue, readCustomProperty } from "./customProperties.js";
|
|
2
|
+
import { propertyChild, propertyList, propertyText, readPropertyBlock } from "./projectProperties.js";
|
|
3
|
+
/**
|
|
4
|
+
* The layer the QFieldSync plugin names as the one a project opens with as
|
|
5
|
+
* the active layer: **Initial active layer** on the QField tab of Project
|
|
6
|
+
* Properties, saved as `<properties><qfieldsync><initialActiveLayer>`, a layer
|
|
7
|
+
* id (`ProjectConfig.initial_active_layer`, `libqfieldsync/project.py`,
|
|
8
|
+
* `opengisch/libqfieldsync@aad2ea6`).
|
|
9
|
+
*
|
|
10
|
+
* QFieldSync writes the key on every OK of Project Properties, but writes it
|
|
11
|
+
* blank until an author picks a layer: the list offers no empty choice, and
|
|
12
|
+
* opens on none where none is saved (`ProjectConfigurationWidget`,
|
|
13
|
+
* `qfieldsync/gui/project_configuration_widget.py`,
|
|
14
|
+
* `opengisch/qfieldsync@c8abedb`; `QgsMapLayerComboBox::setLayer`,
|
|
15
|
+
* `src/gui/qgsmaplayercombobox.cpp`, `qgis/QGIS@16eddb2`). So a saved id is
|
|
16
|
+
* an author's choice. Null where the project names none.
|
|
17
|
+
*/
|
|
18
|
+
export function parseInitialActiveLayerId(qgisRoot) {
|
|
19
|
+
const block = readPropertyBlock(qgisRoot, 'qfieldsync');
|
|
20
|
+
return block ? propertyText(block, 'initialActiveLayer') : null;
|
|
21
|
+
}
|
|
22
|
+
/** The part of each lock's three keys that names the edit, as QFieldSync spells it. */
|
|
23
|
+
const LOCK_KEY_PARTS = {
|
|
24
|
+
add: 'feature_addition',
|
|
25
|
+
attributes: 'attribute_editing',
|
|
26
|
+
geometry: 'geometry_editing',
|
|
27
|
+
delete: 'feature_deletion'
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The edits QFieldSync locks on a layer: **Disable feature addition**,
|
|
31
|
+
* **Disable attribute editing**, **Disable geometry editing** and **Disable
|
|
32
|
+
* feature deletion**, under Permissions on the QField tab of Layer Properties.
|
|
33
|
+
* Each is three custom properties: the box, `QFieldSync/is_<edit>_locked`; the
|
|
34
|
+
* switch of its data-defined button, `QFieldSync/is_<edit>_locked_expression_active`;
|
|
35
|
+
* and the button's expression, `QFieldSync/<edit>_locked_expression`
|
|
36
|
+
* (`LayerSource.apply`, `libqfieldsync/layer.py`, `opengisch/libqfieldsync@aad2ea6`).
|
|
37
|
+
*
|
|
38
|
+
* With the switch on and an expression that is not blank, the expression
|
|
39
|
+
* decides in place of the box, and a true result locks the feature it is
|
|
40
|
+
* evaluated for; otherwise the box decides (`QfFeatureModel`,
|
|
41
|
+
* `src/core/qffeaturemodel.cpp`, `opengisch/QField@2cd8695`). The expression is
|
|
42
|
+
* kept as QFieldSync saved it. A layer QFieldSync saved before 4.15 holds one
|
|
43
|
+
* lock, `QFieldSync/is_geometry_locked` and its two companions, which QField
|
|
44
|
+
* reads as adding, geometry editing and deleting locked, and attributes free.
|
|
45
|
+
*/
|
|
46
|
+
export function parseQfieldSyncLocks(maplayer) {
|
|
47
|
+
const properties = Array.from(maplayer.children).find((child) => child.tagName === 'customproperties');
|
|
48
|
+
if (!properties)
|
|
49
|
+
return {};
|
|
50
|
+
const read = (key) => readCustomProperty(properties, `QFieldSync/${key}`);
|
|
51
|
+
const lockOf = (part) => {
|
|
52
|
+
const expression = isTrueValue(read(`is_${part}_locked_expression_active`)) ? read(`${part}_locked_expression`)?.trim() : null;
|
|
53
|
+
if (expression)
|
|
54
|
+
return { expression };
|
|
55
|
+
return isTrueValue(read(`is_${part}_locked`)) ? true : null;
|
|
56
|
+
};
|
|
57
|
+
const locks = {};
|
|
58
|
+
if (read('is_geometry_locked') !== null) {
|
|
59
|
+
const lock = lockOf('geometry');
|
|
60
|
+
if (lock)
|
|
61
|
+
for (const edit of ['add', 'geometry', 'delete'])
|
|
62
|
+
locks[edit] = lock;
|
|
63
|
+
return locks;
|
|
64
|
+
}
|
|
65
|
+
for (const [edit, part] of Object.entries(LOCK_KEY_PARTS)) {
|
|
66
|
+
const lock = lockOf(part);
|
|
67
|
+
if (lock)
|
|
68
|
+
locks[edit] = lock;
|
|
69
|
+
}
|
|
70
|
+
return locks;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The layers a project publishes for WFS, and the WFS-T operations each takes:
|
|
74
|
+
* **Published**, **Update**, **Insert** and **Delete** in Project Properties →
|
|
75
|
+
* QGIS Server → WFS capabilities. QGIS saves them as lists of layer ids,
|
|
76
|
+
* `<properties><WFSLayers>` and `<WFSTLayers><Update>`, `<Insert>` and
|
|
77
|
+
* `<Delete>`, writing a layer to the last three only while it is published
|
|
78
|
+
* (`QgsProjectProperties::apply`, `src/app/qgsprojectproperties.cpp`; read back
|
|
79
|
+
* by `QgsServerProjectUtils::wfstUpdateLayerIds` and its siblings,
|
|
80
|
+
* `src/server/qgsserverprojectutils.cpp`; `qgis/QGIS@16eddb2`). Null where the
|
|
81
|
+
* project saves no `WFSLayers`.
|
|
82
|
+
*/
|
|
83
|
+
export function parseWfsTransactionLayers(qgisRoot) {
|
|
84
|
+
const properties = qgisRoot.querySelector(':scope > properties');
|
|
85
|
+
if (!properties || !propertyChild(properties, 'WFSLayers'))
|
|
86
|
+
return null;
|
|
87
|
+
const transactions = readPropertyBlock(qgisRoot, 'WFSTLayers');
|
|
88
|
+
const listOf = (name) => transactions ? propertyList(transactions, name) : [];
|
|
89
|
+
return {
|
|
90
|
+
published: propertyList(properties, 'WFSLayers'),
|
|
91
|
+
insert: listOf('Insert'),
|
|
92
|
+
update: listOf('Update'),
|
|
93
|
+
delete: listOf('Delete')
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { QgsProject } from '../model/QgsProject.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Top-level orchestrator: reads a .qgs XML string and returns a typed
|
|
4
|
+
* QgsProject.
|
|
5
|
+
*
|
|
6
|
+
* Parsing strategy:
|
|
7
|
+
* 1. DOMParser → DOM tree (jsdom in tests, real DOM in browser).
|
|
8
|
+
* 2. Locate the root <qgis> element.
|
|
9
|
+
* 3. Each sub-parser handles one concern and isolates its own failures —
|
|
10
|
+
* a malformed legend tree shouldn't take down the layer list, etc.
|
|
11
|
+
*
|
|
12
|
+
* Throws only when the XML itself is unparseable or has no <qgis> root.
|
|
13
|
+
* Sub-parser failures yield empty / null fields rather than exceptions.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseQgsXml(xmlText: string): QgsProject;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { collectLayerVisibility } from "./collectLayerVisibility.js";
|
|
2
|
+
import { parseBrandColour } from "./parseBrandColour.js";
|
|
3
|
+
import { parseMapExtent } from "./parseExtent.js";
|
|
4
|
+
import { parseProjectLayers } from "./parseLayers.js";
|
|
5
|
+
import { parseLegendTree } from "./parseLegendTree.js";
|
|
6
|
+
import { parseProjectMeasurement } from "./parseMeasurement.js";
|
|
7
|
+
import { parseMerginFilters } from "./parseMergin.js";
|
|
8
|
+
import { parseProjectVariables } from "./parseProjectVariables.js";
|
|
9
|
+
import { parseInitialActiveLayerId, parseWfsTransactionLayers } from "./parseQfieldSync.js";
|
|
10
|
+
import { parseProjectRelations } from "./parseRelations.js";
|
|
11
|
+
import { parseWmsCrsList, parseWmsPublishing } from "./parseWmsPublishing.js";
|
|
12
|
+
import { devLog } from "../util/devLog.js";
|
|
13
|
+
/**
|
|
14
|
+
* Top-level orchestrator: reads a .qgs XML string and returns a typed
|
|
15
|
+
* QgsProject.
|
|
16
|
+
*
|
|
17
|
+
* Parsing strategy:
|
|
18
|
+
* 1. DOMParser → DOM tree (jsdom in tests, real DOM in browser).
|
|
19
|
+
* 2. Locate the root <qgis> element.
|
|
20
|
+
* 3. Each sub-parser handles one concern and isolates its own failures —
|
|
21
|
+
* a malformed legend tree shouldn't take down the layer list, etc.
|
|
22
|
+
*
|
|
23
|
+
* Throws only when the XML itself is unparseable or has no <qgis> root.
|
|
24
|
+
* Sub-parser failures yield empty / null fields rather than exceptions.
|
|
25
|
+
*/
|
|
26
|
+
export function parseQgsXml(xmlText) {
|
|
27
|
+
const parser = new DOMParser();
|
|
28
|
+
const doc = parser.parseFromString(xmlText, 'text/xml');
|
|
29
|
+
// DOMParser surfaces XML errors as a <parsererror> node in the document.
|
|
30
|
+
const parserError = doc.querySelector('parsererror');
|
|
31
|
+
if (parserError) {
|
|
32
|
+
throw new Error(`Failed to parse QGS XML: ${parserError.textContent?.slice(0, 200) ?? 'unknown error'}`);
|
|
33
|
+
}
|
|
34
|
+
const qgisRoot = doc.documentElement;
|
|
35
|
+
if (!qgisRoot || qgisRoot.tagName !== 'qgis') {
|
|
36
|
+
throw new Error(`Expected <qgis> root element, got <${qgisRoot?.tagName ?? 'nothing'}>`);
|
|
37
|
+
}
|
|
38
|
+
const qgisVersion = qgisRoot.getAttribute('version') || null;
|
|
39
|
+
const title = qgisRoot.querySelector(':scope > title')?.textContent?.trim() ?? '';
|
|
40
|
+
const projectCrs = readProjectCrs(qgisRoot);
|
|
41
|
+
const mapExtent = parseMapExtent(qgisRoot, projectCrs);
|
|
42
|
+
const rawLayers = parseProjectLayers(qgisRoot);
|
|
43
|
+
const layerTree = parseLegendTree(qgisRoot);
|
|
44
|
+
const relations = parseProjectRelations(qgisRoot);
|
|
45
|
+
// Visibility flows from the layer tree (where checked state is stored), not
|
|
46
|
+
// from the maplayer itself. Walk the tree once, build a layerId →
|
|
47
|
+
// effective visibility map, and apply it to each LayerEntry.
|
|
48
|
+
const visibilityByLayerId = collectLayerVisibility(layerTree);
|
|
49
|
+
const layers = rawLayers.map((layer) => ({
|
|
50
|
+
...layer,
|
|
51
|
+
isVisible: visibilityByLayerId.get(layer.id) ?? true
|
|
52
|
+
}));
|
|
53
|
+
devLog('qgs/parseQgsXml', 'parsed project', {
|
|
54
|
+
qgisVersion,
|
|
55
|
+
title,
|
|
56
|
+
projectCrs,
|
|
57
|
+
layerCount: layers.length,
|
|
58
|
+
relationCount: relations.length
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
qgisVersion,
|
|
62
|
+
title,
|
|
63
|
+
projectCrs,
|
|
64
|
+
mapExtent,
|
|
65
|
+
layers,
|
|
66
|
+
layerTree,
|
|
67
|
+
relations,
|
|
68
|
+
metadata: parseProjectMetadata(qgisRoot),
|
|
69
|
+
measurement: parseProjectMeasurement(qgisRoot),
|
|
70
|
+
brandColour: parseBrandColour(qgisRoot),
|
|
71
|
+
variables: parseProjectVariables(qgisRoot),
|
|
72
|
+
initialActiveLayerId: parseInitialActiveLayerId(qgisRoot),
|
|
73
|
+
wfsTransactionLayers: parseWfsTransactionLayers(qgisRoot),
|
|
74
|
+
wmsPublishing: parseWmsPublishing(qgisRoot),
|
|
75
|
+
wmsCrsList: parseWmsCrsList(qgisRoot),
|
|
76
|
+
merginFilters: parseMerginFilters(qgisRoot),
|
|
77
|
+
rawXml: xmlText
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function readProjectCrs(qgisRoot) {
|
|
81
|
+
// <qgis><projectCrs><spatialrefsys><authid>EPSG:4326</authid>
|
|
82
|
+
return (qgisRoot.querySelector('projectCrs spatialrefsys authid')?.textContent?.trim() || null);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Reads `<qgis><projectMetadata>` — separate from `<qgis><title>`, which
|
|
86
|
+
* `parseQgsXml` reads directly above. QGIS's Project Properties > Metadata
|
|
87
|
+
* dialog writes the element on every project, empty fields and all
|
|
88
|
+
* (`src/tests/fixtures/qgis/simple-styles/sample.qgs`, `src/tests/fixtures/qgis/graffiti/graffiti.qgs`,
|
|
89
|
+
* read 2026-08-12), so an absent element reads the same as one with nothing
|
|
90
|
+
* filled in.
|
|
91
|
+
*/
|
|
92
|
+
function parseProjectMetadata(qgisRoot) {
|
|
93
|
+
const block = qgisRoot.querySelector(':scope > projectMetadata');
|
|
94
|
+
const abstractText = block?.querySelector(':scope > abstract')?.textContent?.trim();
|
|
95
|
+
const authorText = block?.querySelector(':scope > author')?.textContent?.trim();
|
|
96
|
+
return {
|
|
97
|
+
abstract: abstractText && abstractText.length > 0 ? abstractText : null,
|
|
98
|
+
author: authorText && authorText.length > 0 ? authorText : null
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { QgsRelation } from '../model/QgsProject.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Parses `<qgis><relations>` into the project's declared relations.
|
|
4
|
+
*
|
|
5
|
+
* QGIS writes each one as
|
|
6
|
+
*
|
|
7
|
+
* <relation id="…" name="…" referencedLayer="<parent layer id>"
|
|
8
|
+
* referencingLayer="<child layer id>" strength="…">
|
|
9
|
+
* <fieldRef referencedField="<parent field>" referencingField="<child field>"/>
|
|
10
|
+
* </relation>
|
|
11
|
+
*
|
|
12
|
+
* where the *referenced* layer is the parent and the *referencing* layer the
|
|
13
|
+
* child, and several `<fieldRef>` children make one composite key. That shape
|
|
14
|
+
* was read out of QGIS's own `qgsrelation.cpp` on 2026-08-27.
|
|
15
|
+
*
|
|
16
|
+
* A relation missing its id, either layer id, or every field pair is skipped —
|
|
17
|
+
* there is no complete join for it to describe.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseProjectRelations(qgisRoot: Element): QgsRelation[];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { devLog } from "../util/devLog.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parses `<qgis><relations>` into the project's declared relations.
|
|
4
|
+
*
|
|
5
|
+
* QGIS writes each one as
|
|
6
|
+
*
|
|
7
|
+
* <relation id="…" name="…" referencedLayer="<parent layer id>"
|
|
8
|
+
* referencingLayer="<child layer id>" strength="…">
|
|
9
|
+
* <fieldRef referencedField="<parent field>" referencingField="<child field>"/>
|
|
10
|
+
* </relation>
|
|
11
|
+
*
|
|
12
|
+
* where the *referenced* layer is the parent and the *referencing* layer the
|
|
13
|
+
* child, and several `<fieldRef>` children make one composite key. That shape
|
|
14
|
+
* was read out of QGIS's own `qgsrelation.cpp` on 2026-08-27.
|
|
15
|
+
*
|
|
16
|
+
* A relation missing its id, either layer id, or every field pair is skipped —
|
|
17
|
+
* there is no complete join for it to describe.
|
|
18
|
+
*/
|
|
19
|
+
export function parseProjectRelations(qgisRoot) {
|
|
20
|
+
const block = qgisRoot.querySelector(':scope > relations');
|
|
21
|
+
if (!block)
|
|
22
|
+
return [];
|
|
23
|
+
const relations = [];
|
|
24
|
+
for (const node of Array.from(block.children)) {
|
|
25
|
+
if (node.tagName !== 'relation')
|
|
26
|
+
continue;
|
|
27
|
+
const id = attribute(node, 'id');
|
|
28
|
+
const parentLayerId = attribute(node, 'referencedLayer');
|
|
29
|
+
const childLayerId = attribute(node, 'referencingLayer');
|
|
30
|
+
const fieldPairs = parseFieldRefs(node);
|
|
31
|
+
if (!id || !parentLayerId || !childLayerId || fieldPairs.length === 0) {
|
|
32
|
+
devLog('qgs/parseRelations', 'skipping an incomplete relation', {
|
|
33
|
+
id, parentLayerId, childLayerId, fieldPairCount: fieldPairs.length
|
|
34
|
+
});
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
relations.push({
|
|
38
|
+
id,
|
|
39
|
+
name: attribute(node, 'name'),
|
|
40
|
+
parentLayerId,
|
|
41
|
+
childLayerId,
|
|
42
|
+
fieldPairs,
|
|
43
|
+
strength: attribute(node, 'strength') || null
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return relations;
|
|
47
|
+
}
|
|
48
|
+
/** The `<fieldRef>` children of one `<relation>`, in file order. */
|
|
49
|
+
function parseFieldRefs(relation) {
|
|
50
|
+
const pairs = [];
|
|
51
|
+
for (const node of Array.from(relation.children)) {
|
|
52
|
+
if (node.tagName !== 'fieldRef')
|
|
53
|
+
continue;
|
|
54
|
+
const parentField = attribute(node, 'referencedField');
|
|
55
|
+
const childField = attribute(node, 'referencingField');
|
|
56
|
+
if (!parentField || !childField)
|
|
57
|
+
continue;
|
|
58
|
+
pairs.push({ parentField, childField });
|
|
59
|
+
}
|
|
60
|
+
return pairs;
|
|
61
|
+
}
|
|
62
|
+
function attribute(element, name) {
|
|
63
|
+
return element.getAttribute(name)?.trim() ?? '';
|
|
64
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LayerStyle } from '../model/QgsProject.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Captures all named styles defined for a layer, plus the index of the
|
|
4
|
+
* active one.
|
|
5
|
+
*
|
|
6
|
+
* QGIS layer style structure:
|
|
7
|
+
* <maplayer>
|
|
8
|
+
* ...
|
|
9
|
+
* <map-layer-style-manager current="Priority">
|
|
10
|
+
* <map-layer-style name="Asset Owner">
|
|
11
|
+
* <style ...><renderer-v2 ...>...</renderer-v2>...</style>
|
|
12
|
+
* </map-layer-style>
|
|
13
|
+
* <map-layer-style name="Priority"/> ← empty: active style's
|
|
14
|
+
* </map-layer-style-manager> contents are duplicated
|
|
15
|
+
* ... at the maplayer level
|
|
16
|
+
* <renderer-v2 ...>...</renderer-v2> ← the active style's renderer
|
|
17
|
+
* </maplayer>
|
|
18
|
+
*
|
|
19
|
+
* If <map-layer-style-manager> is absent (older or simpler projects), we
|
|
20
|
+
* fall back to a single anonymous "default" style sourced from the direct-
|
|
21
|
+
* child <renderer-v2>.
|
|
22
|
+
*
|
|
23
|
+
* A vector tile layer (`type="vector-tile"`) has a `<renderer>` in place of
|
|
24
|
+
* `<renderer-v2>`, in the same places, and its XML is kept as
|
|
25
|
+
* `vectorTileRendererRawXml` instead.
|
|
26
|
+
*
|
|
27
|
+
* Returns { styles: [], activeIndex: -1 } when nothing is found, so callers
|
|
28
|
+
* can downgrade gracefully to default styling.
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseLayerStyles(maplayer: Element): {
|
|
31
|
+
styles: LayerStyle[];
|
|
32
|
+
activeIndex: number;
|
|
33
|
+
};
|