Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed QWidget -> QMainWindow to allow the application menu bar. QgsInterface returns a new QToolBar when addToolBar is called #14

Merged
merged 6 commits into from
Jan 18, 2022
3 changes: 2 additions & 1 deletion src/pytest_qgis/pytest_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from qgis.PyQt import QtCore, QtWidgets
from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtWidgets import QMessageBox, QWidget
from qgis.PyQt.QtWidgets import QMainWindow

from pytest_qgis.mock_qgis_classes import MockMessageBar
from pytest_qgis.qgis_interface import QgisInterface
Expand Down Expand Up @@ -272,7 +273,7 @@ def _start_and_configure_qgis_app(config: "Config") -> None:
_APP = QgsApplication([], GUIenabled=settings.gui_enabled)
_APP.initQgis()
QgsGui.editorWidgetRegistry().initEditors()
_PARENT = QWidget()
_PARENT = QMainWindow()
_CANVAS = QgsMapCanvas(_PARENT)
_CANVAS.resize(QtCore.QSize(settings.canvas_width, settings.canvas_height))

Expand Down
19 changes: 15 additions & 4 deletions src/pytest_qgis/qgis_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
from qgis.gui import QgsMapCanvas
from qgis.PyQt.QtCore import QObject, pyqtSignal, pyqtSlot
from qgis.PyQt.QtWidgets import QAction, QDockWidget, QWidget

from qgis.PyQt.QtWidgets import QMainWindow
from qgis.PyQt.QtWidgets import QMenuBar
from qgis.PyQt.QtWidgets import QToolBar
from pytest_qgis.mock_qgis_classes import MockMessageBar

LOGGER = logging.getLogger("QGIS")
Expand All @@ -57,7 +59,7 @@ class QgisInterface(QObject):
currentLayerChanged = pyqtSignal(QgsMapCanvas) # noqa N802

def __init__(
self, canvas: QgsMapCanvas, messageBar: MockMessageBar, mainWindow: QWidget
self, canvas: QgsMapCanvas, messageBar: MockMessageBar, mainWindow: QMainWindow
) -> None:
"""Constructor
:param canvas:
Expand All @@ -80,6 +82,13 @@ def __init__(
self.destCrs = None
self._layers: List[QgsMapLayer] = []

# Add the MenuBar
menu_bar = QMenuBar()
self._mainWindow.setMenuBar(menu_bar)

# Add the toolbar list
self._toolbars = list()
JaumeFigueras marked this conversation as resolved.
Show resolved Hide resolved

@pyqtSlot("QList<QgsMapLayer*>")
def addLayers(self, layers: List[QgsMapLayer]) -> None:
"""Handle layers being added to the registry so they show up in canvas.
Expand Down Expand Up @@ -204,13 +213,15 @@ def removeToolBarIcon(self, action: QAction) -> None:
"""
pass

def addToolBar(self, name: str) -> None:
def addToolBar(self, name: str) -> QToolBar:
"""Add toolbar with specified name.

:param name: Name for the toolbar.
:type name: str
"""
pass
toolbar = QToolBar(self._mainWindow)
JaumeFigueras marked this conversation as resolved.
Show resolved Hide resolved
self._toolbars.append(toolbar)
JaumeFigueras marked this conversation as resolved.
Show resolved Hide resolved
JaumeFigueras marked this conversation as resolved.
Show resolved Hide resolved
return toolbar

def mapCanvas(self) -> QgsMapCanvas:
"""Return a pointer to the map canvas."""
Expand Down