Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/forms/widgets/kexidbautofield.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 49 | public: | |||
---|---|---|---|---|---|
58 | QLabel *label; | 58 | QLabel *label; | ||
59 | QString caption; | 59 | QString caption; | ||
60 | KDbField::Type fieldTypeInternal; | 60 | KDbField::Type fieldTypeInternal; | ||
61 | QString fieldCaptionInternal; | 61 | QString fieldCaptionInternal; | ||
62 | QBrush baseBrush; //!< needed because for unbound mode editor==0 | 62 | QBrush baseBrush; //!< needed because for unbound mode editor==0 | ||
63 | QBrush textBrush; //!< needed because for unbound mode editor==0 | 63 | QBrush textBrush; //!< needed because for unbound mode editor==0 | ||
64 | bool autoCaption; | 64 | bool autoCaption; | ||
65 | bool focusPolicyChanged; | 65 | bool focusPolicyChanged; | ||
66 | KDbConnection *conn = nullptr; | ||||
66 | }; | 67 | }; | ||
67 | 68 | | |||
68 | //------------------------------------- | 69 | //------------------------------------- | ||
69 | 70 | | |||
70 | KexiDBAutoField::KexiDBAutoField(const QString &text, WidgetType type, LabelPosition pos, | 71 | KexiDBAutoField::KexiDBAutoField(const QString &text, WidgetType type, LabelPosition pos, | ||
71 | QWidget *parent) | 72 | QWidget *parent) | ||
72 | : QWidget(parent) | 73 | : QWidget(parent) | ||
73 | , KexiFormDataItemInterface() | 74 | , KexiFormDataItemInterface() | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 177 | if (newSubwidget) { | |||
177 | newSubwidget->setObjectName( | 178 | newSubwidget->setObjectName( | ||
178 | QString::fromLatin1("KexiDBAutoField_") + newSubwidget->metaObject()->className()); | 179 | QString::fromLatin1("KexiDBAutoField_") + newSubwidget->metaObject()->className()); | ||
179 | KexiDataItemInterface *iface = dynamic_cast<KexiDataItemInterface*>(newSubwidget); | 180 | KexiDataItemInterface *iface = dynamic_cast<KexiDataItemInterface*>(newSubwidget); | ||
180 | if (iface) { | 181 | if (iface) { | ||
181 | iface->setParentDataItemInterface(this); | 182 | iface->setParentDataItemInterface(this); | ||
182 | } | 183 | } | ||
183 | KexiFormDataItemInterface *formIface = dynamic_cast<KexiFormDataItemInterface*>(newSubwidget); | 184 | KexiFormDataItemInterface *formIface = dynamic_cast<KexiFormDataItemInterface*>(newSubwidget); | ||
184 | if (formIface) { | 185 | if (formIface) { | ||
185 | formIface->setColumnInfo(columnInfo()); //needed at least by KexiDBImageBox | 186 | formIface->setColumnInfo(d->conn, columnInfo()); //needed at least by KexiDBImageBox | ||
186 | formIface->setVisibleColumnInfo(visibleColumnInfo()); //needed at least by KexiDBComboBox | 187 | formIface->setVisibleColumnInfo(visibleColumnInfo()); //needed at least by KexiDBComboBox | ||
187 | } | 188 | } | ||
188 | newSubwidget->setProperty("dataSource", dataSource()); //needed at least by KexiDBImageBox | 189 | newSubwidget->setProperty("dataSource", dataSource()); //needed at least by KexiDBImageBox | ||
189 | KFormDesigner::DesignTimeDynamicChildWidgetHandler::childWidgetAdded(this); | 190 | KFormDesigner::DesignTimeDynamicChildWidgetHandler::childWidgetAdded(this); | ||
190 | newSubwidget->show(); | 191 | newSubwidget->show(); | ||
191 | d->label->setBuddy(newSubwidget); | 192 | d->label->setBuddy(newSubwidget); | ||
192 | if (d->focusPolicyChanged) {//if focusPolicy is changed at top level, editor inherits it | 193 | if (d->focusPolicyChanged) {//if focusPolicy is changed at top level, editor inherits it | ||
193 | newSubwidget->setFocusPolicy(focusPolicy()); | 194 | newSubwidget->setFocusPolicy(focusPolicy()); | ||
▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Line(s) | 478 | { | |||
479 | //change text only if autocaption is set and no columnInfo is available | 480 | //change text only if autocaption is set and no columnInfo is available | ||
480 | KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((QWidget*)subwidget()); | 481 | KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((QWidget*)subwidget()); | ||
481 | if ((!iface || !iface->columnInfo()) && d->autoCaption) { | 482 | if ((!iface || !iface->columnInfo()) && d->autoCaption) { | ||
482 | changeText(d->fieldCaptionInternal); | 483 | changeText(d->fieldCaptionInternal); | ||
483 | } | 484 | } | ||
484 | } | 485 | } | ||
485 | 486 | | |||
486 | void | 487 | void | ||
487 | KexiDBAutoField::setColumnInfo(KDbQueryColumnInfo* cinfo) | 488 | KexiDBAutoField::setColumnInfo(KDbConnection *conn, KDbQueryColumnInfo* cinfo) | ||
488 | { | 489 | { | ||
489 | KexiFormDataItemInterface::setColumnInfo(cinfo); | 490 | KexiFormDataItemInterface::setColumnInfo(conn, cinfo); | ||
491 | d->conn = conn; | ||||
490 | setColumnInfoInternal(cinfo, cinfo); | 492 | setColumnInfoInternal(cinfo, cinfo); | ||
491 | } | 493 | } | ||
492 | 494 | | |||
493 | void | 495 | void KexiDBAutoField::setColumnInfoInternal(KDbQueryColumnInfo *cinfo, | ||
494 | KexiDBAutoField::setColumnInfoInternal(KDbQueryColumnInfo* cinfo, KDbQueryColumnInfo* visibleColumnInfo) | 496 | KDbQueryColumnInfo *visibleColumnInfo) | ||
495 | { | 497 | { | ||
496 | // change widget type depending on field type | 498 | // change widget type depending on field type | ||
497 | if (d->widgetType_property == Auto) { | 499 | if (d->widgetType_property == Auto) { | ||
498 | WidgetType newWidgetType = Auto; | 500 | WidgetType newWidgetType = Auto; | ||
499 | KDbField::Type fieldType; | 501 | KDbField::Type fieldType; | ||
500 | if (cinfo) | 502 | if (cinfo) | ||
501 | fieldType = visibleColumnInfo->field()->type(); | 503 | fieldType = visibleColumnInfo->field()->type(); | ||
502 | else if (dataSource().isEmpty()) | 504 | else if (dataSource().isEmpty()) | ||
Show All 9 Lines | 512 | if (d->widgetType != newWidgetType || newWidgetType == Auto) { | |||
512 | createEditor(); | 514 | createEditor(); | ||
513 | } | 515 | } | ||
514 | } | 516 | } | ||
515 | // update label's text | 517 | // update label's text | ||
516 | changeText((cinfo && d->autoCaption) ? cinfo->captionOrAliasOrName() : d->caption); | 518 | changeText((cinfo && d->autoCaption) ? cinfo->captionOrAliasOrName() : d->caption); | ||
517 | 519 | | |||
518 | KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((QWidget*)subwidget()); | 520 | KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((QWidget*)subwidget()); | ||
519 | if (iface) | 521 | if (iface) | ||
520 | iface->setColumnInfo(visibleColumnInfo); | 522 | iface->setColumnInfo(d->conn, visibleColumnInfo); | ||
521 | } | 523 | } | ||
522 | 524 | | |||
523 | //static | 525 | //static | ||
524 | KexiDBAutoField::WidgetType | 526 | KexiDBAutoField::WidgetType | ||
525 | KexiDBAutoField::widgetTypeForFieldType(KDbField::Type type) | 527 | KexiDBAutoField::widgetTypeForFieldType(KDbField::Type type) | ||
526 | { | 528 | { | ||
527 | switch (type) { | 529 | switch (type) { | ||
528 | case KDbField::Integer: | 530 | case KDbField::Integer: | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 620 | } else | |||
619 | changeText(d->caption); | 621 | changeText(d->caption); | ||
620 | } | 622 | } | ||
621 | 623 | | |||
622 | void | 624 | void | ||
623 | KexiDBAutoField::setDataSource(const QString &ds) | 625 | KexiDBAutoField::setDataSource(const QString &ds) | ||
624 | { | 626 | { | ||
625 | KexiFormDataItemInterface::setDataSource(ds); | 627 | KexiFormDataItemInterface::setDataSource(ds); | ||
626 | if (ds.isEmpty()) { | 628 | if (ds.isEmpty()) { | ||
627 | setColumnInfo(0); | 629 | setColumnInfo(d->conn, nullptr); | ||
628 | } | 630 | } | ||
629 | } | 631 | } | ||
630 | 632 | | |||
631 | QSize | 633 | QSize | ||
632 | KexiDBAutoField::sizeHint() const | 634 | KexiDBAutoField::sizeHint() const | ||
633 | { | 635 | { | ||
634 | if (d->lblPosition == NoLabel) | 636 | if (d->lblPosition == NoLabel) | ||
635 | return subwidget() ? subwidget()->sizeHint() : QWidget::sizeHint(); | 637 | return subwidget() ? subwidget()->sizeHint() : QWidget::sizeHint(); | ||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Line(s) | |||||
806 | 808 | | |||
807 | bool KexiDBAutoField::keyPressed(QKeyEvent *ke) | 809 | bool KexiDBAutoField::keyPressed(QKeyEvent *ke) | ||
808 | { | 810 | { | ||
809 | KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((QWidget*)subwidget()); | 811 | KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>((QWidget*)subwidget()); | ||
810 | if (iface && iface->keyPressed(ke)) | 812 | if (iface && iface->keyPressed(ke)) | ||
811 | return true; | 813 | return true; | ||
812 | return false; | 814 | return false; | ||
813 | } | 815 | } | ||
814 | |