# coding=utf-8
"""Common functionality used by regression tests."""
# This file was generated from the QGIS Plugin builder plugin
# See https://github.com/g-sherman/Qgis-Plugin-Builder/
import sys
import logging
LOGGER = logging.getLogger('QGIS')
QGIS_APP = None # Static variable used to hold hand to running QGIS app
CANVAS = None
PARENT = None
IFACE = None
[docs]def get_qgis_app():
""" Start one QGIS application to test against.
:returns: Handle to QGIS app, canvas, iface and parent. If there are any
errors the tuple members will be returned as None.
:rtype: (QgsApplication, CANVAS, IFACE, PARENT)
If QGIS is already running the handle to that app will be returned.
"""
from qgis.PyQt import QtGui, QtCore
from qgis.core import QgsApplication
from qgis.gui import QgsMapCanvas
from svir.test.qgis_interface import QgisInterface
global QGIS_APP # pylint: disable=W0603
if QGIS_APP is None:
gui_flag = True # All test will run qgis in gui mode
#noinspection PyPep8Naming
QGIS_APP = QgsApplication(sys.argv, gui_flag)
# Make sure QGIS_PREFIX_PATH is set in your env if needed!
QGIS_APP.initQgis()
s = QGIS_APP.showSettings()
LOGGER.debug(s)
global PARENT # pylint: disable=W0603
if PARENT is None:
#noinspection PyPep8Naming
PARENT = QtGui.QWidget()
global CANVAS # pylint: disable=W0603
if CANVAS is None:
#noinspection PyPep8Naming
CANVAS = QgsMapCanvas(PARENT)
CANVAS.resize(QtCore.QSize(400, 400))
global IFACE # pylint: disable=W0603
if IFACE is None:
# QgisInterface is a stub implementation of the QGIS plugin interface
#noinspection PyPep8Naming
IFACE = QgisInterface(CANVAS)
# add some fake methods, where the actual ones were missing
# FIXME: in QgisInterface, legendInterface is returning the canvas
# instead of the legendInterface, which breaks things like setting the
# active layer or refreshing the layer symbology.
def do_nothing(layer):
pass
IFACE.legendInterface().refreshLayerSymbology = do_nothing
return QGIS_APP, CANVAS, IFACE, PARENT