Skip to content

Commit

Permalink
Show CRS info and add to export
Browse files Browse the repository at this point in the history
  • Loading branch information
effjot committed Jan 22, 2024
1 parent 1af04fb commit 57fb660
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 59 deletions.
47 changes: 30 additions & 17 deletions data_sources_panel/dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ class SourcesTableModel(QtCore.QAbstractTableModel):
def __init__(self, data: LayerSources):
super().__init__()
self._data = data
self._header = [tr('Layer'),
tr('Provider'),
tr('Storage Location')]
self._header = [
tr('Layer'),
tr('CRS'),
tr('Provider'),
tr('Storage Location')
]

def data(self, index, role):
if role == Qt.DisplayRole:
src = self._data.by_index(index.row())
item = src.by_index(index.column() + 1) # skip layerid field
if index.column() == 1:
if index.column() == 2:
return nice_provider_name(item)
return str(item)
if role == Qt.DecorationRole:
Expand Down Expand Up @@ -275,12 +278,13 @@ def setup_model_tree(self, data):
self.root_item.append_child(prov_item)
prov_sources = data.by_provider(prov)
locations = prov_sources.locations()
# loc_common = locations_common_part(locations) # FIXME: for no, skip flattening common parts; first, get adding and removing right
for loc in locations:
# loc_common = locations_common_part(locations) # FIXME: for now, skip flattening common parts; first, get adding and removing right
for loc, crs_authid in locations:
crs = f' [{crs_authid}]' if crs_authid else ''
if loc.is_empty():
loc_item = prov_item
elif loc.is_deep():
loc_item = TreeItem(str(loc.hierarchical[-1]),
loc_item = TreeItem(str(loc.hierarchical[-1]) + crs,
'location', parent=None)
# if loc_common and prov in ('ogr', 'gdal'):
# common_part = str(
Expand All @@ -291,11 +295,14 @@ def setup_model_tree(self, data):
where = loc.hierarchical[:-1]
prov_item.insert_in_tree(loc_item, where)
else:
loc_item = TreeItem(str(loc), 'location', prov_item)
loc_item = TreeItem(str(loc) + crs, 'location', prov_item)
prov_item.append_child(loc_item)
sources = prov_sources.by_location(loc)
for src in sources:
src_item = TreeItem(src, 'layer', loc_item)
src_data = src
if loc.is_empty():
src_data.name += crs
src_item = TreeItem(src_data, 'layer', loc_item)
loc_item.append_child(src_item)

def add_source_begin(self):
Expand All @@ -311,10 +318,11 @@ def add_source_end(self, src):
# locations = prov_sources.locations()
# loc_common = locations_common_part(locations) # FIXME: handle case with new common_part
loc = src.location
crs = f' [{src.crs_authid}]' if src.crs_authid else ''
if loc.is_empty():
loc_item = prov_item
elif loc.is_deep():
loc_item = TreeItem(str(loc.hierarchical[-1]),
loc_item = TreeItem(str(loc.hierarchical[-1]) + crs,
'location', parent=None)
# if loc_common and prov in ('ogr', 'gdal'):
# common_part = str(
Expand All @@ -327,9 +335,12 @@ def add_source_end(self, src):
else:
loc_item = prov_item.child_by_data(str(loc))
if not loc_item:
loc_item = TreeItem(str(loc), 'location', prov_item)
loc_item = TreeItem(str(loc) + crs, 'location', prov_item)
prov_item.append_child(loc_item)
src_item = TreeItem(src, 'layer', loc_item)
src_data = src
if loc.is_empty():
src_data.name += crs
src_item = TreeItem(src_data, 'layer', loc_item)
loc_item.append_child(src_item)
self.layoutChanged.emit()

Expand All @@ -341,6 +352,7 @@ def remove_source_begin(self, src):
# locations = prov_sources.locations()
# loc_common = locations_common_part(locations)
loc = src.location
crs = f' [{src.crs_authid}]' if src.crs_authid else ''
if loc.is_empty():
loc_item = prov_item
elif loc.is_deep():
Expand All @@ -350,13 +362,14 @@ def remove_source_begin(self, src):
# remainder = loc.hierarchical[loc_common:]
# where = (common_part,) + remainder
# else:
where = loc.hierarchical
where = list(loc.hierarchical) # tuple is immutable
where[-1] += crs
loc_item = prov_item
for node in where:
loc_item = loc_item.child_by_data(node)
else:
loc_item = prov_item.child_by_data(str(loc))
src_item = loc_item.child_by_data(src.name)
loc_item = prov_item.child_by_data(str(loc) + crs)
src_item = loc_item.child_by_data(src.name) # UGLY: src.name now already contains crs
loc_item.remove_child(src_item)
base_for_pruning = loc_item.find_base_for_pruning()
if base_for_pruning:
Expand Down Expand Up @@ -534,12 +547,12 @@ def export_xlsx(self):
def export(self, file_type: str):
if file_type not in ('csv', 'xlsx'):
raise ValueError
mem_layer = self.sources.as_memory_layer(tr('Data Sources'))
# self.proj.addMapLayer(mem_layer) # for testing
file_filters = {
'csv': tr('Comma Separated Values (*.csv)'),
'xlsx': tr('Excel workbook (*.xlsx)')
}
mem_layer = self.sources.as_memory_layer()
# self.proj.addMapLayer(mem_layer) # for testing
file_path = (Path(QgsSettings().value("UI/lastFileNameWidgetDir"))
/ f'{mem_layer.name()}.{file_type}')
output_file, _ = QFileDialog.getSaveFileName(
Expand Down
65 changes: 35 additions & 30 deletions data_sources_panel/i18n/data_sources_panel_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,142 +9,142 @@
<translation>&amp;Datenquellen-Bedienfeld</translation>
</message>
<message>
<location filename="../dockwidget.py" line="52"/>
<location filename="../dockwidget.py" line="53"/>
<source>Layer</source>
<translation>Layer</translation>
</message>
<message>
<location filename="../layer_sources.py" line="190"/>
<location filename="../layer_sources.py" line="195"/>
<source>Provider</source>
<translation>Datenanbieter</translation>
</message>
<message>
<location filename="../layer_sources.py" line="190"/>
<location filename="../layer_sources.py" line="195"/>
<source>Storage Location</source>
<translation>Speicherort</translation>
</message>
<message>
<location filename="../layer_sources.py" line="187"/>
<location filename="../dockwidget.py" line="540"/>
<source>Data Sources</source>
<translation>Datenquellen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="410"/>
<location filename="../dockwidget.py" line="413"/>
<source>&amp;Table View</source>
<translation>&amp;Tabellenansicht</translation>
</message>
<message>
<location filename="../dockwidget.py" line="413"/>
<location filename="../dockwidget.py" line="416"/>
<source>T&amp;ree View</source>
<translation>&amp;Baumansicht</translation>
</message>
<message>
<location filename="../dockwidget.py" line="416"/>
<location filename="../dockwidget.py" line="419"/>
<source>&amp;Expand All</source>
<translation>Alle &amp;ausklappen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="419"/>
<location filename="../dockwidget.py" line="422"/>
<source>&amp;Collapse All</source>
<translation>Alle &amp;einklappen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="425"/>
<location filename="../dockwidget.py" line="428"/>
<source>Export</source>
<translation>Export</translation>
</message>
<message>
<location filename="../dockwidget.py" line="428"/>
<location filename="../dockwidget.py" line="431"/>
<source>Export as &amp;Excel file</source>
<translation>Als &amp;Excel-Datei exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="430"/>
<location filename="../dockwidget.py" line="433"/>
<source>Export as &amp;CSV file</source>
<translation>Als &amp;CSV-Datei exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="538"/>
<location filename="../dockwidget.py" line="543"/>
<source>Comma Separated Values (*.csv)</source>
<translation>CSV (Komma-getrennte Werte)</translation>
</message>
<message>
<location filename="../dockwidget.py" line="539"/>
<location filename="../dockwidget.py" line="544"/>
<source>Excel workbook (*.xlsx)</source>
<translation>Excel-Arbeitsmappe (*.xlsx)</translation>
</message>
<message>
<location filename="../dockwidget.py" line="545"/>
<location filename="../dockwidget.py" line="548"/>
<source>Export Data Sources Table</source>
<translation>Datenquellen-Tabelle exportieren</translation>
</message>
<message>
<location filename="../dockwidget.py" line="550"/>
<location filename="../dockwidget.py" line="553"/>
<source>Export cancelled</source>
<translation>Export abgebrochen</translation>
</message>
<message>
<location filename="../dockwidget.py" line="562"/>
<location filename="../dockwidget.py" line="565"/>
<source>Data sources table successfully exported to {output_file}</source>
<translation>Datenquellen-Tabelle erfolgreich nach {output_file} exportiert</translation>
</message>
<message>
<location filename="../dockwidget.py" line="570"/>
<location filename="../dockwidget.py" line="573"/>
<source>Export to {output_file} failed: {error} {message}</source>
<translation>Export nach {output_file} fehlgeschlagen: {error} {message}</translation>
</message>
<message>
<location filename="../layer_sources.py" line="145"/>
<location filename="../layer_sources.py" line="149"/>
<source>(unknown)</source>
<translation>(unbekannt)</translation>
</message>
<message>
<location filename="../layer_sources.py" line="190"/>
<location filename="../layer_sources.py" line="195"/>
<source>layerid</source>
<translation>layerid</translation>
</message>
<message>
<location filename="../layer_sources.py" line="190"/>
<location filename="../layer_sources.py" line="195"/>
<source>Name</source>
<translation>Name</translation>
</message>
<message>
<location filename="../layer_sources.py" line="218"/>
<location filename="../layer_sources.py" line="224"/>
<source>WMS/WMTS</source>
<translation>WMS/WMTS</translation>
</message>
<message>
<location filename="../layer_sources.py" line="219"/>
<location filename="../layer_sources.py" line="225"/>
<source>WFS</source>
<translation>WFS</translation>
</message>
<message>
<location filename="../layer_sources.py" line="220"/>
<location filename="../layer_sources.py" line="226"/>
<source>PostgreSQL</source>
<translation>PostgreSQL</translation>
</message>
<message>
<location filename="../layer_sources.py" line="221"/>
<location filename="../layer_sources.py" line="227"/>
<source>PostgreSQL Raster</source>
<translation>PostgreSQL-Raster</translation>
</message>
<message>
<location filename="../layer_sources.py" line="222"/>
<location filename="../layer_sources.py" line="228"/>
<source>SpatiaLite</source>
<translation>SpatiaLite</translation>
</message>
<message>
<location filename="../layer_sources.py" line="223"/>
<location filename="../layer_sources.py" line="229"/>
<source>Memory / Scratch Layer</source>
<translation>Temporärlayer</translation>
</message>
<message>
<location filename="../layer_sources.py" line="129"/>
<location filename="../layer_sources.py" line="133"/>
<source>DB</source>
<translation>DB</translation>
</message>
<message>
<location filename="../layer_sources.py" line="129"/>
<location filename="../layer_sources.py" line="133"/>
<source>Schema</source>
<translation>Schema</translation>
</message>
Expand All @@ -154,15 +154,20 @@
<translation>&amp;Datenquellen</translation>
</message>
<message>
<location filename="../layer_sources.py" line="216"/>
<location filename="../layer_sources.py" line="222"/>
<source>Vector Files (OGR)</source>
<translation>Vektordateien (OGR)</translation>
</message>
<message>
<location filename="../layer_sources.py" line="217"/>
<location filename="../layer_sources.py" line="223"/>
<source>Raster Files (GDAL)</source>
<translation>Rasterdateien (GDAL)</translation>
</message>
<message>
<location filename="../layer_sources.py" line="195"/>
<source>CRS</source>
<translation>KBS</translation>
</message>
</context>
<context>
<name>DataSourceDockWidget</name>
Expand Down
Loading

0 comments on commit 57fb660

Please sign in to comment.