I have been trying to make a local addition to the python code for QGIS plugin Midvatten to allow labels on the stratigraphy plot that give the capacity explanation rather than the capacity value. In my case these capacity values are just meaningless codes but the explanation is the information that I wish display about the plot. The screenshot shows the type of plot with capacity value label and attribute tables that I am using with explanation field.
I found the file stratigraphy.py in .qgis2>plugins>midvatten>tools and have added the following lines of code:
elif self.GeoOrComment == "explanation": p.drawText(tRect, PyQt4.QtCore.Qt.AlignVCenter, '' if layer.hydro=='NULL' else self.digitToText(layer.hydro, 'explanation'))
at line 469
def digitToText(self, id=''): # A function to return 'explanation' for 'capacity' value """ returns explanation for the specified capacity """ if id in self.hydroColors: return getattr(PyQt4.QtCore.Qt, self.hydroColors[id]) # Or possibly ? else: return PyQt4.QtCore.Qt.nolabel
at line 509
at line 572
This does not produce any syntax errors and adds explanation to label menu but interferes with the content of the stratigraphy plot content as shown in the screenshot:
I am now trying to figure out what I need to change. In .qgis2>plugins>midvatten>definitions>midvatten_defs.py I found def hydrocolors(): which has the line of code:
res, dict_qt1 = utils.get_sql_result_as_dict('select a.capacity, a.explanation, b.color_qt from zz_capacity a, zz_capacity_plots b where a.capacity = b.capacity')
This suggests to me that I am looking in the right dictionary to find the explanation label. In the getattr statement I have tried changing the number in [ ] between 0,1 and two to see if this has any effect but it doesn't.
What am I missing?