source: trunk/src/sql/qdataview.cpp@ 203

Last change on this file since 203 was 196, checked in by rudi, 14 years ago

Add SQL module (currently it isn't build by default, however it's needed for QtDesigner)

File size: 5.0 KB
Line 
1/****************************************************************************
2**
3** Implementation of QDataView class
4**
5** Created : 2000-11-03
6**
7** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
8**
9** This file is part of the sql module of the Qt GUI Toolkit.
10**
11** This file may be distributed under the terms of the Q Public License
12** as defined by Trolltech ASA of Norway and appearing in the file
13** LICENSE.QPL included in the packaging of this file.
14**
15** This file may be distributed and/or modified under the terms of the
16** GNU General Public License version 2 as published by the Free Software
17** Foundation and appearing in the file LICENSE.GPL included in the
18** packaging of this file.
19**
20** Licensees holding valid Qt Enterprise Edition licenses may use this
21** file in accordance with the Qt Commercial License Agreement provided
22** with the Software.
23**
24** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26**
27** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
28** information about Qt Commercial License Agreements.
29** See http://www.trolltech.com/qpl/ for QPL licensing information.
30** See http://www.trolltech.com/gpl/ for GPL licensing information.
31**
32** Contact info@trolltech.com if any conditions of this licensing are
33** not clear to you.
34**
35**********************************************************************/
36
37#include "qdataview.h"
38
39#ifndef QT_NO_SQL_VIEW_WIDGETS
40
41#include "qsqlmanager_p.h"
42
43class QDataViewPrivate
44{
45public:
46 QDataViewPrivate() {}
47 QSqlFormManager frm;
48};
49
50
51/*!
52 \class QDataView qdataview.h
53 \brief The QDataView class provides read-only SQL forms.
54
55 \ingroup database
56 \mainclass
57 \module sql
58
59 This class provides a form which displays SQL field data from a
60 record buffer. Because QDataView does not support editing it uses
61 less resources than a QDataBrowser. This class is well suited for
62 displaying read-only data from a SQL database.
63
64 If you want a to present your data in an editable form use
65 QDataBrowser; if you want a table-based presentation of your data
66 use QDataTable.
67
68 The form is associated with the data view with setForm() and the
69 record is associated with setRecord(). You can also pass a
70 QSqlRecord to the refresh() function which will set the record to
71 the given record and read the record's fields into the form.
72*/
73
74/*!
75 Constructs a data view which is a child of \a parent, called \a
76 name, and with widget flags \a fl.
77*/
78
79QDataView::QDataView( QWidget *parent, const char *name, WFlags fl )
80 : QWidget( parent, name, fl )
81{
82 d = new QDataViewPrivate();
83}
84
85/*!
86 Destroys the object and frees any allocated resources.
87*/
88
89QDataView::~QDataView()
90{
91 delete d;
92}
93
94/*!
95 Clears the default form's values. If there is no default form,
96 nothing happens. All the values are set to their 'zero state',
97 e.g. 0 for numeric fields, "" for string fields.
98*/
99
100void QDataView::clearValues()
101{
102 d->frm.clearValues();
103}
104
105/*!
106 Sets the form used by the data view to \a form. If a record has
107 already been assigned to the data view, the form will display that
108 record's data.
109
110 \sa form()
111*/
112
113void QDataView::setForm( QSqlForm* form )
114{
115 d->frm.setForm( form );
116}
117
118
119/*!
120 Returns the default form used by the data view, or 0 if there is
121 none.
122
123 \sa setForm()
124*/
125
126QSqlForm* QDataView::form()
127{
128 return d->frm.form();
129}
130
131
132/*!
133 Sets the record used by the data view to \a record. If a form has
134 already been assigned to the data view, the form will display the
135 data from \a record in that form.
136
137 \sa record()
138*/
139
140void QDataView::setRecord( QSqlRecord* record )
141{
142 d->frm.setRecord( record );
143}
144
145
146/*!
147 Returns the default record used by the data view, or 0 if there is
148 none.
149
150 \sa setRecord()
151*/
152
153QSqlRecord* QDataView::record()
154{
155 return d->frm.record();
156}
157
158
159/*!
160 Causes the default form to read its fields from the record buffer.
161 If there is no default form, or no record, nothing happens.
162
163 \sa setForm()
164*/
165
166void QDataView::readFields()
167{
168 d->frm.readFields();
169}
170
171/*!
172 Causes the default form to write its fields to the record buffer.
173 If there is no default form, or no record, nothing happens.
174
175 \sa setForm()
176*/
177
178void QDataView::writeFields()
179{
180 d->frm.writeFields();
181}
182
183/*!
184 Causes the default form to display the contents of \a buf. If
185 there is no default form, nothing happens.The \a buf also becomes
186 the default record for all subsequent calls to readFields() and
187 writefields(). This slot is equivalant to calling:
188
189 \code
190 myView.setRecord( record );
191 myView.readFields();
192 \endcode
193
194 \sa setRecord() readFields()
195*/
196
197void QDataView::refresh( QSqlRecord* buf )
198{
199 if ( buf && buf != record() )
200 setRecord( buf );
201 readFields();
202}
203
204#endif
Note: See TracBrowser for help on using the repository browser.