def __init__(self, table, parent_view): AbstractReferenceListModel.__init__(self, table, parent_view) self._columns = [("id", ''), ("type_id", ''), ("name", self.tr("Name")), ("currency_id", self.tr("Currency")), ("active", self.tr("Act.")), ("number", self.tr("Account #")), ("reconciled_on", self.tr("Reconciled @")), ("organization_id", self.tr("Bank/Broker")), ("country_id", self.tr("CC"))] self._sort_by = "name" self._group_by = "type_id" self._hidden = ["id", "type_id"] self._stretch = "name" self._lookup_delegate = None self._peer_delegate = None self._timestamp_delegate = None self._bool_delegate = None self._default_values = { 'active': 1, 'reconciled_on': 0, 'country_id': 0 } self.setRelation(self.fieldIndex("type_id"), QSqlRelation("account_types", "id", "name")) self.setRelation(self.fieldIndex("currency_id"), QSqlRelation("currencies", "id", "symbol")) self.setRelation(self.fieldIndex("country_id"), QSqlRelation("countries", "id", "code"))
def __init__(self, table, parent_view): AbstractReferenceListModel.__init__(self, table, parent_view) pk = QSqlIndex( ) # Manual primary key setup is required as we use underlying sql view instead of sql table pk.append(self.record().field("id")) self.setPrimaryKey(pk) self._columns = [("id", ''), ("type_id", ''), ("symbol", self.tr("Symbol")), ("full_name", self.tr("Name")), ("isin", self.tr("ISIN")), ("currency_id", self.tr("Currency")), ("country_id", self.tr("Country")), ("quote_source", self.tr("Data source"))] self._default_name = "symbol" self._sort_by = "symbol" self._group_by = "type_id" self._hidden = ["id", "type_id"] self._stretch = "full_name" self._lookup_delegate = None self._timestamp_delegate = None self._default_values = { 'isin': '', 'country_id': 0, 'quote_source': -1 } self.setRelation(self.fieldIndex("type_id"), QSqlRelation("asset_types", "id", "name")) self.setRelation(self.fieldIndex("currency_id"), QSqlRelation("currencies", "id", "symbol")) self.setRelation(self.fieldIndex("country_id"), QSqlRelation("countries", "id", "name")) self.setRelation(self.fieldIndex("quote_source"), QSqlRelation("data_sources", "id", "name"))
def __init__(self, table, parent_view): AbstractReferenceListModel.__init__(self, table, parent_view) self._columns = [("id", ''), ("timestamp", self.tr("Date")), ("asset_id", self.tr("Asset")), ("quote", self.tr("Quote"))] self._hidden = ["id"] self._default_name = "quote" self._lookup_delegate = None self._timestamp_delegate = None self.setRelation(self.fieldIndex("asset_id"), QSqlRelation("assets", "id", "name"))
def __init__(self, table, parent_view): AbstractReferenceListModel.__init__(self, table, parent_view) self._columns = [("id", ''), ("name", self.tr("Symbol")), ("type_id", ''), ("full_name", self.tr("Name")), ("isin", self.tr("ISIN")), ("country_id", self.tr("Country")), ("src_id", self.tr("Data source")), ("expiry", self.tr("Expiry"))] self._sort_by = "name" self._group_by = "type_id" self._hidden = ["id", "type_id"] self._stretch = "full_name" self._lookup_delegate = None self._timestamp_delegate = None self.setRelation(self.fieldIndex("type_id"), QSqlRelation("asset_types", "id", "name")) self.setRelation(self.fieldIndex("country_id"), QSqlRelation("countries", "id", "name")) self.setRelation(self.fieldIndex("src_id"), QSqlRelation("data_sources", "id", "name"))
def __init__(self, table, parent_view): AbstractReferenceListModel.__init__(self, table, parent_view) self._columns = [("id", ''), ("asset_id", ''), ("symbol", self.tr("Symbol")), ("currency_id", self.tr("Currency")), ("description", self.tr("Description")), ("quote_source", self.tr("Quotes")), ("active", self.tr("Act."))] self._default_name = "symbol" self._sort_by = "symbol" self._hidden = ["id", "asset_id"] self._stretch = "description" self._lookup_delegate = None self._bool_delegate = None self._default_values = { 'description': '', 'currency_id': 1, 'quote_source': -1, 'active': 1 } self.setRelation(self.fieldIndex("currency_id"), QSqlRelation("currencies", "id", "symbol")) self.setRelation(self.fieldIndex("quote_source"), QSqlRelation("data_sources", "id", "name"))
def __init__(self): QMainWindow.__init__(self) self.setupUi(self) #Initialize db createdb.init_db() model = QSqlRelationalTableModel(self.bookTable) model.setEditStrategy(QSqlTableModel.OnManualSubmit) model.setTable("books") # Remember the indexes of the columns: author_idx = model.fieldIndex("author") genre_idx = model.fieldIndex("genre") # Set the relations to the other database tables: model.setRelation(author_idx, QSqlRelation("authors", "id", "name")) model.setRelation(genre_idx, QSqlRelation("genres", "id", "name")) # Set the localized header captions: model.setHeaderData(author_idx, Qt.Horizontal, self.tr("Author Name")) model.setHeaderData(genre_idx, Qt.Horizontal, self.tr("Genre")) model.setHeaderData(model.fieldIndex("title"), Qt.Horizontal, self.tr("Title")) model.setHeaderData(model.fieldIndex("year"), Qt.Horizontal, self.tr("Year")) model.setHeaderData(model.fieldIndex("rating"), Qt.Horizontal, self.tr("Rating")) if not model.select(): print(model.lastError()) # Set the model and hide the ID column: self.bookTable.setModel(model) self.bookTable.setItemDelegate(BookDelegate(self.bookTable)) self.bookTable.setColumnHidden(model.fieldIndex("id"), True) self.bookTable.setSelectionMode(QAbstractItemView.SingleSelection) # Initialize the Author combo box: self.authorEdit.setModel(model.relationModel(author_idx)) self.authorEdit.setModelColumn( model.relationModel(author_idx).fieldIndex("name")) self.genreEdit.setModel(model.relationModel(genre_idx)) self.genreEdit.setModelColumn( model.relationModel(genre_idx).fieldIndex("name")) # Lock and prohibit resizing of the width of the rating column: self.bookTable.horizontalHeader().setSectionResizeMode( model.fieldIndex("rating"), QHeaderView.ResizeToContents) mapper = QDataWidgetMapper(self) mapper.setModel(model) mapper.setItemDelegate(BookDelegate(self)) mapper.addMapping(self.titleEdit, model.fieldIndex("title")) mapper.addMapping(self.yearEdit, model.fieldIndex("year")) mapper.addMapping(self.authorEdit, author_idx) mapper.addMapping(self.genreEdit, genre_idx) mapper.addMapping(self.ratingEdit, model.fieldIndex("rating")) selection_model = self.bookTable.selectionModel() selection_model.currentRowChanged.connect(mapper.setCurrentModelIndex) self.bookTable.setCurrentIndex(model.index(0, 0)) self.create_menubar()