⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3databrowser.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    nav(&Q3SqlCursor::last);}/*!    Moves the default cursor to the next record and refreshes the    default form to display this record. If there is no default form    or no default cursor, nothing happens. If the data browser    successfully navigated to the next record, the default cursor is    primed for update and the primeUpdate() signal is emitted.    If the browser is positioned on the last record nothing happens.*/void Q3DataBrowser::next(){    nav(&Q3SqlCursor::next);}/*!    Moves the default cursor to the previous record and refreshes the    default form to display this record. If there is no default form    or no default cursor, nothing happens. If the data browser    successfully navigated to the previous record, the default cursor    is primed for update and the primeUpdate() signal is emitted.    If the browser is positioned on the first record nothing happens.*/void Q3DataBrowser::prev(){    nav(&Q3SqlCursor::previous);}/*!    Reads the fields from the default cursor's edit buffer and    displays them in the form. If there is no default cursor or no    default form, nothing happens.*/void Q3DataBrowser::readFields(){    d->frm.readFields();}/*!    Writes the form's data to the default cursor's edit buffer. If    there is no default cursor or no default form, nothing happens.*/void Q3DataBrowser::writeFields(){    d->frm.writeFields();}/*!    Clears all the values in the form.    All the edit buffer field values are set to their 'zero state',    e.g. 0 for numeric fields and "" for string fields. Then the    widgets are updated using the property map. For example, a    combobox that is property-mapped to integers would scroll to the    first item. See the \l Q3SqlPropertyMap constructor for the default    mappings of widgets to properties.*/void Q3DataBrowser::clearValues(){    d->frm.clearValues();}/*!    Reads the fields from the default form into the default cursor and    performs an insert on the default cursor. If there is no default    form or no default cursor, nothing happens. If an error occurred    during the insert into the database, handleError() is called and    false is returned. If the insert was successfull, the cursor is    refreshed and relocated to the newly inserted record, the    cursorChanged() signal is emitted, and true is returned.    \sa cursorChanged() sqlCursor() form() handleError()*/bool Q3DataBrowser::insertCurrent(){    if (isReadOnly())        return false;    QSqlRecord* buf = d->frm.record();    Q3SqlCursor* cur = d->cur.cursor();    if (!buf || !cur)        return false;    writeFields();    emit beforeInsert(buf);    int ar = cur->insert();    if (!ar || !cur->isActive()) {        handleError(cur->lastError());        refresh();        updateBoundary();    } else {        refresh();        d->cur.findBuffer(cur->primaryIndex());        updateBoundary();        cursorChanged(Q3SqlCursor::Insert);        return true;    }    return false;}/*!    Reads the fields from the default form into the default cursor and    performs an update on the default cursor. If there is no default    form or no default cursor, nothing happens. If an error occurred    during the update on the database, handleError() is called and    false is returned. If the update was successfull, the cursor is    refreshed and relocated to the updated record, the cursorChanged()    signal is emitted, and true is returned.    \sa cursor() form() handleError()*/bool Q3DataBrowser::updateCurrent(){    if (isReadOnly())        return false;    QSqlRecord* buf = d->frm.record();    Q3SqlCursor* cur = d->cur.cursor();    if (!buf || !cur)        return false;    writeFields();    emit beforeUpdate(buf);    int ar = cur->update();    if (!ar || !cur->isActive()) {        handleError(cur->lastError());        refresh();        updateBoundary();    } else {        refresh();        d->cur.findBuffer(cur->primaryIndex());        updateBoundary();        cur->editBuffer(true);        cursorChanged(Q3SqlCursor::Update);        readFields();        return true;    }    return false;}/*!    Performs a delete on the default cursor using the values from the    default form and updates the default form. If there is no default    form or no default cursor, nothing happens. If the deletion was    successful, the cursor is repositioned to the nearest record and    true is returned. The nearest record is the next record if there    is one otherwise the previous record if there is one. If an error    occurred during the deletion from the database, handleError() is    called and false is returned.    \sa cursor() form() handleError()*/bool Q3DataBrowser::deleteCurrent(){    if (isReadOnly())        return false;    QSqlRecord* buf = d->frm.record();    Q3SqlCursor* cur = d->cur.cursor();    if (!buf || !cur)        return false;    writeFields();    int n = cur->at();    emit beforeDelete(buf);    int ar = cur->del();    if (ar) {        refresh();        updateBoundary();        cursorChanged(Q3SqlCursor::Delete);        if (!cur->seek(n))            last();        if (cur->isValid()) {            cur->editBuffer(true);            readFields();        } else {            clearValues();        }        return true;    } else {        if (!cur->isActive()) {            handleError(cur->lastError());            refresh();            updateBoundary();        }    }    return false;}/*!    Returns true if the form's edit buffer differs from the current    cursor buffer; otherwise returns false.*/bool Q3DataBrowser::currentEdited(){    QSqlRecord* buf = d->frm.record();    Q3SqlCursor* cur = d->cur.cursor();    if (!buf || !cur)        return false;    if (!cur->isActive() || !cur->isValid())        return false;    writeFields();    for (int i = 0; i < cur->count(); ++i) {        if (cur->value(i) != buf->value(i))            return true;    }    return false;}/*! \internal  Pre-navigation checking.*/bool Q3DataBrowser::preNav(){    QSqlRecord* buf = d->frm.record();    Q3SqlCursor* cur = d->cur.cursor();    if (!buf || !cur)        return false;    if (!isReadOnly() && autoEdit() && currentEdited()) {        bool ok = true;        QSql::Confirm conf = QSql::Yes;        switch (d->dat.mode()){        case QSql::Insert:            if (confirmInsert())                conf = confirmEdit(QSql::Insert);            switch (conf) {            case QSql::Yes:                ok = insertCurrent();                d->dat.setMode(QSql::Update);                break;            case QSql::No:                d->dat.setMode(QSql::Update);                break;            case QSql::Cancel:                return false;            }            break;        default:            if (confirmUpdate())                conf = confirmEdit(QSql::Update);            switch (conf) {            case QSql::Yes:                ok = updateCurrent();                break;            case QSql::No:                break;            case QSql::Cancel:                return false;            }        }        return ok;    }    return true;}/*! \internal  Handles post-navigation according to \a primeUpd.*/void Q3DataBrowser::postNav(bool primeUpd){    if (primeUpd) {        QSqlRecord* buf = d->frm.record();        Q3SqlCursor* cur = d->cur.cursor();        if (!buf || !cur)            return;        currentChanged(cur);        cur->primeUpdate();        emit primeUpdate(buf);        readFields();    }    updateBoundary();}/*! \internal  Navigate default cursor according to \a nav. Handles autoEdit.*/void Q3DataBrowser::nav(Nav nav){    int b = 0;    Q3SqlCursor* cur = d->cur.cursor();    if (!cur)        return;    if (preNav())        b = (cur->*nav)();    postNav(b);}/*!    If boundaryChecking() is true, checks the boundary of the current    default cursor and emits signals which indicate the position of    the cursor.*/void Q3DataBrowser::updateBoundary(){    if (d->boundaryCheck) {        Boundary bound = boundary();        switch (bound) {        case Unknown:        case None:            emit firstRecordAvailable(true);            emit prevRecordAvailable(true);            emit nextRecordAvailable(true);            emit lastRecordAvailable(true);            break;        case BeforeBeginning:            emit firstRecordAvailable(false);            emit prevRecordAvailable(false);            emit nextRecordAvailable(true);            emit lastRecordAvailable(true);            break;        case Beginning:            emit firstRecordAvailable(false);            emit prevRecordAvailable(false);            emit nextRecordAvailable(true);            emit lastRecordAvailable(true);            break;        case End:            emit firstRecordAvailable(true);            emit prevRecordAvailable(true);            emit nextRecordAvailable(false);            emit lastRecordAvailable(false);            break;        case AfterEnd:            emit firstRecordAvailable(true);            emit prevRecordAvailable(true);            emit nextRecordAvailable(false);            emit lastRecordAvailable(false);            break;        }    }}/*!    Virtual function which handles the error \a error. The default    implementation warns the user with a message box.*/void Q3DataBrowser::handleError(const QSqlError& error){    d->dat.handleError(this, error);}/*!    Protected virtual function which returns a confirmation for an    edit of mode \a m. Derived classes can reimplement this function    and provide their own confirmation dialog. The default    implementation uses a message box which prompts the user to    confirm the edit action.*/QSql::Confirm Q3DataBrowser::confirmEdit(QSql::Op m){    return d->dat.confirmEdit(this, m);}/*!    Protected virtual function which returns a confirmation for    cancelling an edit mode \a m. Derived classes can reimplement this    function and provide their own confirmation dialog. The default    implementation uses a message box which prompts the user to    confirm the edit action.*/QSql::Confirm  Q3DataBrowser::confirmCancel(QSql::Op m){    return d->dat.confirmCancel(this, m);}/*!    \fn void Q3DataBrowser::beforeInsert(QSqlRecord* buf)    This signal is emitted just before the cursor's edit buffer is    inserted into the database. The \a buf parameter points to the    edit buffer being inserted. You might connect to this signal to    populate a generated primary key for example.*//*!    \fn void Q3DataBrowser::beforeUpdate(QSqlRecord* buf)    This signal is emitted just before the cursor's edit buffer is    updated in the database. The \a buf parameter points to the edit    buffer being updated. You might connect to this signal to capture    some auditing information about the update.*//*!    \fn void Q3DataBrowser::beforeDelete(QSqlRecord* buf)    This signal is emitted just before the cursor's edit buffer  is    deleted from the database. The \a buf parameter points to the edit    buffer being deleted. You might connect to this signal to capture    some auditing information about the deletion.*/#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -