Skip to content

Commit

Permalink
Support toml in QGIS plugin (#781)
Browse files Browse the repository at this point in the history
Fixes part of #629 (the results are not automatically associated yet).

The Open button now supports toml instead of gpkg. The toml file checks
for the "database" entry and loads that file as it used to do.
The New button now also creates a toml file with the database entry
pointing to the gpkg that is also created like before. And the start and
end dates are 01-01-2020 until 01-01-2030.

An option for another PR would be to add the start and end dates as
fields in the main widget so that they can be adjusted. But that would
mean that we need to keep the open toml file in memory and set the start
and end date, and flush the file after those changes.

Also, error handling is not fancy yet. If the "database" entry is
missing from the toml file, you will get a python KeyError

The folder `qgis` was renamed to `ribasim_qgis` for pylance to handle
the imports better.

---------

Co-authored-by: Martijn Visser <[email protected]>
  • Loading branch information
deltamarnix and visr authored Nov 14, 2023
1 parent 22beb03 commit 5c6a369
Show file tree
Hide file tree
Showing 25 changed files with 881 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .docker/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ version: '2'

services:
qgis:
image: qgis/qgis:release-3_30
image: qgis/qgis:release-3_28
container_name: qgis
volumes:
- ../qgis/:/tests_directory/${PLUGIN_NAME}
- ../ribasim_qgis/:/tests_directory/${PLUGIN_NAME}
environment:
- CI=true
- DISPLAY=:99
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<build-runners>
<runner id="RUNNER_2193" name="" type="simpleRunner">
<parameters>
<param name="script.content"><![CDATA[rsync --verbose --recursive --delete qgis/ ribasim_qgis
<param name="script.content"><![CDATA[rsync --verbose --recursive --delete ribasim_qgis/ ribasim_qgis
rm --force ribasim_qgis.zip
zip -r ribasim_qgis.zip ribasim_qgis]]></param>
<param name="teamcity.step.mode" value="default" />
Expand Down
2 changes: 1 addition & 1 deletion docs/contribute/addnode.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ In `python/ribasim/ribasim/geometry/node.py` add a color and shape description i

# QGIS plugin

The script `qgis/core/nodes.py` has to be updated to specify how the new node type is displayed by the QGIS plugin. Specifically:
The script `ribasim_qgis/core/nodes.py` has to be updated to specify how the new node type is displayed by the QGIS plugin. Specifically:

- Add a color and shape description in the `MARKERS` dictionary in `Node.renderer`,
consistent with the entries added above;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions qgis/core/nodes.py → ribasim_qgis/core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

from PyQt5.QtCore import Qt, QVariant
from PyQt5.QtGui import QColor
from ribasim_qgis.core import geopackage

from qgis.core import (
Qgis,
QgsCategorizedSymbolRenderer,
Expand All @@ -43,6 +41,8 @@
QgsVectorLayerSimpleLabeling,
)

from ribasim_qgis.core import geopackage


class Input(abc.ABC):
"""Abstract base class for Ribasim input layers."""
Expand Down
1 change: 0 additions & 1 deletion qgis/core/topology.py → ribasim_qgis/core/topology.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Tuple

import numpy as np

from qgis import processing
from qgis.core import QgsVectorLayer
from qgis.core.additions.edit import edit
Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions ribasim_qgis/tomllib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copied from https://github.com/python/cpython/blob/v3.12.0/Lib/tomllib/__init__.py
# QGIS does not guarantee a toml reader

# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021 Taneli Hukkinen
# Licensed to PSF under a Contributor Agreement.

__all__ = ("loads", "load", "TOMLDecodeError")

from ._parser import TOMLDecodeError, load, loads

# Pretend this exception was created here.
TOMLDecodeError.__module__ = __name__
Loading

0 comments on commit 5c6a369

Please sign in to comment.