@vectoriahq/quac 0.1.0 → 0.3.0-next.1
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/README.md +10 -3
- package/dist/generate/externalStacCatalogue.d.ts +4 -4
- package/dist/generate/externalStacCatalogue.js +9 -11
- package/dist/generate/fileLayerCollection.d.ts +2 -1
- package/dist/generate/fileLayerCollection.js +4 -2
- package/dist/generate/folderStacCatalogue.d.ts +6 -0
- package/dist/generate/folderStacCatalogue.js +10 -2
- package/dist/generate/normalizedProject.d.ts +5 -4
- package/dist/generate/normalizedProject.js +44 -92
- package/dist/generate/ogcFeaturesStacCatalogue.js +1 -1
- package/dist/generate/stacCatalogue.js +23 -21
- package/dist/generate/wmsStacCatalogue.js +5 -16
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/model/QgsProject.d.ts +54 -9
- package/dist/model/Stac.d.ts +8 -6
- package/dist/model/Stac.js +1 -1
- package/dist/model/featureFilter.d.ts +1 -1
- package/dist/model/fieldIconAddress.d.ts +1 -1
- package/dist/model/fieldIconAddress.js +1 -1
- package/dist/model/ogcFeatures.d.ts +3 -3
- package/dist/model/ogcFeatures.js +2 -2
- package/dist/model/quacExtension.d.ts +1 -1
- package/dist/model/quacExtension.js +1 -1
- package/dist/model/stacAssetRoles.d.ts +1 -1
- package/dist/model/stacAssetRoles.js +1 -1
- package/dist/model/stacHref.d.ts +3 -3
- package/dist/model/stacHref.js +3 -3
- package/dist/model/stacPmtiles.d.ts +1 -1
- package/dist/model/stacWms.d.ts +1 -1
- package/dist/model/stacWms.js +1 -1
- package/dist/model/wfs.d.ts +1 -1
- package/dist/parse/geometrySiblings.d.ts +1 -1
- package/dist/parse/geometrySiblings.js +1 -1
- package/dist/parse/parseBrandColour.d.ts +3 -3
- package/dist/parse/parseBrandColour.js +3 -3
- package/dist/parse/parseDataDefinedEditable.js +2 -2
- package/dist/parse/parseLayers.d.ts +5 -2
- package/dist/parse/parseLayers.js +148 -97
- package/dist/parse/parseMeasurement.d.ts +2 -3
- package/dist/parse/parseMeasurement.js +3 -4
- package/dist/parse/parseMergin.d.ts +3 -3
- package/dist/parse/parseMergin.js +8 -5
- package/dist/parse/parseQgsXml.js +10 -3
- package/dist/parse/projectNotes.d.ts +26 -0
- package/dist/parse/projectNotes.js +52 -0
- package/dist/parse/qgisExpression.d.ts +19 -4
- package/dist/parse/qgisExpression.js +58 -13
- package/dist/parse/qtDateFormat.d.ts +3 -3
- package/dist/parse/qtDateFormat.js +3 -3
- package/dist/parse/qtRegex.d.ts +2 -2
- package/dist/parse/qtRegex.js +2 -2
- package/dist/sources/stacItems.d.ts +1 -1
- package/dist/sources/stacItems.js +2 -2
- package/dist/util/devLog.d.ts +1 -2
- package/dist/util/devLog.js +1 -2
- package/dist/util/nonBlankText.d.ts +2 -0
- package/dist/util/nonBlankText.js +4 -0
- package/dist/util/wfsVersions.js +1 -1
- package/package.json +10 -2
- package/src/schema/quac.schema.json +5 -1
|
@@ -26,8 +26,11 @@ import { devLog } from "../util/devLog.js";
|
|
|
26
26
|
*
|
|
27
27
|
* On any per-layer failure the layer is skipped (logged via devLog) so a
|
|
28
28
|
* single bad layer doesn't take down the whole project.
|
|
29
|
+
*
|
|
30
|
+
* Each setting a layer holds that its Collection will not carry is added to
|
|
31
|
+
* `notes` (`ProjectNote`), as is each layer skipped.
|
|
29
32
|
*/
|
|
30
|
-
export function parseProjectLayers(qgisRoot) {
|
|
33
|
+
export function parseProjectLayers(qgisRoot, notes = []) {
|
|
31
34
|
const projectLayers = qgisRoot.querySelector('projectlayers');
|
|
32
35
|
if (!projectLayers)
|
|
33
36
|
return [];
|
|
@@ -36,11 +39,18 @@ export function parseProjectLayers(qgisRoot) {
|
|
|
36
39
|
if (node.tagName !== 'maplayer')
|
|
37
40
|
continue;
|
|
38
41
|
try {
|
|
39
|
-
const layer = parseMapLayer(node);
|
|
42
|
+
const layer = parseMapLayer(node, notes);
|
|
40
43
|
if (layer)
|
|
41
44
|
layers.push(layer);
|
|
42
45
|
}
|
|
43
46
|
catch (err) {
|
|
47
|
+
notes.push({
|
|
48
|
+
layerId: node.querySelector('id')?.textContent?.trim() ?? '',
|
|
49
|
+
layerName: node.querySelector('layername')?.textContent?.trim() ?? '',
|
|
50
|
+
field: null,
|
|
51
|
+
reason: 'layer',
|
|
52
|
+
text: null
|
|
53
|
+
});
|
|
44
54
|
devLog('qgs/parseLayers', 'failed to parse a maplayer; skipping', {
|
|
45
55
|
error: String(err),
|
|
46
56
|
id: node.querySelector('id')?.textContent ?? '<unknown>'
|
|
@@ -49,11 +59,13 @@ export function parseProjectLayers(qgisRoot) {
|
|
|
49
59
|
}
|
|
50
60
|
return layers;
|
|
51
61
|
}
|
|
52
|
-
function parseMapLayer(maplayer) {
|
|
62
|
+
function parseMapLayer(maplayer, notes) {
|
|
53
63
|
const id = maplayer.querySelector('id')?.textContent?.trim();
|
|
54
64
|
const name = maplayer.querySelector('layername')?.textContent?.trim() ?? '';
|
|
55
65
|
if (!id)
|
|
56
66
|
return null;
|
|
67
|
+
const layerNotes = [];
|
|
68
|
+
const note = (reason, field, text) => layerNotes.push({ layerId: id, layerName: name, field, reason, text });
|
|
57
69
|
const type = maplayer.getAttribute('type') ?? '';
|
|
58
70
|
const geometryType = maplayer.getAttribute('geometry') || null;
|
|
59
71
|
const wkbType = maplayer.getAttribute('wkbType') || null;
|
|
@@ -66,7 +78,12 @@ function parseMapLayer(maplayer) {
|
|
|
66
78
|
const fieldNames = parseFieldNames(maplayer);
|
|
67
79
|
const fieldAliases = parseFieldAliases(maplayer);
|
|
68
80
|
const { styles, activeIndex } = parseLayerStyles(maplayer);
|
|
69
|
-
|
|
81
|
+
const fieldValueRelations = parseFieldValueRelations(maplayer);
|
|
82
|
+
const fieldAttachments = parseFieldAttachments(maplayer);
|
|
83
|
+
if (dataSource.kind === 'unsupported')
|
|
84
|
+
note('source', null, dataSource.hint);
|
|
85
|
+
noteUnreadWidgets(maplayer, { fieldValueRelations, fieldAttachments }, note);
|
|
86
|
+
const layer = {
|
|
70
87
|
id,
|
|
71
88
|
name,
|
|
72
89
|
type,
|
|
@@ -95,9 +112,9 @@ function parseMapLayer(maplayer) {
|
|
|
95
112
|
fieldValueMaps: parseFieldValueMaps(maplayer),
|
|
96
113
|
isPrivate: parsePrivate(maplayer),
|
|
97
114
|
legendImage: parseLegendImage(maplayer),
|
|
98
|
-
fieldValueRelations
|
|
99
|
-
fieldAttachments
|
|
100
|
-
fieldEditRules: parseFieldEditRules(maplayer),
|
|
115
|
+
fieldValueRelations,
|
|
116
|
+
fieldAttachments,
|
|
117
|
+
fieldEditRules: parseFieldEditRules(maplayer, note),
|
|
101
118
|
icon: parseLayerIcon(maplayer),
|
|
102
119
|
fieldIcons: parseFieldIcons(maplayer),
|
|
103
120
|
fieldControls: parseFieldControls(maplayer),
|
|
@@ -106,6 +123,33 @@ function parseMapLayer(maplayer) {
|
|
|
106
123
|
locks: parseQfieldSyncLocks(maplayer),
|
|
107
124
|
rawXml: new XMLSerializer().serializeToString(maplayer)
|
|
108
125
|
};
|
|
126
|
+
// Added once the layer is read whole, so a layer that fails part way leaves one `layer` note.
|
|
127
|
+
notes.push(...layerNotes);
|
|
128
|
+
return layer;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The edit widgets whose settings a Collection carries, by the type QGIS saves
|
|
132
|
+
* in `<editWidget type>`. `TextEdit` is QGIS's plain text box, which needs
|
|
133
|
+
* nothing carried. An empty type is a field with no widget set.
|
|
134
|
+
*/
|
|
135
|
+
const READ_WIDGET_TYPES = new Set(['', 'TextEdit', 'ValueMap', 'ValueRelation', 'ExternalResource', 'Hidden', 'Color', 'CheckBox', 'Range', 'DateTime', 'UuidGenerator']);
|
|
136
|
+
/**
|
|
137
|
+
* Notes each field's widget the Collection does not carry: one of a type not
|
|
138
|
+
* in `READ_WIDGET_TYPES`, and a Value Relation or Attachment widget its reader
|
|
139
|
+
* above passed over.
|
|
140
|
+
*/
|
|
141
|
+
function noteUnreadWidgets(maplayer, read, note) {
|
|
142
|
+
const seen = new Set();
|
|
143
|
+
for (const [name, editWidget] of layerEditWidgets(maplayer)) {
|
|
144
|
+
if (seen.has(name) || !editWidget)
|
|
145
|
+
continue;
|
|
146
|
+
seen.add(name);
|
|
147
|
+
const type = editWidget.getAttribute('type') ?? '';
|
|
148
|
+
const passedOver = (type === 'ValueRelation' && !read.fieldValueRelations[name]) ||
|
|
149
|
+
(type === 'ExternalResource' && !read.fieldAttachments[name]);
|
|
150
|
+
if (!READ_WIDGET_TYPES.has(type) || passedOver)
|
|
151
|
+
note('widget', name, type);
|
|
152
|
+
}
|
|
109
153
|
}
|
|
110
154
|
/**
|
|
111
155
|
* The fields QGIS Server hides from WMS and from WFS. QGIS saves each field's
|
|
@@ -120,12 +164,8 @@ function parseMapLayer(maplayer) {
|
|
|
120
164
|
function serverHiddenFieldsOf(maplayer) {
|
|
121
165
|
const wms = new Set();
|
|
122
166
|
const wfs = new Set();
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
const name = field.getAttribute('name');
|
|
126
|
-
if (!name)
|
|
127
|
-
continue;
|
|
128
|
-
const flags = (field.getAttribute('configurationFlags') ?? '').split('|').map((flag) => flag.trim());
|
|
167
|
+
for (const [name, field] of layerFields(maplayer)) {
|
|
168
|
+
const flags = configurationFlagsOf(field);
|
|
129
169
|
if (flags.includes('HideFromWms'))
|
|
130
170
|
wms.add(name);
|
|
131
171
|
if (flags.includes('HideFromWfs'))
|
|
@@ -269,19 +309,9 @@ const VALUE_MAP_NULL_CODE = '{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}';
|
|
|
269
309
|
*/
|
|
270
310
|
function parseFieldValueMaps(maplayer) {
|
|
271
311
|
const result = {};
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
// `<map-layer-style-manager>`'s embedded per-style documents, whose field
|
|
275
|
-
// configs can genuinely disagree with the layer's own (verified against
|
|
276
|
-
// `packages/quac/src/tests/fixtures/qgis/graffiti/graffiti.qgs`, whose Graffiti Reports
|
|
277
|
-
// layer has `incident_uid` as `UuidGenerator` in a saved style and
|
|
278
|
-
// `TextEdit` at the layer's own level).
|
|
279
|
-
const fieldConfig = directChild(maplayer, 'fieldConfiguration');
|
|
280
|
-
for (const field of fieldConfig?.querySelectorAll(':scope > field') ?? []) {
|
|
281
|
-
const name = field.getAttribute('name');
|
|
282
|
-
if (!name || result[name])
|
|
312
|
+
for (const [name, editWidget] of layerEditWidgets(maplayer)) {
|
|
313
|
+
if (result[name])
|
|
283
314
|
continue;
|
|
284
|
-
const editWidget = directChild(field, 'editWidget');
|
|
285
315
|
if (editWidget?.getAttribute('type') !== 'ValueMap')
|
|
286
316
|
continue;
|
|
287
317
|
const mapList = editWidget.querySelector(':scope > config > Option[type="Map"] > Option[type="List"][name="map"]');
|
|
@@ -334,41 +364,30 @@ function parseFieldValueMaps(maplayer) {
|
|
|
334
364
|
*/
|
|
335
365
|
function parseFieldValueRelations(maplayer) {
|
|
336
366
|
const result = {};
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
for (const field of fieldConfig?.querySelectorAll(':scope > field') ?? []) {
|
|
340
|
-
const name = field.getAttribute('name');
|
|
341
|
-
if (!name || result[name])
|
|
367
|
+
for (const [name, editWidget] of layerEditWidgets(maplayer)) {
|
|
368
|
+
if (result[name])
|
|
342
369
|
continue;
|
|
343
|
-
const editWidget = directChild(field, 'editWidget');
|
|
344
370
|
if (editWidget?.getAttribute('type') !== 'ValueRelation')
|
|
345
371
|
continue;
|
|
346
|
-
const options =
|
|
347
|
-
for (const option of editWidget.querySelectorAll(':scope > config > Option[type="Map"] > Option')) {
|
|
348
|
-
const key = option.getAttribute('name');
|
|
349
|
-
const value = option.getAttribute('value');
|
|
350
|
-
if (key && value !== null)
|
|
351
|
-
options.set(key, value);
|
|
352
|
-
}
|
|
353
|
-
const isOn = (key) => options.get(key) === 'true' || options.get(key) === '1';
|
|
372
|
+
const options = readOptionMap(editWidget);
|
|
354
373
|
const layerId = readTrimmedOption(options, 'Layer') ?? '';
|
|
355
374
|
const layerName = readTrimmedOption(options, 'LayerName') ?? '';
|
|
356
375
|
const keyField = readTrimmedOption(options, 'Key');
|
|
357
376
|
const valueField = readTrimmedOption(options, 'Value');
|
|
358
377
|
if ((!layerId && !layerName) || !keyField || !valueField)
|
|
359
378
|
continue;
|
|
360
|
-
const orderField =
|
|
379
|
+
const orderField = readFlag(options, 'OrderByField') ? readTrimmedOption(options, 'OrderByFieldName') : null;
|
|
361
380
|
result[name] = {
|
|
362
381
|
layerId,
|
|
363
382
|
layerName,
|
|
364
383
|
keyField,
|
|
365
384
|
valueField,
|
|
366
385
|
filterExpression: readTrimmedOption(options, 'FilterExpression') ?? '',
|
|
367
|
-
allowNull:
|
|
368
|
-
allowMulti:
|
|
369
|
-
orderBy:
|
|
370
|
-
orderField:
|
|
371
|
-
descending:
|
|
386
|
+
allowNull: readFlag(options, 'AllowNull'),
|
|
387
|
+
allowMulti: readFlag(options, 'AllowMulti'),
|
|
388
|
+
orderBy: readFlag(options, 'OrderByValue') ? 'value' : orderField ? 'field' : 'key',
|
|
389
|
+
orderField: readFlag(options, 'OrderByValue') ? null : orderField,
|
|
390
|
+
descending: readFlag(options, 'OrderByDescending')
|
|
372
391
|
};
|
|
373
392
|
}
|
|
374
393
|
return result;
|
|
@@ -393,7 +412,7 @@ const RELATIVE_STORAGE = ['absolute', 'project', 'default-root'];
|
|
|
393
412
|
*/
|
|
394
413
|
const SINGLE_FILE_STORAGE_MODES = new Set([0, 3]);
|
|
395
414
|
/**
|
|
396
|
-
* Reads every field's Attachment edit widget into what
|
|
415
|
+
* Reads every field's Attachment edit widget into what the catalogue records,
|
|
397
416
|
* keyed by field name. QGIS registers the widget as `ExternalResource`
|
|
398
417
|
* (`QgsEditorWidgetRegistry::initEditors`,
|
|
399
418
|
* `src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp`, `qgis/QGIS@master`,
|
|
@@ -412,7 +431,7 @@ const SINGLE_FILE_STORAGE_MODES = new Set([0, 3]);
|
|
|
412
431
|
* </editWidget>
|
|
413
432
|
*
|
|
414
433
|
* The widget writes more keys than these four; the rest are left behind
|
|
415
|
-
*
|
|
434
|
+
* and the catalogue does not carry them. A value-less `<Option type="invalid">`,
|
|
416
435
|
* which QGIS writes for an unset key, is skipped rather than read as blank.
|
|
417
436
|
* A widget whose `StorageMode` picks a directory or several files is not an
|
|
418
437
|
* attachment here.
|
|
@@ -421,23 +440,12 @@ const SINGLE_FILE_STORAGE_MODES = new Set([0, 3]);
|
|
|
421
440
|
*/
|
|
422
441
|
function parseFieldAttachments(maplayer) {
|
|
423
442
|
const result = {};
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
const fieldConfig = directChild(maplayer, 'fieldConfiguration');
|
|
427
|
-
for (const field of fieldConfig?.querySelectorAll(':scope > field') ?? []) {
|
|
428
|
-
const name = field.getAttribute('name');
|
|
429
|
-
if (!name || result[name])
|
|
443
|
+
for (const [name, editWidget] of layerEditWidgets(maplayer)) {
|
|
444
|
+
if (result[name])
|
|
430
445
|
continue;
|
|
431
|
-
const editWidget = directChild(field, 'editWidget');
|
|
432
446
|
if (editWidget?.getAttribute('type') !== 'ExternalResource')
|
|
433
447
|
continue;
|
|
434
|
-
const options =
|
|
435
|
-
for (const option of editWidget.querySelectorAll(':scope > config > Option[type="Map"] > Option')) {
|
|
436
|
-
const key = option.getAttribute('name');
|
|
437
|
-
const value = option.getAttribute('value');
|
|
438
|
-
if (key && value !== null)
|
|
439
|
-
options.set(key, value);
|
|
440
|
-
}
|
|
448
|
+
const options = readOptionMap(editWidget);
|
|
441
449
|
const storageMode = options.get('StorageMode');
|
|
442
450
|
if (storageMode !== undefined && !SINGLE_FILE_STORAGE_MODES.has(Number(storageMode)))
|
|
443
451
|
continue;
|
|
@@ -456,7 +464,7 @@ function parseFieldAttachments(maplayer) {
|
|
|
456
464
|
*/
|
|
457
465
|
const NOW_EXPRESSIONS = new Set(['now()', '$now', 'to_date(now())', 'to_datetime(now())']);
|
|
458
466
|
/**
|
|
459
|
-
* Reads the Attributes Form settings
|
|
467
|
+
* Reads the Attributes Form settings the catalogue records for every field, keyed
|
|
460
468
|
* by field name. QGIS writes them as blocks of the layer's own, shown here as
|
|
461
469
|
* `packages/quac/src/tests/fixtures/qgis/graffiti/graffiti.qgs` writes them:
|
|
462
470
|
*
|
|
@@ -484,12 +492,11 @@ const NOW_EXPRESSIONS = new Set(['now()', '$now', 'to_date(now())', 'to_datetime
|
|
|
484
492
|
*
|
|
485
493
|
* A default is kept as a `defaultValue` where `parseDefaultExpression` reads it,
|
|
486
494
|
* as a `defaultExpression` where only `readQgisExpression` does, and otherwise
|
|
487
|
-
* left out
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
* returned map.
|
|
495
|
+
* left out. A constraint expression follows the same rule. A field the
|
|
496
|
+
* `<editable>` block does not list is editable. A field with none of these
|
|
497
|
+
* settings is absent from the returned map.
|
|
491
498
|
*/
|
|
492
|
-
function parseFieldEditRules(maplayer) {
|
|
499
|
+
function parseFieldEditRules(maplayer, note) {
|
|
493
500
|
const result = {};
|
|
494
501
|
const ruleFor = (name) => {
|
|
495
502
|
result[name] ??= { readOnly: false, defaultValue: null, notNull: null, unique: null, hidden: false, reuseLastValue: false, duplicatePolicy: null };
|
|
@@ -508,8 +515,10 @@ function parseFieldEditRules(maplayer) {
|
|
|
508
515
|
const defaultValue = parseDefaultExpression(expression, onUpdate);
|
|
509
516
|
if (defaultValue)
|
|
510
517
|
ruleFor(name).defaultValue = defaultValue;
|
|
511
|
-
else if (readQgisExpression(expression, { geometry: true, aggregates: true, lookups: true }))
|
|
518
|
+
else if (readQgisExpression(expression, { geometry: true, aggregates: true, lookups: true, variables: true }))
|
|
512
519
|
ruleFor(name).defaultExpression = { expression: expression.trim(), onUpdate };
|
|
520
|
+
else
|
|
521
|
+
note('default', name, expression.trim());
|
|
513
522
|
}
|
|
514
523
|
// The UUID Generator widget disables its line edit and fills a null field
|
|
515
524
|
// with `QUuid::createUuid().toString()`, which has braces
|
|
@@ -518,17 +527,21 @@ function parseFieldEditRules(maplayer) {
|
|
|
518
527
|
// first, so the widget's identifier stands only where there is none. The
|
|
519
528
|
// widget's shortening to a string field's declared length is not followed:
|
|
520
529
|
// a `.qgs` file does not carry a WFS field's length.
|
|
521
|
-
const fieldConfig = directChild(maplayer, 'fieldConfiguration');
|
|
522
530
|
const seenWidgets = new Set();
|
|
523
531
|
const allowNullOff = new Set();
|
|
524
|
-
for (const field of
|
|
525
|
-
|
|
526
|
-
if (!name || seenWidgets.has(name))
|
|
532
|
+
for (const [name, field] of layerFields(maplayer)) {
|
|
533
|
+
if (seenWidgets.has(name))
|
|
527
534
|
continue;
|
|
528
535
|
seenWidgets.add(name);
|
|
529
536
|
const widgetType = directChild(field, 'editWidget')?.getAttribute('type');
|
|
530
537
|
if (widgetType === 'Hidden')
|
|
531
538
|
ruleFor(name).hidden = true;
|
|
539
|
+
// The Fields tab's Not searchable, which QGIS's search of the active
|
|
540
|
+
// layer's features skips (`QgsActiveLayerFeaturesLocatorFilter`,
|
|
541
|
+
// `src/app/locator/qgsactivelayerfeatureslocatorfilter.cpp`,
|
|
542
|
+
// `qgis/QGIS@master`, read 2026-11-11).
|
|
543
|
+
if (configurationFlagsOf(field).includes('NotSearchable'))
|
|
544
|
+
ruleFor(name).notSearchable = true;
|
|
532
545
|
// The widget has no settings of its own (`QgsColorWidgetFactory::configWidget`,
|
|
533
546
|
// `src/gui/editorwidgets/qgscolorwidgetfactory.cpp`, `qgis/QGIS@master`,
|
|
534
547
|
// read 2026-10-25).
|
|
@@ -549,7 +562,7 @@ function parseFieldEditRules(maplayer) {
|
|
|
549
562
|
// (`QgsVectorLayer::readSymbology`, `src/core/vector/qgsvectorlayer.cpp`, and
|
|
550
563
|
// `QgsFieldConstraints`, `src/core/qgsfieldconstraints.h`, `qgis/QGIS@master`,
|
|
551
564
|
// read 2026-10-23). An expression is kept only where `readQgisExpression`
|
|
552
|
-
// reads it
|
|
565
|
+
// reads it.
|
|
553
566
|
const constraintExpressions = new Map();
|
|
554
567
|
for (const node of directChild(maplayer, 'constraintExpressions')?.querySelectorAll(':scope > constraint') ?? []) {
|
|
555
568
|
const name = node.getAttribute('field');
|
|
@@ -573,14 +586,16 @@ function parseFieldEditRules(maplayer) {
|
|
|
573
586
|
ruleFor(name).unique = unique;
|
|
574
587
|
}
|
|
575
588
|
const written = constraintExpressions.get(name);
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
if (
|
|
589
|
+
const strength = constraintStrength(node.getAttribute('exp_strength'));
|
|
590
|
+
if (constraints & 4 && written && strength) {
|
|
591
|
+
if (readQgisExpression(written.expression, { geometry: true })) {
|
|
579
592
|
const expression = { expression: written.expression, strength };
|
|
580
593
|
if (written.description)
|
|
581
594
|
expression.description = written.description;
|
|
582
595
|
ruleFor(name).constraintExpression = expression;
|
|
583
596
|
}
|
|
597
|
+
else
|
|
598
|
+
note('constraint', name, written.expression);
|
|
584
599
|
}
|
|
585
600
|
}
|
|
586
601
|
// A Range with Allow NULL off, or a Date/Time with it off, is a required
|
|
@@ -619,17 +634,7 @@ function parseFieldEditRules(maplayer) {
|
|
|
619
634
|
* `allow_null` both default to true; a field with either off goes in `allowNullOff`.
|
|
620
635
|
*/
|
|
621
636
|
function readWidgetOptions(field, name, widgetType, ruleFor, allowNullOff) {
|
|
622
|
-
const options =
|
|
623
|
-
for (const option of directChild(field, 'editWidget')?.querySelectorAll(':scope > config > Option[type="Map"] > Option') ?? []) {
|
|
624
|
-
const key = option.getAttribute('name');
|
|
625
|
-
const value = option.getAttribute('value');
|
|
626
|
-
if (key && value !== null)
|
|
627
|
-
options.set(key, value);
|
|
628
|
-
}
|
|
629
|
-
const flag = (key, fallback) => {
|
|
630
|
-
const value = options.get(key);
|
|
631
|
-
return value === undefined ? fallback : value === 'true' || value === '1';
|
|
632
|
-
};
|
|
637
|
+
const options = readOptionMap(directChild(field, 'editWidget'));
|
|
633
638
|
const number = (key) => {
|
|
634
639
|
const text = options.get(key)?.trim();
|
|
635
640
|
if (!text)
|
|
@@ -643,7 +648,7 @@ function readWidgetOptions(field, name, widgetType, ruleFor, allowNullOff) {
|
|
|
643
648
|
checkedValue: readTrimmedOption(options, 'CheckedState'),
|
|
644
649
|
uncheckedValue: readTrimmedOption(options, 'UncheckedState'),
|
|
645
650
|
showStoredValue: options.get('TextDisplayMethod') === '1',
|
|
646
|
-
allowNull:
|
|
651
|
+
allowNull: readFlag(options, 'AllowNullState', false)
|
|
647
652
|
};
|
|
648
653
|
return;
|
|
649
654
|
case 'Range': {
|
|
@@ -665,18 +670,18 @@ function readWidgetOptions(field, name, widgetType, ruleFor, allowNullOff) {
|
|
|
665
670
|
range.suffix = suffix;
|
|
666
671
|
if (Object.keys(range).length > 0)
|
|
667
672
|
ruleFor(name).range = range;
|
|
668
|
-
if (!
|
|
673
|
+
if (!readFlag(options, 'AllowNull', true))
|
|
669
674
|
allowNullOff.add(name);
|
|
670
675
|
return;
|
|
671
676
|
}
|
|
672
677
|
case 'DateTime': {
|
|
673
|
-
// A date or date-time field ignores `field_format`, which
|
|
674
|
-
// cannot tell here. ISO 8601 and the default for a date are what
|
|
675
|
-
//
|
|
678
|
+
// A date or date-time field ignores `field_format`, which this parser
|
|
679
|
+
// cannot tell here. ISO 8601 and the default for a date are what an
|
|
680
|
+
// application already reads, so they write nothing.
|
|
676
681
|
const format = options.get('field_format')?.trim();
|
|
677
|
-
if (format && format !== 'yyyy-MM-dd' && !
|
|
682
|
+
if (format && format !== 'yyyy-MM-dd' && !readFlag(options, 'field_iso_format', false))
|
|
678
683
|
ruleFor(name).dateFormat = format;
|
|
679
|
-
if (!
|
|
684
|
+
if (!readFlag(options, 'allow_null', true))
|
|
680
685
|
allowNullOff.add(name);
|
|
681
686
|
}
|
|
682
687
|
}
|
|
@@ -697,8 +702,8 @@ function constraintStrength(strength) {
|
|
|
697
702
|
* and reads the older block first so the newer one wins
|
|
698
703
|
* (`QgsEditFormConfig::readXml`, `src/core/editform/qgseditformconfig.cpp`,
|
|
699
704
|
* `qgis/QGIS@master`, read 2026-10-23). `AllowedDefaultOff` reads as not
|
|
700
|
-
* reused: it is off until someone ticks it in QGIS's own form, which
|
|
701
|
-
*
|
|
705
|
+
* reused: it is off until someone ticks it in QGIS's own form, which a
|
|
706
|
+
* reading application's form may have no tick for.
|
|
702
707
|
*/
|
|
703
708
|
function parseReuseLastValue(maplayer) {
|
|
704
709
|
const reuse = new Map();
|
|
@@ -716,7 +721,7 @@ function parseReuseLastValue(maplayer) {
|
|
|
716
721
|
return reuse;
|
|
717
722
|
}
|
|
718
723
|
/**
|
|
719
|
-
* Reads a default-value expression
|
|
724
|
+
* Reads a default-value expression an application can fill: one of
|
|
720
725
|
* `NOW_EXPRESSIONS`, `uuid()` or `$uuid` with an optional format, or a lone
|
|
721
726
|
* literal. Anything else, such as a field reference, a variable or a
|
|
722
727
|
* calculation, is null.
|
|
@@ -1103,6 +1108,52 @@ function parseOpacity(maplayer) {
|
|
|
1103
1108
|
const value = Number(text);
|
|
1104
1109
|
return Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 1;
|
|
1105
1110
|
}
|
|
1111
|
+
/**
|
|
1112
|
+
* The layer's own `<fieldConfiguration>` fields that have a name, as
|
|
1113
|
+
* `[name, <field>]`, in document order. A saved alternate style embeds its
|
|
1114
|
+
* own `<fieldConfiguration>`, which can disagree with the layer's own, so only
|
|
1115
|
+
* the direct child of `<maplayer>` is read (see docs/gotchas.md).
|
|
1116
|
+
*/
|
|
1117
|
+
function* layerFields(maplayer) {
|
|
1118
|
+
for (const field of directChild(maplayer, 'fieldConfiguration')?.querySelectorAll(':scope > field') ?? []) {
|
|
1119
|
+
const name = field.getAttribute('name');
|
|
1120
|
+
if (name)
|
|
1121
|
+
yield [name, field];
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
/**
|
|
1125
|
+
* A `<fieldConfiguration><field>`'s `configurationFlags`: the Fields tab's
|
|
1126
|
+
* Configuration column, saved as `Qgis::FieldConfigurationFlag` names joined
|
|
1127
|
+
* by `|`, such as `NotSearchable|HideFromWms`, and `NoFlag` where none is set.
|
|
1128
|
+
*/
|
|
1129
|
+
function configurationFlagsOf(field) {
|
|
1130
|
+
return (field.getAttribute('configurationFlags') ?? '').split('|').map((flag) => flag.trim());
|
|
1131
|
+
}
|
|
1132
|
+
/** The named fields' `<editWidget>`, as `[name, <editWidget>]`; null where a field has none. */
|
|
1133
|
+
function* layerEditWidgets(maplayer) {
|
|
1134
|
+
for (const [name, field] of layerFields(maplayer))
|
|
1135
|
+
yield [name, directChild(field, 'editWidget')];
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* A flat widget config as key and value: the widget's `<Option type="Map">`
|
|
1139
|
+
* members that have a name and a `value`. An `<Option type="invalid">` that
|
|
1140
|
+
* QGIS writes for an unset key has no `value` and is left out.
|
|
1141
|
+
*/
|
|
1142
|
+
function readOptionMap(editWidget) {
|
|
1143
|
+
const options = new Map();
|
|
1144
|
+
for (const option of editWidget?.querySelectorAll(':scope > config > Option[type="Map"] > Option') ?? []) {
|
|
1145
|
+
const key = option.getAttribute('name');
|
|
1146
|
+
const value = option.getAttribute('value');
|
|
1147
|
+
if (key && value !== null)
|
|
1148
|
+
options.set(key, value);
|
|
1149
|
+
}
|
|
1150
|
+
return options;
|
|
1151
|
+
}
|
|
1152
|
+
/** A Boolean widget option: `true` or `1` is on, any other value off, and an absent key `fallback`. */
|
|
1153
|
+
function readFlag(options, key, fallback = false) {
|
|
1154
|
+
const value = options.get(key);
|
|
1155
|
+
return value === undefined ? fallback : value === 'true' || value === '1';
|
|
1156
|
+
}
|
|
1106
1157
|
function directChild(parent, tag) {
|
|
1107
1158
|
for (const child of Array.from(parent.children)) {
|
|
1108
1159
|
if (child.tagName === tag)
|
|
@@ -2,7 +2,7 @@ import type { ProjectMeasurement } from '../model/QgsProject.ts';
|
|
|
2
2
|
/** QGIS's own defaults for a project that saves no units (`QgsProject::clear`, `src/core/project/qgsproject.cpp`). */
|
|
3
3
|
export declare const DEFAULT_MEASUREMENT: ProjectMeasurement;
|
|
4
4
|
/**
|
|
5
|
-
* The factors that turn
|
|
5
|
+
* The factors that turn metres and square metres into
|
|
6
6
|
* the project's units, or null for a unit it does not convert. An expression
|
|
7
7
|
* that measures in a unit with no factor is unreadable.
|
|
8
8
|
*/
|
|
@@ -15,7 +15,6 @@ export declare function measureFactorsOf(measurement: ProjectMeasurement | null
|
|
|
15
15
|
* The project's area and distance units from `<properties><Measurement>`, as
|
|
16
16
|
* QGIS writes them (`QgsProject::writeProject`, `src/core/project/qgsproject.cpp`).
|
|
17
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.
|
|
18
|
+
* metres. The project's ellipsoid (`<Measure><Ellipsoid>`) is not read.
|
|
20
19
|
*/
|
|
21
20
|
export declare function parseProjectMeasurement(qgisRoot: Element): ProjectMeasurement | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { propertyText, readPropertyBlock } from "./projectProperties.js";
|
|
2
2
|
/**
|
|
3
3
|
* How many of a unit make up one square metre, for the area units QGIS saves
|
|
4
|
-
* as `<Measurement><AreaUnits>` that
|
|
4
|
+
* as `<Measurement><AreaUnits>` that this package converts. The saved names are
|
|
5
5
|
* `QgsUnitTypes::encodeUnit( Qgis::AreaUnit )` (`src/core/qgsunittypes.cpp`,
|
|
6
6
|
* `qgis/QGIS@master`, read 2026-10-25). `deg2` is saved too and is left out: a
|
|
7
7
|
* square degree is no fixed area.
|
|
@@ -21,7 +21,7 @@ const AREA_UNITS_PER_SQUARE_METRE = {
|
|
|
21
21
|
};
|
|
22
22
|
/**
|
|
23
23
|
* How many of a unit make up one metre, for the distance units QGIS saves as
|
|
24
|
-
* `<Measurement><DistanceUnits>` that
|
|
24
|
+
* `<Measurement><DistanceUnits>` that this package converts. The saved names are
|
|
25
25
|
* `QgsUnitTypes::encodeUnit( Qgis::DistanceUnit )`, same file. `degrees` and
|
|
26
26
|
* the survey chains are left out.
|
|
27
27
|
*/
|
|
@@ -49,8 +49,7 @@ export function measureFactorsOf(measurement) {
|
|
|
49
49
|
* The project's area and distance units from `<properties><Measurement>`, as
|
|
50
50
|
* QGIS writes them (`QgsProject::writeProject`, `src/core/project/qgsproject.cpp`).
|
|
51
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.
|
|
52
|
+
* metres. The project's ellipsoid (`<Measure><Ellipsoid>`) is not read.
|
|
54
53
|
*/
|
|
55
54
|
export function parseProjectMeasurement(qgisRoot) {
|
|
56
55
|
const block = readPropertyBlock(qgisRoot, 'Measurement');
|
|
@@ -13,7 +13,7 @@ import type { PresetFilter } from '../model/QgsProject.ts';
|
|
|
13
13
|
* `app/filter/filtercontroller.cpp`, `MerginMaps/mobile@779434d`), as this
|
|
14
14
|
* does. `sql_expression`, a template for the data source's own SQL, is not
|
|
15
15
|
* read beyond that: the filter row filters the field itself. A `Text` filter
|
|
16
|
-
* is left out
|
|
17
|
-
* as JSON.
|
|
16
|
+
* is left out, and added to `textFilters`. Empty where the project sets none,
|
|
17
|
+
* or the list does not read as JSON.
|
|
18
18
|
*/
|
|
19
|
-
export declare function parseMerginFilters(qgisRoot: Element): PresetFilter[];
|
|
19
|
+
export declare function parseMerginFilters(qgisRoot: Element, textFilters?: PresetFilter[]): PresetFilter[];
|
|
@@ -16,10 +16,10 @@ const READ_FILTER_TYPES = new Set(['Number', 'Date', 'Checkbox', 'Single select'
|
|
|
16
16
|
* `app/filter/filtercontroller.cpp`, `MerginMaps/mobile@779434d`), as this
|
|
17
17
|
* does. `sql_expression`, a template for the data source's own SQL, is not
|
|
18
18
|
* read beyond that: the filter row filters the field itself. A `Text` filter
|
|
19
|
-
* is left out
|
|
20
|
-
* as JSON.
|
|
19
|
+
* is left out, and added to `textFilters`. Empty where the project sets none,
|
|
20
|
+
* or the list does not read as JSON.
|
|
21
21
|
*/
|
|
22
|
-
export function parseMerginFilters(qgisRoot) {
|
|
22
|
+
export function parseMerginFilters(qgisRoot, textFilters = []) {
|
|
23
23
|
const block = readPropertyBlock(qgisRoot, 'Mergin');
|
|
24
24
|
const filtering = block ? propertyChild(block, 'Filtering') : null;
|
|
25
25
|
if (!filtering || !isTrueValue(propertyText(filtering, 'Enabled')))
|
|
@@ -44,8 +44,11 @@ export function parseMerginFilters(qgisRoot) {
|
|
|
44
44
|
const layerId = text(filter, 'layer_id');
|
|
45
45
|
const field = text(filter, 'field_name');
|
|
46
46
|
const type = text(filter, 'filter_type');
|
|
47
|
-
if (!layerId || !field || !text(filter, 'sql_expression') || !type
|
|
47
|
+
if (!layerId || !field || !text(filter, 'sql_expression') || !type)
|
|
48
48
|
return [];
|
|
49
|
-
|
|
49
|
+
const preset = { layerId, field, name: text(filter, 'filter_name')?.trim() ?? null };
|
|
50
|
+
if (type === 'Text')
|
|
51
|
+
textFilters.push(preset);
|
|
52
|
+
return READ_FILTER_TYPES.has(type) ? [preset] : [];
|
|
50
53
|
});
|
|
51
54
|
}
|
|
@@ -8,6 +8,7 @@ import { parseMerginFilters } from "./parseMergin.js";
|
|
|
8
8
|
import { parseProjectVariables } from "./parseProjectVariables.js";
|
|
9
9
|
import { parseInitialActiveLayerId, parseWfsTransactionLayers } from "./parseQfieldSync.js";
|
|
10
10
|
import { parseProjectRelations } from "./parseRelations.js";
|
|
11
|
+
import { crossLayerNotes } from "./projectNotes.js";
|
|
11
12
|
import { parseWmsCrsList, parseWmsPublishing } from "./parseWmsPublishing.js";
|
|
12
13
|
import { devLog } from "../util/devLog.js";
|
|
13
14
|
/**
|
|
@@ -39,9 +40,13 @@ export function parseQgsXml(xmlText) {
|
|
|
39
40
|
const title = qgisRoot.querySelector(':scope > title')?.textContent?.trim() ?? '';
|
|
40
41
|
const projectCrs = readProjectCrs(qgisRoot);
|
|
41
42
|
const mapExtent = parseMapExtent(qgisRoot, projectCrs);
|
|
42
|
-
const
|
|
43
|
+
const notes = [];
|
|
44
|
+
const rawLayers = parseProjectLayers(qgisRoot, notes);
|
|
43
45
|
const layerTree = parseLegendTree(qgisRoot);
|
|
44
46
|
const relations = parseProjectRelations(qgisRoot);
|
|
47
|
+
const textFilters = [];
|
|
48
|
+
const merginFilters = parseMerginFilters(qgisRoot, textFilters);
|
|
49
|
+
notes.push(...crossLayerNotes(rawLayers, relations, merginFilters, textFilters));
|
|
45
50
|
// Visibility flows from the layer tree (where checked state is stored), not
|
|
46
51
|
// from the maplayer itself. Walk the tree once, build a layerId →
|
|
47
52
|
// effective visibility map, and apply it to each LayerEntry.
|
|
@@ -55,7 +60,8 @@ export function parseQgsXml(xmlText) {
|
|
|
55
60
|
title,
|
|
56
61
|
projectCrs,
|
|
57
62
|
layerCount: layers.length,
|
|
58
|
-
relationCount: relations.length
|
|
63
|
+
relationCount: relations.length,
|
|
64
|
+
noteCount: notes.length
|
|
59
65
|
});
|
|
60
66
|
return {
|
|
61
67
|
qgisVersion,
|
|
@@ -73,7 +79,8 @@ export function parseQgsXml(xmlText) {
|
|
|
73
79
|
wfsTransactionLayers: parseWfsTransactionLayers(qgisRoot),
|
|
74
80
|
wmsPublishing: parseWmsPublishing(qgisRoot),
|
|
75
81
|
wmsCrsList: parseWmsCrsList(qgisRoot),
|
|
76
|
-
merginFilters
|
|
82
|
+
merginFilters,
|
|
83
|
+
notes,
|
|
77
84
|
rawXml: xmlText
|
|
78
85
|
};
|
|
79
86
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { FieldValueRelation, LayerEntry, PresetFilter, ProjectNote, QgsRelation } from '../model/QgsProject.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The rules that decide whether a setting naming another layer reaches the
|
|
4
|
+
* catalogue, and the notes for those that do not. `generateStacCatalogue`
|
|
5
|
+
* applies the same rules through these functions, so a note and the catalogue
|
|
6
|
+
* cannot disagree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The layer a Value Relation widget reads its choices from: the layer whose
|
|
10
|
+
* id the widget names, and where none has it the first layer with the name it
|
|
11
|
+
* names, as QGIS finds it (`QgsVectorLayerRef::resolveByIdOrNameOnly`,
|
|
12
|
+
* `src/core/qgsvectorlayerref.cpp`, `qgis/QGIS@master`). Undefined where the
|
|
13
|
+
* project holds neither.
|
|
14
|
+
*/
|
|
15
|
+
export declare function findValueRelationLookup(widget: FieldValueRelation, layers: readonly LayerEntry[], layersById: ReadonlyMap<string, LayerEntry>): LayerEntry | undefined;
|
|
16
|
+
/** Whether the project holds both of a relation's layers. */
|
|
17
|
+
export declare function isRelationInProject(relation: QgsRelation, layersById: ReadonlyMap<string, LayerEntry>): boolean;
|
|
18
|
+
/** Whether the project holds a filter's layer and that layer has its field. */
|
|
19
|
+
export declare function isFilterInProject(filter: PresetFilter, layersById: ReadonlyMap<string, LayerEntry>): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The notes for the settings that name another layer and do not reach the
|
|
22
|
+
* catalogue: Value Relations, relations and filters, in that order, and each
|
|
23
|
+
* in the project's order. `textFilters` are the Mergin Maps `Text` filters
|
|
24
|
+
* `parseMerginFilters` passes over.
|
|
25
|
+
*/
|
|
26
|
+
export declare function crossLayerNotes(layers: readonly LayerEntry[], relations: readonly QgsRelation[], filters: readonly PresetFilter[], textFilters: readonly PresetFilter[]): ProjectNote[];
|