From: Drew Fisher Date: Sun, 5 Jul 2009 07:29:50 +0000 (-0500) Subject: Add table view in edit mode. X-Git-Url: http://git.zarvox.org/shortlog/static/%7Bgravatar%7D?a=commitdiff_plain;h=6a8f19ab1af065ab978c369442d59c6cdef32246;p=wp3.git Add table view in edit mode. Change database schema so that first name appears first in QTableView. No data connections yet for editor. TODO. --- diff --git a/editperson.py b/editperson.py index 53808e5..7cf924d 100644 --- a/editperson.py +++ b/editperson.py @@ -1,10 +1,31 @@ from PyQt4.QtCore import * from PyQt4.QtGui import * +from PyQt4.QtSql import * class EditPerson(QDialog): def __init__(self, parent=None, db=None): QDialog.__init__(self,parent) self.db = db + + self.model = QSqlTableModel(self, self.db) + self.model.setEditStrategy(QSqlTableModel.OnManualSubmit) + self.model.setTable("people") + self.model.select() + self.model.setHeaderData(self.model.fieldIndex("forename"), Qt.Horizontal, QVariant("First Name")) + self.model.setHeaderData(self.model.fieldIndex("surname"), Qt.Horizontal, QVariant("Last Name")) + + self.tableview = QTableView(self) + self.tableview.setSelectionBehavior(QAbstractItemView.SelectRows) + self.tableview.setSelectionMode(QAbstractItemView.SingleSelection) + self.tableview.setEditTriggers(QAbstractItemView.NoEditTriggers) + self.tableview.setModel(self.model) + + for i in xrange(self.model.columnCount()): + self.tableview.hideColumn(i) + self.tableview.showColumn(self.model.fieldIndex("forename")) + self.tableview.showColumn(self.model.fieldIndex("surname")) + self.tableview.resizeColumnsToContents() + self.setWindowTitle("Edit records") self.toplayout = QHBoxLayout() # Master layout @@ -15,9 +36,8 @@ class EditPerson(QDialog): self.searchpair = QHBoxLayout() self.searchpair.addWidget(self.search_label) self.searchpair.addWidget(self.search_bar) - self.persontable = QLabel("
Table of people goes here
") self.leftpanel.addLayout(self.searchpair) - self.leftpanel.addWidget(self.persontable) + self.leftpanel.addWidget(self.tableview) self.rightpanel = QVBoxLayout() # Contains fields and buttons self.setupForm() @@ -151,6 +171,7 @@ class EditPerson(QDialog): self.pb_save.setEnabled(True) self.pb_saveclose.setEnabled(True) def updateTable(self): + self.model.select() print "Text changed" def resetPressed(self): self.fillForm([]) diff --git a/mainapp.py b/mainapp.py index 85c78a6..6a5674a 100644 --- a/mainapp.py +++ b/mainapp.py @@ -5,7 +5,7 @@ from PyQt4.QtSql import * from chooseaction import ChooseAction class MainApp (QMainWindow): - schema = "CREATE TABLE people ( id INTEGER PRIMARY KEY AUTOINCREMENT, netid TEXT NOT NULL, surname TEXT NOT NULL, forename TEXT NOT NULL, email TEXT, birthday TEXT, phone TEXT, major TEXT, dorm TEXT, room INTEGER, photo BLOB, createtime TEXT NOT NULL, mtime TEXT NOT NULL);" + schema = "CREATE TABLE people ( id INTEGER PRIMARY KEY AUTOINCREMENT, forename TEXT NOT NULL, surname TEXT NOT NULL, netid TEXT NOT NULL, email TEXT, birthday TEXT, phone TEXT, major TEXT, dorm TEXT, room INTEGER, photo BLOB, createtime TEXT NOT NULL, mtime TEXT NOT NULL);" def __init__(self, Parent=None): QMainWindow.__init__(self, Parent) self.setWindowTitle("Whitepages V3")