Skip to content

Commit

Permalink
Merge pull request #29 from tudelft3d/gio-dev
Browse files Browse the repository at this point in the history
Towards 0.8.5
  • Loading branch information
gioagu authored Sep 6, 2023
2 parents 0d65832 + 343ce94 commit 2096352
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 115 deletions.
2 changes: 1 addition & 1 deletion cdb4/ddl_scripts/postgresql/010_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ IF (usr_name = 'postgres') OR (qgis_pkg.is_superuser(usr_name) IS TRUE) THEN
-- We need access to schema citydb_pkg, that has been granted before the loop
-- The index is created only the very first time, then it won't be created again,
-- no matter if another uses it granted privileges.
EXECUTE format('SELECT qgis_pkg.add_ga_indices(%L);', sch_name);
EXECUTE format('SELECT qgis_pkg.add_ga_indices(%L);', cdb_schema);

END LOOP;

Expand Down
1 change: 1 addition & 0 deletions cdb4/gui_db_connector/functions/conn_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def open_connection(dlg: Union[CDB4LoaderDialog, CDB4DeleterDialog, CDB4AdminDia
else:
return False


def check_connection_uniqueness(dlg: Union[CDB4LoaderDialog, CDB4DeleterDialog], cdbMain: CDBToolsMain) -> bool:
"""
"""
Expand Down
6 changes: 1 addition & 5 deletions cdb4/gui_loader/functions/tab_conn_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ def check_layers_status(dlg: CDB4LoaderDialog) -> bool:
dlg.btnLayerExtentsL.setDisabled(False)
dlg.tabLayers.setDisabled(False)
dlg.btnImport.setDisabled(True)
# Also enables the settings tab

# Fill the combo box with the codelist selection

CityGML_codelist_set_names: list = sql.fetch_CityGML_codelist_set_names(dlg)
# print("Initializing combo box with:", codelist_set_names)
if CityGML_codelist_set_names:
Expand All @@ -312,9 +311,6 @@ def check_layers_status(dlg: CDB4LoaderDialog) -> bool:
# # print("Initializing combo box with:", codelist_set_names)
# if ADE_codelist_set_names:
# tl_wf.fill_ADE_codelist_selection_box(dlg, ADE_codelist_set_names)
#

dlg.tabSettings.setDisabled(False)

else:
tl_wf.tabLayers_reset(dlg) # it disables itself, too
Expand Down
35 changes: 0 additions & 35 deletions cdb4/gui_loader/functions/tab_settings_widget_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,6 @@
FILE_LOCATION = gen_f.get_file_relative_path(file=__file__)


# def fill_CityGML_codelist_selection_box(dlg: CDB4LoaderDialog, CityGML_codelist_set_names: list = None) -> None:
# """Function that fills the 'Select CodeLists group' combo box.
# """
# # Clean combo box from previous leftovers.
# dlg.cbxCodeListSelCityGML.clear()

# if not CityGML_codelist_set_names:
# # Disable the combobox
# dlg.cbxCodeListSelCityGML.setDisabled(True)
# dlg.cbxCodeListSelCityGML.setDisabled(True)
# else:
# label: str = f"None"
# dlg.cbxCodeListSelCityGML.addItem(label, userData=label)
# for codelist_set_name in CityGML_codelist_set_names:
# label: str = f"{codelist_set_name}"
# dlg.cbxCodeListSelCityGML.addItem(label, userData=label)
# if not dlg.cbxCodeListSelCityGML.isEnabled():
# # Enable the combobox
# dlg.cbxCodeListSelCityGML.setDisabled(False)
# dlg.lblCodeListSelCityGML.setDisabled(False)

# # REMEMBER: don't use method 'setSeparator', it adds a custom separator to join string of selected items
# return None


####################################################
## Reset widget functions for 'Settings' tab
####################################################
Expand All @@ -51,7 +26,6 @@ def tabSettings_reset(dlg: CDB4LoaderDialog) -> None:
dlg.tabSettings.setDisabled(True)
gbxGeomSimp_reset(dlg)
gbxLayerOptions_reset(dlg)
# gbxCodeListSelection_reset(dlg)
gbxMisc_reset(dlg)

return None
Expand All @@ -77,18 +51,9 @@ def gbxLayerOptions_reset(dlg: CDB4LoaderDialog) -> None:
return None


# def gbxCodeListSelection_reset(dlg: CDB4LoaderDialog) -> None:
# """Function to reset the 'Miscellaneous option' groupbox to the DEFAULT values
# """
# dlg.cbxCodeListSelCityGML.clear()

# return None


def gbxMisc_reset(dlg: CDB4LoaderDialog) -> None:
"""Function to reset the 'Miscellaneous option' groupbox to the DEFAULT values
"""
dlg.cbxEnable3D.setChecked(dlg.settings.enable_3d_renderer_default)

return None

1 change: 1 addition & 0 deletions cdb4/gui_loader/functions/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def create_layers_thread(self):
dlg.qspbDecimalPrec.value(),
dlg.qspbMinArea.value(),
bbox,
dlg.CRS_is_geographic, # True or False
dlg.cbxForceLayerGen.isChecked() # True or False
]

Expand Down
93 changes: 22 additions & 71 deletions cdb4/gui_loader/loader_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ def __init__(self, cdbMain: CDBToolsMain, parent=None):
# Link the additional canvas to the extents qgroupbox and enable "MapCanvasExtent" Button (Byproduct).
self.qgbxExtents.setMapCanvas(canvas=self.CANVAS, drawOnCanvasOption=False)
# Draw on Canvas tool is disabled. Check notes in tc_wf.qgbxExtents_setup()
#################################################################
# self.qgbxExtents.setOutputCrs(outputCrs=self.CRS)
#################################################################
# 'Extents' groupbox signals
self.btnRefreshCDBExtents.clicked.connect(self.evt_btnRefreshCDBExtents_clicked)

Expand All @@ -222,9 +219,6 @@ def __init__(self, cdbMain: CDBToolsMain, parent=None):
# Link the addition canvas to the extents qgroupbox and enable "MapCanvasExtent" options (Byproduct).
self.qgbxExtentsL.setMapCanvas(canvas=self.CANVAS_L, drawOnCanvasOption=False)
# Draw on Canvas tool is disabled. Check Note on main>widget_setup>ws_layers_tab.py>qgbxExtentsL_setup
#################################################################
# self.qgbxExtentsL.setOutputCrs(outputCrs=self.CRS)
#################################################################

# 'Extents' groupbox signals
self.qgbxExtentsL.extentChanged.connect(self.evt_qgbxExtentsL_ext_changed)
Expand Down Expand Up @@ -339,7 +333,8 @@ def evt_cbxExistingConn_changed(self) -> None:
self.lblConnectToDB.setDisabled(False) # Activate the label

# Close the current open connection.
if self.conn is not None:
#if self.conn is not None:
if self.conn:
self.conn.close()


Expand All @@ -351,7 +346,7 @@ def evt_btnNewConn_clicked(self) -> None:
"""
# Create/Show/Execute additional dialog for the new connection
dlgConnector = DBConnectorDialog()
dlgConnector.setWindowModality(Qt.ApplicationModal) # i.e. 2, the window is modal to the application and blocks input to all windows.
dlgConnector.setWindowModality(Qt.ApplicationModal) # i.e. 2, the window is modal to the application and blocks input to all other windows.
dlgConnector.show()
dlgConnector.exec_()

Expand All @@ -367,12 +362,6 @@ def evt_btnConnectToDb_clicked(self) -> None:
"""
msg: str = None

# In 'Connection Status' groupbox
# Activate the connection status box (red/green checks)
self.gbxConnStatus.setDisabled(False)
# Activate the close connection button at the bottom
self.btnCloseConn.setDisabled(False)

# In 'Connection Status' groupbox
self.gbxConnStatus.setDisabled(False) # Activate the connection status box (red/green checks)
self.btnCloseConn.setDisabled(False) # Activate the close connection button at the bottom
Expand All @@ -399,7 +388,7 @@ def evt_btnConnectToDb_clicked(self) -> None:
self.lblConnToDb_out.setText(c.success_html.format(text=self.DB.database_name))
self.checks.is_conn_successful = True

if self.DB.pg_server_version is not None:
if self.DB.pg_server_version:
# Show server version
self.lblPostInst_out.setText(c.success_html.format(text=self.DB.pg_server_version))
self.checks.is_postgis_installed = True
Expand All @@ -423,7 +412,7 @@ def evt_btnConnectToDb_clicked(self) -> None:
tc_wf.tabConnection_reset(self)

# Close the current open connection.
if self.conn is not None:
if self.conn:
self.conn.close()

return None # Exit
Expand Down Expand Up @@ -452,7 +441,7 @@ def evt_btnConnectToDb_clicked(self) -> None:
tc_wf.tabConnection_reset(self)

# Close the current open connection.
if self.conn is not None:
if self.conn:
self.conn.close()

return None # Exit
Expand Down Expand Up @@ -495,7 +484,7 @@ def evt_btnConnectToDb_clicked(self) -> None:
tc_wf.tabConnection_reset(self)

# Close the current open connection.
if self.conn is not None:
if self.conn:
self.conn.close()

return None # Exit
Expand Down Expand Up @@ -526,7 +515,7 @@ def evt_btnConnectToDb_clicked(self) -> None:
tc_wf.tabConnection_reset(self)

# Close the current open connection.
if self.conn is not None:
if self.conn:
self.conn.close()

return None # Exit
Expand All @@ -536,25 +525,14 @@ def evt_btnConnectToDb_clicked(self) -> None:
cdb_schemas_rw_ro: list = []
cdb_schemas: list = []
# Get the list of 3DCityDB schemas from database as a tuple. If empty, len(tuple)=0
#####################################################################################################
# Namedtuple with: cdb_schema, co_number, priv_type
# cdb_schemas_extended = sql.exec_list_cdb_schemas_with_priv_feat_count(self)
# print('cdb_schema_extended', cdb_schemas_extended)

# Select tuples of cdb_schemas that have number of cityobjects <> 0
# AND the user has 'rw' privileges.
# cdb_schemas_rw_ro = [cdb_schema for cdb_schema in cdb_schemas_extended if cdb_schema.priv_type in ["ro", "rw"]]
# cdb_schemas = [cdb_schema for cdb_schema in cdb_schemas_rw_ro if cdb_schema.co_number != 0]
#####################################################################################################
# Namedtuple with: cdb_schema, is_empty, priv_type
cdb_schemas_extended = sql.exec_list_cdb_schemas_privs(self)
cdb_schemas_all = sql.exec_list_cdb_schemas_privs(self)
# print('cdb_schema_extended', cdb_schemas_extended)

# Select tuples of cdb_schemas that have number of cityobjects <> 0
# AND the user has 'rw' privileges.
cdb_schemas_rw_ro = [cdb_schema for cdb_schema in cdb_schemas_extended if cdb_schema.priv_type in ["ro", "rw"]]
cdb_schemas_rw_ro = [cdb_schema for cdb_schema in cdb_schemas_all if cdb_schema.priv_type in ["ro", "rw"]]
cdb_schemas = [cdb_schema for cdb_schema in cdb_schemas_rw_ro if not cdb_schema.is_empty]
#####################################################################################################
# print(cdb_schemas_rw_ro)
# print(cdb_schemas)

Expand All @@ -568,7 +546,7 @@ def evt_btnConnectToDb_clicked(self) -> None:
tc_wf.tabConnection_reset(self)

# Close the current open connection.
if self.conn is not None:
if self.conn:
self.conn.close()

return None # Exit
Expand All @@ -584,18 +562,13 @@ def evt_btnConnectToDb_clicked(self) -> None:
ts_wf.tabSettings_reset(self)
tc_wf.tabConnection_reset(self)
# Close the current open connection.
if self.conn is not None:
if self.conn:
self.conn.close()

return None

else: # Finally, we have all conditions to fill the cdb_schema combobox

####################################################################
# tc_f.fill_cdb_schemas_box_feat_count(self, cdb_schemas)
####################################################################
tc_f.fill_cdb_schemas_box(self, cdb_schemas)
####################################################################
# At this point, filling the schema box, activates the 'evt_cbxSchema_changed' event.
# So if you're following the code line by line, go to citydb_loader.py>evt_cbxSchema_changed or at 'cbxSchema_setup' function below

Expand All @@ -610,32 +583,31 @@ def evt_cbxSchema_changed(self, cdbMain: CDBToolsMain) -> None:
"""

# By now, the schema variable must have beeen assigned.
# Simple redundant check just to be sure...
if not self.cbxSchema.currentData():
return None

# Namedtuple with: cdb_schema, co_number, priv_type
# Named tuple with: cdb_schema, co_number, priv_type
sel_cdb_schema: tuple = self.cbxSchema.currentData()

# Set the current schema variable
self.CDB_SCHEMA: str = sel_cdb_schema.cdb_schema

is_connection_unique: bool
is_connection_unique = conn_f.check_connection_uniqueness(dlg=self, cdbMain=cdbMain)
# Check that we are not accessing the same cdb_schema from other GUI dialogs of the plugin
is_connection_unique: bool = conn_f.check_connection_uniqueness(dlg=self, cdbMain=cdbMain)
if not is_connection_unique:
return None # Stop and do not proceed

# Set the current schema privileges
self.CDBSchemaPrivileges = sel_cdb_schema.priv_type
# print("CDBSchemaPrivileges", self.isReadOnlyCDBSchema)

# Set the current number of cityobjects
# self.n_cityobjects = sel_cdb_schema.co_number
# print("n_cityobjects", self.n_cityobjects)

# Reset the Layer and Settings tabs in case they were open/changed from before
tl_wf.tabLayers_reset(self) # Reset the Layers tab
ts_wf.tabSettings_reset(self) # Reset the Settings tab to the Default settings

self.tabSettings.setDisabled(False) # Reactivate the tab Settings

self.CDB_SCHEMA_EXTENTS = QgsRectangle()
self.LAYER_EXTENTS = QgsRectangle()
self.QGIS_EXTENTS = QgsRectangle()
Expand All @@ -647,21 +619,22 @@ def evt_cbxSchema_changed(self, cdbMain: CDBToolsMain) -> None:
self.lblLayerExist_out.clear()
self.lblLayerRefr_out.clear()

# Enable schema comboBox
# Enable cdb_schema comboBox
self.cbxSchema.setDisabled(False)
self.lblSchema.setDisabled(False)

# Update labels with the name of the selected cdb_schema
self.btnRefreshCDBExtents.setText(self.btnRefreshCDBExtents.init_text.format(sch=self.CDB_SCHEMA))
self.btnCityExtents.setText(self.btnCityExtents.init_text.format(sch=self.CDB_SCHEMA))

# Update labels with on the layer Create/Refresh/(Drop) buttons with the selected cdb_schema
self.btnCreateLayers.setText(self.btnCreateLayers.init_text.format(sch=self.CDB_SCHEMA))
self.btnRefreshLayers.setText(self.btnRefreshLayers.init_text.format(sch=self.CDB_SCHEMA))
# self.btnDropLayers.setText(self.btnDropLayers.init_text.format(sch=self.CDB_SCHEMA))

# Setup the 'Basemap (OSM)' groupbox.
tc_wf.gbxBasemap_setup(self)
# This fires an update of the medatada library
# This fires an update of the medadata library

# Check whether layers exist, have been refreshed, and set up the GUI elements accordinly
tc_f.check_layers_status(self)
Expand All @@ -686,14 +659,9 @@ def evt_canvasC_ext_changed(self) -> None:
old_poly = QgsGeometry.fromRect(old_extent)

if new_poly.equals(old_poly):
# do nothing
# print("same extents, same CRS, do nothing")
pass
else:
# Set the current extent to show in the 'extent' widget.
# self.qgbxExtents.blockSignals(True)
# self.qgbxExtents.setOutputCrs(outputCrs=self.CRS) # Signal emitted for qgbxExtents. Avoid double signal by blocking signals
# self.qgbxExtents.blockSignals(False)
self.qgbxExtents.setCurrentExtent(currentExtent=new_extent, currentCrs=self.CRS) # Signal emitted for qgbxExtents


Expand Down Expand Up @@ -735,23 +703,6 @@ def evt_btnRefreshCDBExtents_clicked(self) -> None:
- have changed and the new cdb extents contain the old ones (only update the ribbons)
- have changed and the new cdb extents do not strictly contain the old ones (drop existing layers, update ribbons)
"""
# # Recount the number of cityobjects
# new_n_cityobjects = sql.count_cityobjects_in_cdb_schema(self)

# if self.n_cityobjects != new_n_cityobjects:
# self.n_cityobjects = new_n_cityobjects
# # Create a namedtuple to inser in the combobox
# new_sel_cdb_schema = namedtuple("RECORD", "cdb_schema, co_number, priv_type")
# new_sel_cdb_schema.cdb_schema = self.CDB_SCHEMA
# new_sel_cdb_schema.co_number = self.n_cityobjects
# new_sel_cdb_schema.priv_type = self.CDBSchemaPrivileges
# # Update the entry in the cdb_schema combobox
# for i in range(self.cbxSchema.count()):
# curr_itemdata = self.cbxSchema.itemData(i)
# if curr_itemdata.cdb_schema == new_sel_cdb_schema.cdb_schema:
# label: str = f"{new_sel_cdb_schema.cdb_schema} ({new_sel_cdb_schema.priv_type}): {new_sel_cdb_schema.co_number} CityObjects"
# self.cbxSchema.setItemText(i, label)
# self.cbxSchema.setItemData(i, new_sel_cdb_schema)

is_geom_null, x_min, y_min, x_max, y_max, srid = sql.exec_compute_cdb_schema_extents(dlg=self)
srid = None # Discard unneeded variable.
Expand Down Expand Up @@ -915,7 +866,7 @@ def evt_btnRefreshCDBExtents_clicked(self) -> None:
tc_wf.tabConnection_reset(self)

# Close the connection
if self.conn is not None:
if self.conn:
self.conn.close()

return None # Exit
Expand Down
2 changes: 1 addition & 1 deletion cdb_tools_main_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Plugin current version
PLUGIN_VERSION_MAJOR: int = 0
PLUGIN_VERSION_MINOR: int = 8
PLUGIN_VERSION_REV: int = 4
PLUGIN_VERSION_REV: int = 5

# Paths
PLUGIN_ROOT_PATH: str = os.path.split(os.path.dirname(__file__))[0]
Expand Down
5 changes: 3 additions & 2 deletions metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ about=This plugin connects to the 3D City Database (v. 4.x) for PostgreSQL/PostG

- The "QGIS Package Administrator": it allows to install the server-side part of the plug-in, and to manage database user privileges.

Further details can be found in the PDF files contained in the \user_guide subfolder of the plugin installation directory. On the GitHub repository, some test datasets can be downloaded.
Further details can be found in the PDF files contained in the \user_guide subfolder of the plugin installation directory. On the GitHub repository further details are provided, and some test datasets can be downloaded.

tracker=https://github.com/tudelft3d/3DCityDB-Tools-for-QGIS

Expand All @@ -29,7 +29,8 @@ repository=https://github.com/tudelft3d/3DCityDB-Tools-for-QGIS
hasProcessingProvider=no

# Uncomment the following line and add your changelog:
changelog= 0.8.4 Fixed minor bugs in the QGIS Package
changelog= 0.8.5 Fixed minor bugs in the QGIS client
0.8.4 Fixed minor bugs in the QGIS Package
0.8.3 Minor changes to the Layer Loader dialog GUI
0.8.2 Minor changes to comply with QGIS Plugin repository
0.8.1 Detail View are set to ro/rw depending on user privileges
Expand Down

0 comments on commit 2096352

Please sign in to comment.