当前位置: 首页>>代码示例>>Python>>正文


Python QSqlTableModel.insertRows方法代码示例

本文整理汇总了Python中PyQt4.QtSql.QSqlTableModel.insertRows方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlTableModel.insertRows方法的具体用法?Python QSqlTableModel.insertRows怎么用?Python QSqlTableModel.insertRows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtSql.QSqlTableModel的用法示例。


在下文中一共展示了QSqlTableModel.insertRows方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FilterDialog

# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import insertRows [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(
#.........这里部分代码省略.........
开发者ID:L0cutus,项目名称:Gestione-Magazzino,代码行数:103,代码来源:filterdialog.py


注:本文中的PyQt4.QtSql.QSqlTableModel.insertRows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。