本文整理汇总了Python中PyQt4.QtSql.QSqlTableModel.setTable方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlTableModel.setTable方法的具体用法?Python QSqlTableModel.setTable怎么用?Python QSqlTableModel.setTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtSql.QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel.setTable方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_model_to_table
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
def set_model_to_table(self, widget, table_name, filter_):
''' Set a model with selected filter.
Attach that model to selected table '''
# Set model
model = QSqlTableModel();
model.setTable(table_name)
model.setEditStrategy(QSqlTableModel.OnManualSubmit)
model.setFilter(filter_)
model.select()
# Check for errors
if model.lastError().isValid():
self.controller.show_warning(model.lastError().text())
# Attach model to table view
widget.setModel(model)
示例2: MainForm
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
class MainForm(QDialog):
def __init__(self):
super(MainForm, self).__init__()
self.model = QSqlTableModel(self)
self.model.setTable('tbl_symbols')
self.model.select()
self.view = QTableView()
self.view.setModel(self.model)
self.view.horizontalHeader().setResizeMode(QHeaderView.Stretch)
addButton = QPushButton("&Add")
deleteButton = QPushButton("&Delete")
buttonLayout = QVBoxLayout()
buttonLayout.addWidget(addButton)
buttonLayout.addWidget(deleteButton)
buttonLayout.addStretch()
lay = QHBoxLayout()
lay.addWidget(self.view)
lay.addLayout(buttonLayout)
self.setLayout(lay)
self.connect(addButton, SIGNAL("clicked()"), self.addRecord)
self.connect(deleteButton, SIGNAL("clicked()"), self.deleteRecord)
def addRecord(self):
row = self.model.rowCount()
self.model.insertRow(row)
index = self.model.index(row, 1)
self.view.setCurrentIndex(index)
self.view.edit(index)
def deleteRecord(self):
index = self.view.currentIndex()
if not index.isValid():
return
#QSqlDatabase.database().transaction()
record = self.model.record(index.row())
self.model.removeRow(index.row())
self.model.submitAll()
示例3: showTable
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
def showTable(self, table):
"""
Public slot to show the contents of a table.
@param table name of the table to be shown (string or QString)
"""
model = QSqlTableModel(self.table, self.connections.currentDatabase())
model.setEditStrategy(QSqlTableModel.OnRowChange)
model.setTable(table)
model.select()
if model.lastError().type() != QSqlError.NoError:
self.emit(SIGNAL("statusMessage(QString)"), model.lastError().text())
self.table.setModel(model)
self.table.setEditTriggers(
QAbstractItemView.DoubleClicked | QAbstractItemView.EditKeyPressed)
self.table.resizeColumnsToContents()
self.connect(self.table.selectionModel(),
SIGNAL("currentRowChanged(QModelIndex, QModelIndex)"),
self.updateActions)
self.updateActions()
示例4: ReferenceDataDlg
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
class ReferenceDataDlg(QDialog):
def __init__(self, table, title, parent=None):
super(ReferenceDataDlg, self).__init__(parent)
self.create_widgets(table)
self.layout_widgets()
self.create_connections()
self.setWindowTitle(
"Asset Manager - Edit {0} Reference Data".format(title))
def create_widgets(self, table):
self.model = QSqlTableModel(self)
self.model.setTable(table)
self.model.setSort(NAME, Qt.AscendingOrder)
self.model.setHeaderData(ID, Qt.Horizontal, QVariant("ID"))
self.model.setHeaderData(NAME, Qt.Horizontal, QVariant("Name"))
self.model.setHeaderData(DESCRIPTION, Qt.Horizontal,
QVariant("Description"))
self.model.select()
self.view = QTableView()
self.view.setModel(self.model)
self.view.setSelectionMode(QTableView.SingleSelection)
self.view.setSelectionBehavior(QTableView.SelectRows)
self.view.setColumnHidden(ID, True)
self.view.resizeColumnsToContents()
self.addButton = QPushButton("&Add")
self.deleteButton = QPushButton("&Delete")
self.okButton = QPushButton("&OK")
def layout_widgets(self):
buttonLayout = QHBoxLayout()
buttonLayout.addWidget(self.addButton)
buttonLayout.addWidget(self.deleteButton)
buttonLayout.addStretch()
buttonLayout.addWidget(self.okButton)
layout = QVBoxLayout()
layout.addWidget(self.view)
layout.addLayout(buttonLayout)
self.setLayout(layout)
def create_connections(self):
self.addButton.clicked.connect(self.addRecord)
self.deleteButton.clicked.connect(self.deleteRecord)
self.okButton.clicked.connect(self.accept)
def addRecord(self):
row = self.model.rowCount()
self.model.insertRow(row)
index = self.model.index(row, NAME)
self.view.setCurrentIndex(index)
self.view.edit(index)
def deleteRecord(self):
index = self.view.currentIndex()
if not index.isValid():
return
record = self.model.record(index.row())
id = record.value(ID).toInt()[0]
table = self.model.tableName()
query = QSqlQuery()
if table == "deps":
query.exec_(QString("SELECT COUNT(*) FROM employee "
"WHERE deo_id = %1").arg(id))
elif table == "cities":
query.exec_(QString("SELECT COUNT(*) FROM employee "
"WHERE city_id = %1").arg(id))
count = 0
if query.next():
count = query.value(0).toInt()[0]
if count:
QMessageBox.information(self,
QString("Delete %1").arg(table),
(QString("Cannot delete %1<br>"
"from the %2 table because it is used by "
"%3 records")
.arg(record.value(NAME).toString())
.arg(table).arg(count)))
return
self.model.removeRow(index.row())
self.model.submitAll()
示例5: StaffDataDlg
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
class StaffDataDlg(QDialog):
def __init__(self, parent=None):
super(StaffDataDlg, self).__init__(parent)
self.create_widgets()
self.layout_widgets()
self.create_connections()
self.setMinimumWidth(850)
self.setWindowTitle(u"Список сотрудников компании")
def create_widgets(self):
self.model = QSqlTableModel(self)
self.model.setTable("employee")
self.model.setSort(ID, Qt.AscendingOrder)
self.model.setHeaderData(ID, Qt.Horizontal, QVariant("ID"))
self.model.setHeaderData(CITY, Qt.Horizontal, QVariant("City"))
self.model.setHeaderData(DEPARTMENT, Qt.Horizontal, QVariant("Department"))
self.model.setHeaderData(FIRSTNAME, Qt.Horizontal, QVariant("First Name"))
self.model.setHeaderData(LASTNAME, Qt.Horizontal, QVariant("Last Name"))
self.model.setHeaderData(SEX, Qt.Horizontal, QVariant("sex"))
self.model.setHeaderData(ADDRESS, Qt.Horizontal, QVariant("Address"))
self.model.setHeaderData(PID, Qt.Horizontal, QVariant("PID"))
self.model.setHeaderData(TITLE, Qt.Horizontal, QVariant("Title"))
self.model.setHeaderData(SOLARY, Qt.Horizontal, QVariant("SOLARY"))
self.model.setHeaderData(SHIFT, Qt.Horizontal, QVariant("SHIFT"))
self.model.setHeaderData(HOURS, Qt.Horizontal, QVariant("HOURS"))
self.model.select()
self.view = QTableView()
self.view.setModel(self.model)
self.view.setSelectionMode(QTableView.SingleSelection)
self.view.setSelectionBehavior(QTableView.SelectRows)
self.view.setColumnHidden(ID, True)
self.view.resizeColumnsToContents()
self.buttonBox = QDialogButtonBox()
self.addButton = self.buttonBox.addButton(u"&Добавить", QDialogButtonBox.ActionRole)
self.deleteButton = self.buttonBox.addButton(u"&Удалить", QDialogButtonBox.ActionRole)
self.sortButton = self.buttonBox.addButton(u"&Сортировать", QDialogButtonBox.ActionRole)
menu = QMenu(self)
self.sortByTitleAction = menu.addAction(u"Сортировка по &Title")
self.sortBySolaryAction = menu.addAction(u"Сортировка по &SOLARY")
self.sortByIDAction = menu.addAction(u"Сортировка по &ID")
self.sortButton.setMenu(menu)
self.closeButton = self.buttonBox.addButton(QDialogButtonBox.Close)
def layout_widgets(self):
layout = QVBoxLayout()
layout.addWidget(self.view)
layout.addWidget(self.buttonBox)
self.setLayout(layout)
def create_connections(self):
self.addButton.clicked.connect(self.addRecord)
self.deleteButton.clicked.connect(self.deleteRecord)
self.closeButton.clicked.connect(self.accept)
def addRecord(self):
row = self.model.rowCount()
self.model.insertRow(row)
index = self.model.index(row, TITLE)
self.view.setCurrentIndex(index)
self.view.edit(index)
def deleteRecord(self):
index = self.view.currentIndex()
if not index.isValid():
return
record = self.model.record(index.row())
title = record.value(TITLE).toString()
desc = record.value(SOLARY).toString()
if (
QMessageBox.question(
self,
"Reference Data",
QString("Delete %1 from title %2?").arg(desc).arg(title),
QMessageBox.Yes | QMessageBox.No,
)
== QMessageBox.No
):
return
self.model.removeRow(index.row())
self.model.submitAll()
示例6: QuestionDlg
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
#.........这里部分代码省略.........
self.StudentModel.setFilter(strwhere)
self.StudentModel.setSort(2, Qt.AscendingOrder)
self.StudentModel.select()
self.g_curClassName = classname
self.tabWidget.setTabText(0, self.g_curClassName)
def dbclick2(self, indx):
if indx.column() == 2:
self.StudentView.setEditTriggers(QAbstractItemView.NoEditTriggers)
else:
self.StudentView.setEditTriggers(QAbstractItemView.DoubleClicked)
def genTwoTab(self, tabtitle=""):
# Create the tab title sytle.
tabtitle = QLabel()
tabtitle.setFont(QFont('Courier New', 20))
tabtitle.setText("班级学生信息管理")
tabtitle.setStyleSheet("border: 1px solid blue; color:rgba(0,0,255, 220);\
background-color:rgba(201,201,201,60);\
border-radius: 6px; \
padding: 1px 18px 1px 20px;\
min-width: 8em;")
tabtitle.setMinimumHeight(50);
titleLayout = QHBoxLayout()
titleLayout.addWidget(tabtitle)
titleLayout.setAlignment(tabtitle, Qt.AlignCenter)
# Create the classnameView
self.ClassnameView = QTableView()
self.ClassnameModel = QSqlTableModel(self.ClassnameView)
self.ClassnameModel.setTable("classtable")
# self.ClassnameModel.setRelation(2, QSqlRelation("mentalmodel", "id", "name"));
self.ClassnameModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
self.ClassnameModel.select()
self.ClassnameModel.setHeaderData(0, Qt.Horizontal, "班级名称")
# for indx, iheader in enumerate(["classid", "classname"]):
# self.ClassnameModel.setHeaderData(indx+1, Qt.Horizontal, iheader)
self.ClassnameView.setModel(self.ClassnameModel)
# self.ClassnameView.setColumnHidden(0, True)
# self.ClassnameView.show()
self.ClassnameView.verticalHeader().setFixedWidth(30)
self.ClassnameView.verticalHeader().setStyleSheet("color: red;font-size:20px; ");
self.ClassnameView.setStyleSheet("QTableView{background-color: rgb(250, 250, 200, 0);"
"alternate-background-color: rgb(141, 163, 0);}"
"QTableView::item:hover {background-color: rgba(100,200,220,100);} ")
self.ClassnameView.setStyleSheet("font-size:16px; ");
self.ClassnameView.setSelectionMode(QAbstractItemView.SingleSelection)
# self.ClassnameView.dataChanged.connect(self.dataChanged)
# self.ClassnameView.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
# the second list
self.StudentView = QTableView()
self.StudentModel = QSqlTableModel(self.StudentView)
self.StudentModel.setTable("student")
# self.StudentModel.setRelation(2, QSqlRelation("mentalmodel", "id", "name"));
self.StudentModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
# self.StudentModel.select()
query = QSqlQuery(self.db)
示例7: PlayerList
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
class PlayerList(QDialog):
"""QtSQL Model view of the players"""
def __init__(self, parent):
QDialog.__init__(self)
self.parent = parent
self.model = QSqlTableModel(self, DBHandle.default)
self.model.setEditStrategy(QSqlTableModel.OnManualSubmit)
self.model.setTable("player")
self.model.setSort(1, 0)
self.model.setHeaderData(1, Qt.Horizontal, QVariant(m18nc("Player", "Name")))
self.model.setFilter('name not like "ROBOT %" and name not like "Robot %"')
self.view = MJTableView(self)
self.view.verticalHeader().show()
self.view.setModel(self.model)
self.view.hideColumn(0)
self.buttonBox = QDialogButtonBox()
self.buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
self.newButton = self.buttonBox.addButton(m18nc('define a new player', "&New"), QDialogButtonBox.ActionRole)
self.newButton.setIcon(KIcon("document-new"))
self.newButton.clicked.connect(self.slotInsert)
self.deleteButton = self.buttonBox.addButton(m18n("&Delete"), QDialogButtonBox.ActionRole)
self.deleteButton.setIcon(KIcon("edit-delete"))
self.deleteButton.clicked.connect(self.delete)
cmdLayout = QHBoxLayout()
cmdLayout.addWidget(self.buttonBox)
layout = QVBoxLayout()
layout.addWidget(self.view)
layout.addLayout(cmdLayout)
self.setLayout(layout)
self.setWindowTitle(m18n("Players") + ' - Kajongg')
self.setObjectName('Players')
def showEvent(self, dummyEvent):
"""adapt view to content"""
if not self.model.select():
logError("PlayerList: select failed")
sys.exit(1)
self.view.initView()
StateSaver(self, self.view.horizontalHeader())
if not self.view.isColumnHidden(2):
# we loaded a kajonggrc written by an older kajongg version where this table
# still had more columns. This should happen only once.
self.view.hideColumn(2)
self.view.hideColumn(3)
def accept(self):
"""commit all modifications"""
self.view.selectRow(0) # if ALT-O is entered while editing a new row, this is one way
# to end editing and to pass the new value to the model
if not self.model.submitAll():
Sorry(m18n('Cannot save this. Possibly the name already exists. <br><br>' \
'Message from database:<br><br><message>%1</message>',
self.model.lastError().text()))
return
QDialog.accept(self)
def slotInsert(self):
"""insert a record"""
self.model.insertRow(self.model.rowCount())
self.view.selectRow(self.model.rowCount()-1)
def delete(self):
"""delete selected entries"""
sel = self.view.selectionModel()
maxDel = self.view.currentIndex().row() - 1
for idx in sel.selectedIndexes():
if idx.column() != 1:
continue
# sqlite3 does not enforce referential integrity.
# we could add a trigger to sqlite3 but if it raises an exception
# it will be thrown away silently.
# if anybody knows how to propagate sqlite3 exceptions via QtSql
# into python please tell me (wrohdewald)
player = self.model.createIndex(idx.row(), 0).data().toInt()[0]
# no query preparation, we don't expect lots of data
if Query("select 1 from game where p0==%d or p1==%d or p2==%d or p3==%d" % \
(player, player, player, player)).records:
Sorry(m18n('This player cannot be deleted. There are games associated with %1.',
idx.data().toString()))
else:
self.model.removeRow(idx.row())
maxDel = max(maxDel, idx.row())
self.view.selectRow(maxDel+1)
def keyPressEvent(self, event):
"""use insert/delete keys for insert/delete"""
key = event.key()
if key == Qt.Key_Insert:
self.slotInsert()
return
QDialog.keyPressEvent(self, event)
示例8: FilterDialog
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
class FilterDialog(QDialog, filterdialog_ui.Ui_FilterDialog):
def __init__(self, header=None, db=None, parent=None):
super(FilterDialog, self).__init__(parent)
self.setupUi(self)
self.dbi = ""
if not db:
filename = ":memory:"
self.dbi = QSqlDatabase.addDatabase("QSQLITE")
self.dbi.setDatabaseName(filename)
self.dbi.open()
self.creaStrutturaDB(header)
self.sModel = QSqlTableModel(self)
self.sModel.setTable(QString("filtertable"))
self.sModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
self.sModel.select()
self.filterTableView.setModel(self.sModel)
self.filterTableView.setColumnHidden(0, True)
self.filterTableView.setAlternatingRowColors(True)
self.connect(self.sModel, SIGNAL("primeInsert (int,QSqlRecord&)"),
self.updRows)
self.connect(self.addFilterPushButton, SIGNAL("clicked()"),
self.accept)
self.connect(self.addLinePushButton, SIGNAL("clicked()"),
self.addLine)
self.sModel.insertRows(0, 10)
self.sModel.submitAll()
self.restoreSettings()
self.resultFilter = None
def accept(self):
rows = self.sModel.rowCount()
cols = self.sModel.columnCount()
model = self.sModel
mlqry = dict()
qry = None
for r in range(rows):
record = model.record(r)
for c in range(1, cols):
if record.value(c).toString():
if not qry:
qry = "("
elif c > 1 and qry :
qry = "%s AND" % qry
qry = "%s %s %s" % (qry, record.fieldName(c),
record.value(c).toString())
if qry :
mlqry[r] = "%s )" % qry
qry = ""
for q in mlqry.keys():
if not qry:
qry = mlqry[q]
continue
qry = "%s OR %s" % (qry, mlqry[q])
self.resultFilter = qry
query = QSqlQuery()
query.exec_("DROP TABLE filtertable")
if self.dbi:
del self.dbi
QDialog.accept(self)
def addLine(self):
row = self.sModel.rowCount()
self.sModel.insertRows(row, 1)
self.sModel.submitAll()
def updRows(self, row, record):
totcolumn = record.count()
for i in range(1, totcolumn):
record.setValue(i, QVariant(""))
def creaStrutturaDB(self, header=None):
if not header:
sys.exit(1)
query = QSqlQuery()
query.exec_("DROP TABLE filtertable")
qry = """CREATE TABLE filtertable (
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL
"""
for column in header:
qry += ", %s" % column
qry += " )"
if not query.exec_(qry):
QMessageBox.warning(None, "FilterTable",
QString("Creazione tabella fallita!"))
sys.exit(1)
def restoreSettings(self):
settings = QSettings(QString(FILTERDLGORG),
QString(FILTERDLGAPP))
self.restoreGeometry(
#.........这里部分代码省略.........
示例9: MainWindow
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
#.........这里部分代码省略.........
QVariant(60)).toInt()[0]
self.sTableView.setColumnWidth(column,
width if width > 0 else 60)
def keyPressEvent(self, event):
if event.key() == Qt.Key_Down:
self.addDettRecord()
else:
QMainWindow.keyPressEvent(self, event)
def closeEvent(self, event):
self.mapper.submit()
settings = QSettings()
settings.setValue("MainWindow/Geometry", QVariant(
self.saveGeometry()))
if self.filename is not None:
settings.setValue("Settings/lastFile", QVariant(self.filename))
if self.db.isOpen():
# salva larghezza colonne tabella
for column in range(1, self.sModel.columnCount()-1):
width = self.sTableView.columnWidth(column)
if width:
settings.setValue("Settings/sTableView/%s" % column,
QVariant(width))
self.db.close()
del self.db
def setupModels(self):
"""
Initialize all the application models
"""
# setup slaveModel
self.sModel = QSqlTableModel(self)
self.sModel.setTable(QString("ddtslave"))
self.sModel.setHeaderData(SID, Qt.Horizontal, QVariant("ID"))
self.sModel.setHeaderData(SQT, Qt.Horizontal, QVariant("Qt"))
self.sModel.setHeaderData(SDESC, Qt.Horizontal, QVariant("Descrizione"))
self.sModel.setHeaderData(SMID, Qt.Horizontal, QVariant("idlegato"))
self.sModel.setEditStrategy(QSqlTableModel.OnRowChange)
self.sModel.select()
# setup masterModel
self.mModel = QSqlRelationalTableModel(self)
self.mModel.setTable(QString("ddtmaster"))
self.mModel.setSort(MDATA, Qt.AscendingOrder)
self.mModel.setRelation(MIDCLI, QSqlRelation("clienti",
"id", "ragsoc"))
self.mModel.select()
def setupMappers(self):
'''
Initialize all the application mappers
'''
self.mapper = QDataWidgetMapper(self)
self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit)
self.mapper.setModel(self.mModel)
self.mapper.setItemDelegate(QSqlRelationalDelegate(self))
self.mapper.addMapping(self.dateEdit, MDATA)
self.mapper.addMapping(self.ddtLineEdit, MDDT)
relationModel = self.mModel.relationModel(MIDCLI)
relationModel.setSort(CRAGSOC, Qt.AscendingOrder)
relationModel.select()
self.cliComboBox.setModel(relationModel)
self.cliComboBox.setModelColumn(relationModel.fieldIndex("ragsoc"))
self.mapper.addMapping(self.cliComboBox, MIDCLI)
self.mapper.addMapping(self.cauLineEdit, MCAU)
示例10: DatabaseInteraction
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
class DatabaseInteraction(object):
"""Handles all interactions with the database"""
def __init__(self, test=False):
if test:
filename = os.path.join(CONFIG_TEST_DATABASE_PATH, CONFIG_DATABASE_NAME)
else:
filename = os.path.join(CONFIG_DATABASE_PATH, CONFIG_DATABASE_NAME)
self.conn = QSqlDatabase.addDatabase("QSQLITE")
self.conn.setDatabaseName(filename)
result = self.conn.open()
# Check that the db opened successfully, close program if it didn't
# TODO: handle this better?
if result == False:
print "Failed to open database " + filename + \
" with error: " + self.conn.lastError().text()
sys.exit(1)
self.setupModels()
def setupModels(self):
# Participant
self.participantModel = QSqlTableModel(db=self.conn)
self.participantModel.setTable("participants")
self.participantModel.setSort(9, Qt.DescendingOrder)
self.participantModel.select()
# set headers
self.participantModel.setHeaderData(0, Qt.Horizontal, "First")
self.participantModel.setHeaderData(1, Qt.Horizontal, "Last")
self.participantModel.setHeaderData(2, Qt.Horizontal, "Address")
self.participantModel.setHeaderData(3, Qt.Horizontal, "Town")
self.participantModel.setHeaderData(4, Qt.Horizontal, "Postal Code")
self.participantModel.setHeaderData(5, Qt.Horizontal, "Home Phone")
self.participantModel.setHeaderData(6, Qt.Horizontal, "Cell Phone")
self.participantModel.setHeaderData(7, Qt.Horizontal, "Email")
self.participantModel.setHeaderData(9, Qt.Horizontal, "Date of Birth")
self.participantModel.setHeaderData(10, Qt.Horizontal, "School Attending")
self.participantModel.setHeaderData(11, Qt.Horizontal, "Parent")
self.participantModel.setHeaderData(12, Qt.Horizontal, "School Grade")
self.participantModel.setHeaderData(13, Qt.Horizontal, "Group Name")
self.participantModel.setHeaderData(14, Qt.Horizontal, "Group Size")
self.participantModel.setHeaderData(15, Qt.Horizontal, "Earliest Performance Time")
self.participantModel.setHeaderData(16, Qt.Horizontal, "Latest Performance Time")
self.participantModel.setHeaderData(17, Qt.Horizontal, "Participants") # TODO display names
self.participantModel.setHeaderData(18, Qt.Horizontal, "Average Age")
self.participantModel.setHeaderData(19, Qt.Horizontal, "Contact") # TODO display name
# TODO display first piece title for groups
# Teacher
self.teacherModel = QSqlTableModel(db=self.conn)
self.teacherModel.setTable("teachers")
self.teacherModel.setSort(0, Qt.DescendingOrder)
self.teacherModel.select()
# set headers
self.teacherModel.setHeaderData(1, Qt.Horizontal, "First")
self.teacherModel.setHeaderData(2, Qt.Horizontal, "Last")
self.teacherModel.setHeaderData(3, Qt.Horizontal, "Address")
self.teacherModel.setHeaderData(4, Qt.Horizontal, "Town")
self.teacherModel.setHeaderData(5, Qt.Horizontal, "Postal Code")
self.teacherModel.setHeaderData(6, Qt.Horizontal, "Daytime Phone")
self.teacherModel.setHeaderData(7, Qt.Horizontal, "Evening Phone")
self.teacherModel.setHeaderData(8, Qt.Horizontal, "Email")
# Entry
self.entryModel = QSqlTableModel(db=self.conn)
self.entryModel.setTable("entries")
self.entryModel.setSort(0, Qt.DescendingOrder)
self.entryModel.select()
# set headers
self.entryModel.setHeaderData(1, Qt.Horizontal, "Participant") # TODO display name
self.entryModel.setHeaderData(2, Qt.Horizontal, "Teacher") # TODO display name
self.entryModel.setHeaderData(3, Qt.Horizontal, "Discipline")
self.entryModel.setHeaderData(4, Qt.Horizontal, "Level")
self.entryModel.setHeaderData(5, Qt.Horizontal, "Class Number")
self.entryModel.setHeaderData(6, Qt.Horizontal, "Class Name")
self.entryModel.setHeaderData(7, Qt.Horizontal, "Instrument")
self.entryModel.setHeaderData(8, Qt.Horizontal, "Years of Instruction")
self.entryModel.setHeaderData(9, Qt.Horizontal, "Scheduling Requirements")
# Piece
self.pieceModel = QSqlTableModel(db=self.conn)
self.pieceModel.setTable("selections")
self.pieceModel.setSort(0, Qt.DescendingOrder)
self.pieceModel.select()
# set headers
self.pieceModel.setHeaderData(1, Qt.Horizontal, "Title")
self.pieceModel.setHeaderData(2, Qt.Horizontal, "Performance Time")
self.pieceModel.setHeaderData(3, Qt.Horizontal, "Composer/Arranger")
self.pieceModel.setHeaderData(5, Qt.Horizontal, "Title of Musical")
def close(self):
"""Clean everything up and close the connection"""
connName = self.conn.connectionName()
self.conn.close()
self.conn = QSqlDatabase()
self.conn.removeDatabase(connName)
global dbInteractionInstance
dbInteractionInstance = None
def backupDb(self):
#.........这里部分代码省略.........
示例11: MainWindow
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
#.........这里部分代码省略.........
settings.value("MainWindow/Geometry").toByteArray())
def restoreTablesSettings(self):
settings = QSettings(self)
# per la tablelview
for column in range(1, self.cModel.columnCount()-1):
width = settings.value("Settings/cTableView/%s" % column,
QVariant(60)).toInt()[0]
self.cTableView.setColumnWidth(column,
width if width > 0 else 60)
def closeEvent(self, event):
settings = QSettings()
settings.setValue("MainWindow/Geometry", QVariant(
self.saveGeometry()))
if self.filename is not None:
settings.setValue("Settings/lastFile", QVariant(self.filename))
if self.db.isOpen():
# salva larghezza colonne tabella
for column in range(1, self.cModel.columnCount()-1):
width = self.cTableView.columnWidth(column)
if width:
settings.setValue("Settings/cTableView/%s" % column,
QVariant(width))
self.db.close()
del self.db
def setupModels(self):
"""
Initialize all the application models
"""
# setup clientiModel
self.cModel = QSqlTableModel(self)
self.cModel.setTable(QString("clienti"))
self.cModel.setHeaderData(CID, Qt.Horizontal, QVariant("ID"))
self.cModel.setHeaderData(CRAGSOC, Qt.Horizontal, QVariant("RagSoc"))
self.cModel.setHeaderData(CIND, Qt.Horizontal, QVariant("Indirizzo"))
self.cModel.setHeaderData(CPIVA, Qt.Horizontal, QVariant("PIva"))
self.cModel.setHeaderData(CCF, Qt.Horizontal, QVariant("CF"))
self.cModel.setHeaderData(CTEL, Qt.Horizontal, QVariant("Tel"))
self.cModel.setHeaderData(CFAX, Qt.Horizontal, QVariant("Fax"))
self.cModel.setHeaderData(CCELL, Qt.Horizontal, QVariant("Cell"))
self.cModel.setHeaderData(CEMAIL, Qt.Horizontal, QVariant("Email"))
self.cModel.setHeaderData(CNOTE, Qt.Horizontal, QVariant("Note"))
self.cModel.select()
def setupTables(self):
"""
Initialize all the application tablesview
"""
self.cTableView.setModel(self.cModel)
self.cTableView.setItemDelegate(MyQSqlRelationalDelegate(self))
self.cTableView.setColumnHidden(CID, True)
self.cTableView.setWordWrap(True)
self.cTableView.resizeRowsToContents()
self.cTableView.setAlternatingRowColors(True)
self.cItmSelModel = QItemSelectionModel(self.cModel)
self.cTableView.setSelectionModel(self.cItmSelModel)
self.cTableView.setSelectionBehavior(QTableView.SelectRows)
self.cTableView.setSortingEnabled(True)
def updateFilter(self):
self.cModel.select()
self.cTableView.setColumnHidden(CID, True)
def applyFilter(self):
示例12: DataDialog
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
class DataDialog(QDialog):
def __init__(self, name, table, parent=None):
super(DataDialog, self).__init__(parent)
self.name = name
self.resize(600, 300)
self.model = QSqlTableModel(self)
self.model.setTable(table)
self.model.setSort(ID, Qt.AscendingOrder)
self.model.setHeaderData(ID, Qt.Horizontal, QVariant(_("Id")))
self.model.setHeaderData(EMAIL, Qt.Horizontal, QVariant(_("Email")))
self.model.setHeaderData(WWW, Qt.Horizontal, QVariant(_("WWW")))
self.model.setHeaderData(PACKAGE, Qt.Horizontal, QVariant(_("Package")))
self.model.select()
self.view = QTableView()
self.view.setModel(self.model)
self.view.setSelectionMode(QTableView.SingleSelection)
self.view.setSelectionBehavior(QTableView.SelectRows)
# self.view.setColumnHidden(ID, True)
# self.view.resizeColumnsToContents()
addButton = QPushButton(_("&Add"))
addButton.setIcon(QIcon(":/add.png"))
deleteButton = QPushButton(_("&Delete"))
deleteButton.setIcon(QIcon(":/delete.png"))
okButton = QPushButton(_("&OK"))
okButton.setIcon(QIcon(":/quit.png"))
addButton.setFocusPolicy(Qt.NoFocus)
deleteButton.setFocusPolicy(Qt.NoFocus)
buttonLayout = QHBoxLayout()
buttonLayout.addWidget(addButton)
buttonLayout.addWidget(deleteButton)
buttonLayout.addStretch()
buttonLayout.addWidget(okButton)
layout = QVBoxLayout()
layout.addWidget(self.view)
layout.addLayout(buttonLayout)
self.setLayout(layout)
self.connect(addButton, SIGNAL("clicked()"), self.addRecord)
self.connect(deleteButton, SIGNAL("clicked()"), self.deleteRecord)
self.connect(okButton, SIGNAL("clicked()"), self.accept)
self.setWindowTitle(name)
def addRecord(self):
row = self.model.rowCount()
self.model.insertRow(row)
index = self.model.index(row, EMAIL)
self.view.setCurrentIndex(index)
self.view.edit(index)
def deleteRecord(self):
index = self.view.currentIndex()
if not index.isValid():
return
self.model.removeRow(index.row())
self.model.submitAll()
def accept(self):
QDialog.accept(self)
示例13: MainWindow
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setTable [as 别名]
#.........这里部分代码省略.........
self.mapper.toFirst()
def setupTables(self):
"""
Initialize all the application tablesview
"""
self.sTableView.setModel(self.sModel)
self.sTableView.setItemDelegate(MSDelegate(self))
self.sTableView.setColumnHidden(ID, True)
self.sTableView.setColumnHidden(MMID, True)
self.sTableView.setWordWrap(True)
self.sTableView.resizeRowsToContents()
self.sTableView.setAlternatingRowColors(True)
self.sItmSelModel = QItemSelectionModel(self.sModel)
self.sTableView.setSelectionModel(self.sItmSelModel)
self.sTableView.setSelectionBehavior(QTableView.SelectRows)
#self.sTableView.setTabKeyNavigation(True)
self.fTableView.setModel(self.fModel)
self.fTableView.setColumnHidden(ID, True)
self.fTableView.setWordWrap(True)
self.fTableView.resizeRowsToContents()
self.fTableView.setAlternatingRowColors(True)
self.fItmSelModel = QItemSelectionModel(self.fModel)
self.fTableView.setSelectionModel(self.fItmSelModel)
def setupModels(self):
"""
Initialize all the application models
"""
# setup slaveModel
self.sModel = ssModel(self)
self.sModel.setTable(QString("magaslave"))
self.sModel.setHeaderData(ID, Qt.Horizontal, QVariant("ID"))
self.sModel.setHeaderData(DATAINS, Qt.Horizontal, QVariant("DataIns"))
self.sModel.setHeaderData(ABBI, Qt.Horizontal, QVariant("Abbi"))
self.sModel.setHeaderData(ANGRO, Qt.Horizontal, QVariant("Angro"))
self.sModel.setHeaderData(DESC, Qt.Horizontal, QVariant("Desc"))
self.sModel.setHeaderData(QT, Qt.Horizontal, QVariant("Qt"))
self.sModel.setHeaderData(IMP, Qt.Horizontal, QVariant("Imp"))
self.sModel.setHeaderData(EQUIV, Qt.Horizontal, QVariant("Equiv"))
self.sModel.setHeaderData(MMID, Qt.Horizontal, QVariant("ScaffId"))
self.sModel.setHeaderData(FATT, Qt.Horizontal, QVariant("Fatt"))
self.sModel.setHeaderData(NOTE, Qt.Horizontal, QVariant("Note"))
self.sModel.setSort(DATAINS, Qt.AscendingOrder)
self.sModel.setEditStrategy(QSqlTableModel.OnRowChange)
self.sModel.select()
# setup masterModel
self.mModel = QSqlTableModel(self)
self.mModel.setTable(QString("magamaster"))
self.mModel.setSort(SCAFF, Qt.AscendingOrder)
self.mModel.setHeaderData(ID, Qt.Horizontal, QVariant("ID"))
self.mModel.setHeaderData(SCAFF, Qt.Horizontal, QVariant("Scaff"))
self.mModel.select()
# setup findModel
self.fModel = QSqlRelationalTableModel(self)
self.fModel.setTable(QString("magaslave"))
self.fModel.setHeaderData(ID, Qt.Horizontal, QVariant("ID"))
self.fModel.setHeaderData(DATAINS, Qt.Horizontal, QVariant("DataIns"))
self.fModel.setHeaderData(ABBI, Qt.Horizontal, QVariant("Abbi"))
self.fModel.setHeaderData(ANGRO, Qt.Horizontal, QVariant("Angro"))
self.fModel.setHeaderData(DESC, Qt.Horizontal, QVariant("Desc"))
self.fModel.setHeaderData(QT, Qt.Horizontal, QVariant("Qt"))