Q3DataBrowser Class Reference

#include <q3databrowser.h>

Inheritance diagram for Q3DataBrowser:

Inheritance graph
[legend]
Collaboration diagram for Q3DataBrowser:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Q3DataBrowser class provides data manipulation and navigation for data entry forms.

A high-level API is provided for navigating through data records in a cursor, for inserting, updating and deleting records, and for refreshing data in the display.

If you want a read-only form to present database data use Q3DataView; if you want a table-based presentation of your data use Q3DataTable.

A Q3DataBrowser is used to associate a dataset with a form in much the same way as a Q3DataTable associates a dataset with a table. Once the data browser has been constructed it can be associated with a dataset with setSqlCursor(), and with a form with setForm(). Boundary checking, sorting and filtering can be set with setBoundaryChecking(), setSort() and setFilter(), respectively.

The insertCurrent() function reads the fields from the default form into the default cursor and performs the insert. The updateCurrent() and deleteCurrent() functions perform similarly to update and delete the current record respectively.

The user can be asked to confirm all edits with setConfirmEdits(). For more precise control use setConfirmInsert(), setConfirmUpdate(), setConfirmDelete() and setConfirmCancels(). Use setAutoEdit() to control the behavior of the form when the user edits a record and then navigates.

The record set is navigated using first(), next(), prev(), last() and seek(). The form's display is updated with refresh(). When navigation takes place the firstRecordAvailable(), lastRecordAvailable(), nextRecordAvailable() and prevRecordAvailable() signals are emitted. When the cursor record is changed due to navigation the cursorChanged() signal is emitted.

If you want finer control of the insert, update and delete processes then you can use the lower level functions to perform these operations as described below.

The form is populated with data from the database with readFields(). If the user is allowed to edit, (see setReadOnly()), write the form's data back to the cursor's edit buffer with writeFields(). You can clear the values in the form with clearValues(). Editing is performed as follows: insert When the data browser enters insertion mode it emits the primeInsert() signal which you can connect to, for example to pre-populate fields. Call writeFields() to write the user's edits to the cursor's edit buffer then call insert() to insert the record into the database. The beforeInsert() signal is emitted just before the cursor's edit buffer is inserted into the database; connect to this for example, to populate fields such as an auto-generated primary key. update For updates the primeUpdate() signal is emitted when the data browser enters update mode. After calling writeFields() call update() to update the record and connect to the beforeUpdate() signal to manipulate the user's data before the update takes place. delete For deletion the primeDelete() signal is emitted when the data browser enters deletion mode. After calling writeFields() call del() to delete the record and connect to the beforeDelete() signal, for example to record an audit of the deleted record.

Definition at line 44 of file q3databrowser.h.

Public Types

enum  Boundary

Public Slots

virtual void refresh ()
virtual void insert ()
virtual void update ()
virtual void del ()
virtual void first ()
virtual void last ()
virtual void next ()
virtual void prev ()
virtual void readFields ()
virtual void writeFields ()
virtual void clearValues ()
void updateBoundary ()

Signals

void firstRecordAvailable (bool available)
void lastRecordAvailable (bool available)
void nextRecordAvailable (bool available)
void prevRecordAvailable (bool available)
void currentChanged (const QSqlRecord *record)
void primeInsert (QSqlRecord *buf)
void primeUpdate (QSqlRecord *buf)
void primeDelete (QSqlRecord *buf)
void beforeInsert (QSqlRecord *buf)
void beforeUpdate (QSqlRecord *buf)
void beforeDelete (QSqlRecord *buf)
void cursorChanged (Q3SqlCursor::Mode mode)

Public Member Functions

 Q3DataBrowser (QWidget *parent=0, const char *name=0, Qt::WindowFlags fl=0)
 ~Q3DataBrowser ()
Boundary boundary ()
void setBoundaryChecking (bool active)
bool boundaryChecking () const
void setSort (const QSqlIndex &sort)
void setSort (const QStringList &sort)
QStringList sort () const
void setFilter (const QString &filter)
QString filter () const
virtual void setSqlCursor (Q3SqlCursor *cursor, bool autoDelete=false)
Q3SqlCursorsqlCursor () const
virtual void setForm (Q3SqlForm *form)
Q3SqlFormform ()
virtual void setConfirmEdits (bool confirm)
virtual void setConfirmInsert (bool confirm)
virtual void setConfirmUpdate (bool confirm)
virtual void setConfirmDelete (bool confirm)
virtual void setConfirmCancels (bool confirm)
bool confirmEdits () const
bool confirmInsert () const
bool confirmUpdate () const
bool confirmDelete () const
bool confirmCancels () const
virtual void setReadOnly (bool active)
bool isReadOnly () const
virtual void setAutoEdit (bool autoEdit)
bool autoEdit () const
virtual bool seek (int i, bool relative=false)

Protected Member Functions

virtual bool insertCurrent ()
virtual bool updateCurrent ()
virtual bool deleteCurrent ()
virtual bool currentEdited ()
virtual QSql::Confirm confirmEdit (QSql::Op m)
virtual QSql::Confirm confirmCancel (QSql::Op m)
virtual void handleError (const QSqlError &error)

Private Types

typedef bool(Q3SqlCursor::*) Nav ()

Private Member Functions

bool preNav ()
void postNav (bool primeUpd)
void nav (Nav nav)

Private Attributes

Q3DataBrowserPrivated


Member Typedef Documentation

typedef bool(Q3SqlCursor::*) Q3DataBrowser::Nav() [private]

Definition at line 148 of file q3databrowser.h.


Member Enumeration Documentation

enum Q3DataBrowser::Boundary

This enum describes where the data browser is positioned.

Unknown the boundary cannot be determined (usually because there is no default cursor, or the default cursor is not active).

None the browser is not positioned on a boundary, but it is positioned on a record somewhere in the middle.

BeforeBeginning the browser is positioned before the first available record.

Beginning the browser is positioned at the first record.

End the browser is positioned at the last record.

AfterEnd the browser is positioned after the last available record.

Definition at line 62 of file q3databrowser.h.

00062                   {
00063         Unknown,
00064         None,
00065         BeforeBeginning,
00066         Beginning,
00067         End,
00068         AfterEnd
00069     };


Constructor & Destructor Documentation

Q3DataBrowser::Q3DataBrowser ( QWidget parent = 0,
const char *  name = 0,
Qt::WindowFlags  fl = 0 
)

Constructs a data browser which is a child of parent, with the name name and widget flags set to fl.

Definition at line 143 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::dat, and Q3DataManager::setMode().

00144     : QWidget(parent, name, fl)
00145 {
00146     d = new Q3DataBrowserPrivate();
00147     d->dat.setMode(QSql::Update);
00148 }

Here is the call graph for this function:

Q3DataBrowser::~Q3DataBrowser (  ) 

Destroys the object and frees any allocated resources.

Definition at line 154 of file q3databrowser.cpp.

References d.

00155 {
00156     delete d;
00157 }


Member Function Documentation

Q3DataBrowser::Boundary Q3DataBrowser::boundary (  ) 

Returns an enum indicating the boundary status of the browser.

This is achieved by moving the default cursor and checking the position, however the current default form values will not be altered. After checking for the boundary, the cursor is moved back to its former position. See Q3DataBrowser::Boundary.

See also:
Boundary

Definition at line 171 of file q3databrowser.cpp.

References AfterEnd, QSqlQuery::at(), b, BeforeBeginning, Beginning, Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), d, End, QSqlQuery::isActive(), QSqlQuery::isValid(), Q3SqlCursor::next(), None, Q3SqlCursor::previous(), Q3SqlCursor::seek(), and Unknown.

Referenced by updateBoundary().

00172 {
00173     Q3SqlCursor* cur = d->cur.cursor();
00174     if (!cur || !cur->isActive())
00175         return Unknown;
00176     if (!cur->isValid()) {
00177         if (cur->at() == QSql::BeforeFirst)
00178             return BeforeBeginning;
00179         if (cur->at() == QSql::AfterLast)
00180             return AfterEnd;
00181         return Unknown;
00182     }
00183     if (cur->at() == 0)
00184         return Beginning;
00185     int currentAt = cur->at();
00186 
00187     Boundary b = None;
00188     if (!cur->previous())
00189         b = Beginning;
00190     else
00191         cur->seek(currentAt);
00192     if (b == None && !cur->next())
00193         b = End;
00194     cur->seek(currentAt);
00195     return b;
00196 }

Here is the call graph for this function:

void Q3DataBrowser::setBoundaryChecking ( bool  active  ) 

Definition at line 209 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::boundaryCheck, and d.

00210 {
00211     d->boundaryCheck = active;
00212 }

bool Q3DataBrowser::boundaryChecking (  )  const

Definition at line 214 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::boundaryCheck, and d.

00215 {
00216     return d->boundaryCheck;
00217 }

void Q3DataBrowser::setSort ( const QSqlIndex sort  ) 

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets the data browser's sort to the QSqlIndex sort. To apply the new sort, use refresh().

Definition at line 255 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::cur, d, Q3SqlCursorManager::setSort(), and sort().

00256 {
00257     d->cur.setSort(sort);
00258 }

Here is the call graph for this function:

void Q3DataBrowser::setSort ( const QStringList sort  ) 

Definition at line 243 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::cur, d, Q3SqlCursorManager::setSort(), and sort().

00244 {
00245     d->cur.setSort(sort);
00246 }

Here is the call graph for this function:

QStringList Q3DataBrowser::sort (  )  const

Definition at line 260 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::cur, d, and Q3SqlCursorManager::sort().

Referenced by setSort().

00261 {
00262     return d->cur.sort();
00263 }

Here is the call graph for this function:

void Q3DataBrowser::setFilter ( const QString filter  ) 

Definition at line 280 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::cur, d, filter(), and Q3SqlCursorManager::setFilter().

00281 {
00282     d->cur.setFilter(filter);
00283 }

Here is the call graph for this function:

QString Q3DataBrowser::filter (  )  const

Definition at line 286 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::cur, d, and Q3SqlCursorManager::filter().

Referenced by setFilter().

00287 {
00288     return d->cur.filter();
00289 }

Here is the call graph for this function:

void Q3DataBrowser::setSqlCursor ( Q3SqlCursor cursor,
bool  autoDelete = false 
) [virtual]

Sets the default cursor used by the data browser to cursor. If autoDelete is true (the default is false), the data browser takes ownership of the cursor pointer, which will be deleted when the browser is destroyed, or when setSqlCursor() is called again. To activate the cursor use refresh(). The cursor's edit buffer is used in the default form to browse and edit records.

See also:
sqlCursor() form() setForm()

Definition at line 303 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::cur, QWidget::cursor(), d, Q3DataBrowserPrivate::frm, Q3SqlCursorManager::setCursor(), setReadOnly(), and Q3SqlFormManager::setRecord().

00304 {
00305     if (!cursor)
00306         return;
00307     d->cur.setCursor(cursor, autoDelete);
00308     d->frm.setRecord(cursor->editBuffer());
00309     if (cursor->isReadOnly())
00310         setReadOnly(true);
00311 }

Here is the call graph for this function:

Q3SqlCursor * Q3DataBrowser::sqlCursor (  )  const

Returns the default cursor used for navigation, or 0 if there is no default cursor.

See also:
setSqlCursor()

Definition at line 321 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), and d.

Referenced by insert().

00322 {
00323     return d->cur.cursor();
00324 }

Here is the call graph for this function:

void Q3DataBrowser::setForm ( Q3SqlForm form  )  [virtual]

Sets the browser's default form to form. The cursor and all navigation and data manipulation functions that the browser provides become available to the form.

Definition at line 333 of file q3databrowser.cpp.

References d, form(), Q3DataBrowserPrivate::frm, and Q3SqlFormManager::setForm().

00334 {
00335     d->frm.setForm(form);
00336 }

Here is the call graph for this function:

Q3SqlForm * Q3DataBrowser::form (  ) 

Returns the data browser's default form or 0 if no form has been set.

Definition at line 344 of file q3databrowser.cpp.

References d, Q3SqlFormManager::form(), and Q3DataBrowserPrivate::frm.

Referenced by setForm().

00345 {
00346     return d->frm.form();
00347 }

Here is the call graph for this function:

void Q3DataBrowser::setConfirmEdits ( bool  confirm  )  [virtual]

Definition at line 367 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::dat, and Q3DataManager::setConfirmEdits().

00368 {
00369     d->dat.setConfirmEdits(confirm);
00370 }

Here is the call graph for this function:

void Q3DataBrowser::setConfirmInsert ( bool  confirm  )  [virtual]

Definition at line 382 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::dat, and Q3DataManager::setConfirmInsert().

00383 {
00384     d->dat.setConfirmInsert(confirm);
00385 }

Here is the call graph for this function:

void Q3DataBrowser::setConfirmUpdate ( bool  confirm  )  [virtual]

Definition at line 397 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::dat, and Q3DataManager::setConfirmUpdate().

00398 {
00399     d->dat.setConfirmUpdate(confirm);
00400 }

Here is the call graph for this function:

void Q3DataBrowser::setConfirmDelete ( bool  confirm  )  [virtual]

Definition at line 412 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::dat, and Q3DataManager::setConfirmDelete().

00413 {
00414     d->dat.setConfirmDelete(confirm);
00415 }

Here is the call graph for this function:

void Q3DataBrowser::setConfirmCancels ( bool  confirm  )  [virtual]

Definition at line 462 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::dat, and Q3DataManager::setConfirmCancels().

00463 {
00464     d->dat.setConfirmCancels(confirm);
00465 }

Here is the call graph for this function:

bool Q3DataBrowser::confirmEdits (  )  const

Definition at line 430 of file q3databrowser.cpp.

References Q3DataManager::confirmEdits(), d, and Q3DataBrowserPrivate::dat.

00431 {
00432     return (d->dat.confirmEdits());
00433 }

Here is the call graph for this function:

bool Q3DataBrowser::confirmInsert (  )  const

Definition at line 435 of file q3databrowser.cpp.

References Q3DataManager::confirmInsert(), d, and Q3DataBrowserPrivate::dat.

Referenced by insert(), preNav(), and update().

00436 {
00437     return (d->dat.confirmInsert());
00438 }

Here is the call graph for this function:

bool Q3DataBrowser::confirmUpdate (  )  const

Definition at line 440 of file q3databrowser.cpp.

References Q3DataManager::confirmUpdate(), d, and Q3DataBrowserPrivate::dat.

Referenced by insert(), preNav(), and update().

00441 {
00442     return (d->dat.confirmUpdate());
00443 }

Here is the call graph for this function:

bool Q3DataBrowser::confirmDelete (  )  const

Definition at line 445 of file q3databrowser.cpp.

References Q3DataManager::confirmDelete(), d, and Q3DataBrowserPrivate::dat.

Referenced by del().

00446 {
00447     return (d->dat.confirmDelete());
00448 }

Here is the call graph for this function:

bool Q3DataBrowser::confirmCancels (  )  const

Definition at line 467 of file q3databrowser.cpp.

References Q3DataManager::confirmCancels(), d, and Q3DataBrowserPrivate::dat.

Referenced by del().

00468 {
00469     return d->dat.confirmCancels();
00470 }

Here is the call graph for this function:

void Q3DataBrowser::setReadOnly ( bool  active  )  [virtual]

Definition at line 357 of file q3databrowser.cpp.

References d, and Q3DataBrowserPrivate::readOnly.

Referenced by setSqlCursor().

00358 {
00359     d->readOnly = active;
00360 }

bool Q3DataBrowser::isReadOnly (  )  const

Definition at line 362 of file q3databrowser.cpp.

References d, and Q3DataBrowserPrivate::readOnly.

Referenced by deleteCurrent(), insertCurrent(), preNav(), and updateCurrent().

00363 {
00364     return d->readOnly;
00365 }

void Q3DataBrowser::setAutoEdit ( bool  autoEdit  )  [virtual]

Definition at line 486 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::dat, and Q3DataManager::setAutoEdit().

00487 {
00488     d->dat.setAutoEdit(autoEdit);
00489 }

Here is the call graph for this function:

bool Q3DataBrowser::autoEdit (  )  const

Definition at line 491 of file q3databrowser.cpp.

References Q3DataManager::autoEdit(), d, and Q3DataBrowserPrivate::dat.

Referenced by insert(), and preNav().

00492 {
00493     return d->dat.autoEdit();
00494 }

Here is the call graph for this function:

bool Q3DataBrowser::seek ( int  i,
bool  relative = false 
) [virtual]

Moves the default cursor to the record specified by the index i and refreshes the default form to display this record. If there is no default form or no default cursor, nothing happens. If relative is true (the default is false), the cursor is moved relative to its current position. If the data browser successfully navigated to the desired record, the default cursor is primed for update and the primeUpdate() signal is emitted.

If the browser is already positioned on the desired record nothing happens.

Definition at line 802 of file q3databrowser.cpp.

References b, Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), d, postNav(), preNav(), and Q3SqlCursor::seek().

00803 {
00804     int b = 0;
00805     Q3SqlCursor* cur = d->cur.cursor();
00806     if (!cur)
00807         return false;
00808     if (preNav())
00809         b = cur->seek(i, relative);
00810     postNav(b);
00811     return b;
00812 }

Here is the call graph for this function:

void Q3DataBrowser::firstRecordAvailable ( bool  available  )  [signal]

This signal is emitted whenever the position of the cursor changes. The available parameter indicates whether or not the first record in the default cursor is available.

Referenced by updateBoundary().

void Q3DataBrowser::lastRecordAvailable ( bool  available  )  [signal]

This signal is emitted whenever the position of the cursor changes. The available parameter indicates whether or not the last record in the default cursor is available.

Referenced by updateBoundary().

void Q3DataBrowser::nextRecordAvailable ( bool  available  )  [signal]

This signal is emitted whenever the position of the cursor changes. The available parameter indicates whether or not the next record in the default cursor is available.

Referenced by updateBoundary().

void Q3DataBrowser::prevRecordAvailable ( bool  available  )  [signal]

This signal is emitted whenever the position of the cursor changes. The available parameter indicates whether or not the previous record in the default cursor is available.

Referenced by updateBoundary().

void Q3DataBrowser::currentChanged ( const QSqlRecord record  )  [signal]

This signal is emitted whenever the current cursor position changes. The record parameter points to the contents of the current cursor's record.

Referenced by postNav().

void Q3DataBrowser::primeInsert ( QSqlRecord buf  )  [signal]

This signal is emitted when the data browser enters insertion mode. The buf parameter points to the record buffer that is to be inserted. Connect to this signal to, for example, prime the record buffer with default data values, auto-numbered fields etc. (Note that Q3SqlCursor::primeInsert() is not called on the default cursor, as this would corrupt values in the form.)

See also:
insert()

Referenced by insert().

void Q3DataBrowser::primeUpdate ( QSqlRecord buf  )  [signal]

This signal is emitted when the data browser enters update mode. Note that during navigation (first(), last(), next(), prev()), each record that is shown in the default form is primed for update. The buf parameter points to the record buffer being updated. (Note that Q3SqlCursor::primeUpdate() is not called on the default cursor, as this would corrupt values in the form.) Connect to this signal in order to, for example, keep track of which records have been updated, perhaps for auditing purposes.

See also:
update()

Referenced by postNav().

void Q3DataBrowser::primeDelete ( QSqlRecord buf  )  [signal]

This signal is emitted when the data browser enters deletion mode. The buf parameter points to the record buffer being deleted. (Note that Q3SqlCursor::primeDelete() is not called on the default cursor, as this would corrupt values in the form.) Connect to this signal in order to, for example, save a copy of the deleted record for auditing purposes.

See also:
del()

Referenced by del().

void Q3DataBrowser::beforeInsert ( QSqlRecord buf  )  [signal]

This signal is emitted just before the cursor's edit buffer is inserted into the database. The buf parameter points to the edit buffer being inserted. You might connect to this signal to populate a generated primary key for example.

Referenced by insertCurrent().

void Q3DataBrowser::beforeUpdate ( QSqlRecord buf  )  [signal]

This signal is emitted just before the cursor's edit buffer is updated in the database. The buf parameter points to the edit buffer being updated. You might connect to this signal to capture some auditing information about the update.

Referenced by updateCurrent().

void Q3DataBrowser::beforeDelete ( QSqlRecord buf  )  [signal]

This signal is emitted just before the cursor's edit buffer is deleted from the database. The buf parameter points to the edit buffer being deleted. You might connect to this signal to capture some auditing information about the deletion.

Referenced by deleteCurrent().

void Q3DataBrowser::cursorChanged ( Q3SqlCursor::Mode  mode  )  [signal]

This signal is emitted whenever the cursor record was changed due to navigation. The mode parameter is the edit that just took place, e.g. Insert, Update or Delete. See Q3SqlCursor::Mode.

Referenced by deleteCurrent(), insertCurrent(), and updateCurrent().

void Q3DataBrowser::refresh (  )  [virtual, slot]

Refreshes the data browser's data using the default cursor. The browser's current filter and sort are applied if they have been set.

See also:
setFilter() setSort()

Definition at line 599 of file q3databrowser.cpp.

References Q3DataBrowserPrivate::cur, d, and Q3SqlCursorManager::refresh().

Referenced by deleteCurrent(), insertCurrent(), and updateCurrent().

00600 {
00601     d->cur.refresh();
00602 }

void Q3DataBrowser::insert (  )  [virtual, slot]

Performs an insert operation on the data browser's cursor. If there is no default cursor or no default form, nothing happens.

If auto-editing is on (see setAutoEdit()), the following happens:

If the browser is already actively inserting a record, the current form's data is inserted into the database. If the browser is not inserting a record, but the current record was changed by the user, the record is updated in the database with the current form's data (i.e. with the changes).

If there is an error handling any of the above auto-edit actions, handleError() is called and no insert or update is performed.

If no error occurred, or auto-editing is not enabled, the data browser begins actively inserting a record into the database by performing the following actions:

The default cursor is primed for insert using Q3SqlCursor::primeInsert(). The primeInsert() signal is emitted. The form is updated with the values in the default cursor's. edit buffer so that the user can fill in the values to be inserted.

Definition at line 635 of file q3databrowser.cpp.

References autoEdit(), buf, confirmEdit(), confirmInsert(), confirmUpdate(), Q3DataBrowserPrivate::cur, currentEdited(), Q3SqlCursorManager::cursor(), d, Q3DataBrowserPrivate::dat, emit, Q3DataBrowserPrivate::frm, insertCurrent(), Q3DataManager::mode(), Q3SqlCursor::primeInsert(), primeInsert(), readFields(), Q3SqlFormManager::record(), Q3DataManager::setMode(), sqlCursor(), and updateCurrent().

00636 {
00637     QSqlRecord* buf = d->frm.record();
00638     Q3SqlCursor* cur = d->cur.cursor();
00639     if (!buf || !cur)
00640         return;
00641     bool doIns = true;
00642     QSql::Confirm conf = QSql::Yes;
00643     switch (d->dat.mode()) {
00644     case QSql::Insert:
00645         if (autoEdit()) {
00646             if (confirmInsert())
00647                 conf = confirmEdit(QSql::Insert);
00648             switch (conf) {
00649             case QSql::Yes:
00650                 insertCurrent();
00651                 break;
00652             case QSql::No:
00653                 break;
00654             case QSql::Cancel:
00655                 doIns = false;
00656                 break;
00657             }
00658         }
00659         break;
00660     default:
00661         if (autoEdit() && currentEdited()) {
00662             if (confirmUpdate())
00663                 conf = confirmEdit(QSql::Update);
00664             switch (conf) {
00665             case QSql::Yes:
00666                 updateCurrent();
00667                 break;
00668             case QSql::No:
00669                 break;
00670             case QSql::Cancel:
00671                 doIns = false;
00672                 break;
00673             }
00674         }
00675         break;
00676     }
00677     if (doIns) {
00678         d->dat.setMode(QSql::Insert);
00679         sqlCursor()->primeInsert();
00680         emit primeInsert(d->frm.record());
00681         readFields();
00682     }
00683 }

void Q3DataBrowser::update (  )  [virtual, slot]

Performs an update operation on the data browser's cursor.

If there is no default cursor or no default form, nothing happens. Otherwise, the following happens:

If the data browser is actively inserting a record (see insert()), that record is inserted into the database using insertCurrent(). Otherwise, the database is updated with the current form's data using updateCurrent(). If there is an error handling either action, handleError() is called.

Reimplemented from QWidget.

Definition at line 699 of file q3databrowser.cpp.

References buf, confirmEdit(), confirmInsert(), confirmUpdate(), Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), d, Q3DataBrowserPrivate::dat, Q3SqlCursor::editBuffer(), Q3DataBrowserPrivate::frm, insertCurrent(), Q3DataManager::mode(), readFields(), Q3SqlFormManager::record(), Q3DataManager::setMode(), and updateCurrent().

00700 {
00701     QSqlRecord* buf = d->frm.record();
00702     Q3SqlCursor* cur = d->cur.cursor();
00703     if (!buf || !cur)
00704         return;
00705     QSql::Confirm conf = QSql::Yes;
00706     switch (d->dat.mode()){
00707     case QSql::Insert:
00708         if (confirmInsert())
00709             conf = confirmEdit(QSql::Insert);
00710         switch (conf) {
00711             case QSql::Yes:
00712                 if (insertCurrent())
00713                     d->dat.setMode(QSql::Update);
00714             break;
00715             case QSql::No:
00716                 d->dat.setMode(QSql::Update);
00717             cur->editBuffer(true);
00718             readFields();
00719             break;
00720             case QSql::Cancel:
00721             break;
00722         }
00723     break;
00724     default:
00725         d->dat.setMode(QSql::Update);
00726         if (confirmUpdate())
00727             conf = confirmEdit(QSql::Update);
00728         switch (conf) {
00729         case QSql::Yes:
00730             updateCurrent();
00731             break;
00732         case QSql::No:
00733         case QSql::Cancel:
00734             break;
00735         }
00736         break;
00737     }
00738 }

void Q3DataBrowser::del (  )  [virtual, slot]

Performs a delete operation on the data browser's cursor. If there is no default cursor or no default form, nothing happens.

Otherwise, the following happens:

The current form's record is deleted from the database, providing that the data browser is not in insert mode. If the data browser is actively inserting a record (see insert()), the insert action is canceled, and the browser navigates to the last valid record that was current. If there is an error, handleError() is called.

Definition at line 754 of file q3databrowser.cpp.

References buf, confirmCancel(), confirmCancels(), confirmDelete(), confirmEdit(), Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), d, Q3DataBrowserPrivate::dat, deleteCurrent(), Q3SqlCursor::editBuffer(), emit, Q3DataBrowserPrivate::frm, Q3DataManager::mode(), primeDelete(), readFields(), Q3SqlFormManager::record(), and Q3DataManager::setMode().

00755 {
00756     QSqlRecord* buf = d->frm.record();
00757     Q3SqlCursor* cur = d->cur.cursor();
00758     if (!buf || !cur)
00759         return;
00760     QSql::Confirm conf = QSql::Yes;
00761     switch (d->dat.mode()){
00762     case QSql::Insert:
00763         if (confirmCancels())
00764             conf = confirmCancel(QSql::Insert);
00765         if (conf == QSql::Yes) {
00766             cur->editBuffer(true); /* restore from cursor */
00767             readFields();
00768             d->dat.setMode(QSql::Update);
00769         } else
00770             d->dat.setMode(QSql::Insert);
00771         break;
00772     default:
00773         if (confirmDelete())
00774             conf = confirmEdit(QSql::Delete);
00775         switch (conf) {
00776         case QSql::Yes:
00777             emit primeDelete(buf);
00778             deleteCurrent();
00779             break;
00780         case QSql::No:
00781         case QSql::Cancel:
00782             break;
00783         }
00784         d->dat.setMode(QSql::Update);
00785         break;
00786     }
00787 }

void Q3DataBrowser::first (  )  [virtual, slot]

Moves the default cursor to the first 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 first record, the default cursor is primed for update and the primeUpdate() signal is emitted.

If the browser is already positioned on the first record nothing happens.

Definition at line 826 of file q3databrowser.cpp.

References Q3SqlCursor::first(), and nav().

00827 {
00828     nav(&Q3SqlCursor::first);
00829 }

void Q3DataBrowser::last (  )  [virtual, slot]

Moves the default cursor to the last 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 last record, the default cursor is primed for update and the primeUpdate() signal is emitted.

If the browser is already positioned on the last record nothing happens.

Definition at line 843 of file q3databrowser.cpp.

References Q3SqlCursor::last(), and nav().

Referenced by deleteCurrent().

00844 {
00845     nav(&Q3SqlCursor::last);
00846 }

void Q3DataBrowser::next (  )  [virtual, slot]

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.

Definition at line 859 of file q3databrowser.cpp.

References nav(), and Q3SqlCursor::next().

00860 {
00861     nav(&Q3SqlCursor::next);
00862 }

void Q3DataBrowser::prev (  )  [virtual, slot]

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.

Definition at line 875 of file q3databrowser.cpp.

References nav(), and Q3SqlCursor::previous().

00876 {
00877     nav(&Q3SqlCursor::previous);
00878 }

void Q3DataBrowser::readFields (  )  [virtual, slot]

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.

Definition at line 886 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::frm, and Q3SqlFormManager::readFields().

Referenced by del(), deleteCurrent(), insert(), postNav(), update(), and updateCurrent().

00887 {
00888     d->frm.readFields();
00889 }

void Q3DataBrowser::writeFields (  )  [virtual, slot]

Writes the form's data to the default cursor's edit buffer. If there is no default cursor or no default form, nothing happens.

Definition at line 897 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::frm, and Q3SqlFormManager::writeFields().

Referenced by currentEdited(), deleteCurrent(), insertCurrent(), and updateCurrent().

00898 {
00899     d->frm.writeFields();
00900 }

void Q3DataBrowser::clearValues (  )  [virtual, slot]

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 Q3SqlPropertyMap constructor for the default mappings of widgets to properties.

Definition at line 914 of file q3databrowser.cpp.

References Q3SqlFormManager::clearValues(), d, and Q3DataBrowserPrivate::frm.

Referenced by deleteCurrent().

00915 {
00916     d->frm.clearValues();
00917 }

void Q3DataBrowser::updateBoundary (  )  [slot]

If boundaryChecking() is true, checks the boundary of the current default cursor and emits signals which indicate the position of the cursor.

Definition at line 1158 of file q3databrowser.cpp.

References AfterEnd, BeforeBeginning, Beginning, boundary(), Q3DataBrowserPrivate::boundaryCheck, d, emit, End, firstRecordAvailable(), lastRecordAvailable(), nextRecordAvailable(), None, prevRecordAvailable(), and Unknown.

Referenced by deleteCurrent(), insertCurrent(), postNav(), and updateCurrent().

01159 {
01160     if (d->boundaryCheck) {
01161         Boundary bound = boundary();
01162         switch (bound) {
01163         case Unknown:
01164         case None:
01165             emit firstRecordAvailable(true);
01166             emit prevRecordAvailable(true);
01167             emit nextRecordAvailable(true);
01168             emit lastRecordAvailable(true);
01169             break;
01170 
01171         case BeforeBeginning:
01172             emit firstRecordAvailable(false);
01173             emit prevRecordAvailable(false);
01174             emit nextRecordAvailable(true);
01175             emit lastRecordAvailable(true);
01176             break;
01177 
01178         case Beginning:
01179             emit firstRecordAvailable(false);
01180             emit prevRecordAvailable(false);
01181             emit nextRecordAvailable(true);
01182             emit lastRecordAvailable(true);
01183             break;
01184 
01185         case End:
01186             emit firstRecordAvailable(true);
01187             emit prevRecordAvailable(true);
01188             emit nextRecordAvailable(false);
01189             emit lastRecordAvailable(false);
01190             break;
01191 
01192         case AfterEnd:
01193             emit firstRecordAvailable(true);
01194             emit prevRecordAvailable(true);
01195             emit nextRecordAvailable(false);
01196             emit lastRecordAvailable(false);
01197             break;
01198         }
01199     }
01200 }

bool Q3DataBrowser::insertCurrent (  )  [protected, virtual]

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 successful, the cursor is refreshed and relocated to the newly inserted record, the cursorChanged() signal is emitted, and true is returned.

See also:
cursorChanged() sqlCursor() form() handleError()

Definition at line 931 of file q3databrowser.cpp.

References beforeInsert(), buf, Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), cursorChanged(), d, emit, Q3SqlCursorManager::findBuffer(), Q3DataBrowserPrivate::frm, handleError(), Q3SqlCursor::insert(), Q3SqlCursor::Insert, QSqlQuery::isActive(), isReadOnly(), QSqlQuery::lastError(), Q3SqlCursor::primaryIndex(), Q3SqlFormManager::record(), refresh(), updateBoundary(), and writeFields().

Referenced by insert(), preNav(), and update().

00932 {
00933     if (isReadOnly())
00934         return false;
00935     QSqlRecord* buf = d->frm.record();
00936     Q3SqlCursor* cur = d->cur.cursor();
00937     if (!buf || !cur)
00938         return false;
00939     writeFields();
00940     emit beforeInsert(buf);
00941     int ar = cur->insert();
00942     if (!ar || !cur->isActive()) {
00943         handleError(cur->lastError());
00944         refresh();
00945         updateBoundary();
00946     } else {
00947         refresh();
00948         d->cur.findBuffer(cur->primaryIndex());
00949         updateBoundary();
00950         cursorChanged(Q3SqlCursor::Insert);
00951         return true;
00952     }
00953     return false;
00954 }

Here is the call graph for this function:

bool Q3DataBrowser::updateCurrent (  )  [protected, virtual]

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 successful, the cursor is refreshed and relocated to the updated record, the cursorChanged() signal is emitted, and true is returned.

See also:
cursor() form() handleError()

Definition at line 969 of file q3databrowser.cpp.

References beforeUpdate(), buf, Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), cursorChanged(), d, Q3SqlCursor::editBuffer(), emit, Q3SqlCursorManager::findBuffer(), Q3DataBrowserPrivate::frm, handleError(), QSqlQuery::isActive(), isReadOnly(), QSqlQuery::lastError(), Q3SqlCursor::primaryIndex(), readFields(), Q3SqlFormManager::record(), refresh(), Q3SqlCursor::update(), Q3SqlCursor::Update, updateBoundary(), and writeFields().

Referenced by insert(), preNav(), and update().

00970 {
00971     if (isReadOnly())
00972         return false;
00973     QSqlRecord* buf = d->frm.record();
00974     Q3SqlCursor* cur = d->cur.cursor();
00975     if (!buf || !cur)
00976         return false;
00977     writeFields();
00978     emit beforeUpdate(buf);
00979     int ar = cur->update();
00980     if (!ar || !cur->isActive()) {
00981         handleError(cur->lastError());
00982         refresh();
00983         updateBoundary();
00984     } else {
00985         refresh();
00986         d->cur.findBuffer(cur->primaryIndex());
00987         updateBoundary();
00988         cur->editBuffer(true);
00989         cursorChanged(Q3SqlCursor::Update);
00990         readFields();
00991         return true;
00992     }
00993     return false;
00994 }

Here is the call graph for this function:

bool Q3DataBrowser::deleteCurrent (  )  [protected, virtual]

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.

See also:
cursor() form() handleError()

Definition at line 1010 of file q3databrowser.cpp.

References QSqlQuery::at(), beforeDelete(), buf, clearValues(), Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), cursorChanged(), d, Q3SqlCursor::del(), Q3SqlCursor::Delete, Q3SqlCursor::editBuffer(), emit, Q3DataBrowserPrivate::frm, handleError(), QSqlQuery::isActive(), isReadOnly(), QSqlQuery::isValid(), last(), QSqlQuery::lastError(), n, readFields(), Q3SqlFormManager::record(), refresh(), Q3SqlCursor::seek(), updateBoundary(), and writeFields().

Referenced by del().

01011 {
01012     if (isReadOnly())
01013         return false;
01014     QSqlRecord* buf = d->frm.record();
01015     Q3SqlCursor* cur = d->cur.cursor();
01016     if (!buf || !cur)
01017         return false;
01018     writeFields();
01019     int n = cur->at();
01020     emit beforeDelete(buf);
01021     int ar = cur->del();
01022     if (ar) {
01023         refresh();
01024         updateBoundary();
01025         cursorChanged(Q3SqlCursor::Delete);
01026         if (!cur->seek(n))
01027             last();
01028         if (cur->isValid()) {
01029             cur->editBuffer(true);
01030             readFields();
01031         } else {
01032             clearValues();
01033         }
01034         return true;
01035     } else {
01036         if (!cur->isActive()) {
01037             handleError(cur->lastError());
01038             refresh();
01039             updateBoundary();
01040         }
01041     }
01042     return false;
01043 }

Here is the call graph for this function:

bool Q3DataBrowser::currentEdited (  )  [protected, virtual]

Returns true if the form's edit buffer differs from the current cursor buffer; otherwise returns false.

Definition at line 1051 of file q3databrowser.cpp.

References buf, QSqlRecord::count(), Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), d, Q3DataBrowserPrivate::frm, i, QSqlQuery::isActive(), QSqlQuery::isValid(), Q3SqlFormManager::record(), Q3SqlCursor::value(), and writeFields().

Referenced by insert(), and preNav().

01052 {
01053     QSqlRecord* buf = d->frm.record();
01054     Q3SqlCursor* cur = d->cur.cursor();
01055     if (!buf || !cur)
01056         return false;
01057     if (!cur->isActive() || !cur->isValid())
01058         return false;
01059     writeFields();
01060     for (int i = 0; i < cur->count(); ++i) {
01061         if (cur->value(i) != buf->value(i))
01062             return true;
01063     }
01064     return false;
01065 }

Here is the call graph for this function:

QSql::Confirm Q3DataBrowser::confirmEdit ( QSql::Op  m  )  [protected, virtual]

Protected virtual function which returns a confirmation for an edit of mode 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.

Definition at line 1220 of file q3databrowser.cpp.

References Q3DataManager::confirmEdit(), d, and Q3DataBrowserPrivate::dat.

Referenced by del(), insert(), preNav(), and update().

01221 {
01222     return d->dat.confirmEdit(this, m);
01223 }

Here is the call graph for this function:

QSql::Confirm Q3DataBrowser::confirmCancel ( QSql::Op  m  )  [protected, virtual]

Protected virtual function which returns a confirmation for canceling an edit mode 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.

Definition at line 1233 of file q3databrowser.cpp.

References Q3DataManager::confirmCancel(), d, and Q3DataBrowserPrivate::dat.

Referenced by del().

01234 {
01235     return d->dat.confirmCancel(this, m);
01236 }

Here is the call graph for this function:

void Q3DataBrowser::handleError ( const QSqlError error  )  [protected, virtual]

Virtual function which handles the error error. The default implementation warns the user with a message box.

Definition at line 1207 of file q3databrowser.cpp.

References d, Q3DataBrowserPrivate::dat, error, and Q3DataManager::handleError().

Referenced by deleteCurrent(), insertCurrent(), and updateCurrent().

01208 {
01209     d->dat.handleError(this, error);
01210 }

Here is the call graph for this function:

bool Q3DataBrowser::preNav (  )  [private]

Definition at line 1072 of file q3databrowser.cpp.

References autoEdit(), buf, confirmEdit(), confirmInsert(), confirmUpdate(), Q3DataBrowserPrivate::cur, currentEdited(), Q3SqlCursorManager::cursor(), d, Q3DataBrowserPrivate::dat, Q3DataBrowserPrivate::frm, insertCurrent(), isReadOnly(), Q3DataManager::mode(), Q3SqlFormManager::record(), Q3DataManager::setMode(), and updateCurrent().

Referenced by nav(), and seek().

01073 {
01074     QSqlRecord* buf = d->frm.record();
01075     Q3SqlCursor* cur = d->cur.cursor();
01076     if (!buf || !cur)
01077         return false;
01078 
01079     if (!isReadOnly() && autoEdit() && currentEdited()) {
01080         bool ok = true;
01081         QSql::Confirm conf = QSql::Yes;
01082         switch (d->dat.mode()){
01083         case QSql::Insert:
01084             if (confirmInsert())
01085                 conf = confirmEdit(QSql::Insert);
01086             switch (conf) {
01087             case QSql::Yes:
01088                 ok = insertCurrent();
01089                 d->dat.setMode(QSql::Update);
01090                 break;
01091             case QSql::No:
01092                 d->dat.setMode(QSql::Update);
01093                 break;
01094             case QSql::Cancel:
01095                 return false;
01096             }
01097             break;
01098         default:
01099             if (confirmUpdate())
01100                 conf = confirmEdit(QSql::Update);
01101             switch (conf) {
01102             case QSql::Yes:
01103                 ok = updateCurrent();
01104                 break;
01105             case QSql::No:
01106                 break;
01107             case QSql::Cancel:
01108                 return false;
01109             }
01110         }
01111         return ok;
01112     }
01113     return true;
01114 }

Here is the call graph for this function:

void Q3DataBrowser::postNav ( bool  primeUpd  )  [private]

Definition at line 1121 of file q3databrowser.cpp.

References buf, Q3DataBrowserPrivate::cur, currentChanged(), Q3SqlCursorManager::cursor(), d, emit, Q3DataBrowserPrivate::frm, primeUpdate(), Q3SqlCursor::primeUpdate(), readFields(), Q3SqlFormManager::record(), and updateBoundary().

Referenced by nav(), and seek().

01122 {
01123     if (primeUpd) {
01124         QSqlRecord* buf = d->frm.record();
01125         Q3SqlCursor* cur = d->cur.cursor();
01126         if (!buf || !cur)
01127             return;
01128         currentChanged(cur);
01129         cur->primeUpdate();
01130         emit primeUpdate(buf);
01131         readFields();
01132     }
01133     updateBoundary();
01134 }

Here is the call graph for this function:

void Q3DataBrowser::nav ( Nav  nav  )  [private]

Definition at line 1141 of file q3databrowser.cpp.

References b, Q3DataBrowserPrivate::cur, Q3SqlCursorManager::cursor(), d, postNav(), and preNav().

Referenced by first(), last(), next(), and prev().

01142 {
01143     int b = 0;
01144     Q3SqlCursor* cur = d->cur.cursor();
01145     if (!cur)
01146         return;
01147     if (preNav())
01148         b = (cur->*nav)();
01149     postNav(b);
01150 }

Here is the call graph for this function:


Member Data Documentation

Q3DataBrowserPrivate* Q3DataBrowser::d [private]

Definition at line 152 of file q3databrowser.h.

Referenced by autoEdit(), boundary(), boundaryChecking(), clearValues(), confirmCancel(), confirmCancels(), confirmDelete(), confirmEdit(), confirmEdits(), confirmInsert(), confirmUpdate(), currentEdited(), del(), deleteCurrent(), filter(), form(), handleError(), insert(), insertCurrent(), isReadOnly(), nav(), postNav(), preNav(), Q3DataBrowser(), readFields(), refresh(), seek(), setAutoEdit(), setBoundaryChecking(), setConfirmCancels(), setConfirmDelete(), setConfirmEdits(), setConfirmInsert(), setConfirmUpdate(), setFilter(), setForm(), setReadOnly(), setSort(), setSqlCursor(), sort(), sqlCursor(), update(), updateBoundary(), updateCurrent(), writeFields(), and ~Q3DataBrowser().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 15:48:17 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1