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):
self.mIsVisible = True
self.setTitle(name)
self.tbInfoExpression: QLineEdit
self.mDefaultInfoExpressionToolTip:str = self.tbInfoExpression.toolTip()
self.tbInfoExpression.textChanged.connect(self.onMapInfoExpressionChanged)
self.btnShowInfoExpression.setDefaultAction(self.optionShowInfoExpression)
self.optionShowInfoExpression.toggled.connect(self.tbInfoExpression.setEnabled)
......@@ -219,6 +221,16 @@ class MapView(QFrame):
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):
self.sigCanvasAppearanceChanged.emit()
......@@ -2155,7 +2167,7 @@ class MapWidget(QFrame):
tf = mapView.mapTextFormat()
infoItemVisible: bool = mapView.optionShowInfoExpression.isChecked()
errorText = ''
for canvas in self.mCanvases[mapView]:
assert isinstance(canvas, MapCanvas)
......@@ -2168,6 +2180,7 @@ class MapWidget(QFrame):
infoItem.setVisible(infoItemVisible)
expr = QgsExpression(mapView.mapInfoExpression())
infoItem.setInfoText(None)
if isinstance(expr, QgsExpression) and expr.expression() != '':
# context = QgsExpressionContext([QgsExpressionContextScope(canvas.expressionContextScope())])
context: QgsExpressionContext = QgsExpressionContext()
......@@ -2182,13 +2195,17 @@ class MapWidget(QFrame):
# print(infoText)
infoItem.setInfoText(str(infoText))
else:
# print(expr.evalErrorString(), file=sys.stderr)
infoItem.setInfoText('')
if errorText == '':
errorText = expr2.evalErrorString()
else:
if errorText == '':
errorText = expr.parserErrorString()
canvas.addToRefreshPipeLine(MapCanvas.Command.UpdateMapItems)
if canvas.canvasColor() != bg:
canvas.addToRefreshPipeLine(mapView.mapBackgroundColor())
mapView.setInfoExpressionError(errorText)
class MapViewDock(QgsDockWidget):
sigMapViewAdded = pyqtSignal(MapView)
......
......@@ -226,7 +226,7 @@ QToolBox::tab:selected { /* italicize selected tabs */
<string/>
</property>
<property name="minimum">
<number>0</number>
<number>1</number>
</property>
<property name="maximum">
<number>100</number>
......
......@@ -83,11 +83,17 @@
<height>100</height>
</size>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QGridLayout" name="mGrid">
<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