返回介绍

QSqlPropertyMap Class

发布于 2019-10-04 15:03:00 字数 5351 浏览 783 评论 0 收藏 0

The QSqlPropertyMap class is used to map widgets to SQL fields.
More...

#include <qsqlpropertymap.h>

List of all member functions.

Public Members

  • QSqlPropertyMap ()
  • virtual ~QSqlPropertyMap ()
  • QVariant property ( QWidget*widget )
  • virtual void setProperty ( QWidget*widget, constQVariant&value )
  • void insert ( constQString&classname, constQString&property )
  • void remove ( constQString&classname )

Static Public Members

  • QSqlPropertyMap * defaultMap ()
  • void installDefaultMap ( QSqlPropertyMap*map )

Detailed Description

The QSqlPropertyMap class is used to map widgets to SQL fields.

The SQL module uses Qt object properties
to insert and extract values from editor widgets.

This class is used to map editors to SQL fields. This works by
associating SQL editor class names to the properties used to insert
and extract values to/from the editor.

For example, a QLineEdit can be used to edit text strings and other
data types in QDataTables or QSqlForms. Several properties are
defined in QLineEdit, but only the text property is used to
insert and extract text from a QLineEdit. Both QDataTable and QSqlForm
use the global QSqlPropertyMap for inserting and extracting values
to and from an editor widget. The global property map defines
several common widgets and properties that are suitable for many
applications. You can add and remove widget properties to suit your
specific needs.

If you want to use custom editors with your QDataTable or QSqlForm,
you have to install your own QSqlPropertyMap for that table or form.
Example:

  QSqlPropertyMap *myMap  = new QSqlPropertyMap();
  QSqlForm        *myForm = new QSqlForm( this );
  MyEditor         myEditor( this );

  // Set the QSqlForm's record buffer to the update buffer of
  // a pre-existing QSqlCursor called 'cur'.
  myForm->setRecord( cur->primeUpdate() );

  // Install the customized map
  myMap->insert( "MyEditor", "content" );
  myForm->installPropertyMap( myMap ); // myForm now owns myMap
  ...
  // Insert a field into the form that uses a myEditor to edit the
  // field 'somefield'
  myForm->insert( &myEditor, "somefield" );

  // Update myEditor with the value from the mapped database field
  myForm->readFields();
  ...
  // Let the user edit the form
  ...
  // Update the database fields with the values in the form
  myForm->writeFields();
  ...
  

You can also replace the global QSqlPropertyMap that is used by
default. (Bear in mind that QSqlPropertyMap takes ownership of the new
default map.)

  QSqlPropertyMap *myMap = new QSqlPropertyMap;

  myMap->insert( "MyEditor", "content" );
  QSqlPropertyMap::installDefaultMap( myMap );
  ...
  

See also QDataTable, QSqlForm, QSqlEditorFactory and Database Classes.


Member Function Documentation

QSqlPropertyMap::QSqlPropertyMap ()

Constructs a QSqlPropertyMap.

The default property mappings used by Qt widgets are:

  • QButton -- text
  • QCheckBox -- checked
  • QComboBox -- currentItem
  • QDateEdit -- date
  • QDateTimeEdit -- dateTime
  • QDial -- value
  • QLabel -- text
  • QLCDNumber -- value
  • QLineEdit -- text
  • QListBox -- currentItem
  • QMultiLineEdit -- text
  • QPushButton -- text
  • QRadioButton -- text
  • QScrollBar -- value
  • QSlider -- value
  • QSpinBox -- value
  • QTextBrowser -- source
  • QTextEdit -- text
  • QTextView -- text
  • QTimeEdit -- time

QSqlPropertyMap::~QSqlPropertyMap () [virtual]

Destroys the QSqlPropertyMap.

Note that if the QSqlPropertyMap is installed with
installPropertyMap() the object it was installed into, e.g. the
QSqlForm, takes ownership and will delete the QSqlPropertyMap when
necessary.

QSqlPropertyMap* QSqlPropertyMap::defaultMap () [static]

Returns the application global QSqlPropertyMap.

void QSqlPropertyMap::insert ( constQString&classname, constQString&property )

Insert a new classname/property pair, which is used for custom SQL
field editors. There must be a Q_PROPERTY clause in the classname
class declaration for the property.

Example: sql/overview/custom1/main.cpp.

void QSqlPropertyMap::installDefaultMap ( QSqlPropertyMap*map ) [static]

Replaces the global default property map with map. All QDataTable and
QSqlForm instantiations will use this new map for inserting and
extracting values to and from editors. QSqlPropertyMap takes
ownership of map, and destroys it when it is no longer needed.

QVariant QSqlPropertyMap::property ( QWidget*widget )

Returns the mapped property of widget as a QVariant.

void QSqlPropertyMap::remove ( constQString&classname )

Removes classname from the map.

void QSqlPropertyMap::setProperty ( QWidget*widget, constQVariant&value ) [virtual]

Sets the property of widget to value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文