QField icon indicating copy to clipboard operation
QField copied to clipboard

Support for executing SQL on layers

Open gitpydev opened this issue 10 months ago • 9 comments

What is the bug or the crash? What were your expectations and what actually happened?

AFAIK, v3.5.0's Plugin System is including qt6's qtdeclarative module which is with QtQuick.Dialogs Module and QtQuick.Controls Module, but only the latter could be imported in a plugin's main.qml file, and the Dialogs one could not be imported normally.

Steps to reproduce the issue

Write a main.qml with QtQuick.Dialogs imported, and this plugin wouldn't load normally.

Version

3.5.0

Operating system name

Android

Operating system version

10

Reinstall QField

  • [ ] I have a fresh install of the latest QField version, but the problem persists.
  • [ ] Problem can be reliably reproduced, doesn't happen randomly.
  • [ ] Problem happens with all files and projects, not only some files or projects.

Additional context

No response

gitpydev avatar Feb 23 '25 08:02 gitpydev

@gitpydev , we don't ship with that QML module (yet), I've marked this as an enhancement request. Which item were you interested in?

nirvn avatar Feb 23 '25 08:02 nirvn

@gitpydev , we don't ship with that QML module (yet), I've marked this as an enhancement request. Which item were you interested in?

Uh huh, perhaps I need more code reading, I thought the whole qtdeclarative submodule had been included. I am implementing a plugin in android platform which would read gpkg file in for further processing, and try to utilize the FileDialog Component in QtQuick.Dialogs Module to do it. I've checked qt's doc and confirmed that in qt6 it already supports android platform, so I wrote the import line in the plugin main.qml file, and find it not working.

gitpydev avatar Feb 23 '25 08:02 gitpydev

@gitpydev , that module was added in Qt 6.2 and doesn't appear to be built by default (https://github.com/qt/qtdeclarative/blob/63646efa485b8f5ef00c1e7dadbfa69bb157f05f/src/CMakeLists.txt#L72-L74), at least not on vcpkg.

nirvn avatar Feb 23 '25 08:02 nirvn

@gitpydev , that module was added in Qt 6.2 and doesn't appear to be built by default (https://github.com/qt/qtdeclarative/blob/63646efa485b8f5ef00c1e7dadbfa69bb157f05f/src/CMakeLists.txt#L72-L74), at least not on vcpkg.

I see, plenty of helps for me, thanks a lot for nirvn's nice replies.

Before trying to utilize this local file accessing capability provided by Qml, I also tried to utilize the built-in capability provided by QField itself, aka the platformUtilityies.import* Q_INVOKABLE API, which were used by importing local project files etc., I could invoke it successfully in a plugin's main.qml, but finally found it not general enough for local file accessing purpose, more like for dedicated purpose. Anyway, QField is really a great open source project, praising.

gitpydev avatar Feb 23 '25 09:02 gitpydev

By the way, will QField plugins consider adding support for QtQuick.LocalStorage Module? It would be convenient utilizing this module for sqlite db accessing which is also suitable for gpkg files.

gitpydev avatar Feb 23 '25 10:02 gitpydev

There's also QfDialog to show dialogs, do you need access to system dialogs via QtQuick.Dialogs, if yes, which one specifically? Note that especially file system access is very limited on android and ios.

Are you confident that you'll be able to interact with gpkg through QtQuick.LocalStorage in a satisfying way? Normally interaction with gpkg's is best done through spatially aware libraries like gdal and I don't see this possible. Depending on the needs another approach could be envisioned that allows executing SQL on a loaded layer through its data provider.

m-kuhn avatar Feb 28 '25 05:02 m-kuhn

There's also QfDialog to show dialogs, do you need access to system dialogs via QtQuick.Dialogs, if yes, which one specifically? Note that especially file system access is very limited on android and ios.

Are you confident that you'll be able to interact with gpkg through QtQuick.LocalStorage in a satisfying way? Normally interaction with gpkg's is best done through spatially aware libraries like gdal and I don't see this possible. Depending on the needs another approach could be envisioned that allows executing SQL on a loaded layer through its data provider.

Thanks m-kuhn for your reply.

Generally speaking, I just want to access local file in qfield's qml plugin code in android platform, after searching for related API in qfield itself, I couldn't find one for this purpose. So I put my eyes on the Qml's FileDialog Component which is provided by QtQuick.Dialog Module.

So actually I am not about to show dialogs but find ways to access local file.

It's true that managing gpkg file with plain QtQuick.LocalStorage which is for general sqlite db file won't be a satisfying way, but at least providing a convenient way to acess it compared to reading the file content out and parsing it manually as sqlite/gpkg format.

gitpydev avatar Mar 01 '25 07:03 gitpydev

@gitpydev I believe we would ideally look for exposing qgis-native API's to execute SQL on the layer source (similar to what with the db manager / browser can be done in QGIS). This way we will have proper access to the providers of loaded layers which should be the most powerful, safe and future proof approach.

m-kuhn avatar Mar 17 '25 16:03 m-kuhn

@m-kuhn Having SQL access to the layer source would add lots of flexibility for plugin development. I would love to have that!

HeatherHillers avatar Mar 31 '25 06:03 HeatherHillers