def _get_widget_factory(self, entity): """ Get widget factory for specific column type :param entity: Current column entity object :type entity: Entity :return c: Column object corresponding to the widget factory :rtype c: BaseColumn :return col_factory: Widget factory corresponding to the column type :rtype col_factory: ColumnWidgetRegistry """ for c in entity.columns.values(): col_factory = ColumnWidgetRegistry.factory(c.TYPE_INFO) if col_factory is not None: yield c, col_factory(c)
def format_columns(self, entity=None): if entity is None: entity = self._entity if entity is None: return for col in entity.columns.values(): col_name = col.name # Get widget factory so that we can use the value formatter widget_factory = ColumnWidgetRegistry.factory( col.TYPE_INFO ) if not widget_factory is None: formatter = widget_factory(col) self.column_formatter[col_name] = formatter
def _init_entity_columns(self): """ Asserts if the entity columns actually do exist in the database. The method also initializes the table headers, entity column and cell formatters. """ self._headers[:] = [] table_name = self._entity.name columns = table_column_names(table_name) missing_columns = [] header_idx = 0 #Iterate entity column and assert if they exist for c in self._entity.columns.values(): # Exclude geometry columns if isinstance(c, GeometryColumn): continue #Do not include virtual columns in list of missing columns if not c.name in columns and not isinstance(c, VirtualColumn): missing_columns.append(c.name) else: header = c.ui_display() self._headers.append(header) col_name = c.name ''' If it is a virtual column then use column name as the header but fully qualified column name (created by SQLAlchemy relationship) as the entity attribute name. ''' if isinstance(c, MultipleSelectColumn): col_name = c.model_attribute_name self._entity_attrs.append(col_name) # Get widget factory so that we can use the value formatter w_factory = ColumnWidgetRegistry.factory(c.TYPE_INFO) if not w_factory is None: formatter = w_factory(c) self._cell_formatters[col_name] = formatter #Set searchable columns if c.searchable: self._searchable_columns[c.ui_display()] = { 'name': c.name, 'header_index': header_idx } header_idx += 1 if len(missing_columns) > 0: msg = QApplication.translate( 'EntityBrowser', u'The following columns have been defined in the ' u'configuration but are missing in corresponding ' u'database table, please re-run the configuration wizard ' u'to create them.\n{0}'.format('\n'.join(missing_columns))) QMessageBox.warning( self, QApplication.translate('EntityBrowser', 'Entity Browser'), msg)
def _init_fk_columns(self): """ Asserts if the entity columns actually do exist in the database. The method also initializes the table headers, entity column and cell formatters. """ self._headers[:] = [] self._entity_attrs[:] = [] if self._dbmodel is None: msg = QApplication.translate( 'ForeignKeyMapper', 'The data model for ' 'the entity could ' 'not be loaded, ' 'please contact ' 'your database ' 'administrator.') QMessageBox.critical( self, QApplication.translate('EntityBrowser', 'Entity Browser'), msg) return table_name = self._entity.name columns = table_column_names(table_name) missing_columns = [] header_idx = 0 # Iterate entity column and assert if they exist for c in self._entity.columns.values(): # Do not include virtual columns in list of missing columns if not c.name in columns and not isinstance(c, VirtualColumn): missing_columns.append(c.name) else: header = c.header() self._headers.append(header) ''' If it is a virtual column then use column name as the header but fully qualified column name (created by SQLAlchemy relationship) as the entity attribute name. ''' col_name = c.name if isinstance(c, MultipleSelectColumn): col_name = c.model_attribute_name self._entity_attrs.append(col_name) # Get widget factory so that we can use the value formatter w_factory = ColumnWidgetRegistry.factory(c.TYPE_INFO) if not w_factory is None: try: formatter = w_factory(c) self._cell_formatters[col_name] = formatter except WidgetException as we: msg = QApplication.translate( 'ForeignKeyMapper', 'Error in creating column:') msg = '{0} {1}:{2}\n{3}'.format( msg, self._entity.name, c.name, str(we)) QMessageBox.critical( self, QApplication.translate('ForeignKeyMapper', 'Widget Creation Error'), msg) # Set searchable columns if c.searchable: self._searchable_columns[header] = { 'name': c.name, 'header_index': header_idx } header_idx += 1 if len(missing_columns) > 0: msg = QApplication.translate( 'ForeignKeyMapper', 'The following columns have been defined in the ' 'configuration but are missing in corresponding ' 'database table, please re-run the configuration wizard ' 'to create them.\n{0}'.format('\n'.join(missing_columns))) QMessageBox.warning( self, QApplication.translate('ForeignKeyMapper', 'Entity Browser'), msg) self._tableModel = BaseSTDMTableModel([], self._headers, self) self._tbFKEntity.setModel(self._tableModel) # First (id) column will always be hidden self._tbFKEntity.hideColumn(0) self._tbFKEntity.horizontalHeader().setSectionResizeMode( QHeaderView.Interactive) self._tbFKEntity.horizontalHeader().setStretchLastSection(True) self._tbFKEntity.verticalHeader().setVisible(True)
def _init_fk_columns(self): """ Asserts if the entity columns actually do exist in the database. The method also initializes the table headers, entity column and cell formatters. """ self._headers[:] = [] self._entity_attrs[:] = [] if self._dbmodel is None: msg = QApplication.translate( 'ForeignKeyMapper', 'The data model for ' 'the entity could ' 'not be loaded, ' 'please contact ' 'your database ' 'administrator.' ) QMessageBox.critical( self, QApplication.translate( 'EntityBrowser', 'Entity Browser' ), msg ) return table_name = self._entity.name columns = table_column_names(table_name) missing_columns = [] header_idx = 0 #Iterate entity column and assert if they exist for c in self._entity.columns.values(): #Do not include virtual columns in list of missing columns if not c.name in columns and not isinstance(c, VirtualColumn): missing_columns.append(c.name) else: header = c.header() self._headers.append(header) ''' If it is a virtual column then use column name as the header but fully qualified column name (created by SQLAlchemy relationship) as the entity attribute name. ''' col_name = c.name if isinstance(c, MultipleSelectColumn): col_name = c.model_attribute_name self._entity_attrs.append(col_name) #Get widget factory so that we can use the value formatter w_factory = ColumnWidgetRegistry.factory(c.TYPE_INFO) if not w_factory is None: try: formatter = w_factory(c) self._cell_formatters[col_name] = formatter except WidgetException as we: msg = QApplication.translate( 'ForeignKeyMapper', 'Error in creating column:' ) msg = '{0} {1}:{2}\n{3}'.format( msg, self._entity.name, c.name, unicode(we) ) QMessageBox.critical( self, QApplication.translate( 'ForeignKeyMapper', 'Widget Creation Error' ), msg ) #Set searchable columns if c.searchable: self._searchable_columns[header] = { 'name': c.name, 'header_index': header_idx } header_idx += 1 if len(missing_columns) > 0: msg = QApplication.translate( 'ForeignKeyMapper', u'The following columns have been defined in the ' u'configuration but are missing in corresponding ' u'database table, please re-run the configuration wizard ' u'to create them.\n{0}'.format( '\n'.join(missing_columns) ) ) QMessageBox.warning( self, QApplication.translate('ForeignKeyMapper','Entity Browser'), msg ) self._tableModel = BaseSTDMTableModel([], self._headers, self) self._tbFKEntity.setModel(self._tableModel) self._tbFKEntity.resizeColumnsToContents() #First (id) column will always be hidden self._tbFKEntity.hideColumn(0) self._tbFKEntity.horizontalHeader().setResizeMode( QHeaderView.Interactive ) self._tbFKEntity.verticalHeader().setVisible(True)
def _init_entity_columns(self): """ Asserts if the entity columns actually do exist in the database. The method also initializes the table headers, entity column and cell formatters. """ self._headers[:] = [] table_name = self._entity.name columns = table_column_names(table_name) missing_columns = [] header_idx = 0 #Iterate entity column and assert if they exist for c in self._entity.columns.values(): # Exclude geometry columns if isinstance(c, GeometryColumn): continue # Do not include virtual columns in list of missing columns if not c.name in columns and not isinstance(c, VirtualColumn): missing_columns.append(c.name) else: header = c.ui_display() self._headers.append(header) col_name = c.name ''' If it is a virtual column then use column name as the header but fully qualified column name (created by SQLAlchemy relationship) as the entity attribute name. ''' if isinstance(c, MultipleSelectColumn): col_name = c.model_attribute_name self._entity_attrs.append(col_name) # Get widget factory so that we can use the value formatter w_factory = ColumnWidgetRegistry.factory(c.TYPE_INFO) if not w_factory is None: formatter = w_factory(c) self._cell_formatters[col_name] = formatter # Set searchable columns if c.searchable: self._searchable_columns[c.ui_display()] = { 'name': c.name, 'header_index': header_idx } header_idx += 1 if len(missing_columns) > 0: msg = QApplication.translate( 'EntityBrowser', u'The following columns have been defined in the ' u'configuration but are missing in corresponding ' u'database table, please re-run the configuration wizard ' u'to create them.\n{0}'.format( '\n'.join(missing_columns) ) ) QMessageBox.warning( self, QApplication.translate('EntityBrowser','Entity Browser'), msg )