]> git.zarvox.org Git - wp3.git/commitdiff
Add table view in edit mode.
authorDrew Fisher <drew.m.fisher@gmail.com>
Sun, 5 Jul 2009 07:29:50 +0000 (02:29 -0500)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sun, 5 Jul 2009 07:29:50 +0000 (02:29 -0500)
Change database schema so that first name appears first in QTableView.
No data connections yet for editor.  TODO.

editperson.py
mainapp.py

index 53808e5d11cfebf4fe43e5feb1afae1b78ed814e..7cf924dc2f67f82dddeec980c30cb0d02402ae71 100644 (file)
@@ -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("<center>Table of people goes here</center>")
                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([])
index 85c78a6b3fd194fd71790ed5e976abd9e3e64a24..6a5674a904895cde84b78e4ec9e06ffbfdab1ee5 100644 (file)
@@ -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")