Commit feac734b authored by Benjamin Jakimow's avatar Benjamin Jakimow

map view info text reports expression errors via tooltip

Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow benjamin.jakimow@geo.hu-berlin.de <benjamin.jakimow@geo.hu-berlin.de>
parent 66dd9cc4
...@@ -195,6 +195,8 @@ class MapView(QFrame): ...@@ -195,6 +195,8 @@ class MapView(QFrame):
self.mIsVisible = True self.mIsVisible = True
self.setTitle(name) self.setTitle(name)
self.tbInfoExpression: QLineEdit self.tbInfoExpression: QLineEdit
self.mDefaultInfoExpressionToolTip:str = self.tbInfoExpression.toolTip()
self.tbInfoExpression.textChanged.connect(self.onMapInfoExpressionChanged) self.tbInfoExpression.textChanged.connect(self.onMapInfoExpressionChanged)
self.btnShowInfoExpression.setDefaultAction(self.optionShowInfoExpression) self.btnShowInfoExpression.setDefaultAction(self.optionShowInfoExpression)
self.optionShowInfoExpression.toggled.connect(self.tbInfoExpression.setEnabled) self.optionShowInfoExpression.toggled.connect(self.tbInfoExpression.setEnabled)
...@@ -219,6 +221,16 @@ class MapView(QFrame): ...@@ -219,6 +221,16 @@ class MapView(QFrame):
fixMenuButtons(self) fixMenuButtons(self)
def setInfoExpressionError(self, error: str):
if error in ['', None]:
self.tbInfoExpression.setStyleSheet('')
self.tbInfoExpression.setToolTip(self.mDefaultInfoExpressionToolTip)
else:
self.tbInfoExpression.setStyleSheet('QLineEdit#tbInfoExpression{color:red; border: 2px solid red;}')
self.tbInfoExpression.setToolTip(f'<span style="color:red">{error}</span>')
def onMapInfoExpressionChanged(self, text: str): def onMapInfoExpressionChanged(self, text: str):
self.sigCanvasAppearanceChanged.emit() self.sigCanvasAppearanceChanged.emit()
...@@ -2155,7 +2167,7 @@ class MapWidget(QFrame): ...@@ -2155,7 +2167,7 @@ class MapWidget(QFrame):
tf = mapView.mapTextFormat() tf = mapView.mapTextFormat()
infoItemVisible: bool = mapView.optionShowInfoExpression.isChecked() infoItemVisible: bool = mapView.optionShowInfoExpression.isChecked()
errorText = ''
for canvas in self.mCanvases[mapView]: for canvas in self.mCanvases[mapView]:
assert isinstance(canvas, MapCanvas) assert isinstance(canvas, MapCanvas)
...@@ -2168,6 +2180,7 @@ class MapWidget(QFrame): ...@@ -2168,6 +2180,7 @@ class MapWidget(QFrame):
infoItem.setVisible(infoItemVisible) infoItem.setVisible(infoItemVisible)
expr = QgsExpression(mapView.mapInfoExpression()) expr = QgsExpression(mapView.mapInfoExpression())
infoItem.setInfoText(None)
if isinstance(expr, QgsExpression) and expr.expression() != '': if isinstance(expr, QgsExpression) and expr.expression() != '':
# context = QgsExpressionContext([QgsExpressionContextScope(canvas.expressionContextScope())]) # context = QgsExpressionContext([QgsExpressionContextScope(canvas.expressionContextScope())])
context: QgsExpressionContext = QgsExpressionContext() context: QgsExpressionContext = QgsExpressionContext()
...@@ -2182,13 +2195,17 @@ class MapWidget(QFrame): ...@@ -2182,13 +2195,17 @@ class MapWidget(QFrame):
# print(infoText) # print(infoText)
infoItem.setInfoText(str(infoText)) infoItem.setInfoText(str(infoText))
else: else:
# print(expr.evalErrorString(), file=sys.stderr) if errorText == '':
infoItem.setInfoText('') errorText = expr2.evalErrorString()
else:
if errorText == '':
errorText = expr.parserErrorString()
canvas.addToRefreshPipeLine(MapCanvas.Command.UpdateMapItems) canvas.addToRefreshPipeLine(MapCanvas.Command.UpdateMapItems)
if canvas.canvasColor() != bg: if canvas.canvasColor() != bg:
canvas.addToRefreshPipeLine(mapView.mapBackgroundColor()) canvas.addToRefreshPipeLine(mapView.mapBackgroundColor())
mapView.setInfoExpressionError(errorText)
class MapViewDock(QgsDockWidget): class MapViewDock(QgsDockWidget):
sigMapViewAdded = pyqtSignal(MapView) sigMapViewAdded = pyqtSignal(MapView)
......
...@@ -226,7 +226,7 @@ QToolBox::tab:selected { /* italicize selected tabs */ ...@@ -226,7 +226,7 @@ QToolBox::tab:selected { /* italicize selected tabs */
<string/> <string/>
</property> </property>
<property name="minimum"> <property name="minimum">
<number>0</number> <number>1</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>100</number> <number>100</number>
......
...@@ -83,11 +83,17 @@ ...@@ -83,11 +83,17 @@
<height>100</height> <height>100</height>
</size> </size>
</property> </property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::StyledPanel</enum> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property> </property>
<layout class="QGridLayout" name="mGrid"> <layout class="QGridLayout" name="mGrid">
<property name="leftMargin"> <property name="leftMargin">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment