Skip to content

Commit

Permalink
Check Processing plugin again when running the main process
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Jan 30, 2023
1 parent b22b6b6 commit a8474ba
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Unreleased

* Bump QGIS minimum version to 3.22
* Add more checks about invalid XML/OQL, like `center`
* Check that QGIS Processing algorithm when running the main process
* Add more checks about invalid XML/OQL, like the input syntax `centre`

## 2.1.1 - 2022-08-21
Expand Down
16 changes: 15 additions & 1 deletion QuickOSM/core/parser/osm_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
import processing

from osgeo import gdal
from qgis.core import QgsField, QgsProcessingFeedback, QgsVectorLayer
from qgis.core import (
QgsField,
QgsProcessingException,
QgsProcessingFeedback,
QgsVectorLayer,
)
from qgis.PyQt.QtCore import QObject, QVariant, pyqtSignal

from QuickOSM.core.exceptions import FileOutPutException, QuickOsmException
from QuickOSM.core.utilities.tools import check_processing_enable
from QuickOSM.definitions.format import Format
from QuickOSM.definitions.osm import WHITE_LIST, Osm_Layers
from QuickOSM.qgis_plugin_tools.tools.i18n import tr
Expand Down Expand Up @@ -130,6 +136,14 @@ def processing_parse(self):

if self.feedback_alg:
self.feedback.pushInfo('Checking the validity of the geometry of the layer {}.'.format(layer))

# Let's check again Processing...
# Checking again at the opening of the dialog is not enough according to GH tickets
# https://github.com/3liz/QuickOSM/issues/422
flag, _, error = check_processing_enable()
if not flag:
raise QgsProcessingException(error)

validity = processing.run(
"qgis:checkvalidity", {
'INPUT_LAYER': layers[layer]['vectorLayer'],
Expand Down
20 changes: 20 additions & 0 deletions QuickOSM/core/utilities/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from os import mkdir
from os.path import abspath, isdir, isfile, join
from typing import Tuple

from qgis.core import QgsApplication, QgsSettings
from qgis.PyQt.QtCore import QDir
Expand All @@ -14,6 +15,8 @@
__license__ = 'GPL version 3'
__email__ = 'info@3liz.org'

from QuickOSM.qgis_plugin_tools.tools.i18n import tr


def custom_config_file() -> str:
"""Get the custom config file or None."""
Expand Down Expand Up @@ -76,6 +79,23 @@ def quickosm_user_folder() -> str:
return path


def check_processing_enable() -> Tuple[bool, str, str]:
""" Check if Processing is enabled. """
# https://github.com/3liz/QuickOSM/issues/422
# https://github.com/3liz/QuickOSM/issues/352
if QgsApplication.processingRegistry().algorithmById("native:buffer"):
return True, '', ''

return (
False,
tr('Error with the Processing plugin'),
tr(
'To be able to use QuickOSM, you need to have the "Processing" plugin enabled. '
'Please check in your QGIS Plugin manager that the "Processing" plugin is enabled.'
)
)


def get_setting(key: str, default: str = None) -> str:
"""Get a value in the QgsSettings.
Expand Down
23 changes: 10 additions & 13 deletions QuickOSM/quick_osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
QPushButton,
)

from QuickOSM.core.utilities.tools import get_setting, set_setting
from QuickOSM.core.utilities.tools import (
check_processing_enable,
get_setting,
set_setting,
)
from QuickOSM.core.utilities.utilities_qgis import open_webpage
from QuickOSM.definitions.urls import DOC_PLUGIN_URL
from QuickOSM.qgis_plugin_tools.tools.custom_logging import setup_logger
Expand Down Expand Up @@ -232,19 +236,12 @@ def josm_remote(self):

def open_dialog(self):
"""Create and open the main dialog."""

# Check if Processing is enabled
# Ticket #352
if QgsApplication.processingRegistry().algorithmById("native:buffer") is None:
error_dialog = QMessageBox(
QMessageBox.Critical,
tr('Error with the Processing plugin'),
tr(
'To be able to use QuickOSM, you need to have the "Processing" plugin enabled. '
'Please check in your QGIS Plugin manager that the "Processing" plugin is enabled.'),
QMessageBox.Ok,
self
)
# https://github.com/3liz/QuickOSM/issues/352
# https://github.com/3liz/QuickOSM/issues/422
flag, title, error = check_processing_enable()
if not flag:
error_dialog = QMessageBox(QMessageBox.Critical, title, error, QMessageBox.Ok, self)
error_dialog.exec()
return

Expand Down

0 comments on commit a8474ba

Please sign in to comment.