Changeset View
Changeset View
Standalone View
Standalone View
kexi/plugins/forms/kexiformview.cpp
Show First 20 Lines • Show All 534 Lines • ▼ Show 20 Line(s) | 509 | { | |||
---|---|---|---|---|---|
535 | } | 535 | } | ||
536 | else { | 536 | else { | ||
537 | //set "autoTabStops" property | 537 | //set "autoTabStops" property | ||
538 | d->dbform->setAutoTabStops(form()->autoTabStops()); | 538 | d->dbform->setAutoTabStops(form()->autoTabStops()); | ||
539 | } | 539 | } | ||
540 | 540 | | |||
541 | if (viewMode() == Kexi::DataViewMode) { | 541 | if (viewMode() == Kexi::DataViewMode) { | ||
542 | //TMP!! | 542 | //TMP!! | ||
543 | initDataSource(); | 543 | if (!initDataSource()) { | ||
544 | return false; | ||||
545 | } | ||||
544 | 546 | | |||
545 | //handle events for this form | 547 | //handle events for this form | ||
546 | d->scrollView->setMainWidgetForEventHandling(d->dbform); | 548 | d->scrollView->setMainWidgetForEventHandling(d->dbform); | ||
547 | 549 | | |||
548 | //set focus on 1st focusable widget which has valid dataSource property set | 550 | //set focus on 1st focusable widget which has valid dataSource property set | ||
549 | QList<QWidget*> *orderedFocusWidgets = d->dbform->orderedFocusWidgets(); | 551 | QList<QWidget*> *orderedFocusWidgets = d->dbform->orderedFocusWidgets(); | ||
550 | if (!orderedFocusWidgets->isEmpty()) { | 552 | if (!orderedFocusWidgets->isEmpty()) { | ||
551 | KexiUtils::unsetFocusWithReason(QApplication::focusWidget(), Qt::TabFocusReason); | 553 | KexiUtils::unsetFocusWithReason(QApplication::focusWidget(), Qt::TabFocusReason); | ||
Show All 39 Lines | 592 | { | |||
591 | return dynamic_cast<KexiFormPartTempData*>(window()->data()); | 593 | return dynamic_cast<KexiFormPartTempData*>(window()->data()); | ||
592 | } | 594 | } | ||
593 | 595 | | |||
594 | KexiFormPart* KexiFormView::formPart() const | 596 | KexiFormPart* KexiFormView::formPart() const | ||
595 | { | 597 | { | ||
596 | return dynamic_cast<KexiFormPart*>(part()); | 598 | return dynamic_cast<KexiFormPart*>(part()); | ||
597 | } | 599 | } | ||
598 | 600 | | |||
599 | void KexiFormView::initDataSource() | 601 | bool KexiFormView::initDataSource() | ||
600 | { | 602 | { | ||
601 | deleteQuery(); | 603 | deleteQuery(); | ||
602 | //! @todo also handle anonymous (not stored) queries provided as statements here | 604 | //! @todo also handle anonymous (not stored) queries provided as statements here | ||
603 | KexiDB::TableSchema *tableSchema = 0; | 605 | KexiDB::TableSchema *tableSchema = 0; | ||
604 | KexiDB::Connection *conn = 0; | 606 | KexiDB::Connection *conn = 0; | ||
605 | QStringList sources; | 607 | QStringList sources; | ||
606 | bool forceReadOnlyDataSource = false; | 608 | bool forceReadOnlyDataSource = false; | ||
607 | QString dataSourceString(d->dbform->dataSource()); | 609 | QString dataSourceString(d->dbform->dataSource()); | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 655 | if (ok) { | |||
695 | else { | 697 | else { | ||
696 | KexiDB::debug(d->query->parameters()); | 698 | KexiDB::debug(d->query->parameters()); | ||
697 | // like in KexiQueryView::executeQuery() | 699 | // like in KexiQueryView::executeQuery() | ||
698 | QList<QVariant> params; | 700 | QList<QVariant> params; | ||
699 | { | 701 | { | ||
700 | KexiUtils::WaitCursorRemover remover; | 702 | KexiUtils::WaitCursorRemover remover; | ||
701 | params = KexiQueryParameters::getParameters(this, *conn->driver(), *d->query, ok); | 703 | params = KexiQueryParameters::getParameters(this, *conn->driver(), *d->query, ok); | ||
702 | } | 704 | } | ||
703 | if (ok) //input cancelled | 705 | if (ok) { //input cancelled | ||
704 | d->cursor = conn->executeQuery(*d->query, params); | 706 | d->cursor = conn->prepareQuery(*d->query, params); | ||
707 | } | ||||
705 | } | 708 | } | ||
706 | d->scrollView->invalidateDataSources(invalidSources, d->query); | 709 | d->scrollView->invalidateDataSources(invalidSources, d->query); | ||
707 | ok = d->cursor != 0; | 710 | ok = d->cursor != 0; | ||
711 | if (ok) { | ||||
712 | ok = setData(d->cursor); | ||||
713 | } | ||||
708 | } | 714 | } | ||
709 | 715 | | |||
710 | if (!invalidSources.isEmpty()) | 716 | if (!invalidSources.isEmpty()) | ||
711 | d->dbform->updateTabStopsOrder(); | 717 | d->dbform->updateTabStopsOrder(); | ||
712 | 718 | | |||
713 | if (ok) { | 719 | if (ok) { | ||
714 | //! @todo PRIMITIVE!! data setting: | 720 | //! @todo PRIMITIVE!! data setting: | ||
715 | //! @todo KexiDB::TableViewData is not a great name for data class here... rename/move? | 721 | //! @todo KexiDB::TableViewData is not a great name for data class here... rename/move? | ||
716 | KexiDB::TableViewData* data = new KexiDB::TableViewData(d->cursor); | 722 | KexiDB::TableViewData* data = new KexiDB::TableViewData(d->cursor); | ||
717 | if (forceReadOnlyDataSource) | 723 | if (forceReadOnlyDataSource) | ||
piggz: add some {} ? | |||||
Yes, originally I did but decided to keep the patch minimal/ready to study for now. staniek: Yes, originally I did but decided to keep the patch minimal/ready to study for now. | |||||
718 | data->setReadOnly(true); | 724 | data->setReadOnly(true); | ||
719 | data->preloadAllRows(); | 725 | ok = data->preloadAllRows(); | ||
720 | 726 | | |||
721 | ///*! @todo few backends return result count for free! - no need to reopen() */ | 727 | ///*! @todo few backends return result count for free! - no need to reopen() */ | ||
722 | // int resultCount = -1; | 728 | // int resultCount = -1; | ||
723 | // if (ok) { | 729 | // if (ok) { | ||
724 | // resultCount = d->conn->resultCount(d->conn->selectStatement(*d->query)); | 730 | // resultCount = d->conn->resultCount(d->conn->selectStatement(*d->query)); | ||
725 | // ok = d->cursor->reopen(); | 731 | // ok = d->cursor->reopen(); | ||
726 | // } | 732 | // } | ||
727 | // if (ok) | 733 | // if (ok) | ||
728 | // ok = ! (!d->cursor->moveFirst() && d->cursor->error()); | 734 | // ok = ! (!d->cursor->moveFirst() && d->cursor->error()); | ||
729 | 735 | | |||
736 | if (ok) { | ||||
730 | d->scrollView->setData(data, true /*owner*/); | 737 | d->scrollView->setData(data, true /*owner*/); | ||
738 | } else { | ||||
739 | delete data; | ||||
740 | } | ||||
731 | } | 741 | } | ||
732 | else { | 742 | else { | ||
733 | d->scrollView->setData(0, false); | 743 | d->scrollView->setData(0, false); | ||
734 | } | 744 | } | ||
745 | return ok; | ||||
735 | } | 746 | } | ||
736 | 747 | | |||
737 | void KexiFormView::setFormModified() | 748 | void KexiFormView::setFormModified() | ||
738 | { | 749 | { | ||
739 | form()->setModified(true); | 750 | form()->setModified(true); | ||
740 | } | 751 | } | ||
741 | 752 | | |||
742 | KexiDB::SchemaData* KexiFormView::storeNewData(const KexiDB::SchemaData& sdata, | 753 | KexiDB::SchemaData* KexiFormView::storeNewData(const KexiDB::SchemaData& sdata, | ||
▲ Show 20 Lines • Show All 540 Lines • Show Last 20 Lines |
add some {} ?