def __init__(self, parent = None):
     PyQt4.QtGui.QFrame.__init__(self, parent)
     self.setFrameShape(PyQt4.QtGui.QFrame.StyledPanel)
     self.setLineWidth(3)
     self.sondaggio = {}
     # In the original ARPAT plugin the following convention was used F = points, T = vertical lines and  C = horizontal lines
     """  Following standard Qt Colors exist
         Qt.white            White (#ffffff)
         Qt.black            Black (#000000)
         Qt.red            Red (#ff0000)
         Qt.darkRed            Dark red (#800000)
         Qt.green            Green (#00ff00)
         Qt.darkGreen            Dark green (#008000)
         Qt.blue            Blue (#0000ff)
         Qt.darkBlue            Dark blue (#000080)
         Qt.cyan            Cyan (#00ffff)
         Qt.darkCyan            Dark cyan (#008080)
         Qt.magenta            Magenta (#ff00ff)
         Qt.darkMagenta            Dark magenta (#800080)
         Qt.yellow            Yellow (#ffff00)
         Qt.darkYellow            Dark yellow (#808000)
         Qt.gray            Gray (#a0a0a4)
         Qt.darkGray            Dark gray (#808080)
         Qt.lightGray            Light gray (#c0c0c0)
         Qt.transparent    a transparent black value (i.e., PySide.QtGui.QColor (0, 0, 0, 0))
     """
     #------------------Please note!---------------------
     # Due to unicode normalize in getData function below, swedish national characters will be 
     # transformed to a, a, and o when read from the stratigraphy table 
     self.geoColorSymbols = defs.geocolorsymbols()
     self.hydroColors = defs.hydrocolors()
     self.switchGeoHydro = 0        #Default is to show colors according to geo
     self.GeoOrComment = "geology"     #Default is that text =  geology description
     self.showDesc = True        #Default is to show text
    def test_missing_colors_patterns(self):
        db_utils.sql_alter_db('DELETE FROM zz_strat')
        db_utils.sql_alter_db('DELETE FROM zz_stratigraphy_plots')
        db_utils.sql_alter_db("""INSERT INTO zz_strat(geoshort, strata) VALUES('nostrata', 'noshort')""")
        db_utils.sql_alter_db("""INSERT INTO zz_stratigraphy_plots(strata, color_mplot, hatch_mplot, color_qt, brush_qt) VALUES('moran', 'theMPcolor', '/', 'theQTcolor', 'thePattern')""")

        test_string = utils.anything_to_string_representation(midvatten_defs.geocolorsymbols())
        reference_string = '''{"nostrata": ("NoBrush", "white", )}'''
        assert test_string == reference_string
示例#3
0
    def test_missing_colors_patterns(self):
        db_utils.sql_alter_db('DELETE FROM zz_strat')
        db_utils.sql_alter_db('DELETE FROM zz_stratigraphy_plots')
        db_utils.sql_alter_db("""INSERT INTO zz_strat(geoshort, strata) VALUES('nostrata', 'noshort')""")
        db_utils.sql_alter_db("""INSERT INTO zz_stratigraphy_plots(strata, color_mplot, hatch_mplot, color_qt, brush_qt) VALUES('moran', 'theMPcolor', '/', 'theQTcolor', 'thePattern')""")

        test_string = utils.anything_to_string_representation(midvatten_defs.geocolorsymbols())
        reference_string = '''{"nostrata": ("NoBrush", "white", )}'''
        assert test_string == reference_string
示例#4
0
    def test_only_moran(self):
        db_utils.sql_alter_db('DELETE FROM zz_strat')
        db_utils.sql_alter_db('DELETE FROM zz_stratigraphy_plots')
        db_utils.sql_alter_db("""INSERT INTO zz_strat(geoshort, strata) VALUES('morän', 'morän')""")
        db_utils.sql_alter_db("""INSERT INTO zz_strat(geoshort, strata) VALUES('moran', 'morän')""")
        db_utils.sql_alter_db("""INSERT INTO zz_stratigraphy_plots(strata, color_mplot, hatch_mplot, color_qt, brush_qt) VALUES('morän', 'theMPcolor', '/', 'theQTcolor', 'thePattern')""")

        test_string = utils.anything_to_string_representation(midvatten_defs.geocolorsymbols())
        reference_string = '''{"moran": ("thePattern", "theQTcolor", ), "morän": ("thePattern", "theQTcolor", )}'''
        print(test_string)
        assert test_string == reference_string
    def test_only_moran(self):
        db_utils.sql_alter_db('DELETE FROM zz_strat')
        db_utils.sql_alter_db('DELETE FROM zz_stratigraphy_plots')
        db_utils.sql_alter_db("""INSERT INTO zz_strat(geoshort, strata) VALUES('morän', 'morän')""")
        db_utils.sql_alter_db("""INSERT INTO zz_strat(geoshort, strata) VALUES('moran', 'morän')""")
        db_utils.sql_alter_db("""INSERT INTO zz_stratigraphy_plots(strata, color_mplot, hatch_mplot, color_qt, brush_qt) VALUES('morän', 'theMPcolor', '/', 'theQTcolor', 'thePattern')""")

        test_string = utils.anything_to_string_representation(midvatten_defs.geocolorsymbols())
        reference_string = '''{"moran": ("thePattern", "theQTcolor", ), "morän": ("thePattern", "theQTcolor", )}'''
        print(test_string)
        assert test_string == reference_string
示例#6
0
 def __init__(self, parent=None):
     PyQt4.QtGui.QFrame.__init__(self, parent)
     self.setFrameShape(PyQt4.QtGui.QFrame.StyledPanel)
     self.setLineWidth(3)
     self.sondaggio = {}
     # In the original ARPAT plugin the following convention was used F = points, T = vertical lines and  C = horizontal lines
     """  Following standard Qt Colors exist
         Qt.white            White (#ffffff)
         Qt.black            Black (#000000)
         Qt.red            Red (#ff0000)
         Qt.darkRed            Dark red (#800000)
         Qt.green            Green (#00ff00)
         Qt.darkGreen            Dark green (#008000)
         Qt.blue            Blue (#0000ff)
         Qt.darkBlue            Dark blue (#000080)
         Qt.cyan            Cyan (#00ffff)
         Qt.darkCyan            Dark cyan (#008080)
         Qt.magenta            Magenta (#ff00ff)
         Qt.darkMagenta            Dark magenta (#800080)
         Qt.yellow            Yellow (#ffff00)
         Qt.darkYellow            Dark yellow (#808000)
         Qt.gray            Gray (#a0a0a4)
         Qt.darkGray            Dark gray (#808080)
         Qt.lightGray            Light gray (#c0c0c0)
         Qt.transparent    a transparent black value (i.e., PySide.QtGui.QColor (0, 0, 0, 0))
     """
     #------------------Please note!---------------------
     # Due to unicode normalize in getData function below, swedish national characters will be
     # transformed to a, a, and o when read from the stratigraphy table
     self.geoColorSymbols = defs.geocolorsymbols()
     #print(self.geoColorSymbols)#debug
     self.hydroColors = defs.hydrocolors()
     #print(self.hydroColors)#debug
     self.switchGeoHydro = 0  #Default is to show colors according to geo
     self.GeoOrComment = "geology"  #Default is that text =  geology description
     self.showDesc = True  #Default is to show text
def strat_symbology(iface, plot_rings, plot_bars, plot_static_bars, bars_xfactor, bars_yfactor, static_bars_xfactor,
                    static_bars_yfactor):
    """
    TODO: There is a logical bug where layers that should get caught as ELSE isn't because the shadow  ("maxdepthbot"  =  "depthbot")
          gets them... I might have to put the shadow in other layer...
    :param iface:
    :return:
    """
    root = QgsProject.instance().layerTreeRoot()
    dbconnection = db_utils.DbConnectionManager()
    plot_types = defs.PlotTypesDict()
    bedrock_geoshort = defs.bedrock_geoshort()
    bedrock_types = plot_types[bedrock_geoshort]
    geo_colors = defs.geocolorsymbols()
    hydro_colors = defs.hydrocolors()
    groupname = 'Midvatten strat symbology'
    try:
        add_views_to_db(dbconnection, bedrock_types)
    except:
        utils.MessagebarAndLog.critical(bar_msg=QCoreApplication.translate('strat_symbology', '''Creating database views failed, see log message panel'''),
                                        log_msg=QCoreApplication.translate('strat_symbology', '''%s''')%str(traceback.format_exc()))
        dbconnection.closedb()
        return

    old_group = root.findGroup(groupname)
    previously_visible = ''
    if old_group:
        for child in old_group.children():
            if child.isVisible():
                previously_visible = child.name()
    else:
        previously_visible = 'Bars'

    root.removeChildNode(root.findGroup(groupname))
    stratigraphy_group = qgis.core.QgsLayerTreeGroup(name=groupname, checked=True)
    root.insertChildNode(0, stratigraphy_group)
    stratigraphy_group.setIsMutuallyExclusive(True)

    settings = {'bars': [plot_bars, bars_xfactor, bars_yfactor],
                'static bars': [plot_static_bars, static_bars_xfactor, static_bars_yfactor],
                'rings': [plot_rings, None, None]}
    for name, stylename, wlvls_stylename, bedrock_stylename in (('Bars', 'bars_strat', 'bars_w_lvls_last_geom', 'bars_bedrock'),
                                                                ('Static bars', 'bars_static_strat', 'bars_static_w_lvls_last_geom', 'bars_static_bedrock'),
                                                                ('Rings', 'rings_strat', None, 'rings_bedrock')):
        if not settings[name.lower()][0]:
            continue
        xfactor = settings[name.lower()][1]
        yfactor = settings[name.lower()][2]

        group = qgis.core.QgsLayerTreeGroup(name=name)
        group.setExpanded(False)
        stratigraphy_group.insertChildNode(0, group)
        layers = []
        add_layers_to_list(layers, ['bars_strat', 'bars_strat', 'w_lvls_last_geom', 'bedrock'], geometrycolumn='geometry', dbconnection=dbconnection, layernames=['Geology', 'Hydro', 'W levels', 'Bedrock'])
        symbology_using_cloning(plot_types, geo_colors, layers[0], stylename, 'geoshort')
        symbology_using_cloning({k: "= '{}'".format(k) for k in sorted(hydro_colors.keys())}, hydro_colors, layers[1], stylename, 'capacity')
        scale_geometry_by_factor(layers[0], xfactor=xfactor, yfactor=yfactor)
        scale_geometry_by_factor(layers[1], xfactor=xfactor, yfactor=yfactor)
        QgsProject.instance().addMapLayers(layers[:2], False)
        if wlvls_stylename is not None and 'h_tocags' in layers[2].fields().names():
            apply_style(layers[2], wlvls_stylename)
            scale_geometry_by_factor(layers[2], xfactor=xfactor, yfactor=yfactor)
            QgsProject.instance().addMapLayer(layers[2], False)
            group.addLayer(layers[2])
            group.children()[-1].setExpanded(False)

        if bedrock_stylename is not None:
            create_bedrock_symbology(layers[3], bedrock_stylename, bedrock_geoshort, group)
            scale_geometry_by_factor(layers[3], xfactor=xfactor, yfactor=yfactor)
        color_group = qgis.core.QgsLayerTreeGroup(name='Layers', checked=True)
        color_group.setIsMutuallyExclusive(True)
        group.insertChildNode(-1, color_group)
        color_group.addLayer(layers[0])
        color_group.addLayer(layers[1])

    for child in stratigraphy_group.children():
        if child.name() == previously_visible:
            child.setItemVisibilityChecked(True)
    iface.mapCanvas().refresh()