def _table_columns(self, table_name): """ Return the column names for a given table_name name. :param table_name: Table name :type table_name: str :return: Collection of column names. If not found then an empty list is returned. :rtype: list """ return table_column_names(table_name)
def _load_source_table_fields(self, sel): self.cbo_referencing_col.clear() if not sel: return columns_names = table_column_names(sel) self.cbo_referencing_col.clear() self.cbo_referencing_col.addItem("") self.cbo_referencing_col.addItems(columns_names)
def _loadFields(self): """ Load labeling fields/columns. """ if self._dsName == "": self.cboLabelField.clear() return cols = table_column_names(self._dsName) spatialCols = table_column_names(self._dsName, True) spSet = set(spatialCols) nonSpatialCols = [c for c in cols if c not in spSet] if len(nonSpatialCols) == 0: return self.cboLabelField.clear() self.cboLabelField.addItem("") self.cboLabelField.addItems(nonSpatialCols)
def _loadFields(self): """ Load labeling fields/columns. """ if not self._dsName: self.cboLabelField.clear() return cols = table_column_names(self._dsName) spatialCols = table_column_names(self._dsName,True) spSet = set(spatialCols) nonSpatialCols = [c for c in cols if c not in spSet] if len(nonSpatialCols) == 0: return self.cboLabelField.clear() self.cboLabelField.addItem("") self.cboLabelField.addItems(nonSpatialCols)
def loadColumns(self,table): #Load textual and spatial (if available) columns #Get spatial columns first spColumns = table_column_names(table,True) self.cboSpatialCols_2.clear() self.cboSpatialCols_2.addItems(spColumns) #Textual Columns self.lstSrcCols_2.clear() self.allCols = table_column_names(table) for sc in spColumns: colIndex = getIndex(self.allCols,sc) if colIndex != -1: self.allCols.remove(sc) for col in self.allCols: tabItem = QListWidgetItem(col,self.lstSrcCols_2) tabItem.setCheckState(Qt.Unchecked) tabItem.setIcon(QIcon(":/plugins/stdm/images/icons/column.png")) self.lstSrcCols_2.addItem(tabItem) if len(spColumns) > 0: self.cboSpatialCols_2.setEnabled(True)
def loadTabFields(self,comboItemIndex): #Load the associated fields from specified table name if isinstance(comboItemIndex, str) or isinstance(comboItemIndex, unicode): comboItemIndex = self.comboBox.findData(comboItemIndex) if comboItemIndex == -1: QMessageBox.critical(self, QApplication.translate("ReportBuilder", "Report Error"), QApplication.translate("ReportBuilder","Table does not exist in the drop-down list")) return self.tabName = self.comboBox.itemData(comboItemIndex) self.tabFields = table_column_names(self.tabName) self.listWidget.addItems(self.tabFields) #Set table name in the Fields Query Builder self.lblSqlEntity.setText("Select * FROM " + self.tabName + " WHERE:")
def on_table_name_changed(self, table): """ Slot raised when table name changes so that the corresponding column names can be updated. :param table: Name of the current table :type table: str """ self.cbo_value_field.clear() self.cbo_x_field.clear() numeric_cols = numeric_columns(table) x_cols = table_column_names(table) self.cbo_value_field.addItems(numeric_cols) self.cbo_x_field.addItems(x_cols)
def _on_source_table_changed(self, index): source_table = self.cbo_source_tables.currentText() self.cbo_output_column.clear() if source_table: ref_table_cols = table_column_names(source_table) self.tb_source_trans_cols.set_combo_selection([self._source_cols, ref_table_cols]) #self.cbo_output_column.addItem("") self.cbo_output_column.addItems(ref_table_cols) else: self.tb_source_trans_cols.clear_view()
def _loadFields(self): """ Load spatial fields/columns of the given data source. """ if self._dsName == "": self.cboSpatialFields.clear() return spatialColumns = table_column_names(self._dsName, True) if len(spatialColumns) == 0: return self.cboSpatialFields.clear() self.cboSpatialFields.addItem("") self.cboSpatialFields.addItems(spatialColumns)
def _loadFields(self,dataSourceName): """ Load fields/columns of the given data source. """ if dataSourceName == "": self.cboDataField.clear() return columnsNames = table_column_names(dataSourceName) if len(columnsNames) == 0: return self.cboDataField.clear() self.cboDataField.addItem("") self.cboDataField.addItems(columnsNames)
def _loadFields(self): """ Load spatial fields/columns of the given data source. """ if self._dsName == "": self.cboSpatialFields.clear() return spatialColumns = table_column_names(self._dsName,True) if len(spatialColumns) == 0: return self.cboSpatialFields.clear() self.cboSpatialFields.addItem("") self.cboSpatialFields.addItems(spatialColumns)
def _loadFields(self, dataSourceName): """ Load fields/columns of the given data source. """ if dataSourceName == "": self.cboDataField.clear() return columnsNames = table_column_names(dataSourceName) if len(columnsNames) == 0: return self.cboDataField.clear() self.cboDataField.addItem("") self.cboDataField.addItems(columnsNames)
def load_data_source_fields(self, data_source_name): """ Load fields/columns of the given data source. """ if data_source_name == "": self.clear() return columns_names = table_column_names(data_source_name) if len(columns_names) == 0: return self.cbo_source_field.clear() self.cbo_source_field.addItem("") self.cbo_source_field.addItems(columns_names)
def assignCols(self): #Load source and target columns respectively srcCols=self.dataReader.getFields() for c in srcCols: srcItem = QListWidgetItem(c,self.lstSrcFields) srcItem.setCheckState(Qt.Unchecked) srcItem.setIcon(QIcon(":/plugins/stdm/images/icons/column.png")) self.lstSrcFields.addItem(srcItem) #Destination Columns tabIndex = int(self.field("tabIndex")) self.targetTab = self.destCheckedItem.text() targetCols = table_column_names(self.targetTab) #Remove geometry columns in the target columns list for gc in self.geomcols: colIndex = getIndex(targetCols,gc) if colIndex!=-1: targetCols.remove(gc) self.lstTargetFields.addItems(targetCols)
def _on_enum_table_changed(self, index): """ Slot raised when an enumeration table is selected. :param index: Index of currently selected item. :type index: int """ enum_table = self.cbo_enum_table.currentText() self.cbo_primary_col.clear() self.cbo_other_col.clear() self._enum_col_names = [] if enum_table: self._enum_col_names = table_column_names(enum_table) # Remove id column name id_col = "id" id_idx = getIndex(self._enum_col_names, id_col) if id_idx != -1: self._enum_col_names.remove(id_col) self.cbo_primary_col.addItem("") self.cbo_primary_col.addItems(self._enum_col_names)
def loadReportSettings(self,file): #Helper for restoring previously saved report settings #Deserialize report settings rptSerializer = ReportSerializer(file) rptValid, rptConf = rptSerializer.deserialize() #Validate if the object is an STDM Report Settings file if rptValid: #Check if the table exists tabExists = self._tableExists(rptConf.table) #QMessageBox.information(self, "List of tables", str(rptConf.table)) if tabExists: self.showhideProgressDialog(QApplication.translate("ReportBuilder","Restoring Report Settings...")) #friendlyTabName = self.tabNames[rptConf.table] friendlyTabName = rptConf.table #Force builder reset even if the loaded report refers to the previously loaded table if rptConf.table == self.tabName: self.tabChanged(friendlyTabName) else: self.tabName = rptConf.table #QMessageBox.information(self, "table name name", str(self.tabName)) #Set focus to report table in the drop down menu setComboCurrentIndexWithItemData(self.comboBox, friendlyTabName) #Validate the fields validTabFields = table_column_names(rptConf.table) validRptFields, invalidRptFields = compareLists(validTabFields, rptConf.fields) #Configure supporting controls self.loadSettings_activateControls(validRptFields) #Set filter statement self.txtSqlParser.setText(rptConf.filter) #Group order container gpInfoCollection =[] #Sort info container sortInfoCollection =[] #Iterate report elements for r in rptConf.reportElementCollection: if r.parent != "Groups": #Get corresponding widget and load the settings rptWidg = self.__displayGetStWidget(r.name) if not rptWidg == None: rptWidg.loadSettings(r.dialogSettings) #Set grouping and sorting configuration if r.parent == "Fields": gpInfo = r.uiConfiguration.groupingInfo if gpInfo != None: gpInfo.field = r.name gpInfoCollection.append(gpInfo) fieldSort = r.uiConfiguration.sortInfo if fieldSort.direction != SortDir.Null: fieldSort.field = r.name sortInfoCollection.append(fieldSort) #Sort GROUPINFO items using the order attribute then add fields to the report builder controls gpInfoCollection.sort(key=lambda g: g.order) for g in gpInfoCollection: groupDlg = self.grouping_addFieldByName(g.field) groupDlg.loadSettings(g.dialogSettings) #Order SORTINFO items using the order attribute then add fields to the report builder controls sortInfoCollection.sort(key=lambda s: s.order) for s in sortInfoCollection: sortItem = self.sorting_getFieldItem(s.field) if sortItem is not None: rowIndex = sortItem.row() dirCombo = self.tbSortFields.cellWidget(rowIndex,1) if s.direction == SortDir.Ascending: setComboCurrentIndexWithText(dirCombo, "Ascending") elif s.direction == SortDir.Descending: setComboCurrentIndexWithText(dirCombo, "Descending") #Show message of invalid fields if len(invalidRptFields) > 0: fieldsStr = ",".join(invalidRptFields) msg = QApplication.translate("ReportBuilder"," columns do not exist in the current table definition." "\nThey will not be included in the report") self.ErrorInfoMessage(fieldsStr + msg) else: self.showhideProgressDialog("", False) msg = QApplication.translate("ReportBuilder"," table or view does not exist in the database") self.ErrorInfoMessage(rptConf.table + msg) else: self.showhideProgressDialog("", False) fileName = str(file.section("/",-1)) msg = QApplication.translate("ReportBuilder"," is not a valid STDM Report Settings file.\n " "Please validate the source of the file") self.ErrorInfoMessage(fileName +msg ) self.showhideProgressDialog("", False)
def loadGeomCols(self,table): #Load geometry columns based on the selected table self.geomcols = table_column_names(table,True) self.geomClm.clear() self.geomClm.addItems(self.geomcols)
def draw_spatial_unit(self, model, clear_existing=True): """ Draw geometry of the given model in the respective local and web views. :param model: Source model whose geometry will be drawn. :type model: object :param clear_existing: Clears any existing features prior to adding the new features. :type clear_existing: bool """ if model is None: msg = QApplication.translate("SpatialPreview", "Data model is empty, the spatial " "unit cannot be rendered.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return table_name = model.__class__.__name__.replace(' ', '_').lower() if not pg_table_exists(table_name): msg = QApplication.translate("SpatialPreview", "The spatial unit data source could " "not be retrieved, the feature cannot " "be rendered.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return spatial_cols = table_column_names(table_name, True) geom, geom_col = None, "" for sc in spatial_cols: geom = getattr(model, sc) #Use the first non-empty geometry value in the collection if not geom is None: geom_col = sc if geom is None: msg = QApplication.translate("SpatialPreview", "The selected spatial unit does not " "contain a valid geometry.") QMessageBox.critical(self, QApplication.translate("SpatialPreview", "Spatial Unit Preview"), msg) return geom_type, epsg_code = geometryType(table_name, geom_col) if self._overlay_layer is None: self._create_vector_layer(geom_type, epsg_code) #Add layer to map QgsMapLayerRegistry.instance().addMapLayer(self._overlay_layer, False) #Ensure it is always added on top QgsProject.instance().layerTreeRoot().insertLayer(0, self._overlay_layer) if clear_existing: self.delete_local_features() feat, extent = self._add_geom_to_map(geom) #Add spatial unit to web viewer self._web_spatial_loader.add_overlay(model, geom_col) #Increase bounding box by 50%, so that layer slightly zoomed out extent.scale(1.5) #Select feature. Hack for forcing a selection by using inversion self._overlay_layer.invertSelection() self._iface.mapCanvas().setExtent(extent) self._iface.mapCanvas().refresh() self.refresh_canvas_layers() #Need to force event so that layer is shown QCoreApplication.sendEvent(self.local_map, QShowEvent())