You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/man/man3/tqsqlform.3qt

245 lines
8.6 KiB

'\" t
.TH QSqlForm 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QSqlForm \- Creates and manages data entry forms tied to SQL databases
.SH SYNOPSIS
\fC#include <ntqsqlform.h>\fR
.PP
Inherits QObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQSqlForm\fR ( QObject * parent = 0, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~QSqlForm\fR ()"
.br
.ti -1c
.BI "virtual void \fBinsert\fR ( QWidget * widget, const QString & field )"
.br
.ti -1c
.BI "virtual void \fBremove\fR ( const QString & field )"
.br
.ti -1c
.BI "uint \fBcount\fR () const"
.br
.ti -1c
.BI "QWidget * \fBwidget\fR ( uint i ) const"
.br
.ti -1c
.BI "QSqlField * \fBwidgetToField\fR ( QWidget * widget ) const"
.br
.ti -1c
.BI "QWidget * \fBfieldToWidget\fR ( QSqlField * field ) const"
.br
.ti -1c
.BI "void \fBinstallPropertyMap\fR ( QSqlPropertyMap * pmap )"
.br
.ti -1c
.BI "virtual void \fBsetRecord\fR ( QSqlRecord * buf )"
.br
.in -1c
.SS "Public Slots"
.in +1c
.ti -1c
.BI "virtual void \fBreadField\fR ( QWidget * widget )"
.br
.ti -1c
.BI "virtual void \fBwriteField\fR ( QWidget * widget )"
.br
.ti -1c
.BI "virtual void \fBreadFields\fR ()"
.br
.ti -1c
.BI "virtual void \fBwriteFields\fR ()"
.br
.ti -1c
.BI "virtual void \fBclear\fR ()"
.br
.ti -1c
.BI "virtual void \fBclearValues\fR ( bool nullify = FALSE )"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "virtual void \fBinsert\fR ( QWidget * widget, QSqlField * field )"
.br
.ti -1c
.BI "virtual void \fBremove\fR ( QWidget * widget )"
.br
.in -1c
.SH DESCRIPTION
The QSqlForm class creates and manages data entry forms tied to SQL databases.
.PP
Typical use of a QSqlForm consists of the following steps:
.TP
Create the widgets you want to appear in the form.
.TP
Create a cursor and navigate to the record to be edited.
.TP
Create the QSqlForm.
.TP
Set the form's record buffer to the cursor's update buffer.
.TP
Insert each widget and the field it is to edit into the form.
.TP
Use readFields() to update the editor widgets with values from the database's fields.
.TP
Display the form and let the user edit values etc.
.TP
Use writeFields() to update the database's field values with the values in the editor widgets.
.PP
Note that a QSqlForm does not access the database directly, but most often via QSqlFields which are part of a QSqlCursor. A QSqlCursor::insert(), QSqlCursor::update() or QSqlCursor::del() call is needed to actually write values to the database.
.PP
Some sample code to initialize a form successfully:
.PP
.nf
.br
QLineEdit myEditor( this );
.br
QSqlForm myForm( this );
.br
QSqlCursor myCursor( "mytable" );
.br
.br
// Execute a query to make the cursor valid
.br
myCursor.select();
.br
// Move the cursor to a valid record (the first record)
.br
myCursor.next();
.br
// Set the form's record pointer to the cursor's edit buffer (which
.br
// contains the current record's values)
.br
myForm.setRecord( myCursor.primeUpdate() );
.br
.br
// Insert a field into the form that uses myEditor to edit the
.br
// field 'somefield' in 'mytable'
.br
myForm.insert( &myEditor, "somefield" );
.br
.br
// Update myEditor with the value from the mapped database field
.br
myForm.readFields();
.br
...
.br
// Let the user edit the form
.br
...
.br
// Update the database
.br
myForm.writeFields(); // Update the cursor's edit buffer from the form
.br
myCursor.update(); // Update the database from the cursor's buffer
.br
.fi
.PP
If you want to use custom editors for displaying and editing data fields, you must install a custom QSqlPropertyMap. The form uses this object to get or set the value of a widget.
.PP
Note that TQt Designer provides a visual means of creating data-aware forms.
.PP
See also installPropertyMap(), QSqlPropertyMap, and Database Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QSqlForm::QSqlForm ( QObject * parent = 0, const char * name = 0 )"
Constructs a QSqlForm with parent \fIparent\fR and called \fIname\fR.
.SH "QSqlForm::~QSqlForm ()"
Destroys the object and frees any allocated resources.
.SH "void QSqlForm::clear ()\fC [virtual slot]\fR"
Removes every widget, and the fields they're mapped to, from the form.
.SH "void QSqlForm::clearValues ( bool nullify = FALSE )\fC [virtual slot]\fR"
Clears the values in all the widgets, and the fields they are mapped to, in the form. If \fInullify\fR is TRUE (the default is FALSE), each field is also set to NULL.
.SH "uint QSqlForm::count () const"
Returns the number of widgets in the form.
.SH "QWidget * QSqlForm::fieldToWidget ( QSqlField * field ) const"
Returns the widget that field \fIfield\fR is mapped to.
.SH "void QSqlForm::insert ( QWidget * widget, const QString & field )\fC [virtual]\fR"
Inserts a \fIwidget\fR, and the name of the \fIfield\fR it is to be mapped to, into the form. To actually associate inserted widgets with an edit buffer, use setRecord().
.PP
See also setRecord().
.PP
Examples:
.)l sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.
.SH "void QSqlForm::insert ( QWidget * widget, QSqlField * field )\fC [virtual protected]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Inserts a \fIwidget\fR, and the \fIfield\fR it is to be mapped to, into the form.
.SH "void QSqlForm::installPropertyMap ( QSqlPropertyMap * pmap )"
Installs a custom QSqlPropertyMap. This is useful if you plan to create your own custom editor widgets.
.PP
QSqlForm takes ownership of \fIpmap\fR, so \fIpmap\fR is deleted when QSqlForm goes out of scope.
.PP
See also QDataTable::installEditorFactory().
.PP
Example: sql/overview/custom1/main.cpp.
.SH "void QSqlForm::readField ( QWidget * widget )\fC [virtual slot]\fR"
Updates the widget \fIwidget\fR with the value from the SQL field it is mapped to. Nothing happens if no SQL field is mapped to the \fIwidget\fR.
.SH "void QSqlForm::readFields ()\fC [virtual slot]\fR"
Updates the widgets in the form with current values from the SQL fields they are mapped to.
.PP
Examples:
.)l sql/overview/form1/main.cpp and sql/overview/form2/main.cpp.
.SH "void QSqlForm::remove ( QWidget * widget )\fC [virtual protected]\fR"
Removes a \fIwidget\fR, and hence the field it's mapped to, from the form.
.SH "void QSqlForm::remove ( const QString & field )\fC [virtual]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Removes \fIfield\fR from the form.
.SH "void QSqlForm::setRecord ( QSqlRecord * buf )\fC [virtual]\fR"
Sets \fIbuf\fR as the record buffer for the form. To force the display of the data from \fIbuf\fR, use readFields().
.PP
See also readFields() and writeFields().
.PP
Examples:
.)l sql/overview/custom1/main.cpp, sql/overview/form1/main.cpp, and sql/overview/form2/main.cpp.
.SH "QWidget * QSqlForm::widget ( uint i ) const"
Returns the \fIi\fR-th widget in the form. Useful for traversing the widgets in the form.
.SH "QSqlField * QSqlForm::widgetToField ( QWidget * widget ) const"
Returns the SQL field that widget \fIwidget\fR is mapped to.
.SH "void QSqlForm::writeField ( QWidget * widget )\fC [virtual slot]\fR"
Updates the SQL field with the value from the \fIwidget\fR it is mapped to. Nothing happens if no SQL field is mapped to the \fIwidget\fR.
.SH "void QSqlForm::writeFields ()\fC [virtual slot]\fR"
Updates the SQL fields with values from the widgets they are mapped to. To actually update the database with the contents of the record buffer, use QSqlCursor::insert(), QSqlCursor::update() or QSqlCursor::del() as appropriate.
.PP
Example: sql/overview/form2/main.cpp.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqsqlform.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqsqlform.3qt) and the Qt
version (3.3.8).