qgis-js icon indicating copy to clipboard operation
qgis-js copied to clipboard

Prefix QGIS models with `Qgs` and qgis-js models with `Qjs`

Open boardend opened this issue 8 months ago • 2 comments

I dislike that we exported QgsPointXY as PointXY, QgsRectangle as Rectangle etc.

I suggest to transparently export the Qgs-prefix to the JS/TS API and add a Qjs-prefix to models that only exist in qgis-js (e.g. out MapLayer abstraction)

@wonder-sk what do you think? I Would love to merge a PR and create a new npm version before the next workshop at FOSSGIS (27.03.)

boardend avatar Mar 24 '25 10:03 boardend

My general preference is to drop Qgs prefix as 1. it feels like a C-style programming relict from times that namespaces did not exist and it looks alien in JS/TS, 2. we're probably not going to provide the same API as C++ anyway, so that can be misleading too. So you can imagine I am not a huge fan of Qjs prefix for any qgis-js specific classes 😆 For example, with MapLayer, would you like to name it QjsMapLayer, and there would be no QgsMapLayer ? or there would be both?

I would suggest that we either try to mimic QGIS API as much as possible (so there would be QgsMapLayer JS objects with only methods that C++ QgsMapLayer provides), and other functionality (like opacity, visibility) would be handled with exposed classes like QgsProject and QgsLayerTreeNode. Having QjsMapLayer would be IMHO confusing...

That said, I do not have strong opinion on this, so if you still want to do such changes, then feel free to go ahead 🙂

wonder-sk avatar Mar 24 '25 13:03 wonder-sk

At the moment we have a mix of both styles, see the new MapRenderer related classes in src/model/.

I tend to add the Qgs-prefix, whenever a core QGIS class is exposed, so it will clear to the user and the class will have the same name across C++, Python and JS/TS.

And I agree, the MapLayer should actually be replaced with core QGIS QgsMapLayer and QgsLayerTreeLayer (and then be named accordingly). But if we have to ship such qgis-js only classes, I would prefix them with Qjs to have a clear distinction.

But no need to rush here. Will base the workshop on the current 0.0.5 version and discuss this also with @andreasneumann and @amuedespacher

boardend avatar Mar 24 '25 13:03 boardend