Changeset View
Changeset View
Standalone View
Standalone View
kexi/plugins/queries/kexiquerydesignerguieditor.cpp
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2004 Lucijan Busch <lucijan@kde.org> | 2 | Copyright (C) 2004 Lucijan Busch <lucijan@kde.org> | ||
3 | Copyright (C) 2004-2015 Jarosław Staniek <staniek@kde.org> | 3 | Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org> | ||
4 | 4 | | |||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. | ||
9 | 9 | | |||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 585 Lines • ▼ Show 20 Line(s) | |||||
597 | tristate | 597 | tristate | ||
598 | KexiQueryDesignerGuiEditor::beforeSwitchTo(Kexi::ViewMode mode, bool &dontStore) | 598 | KexiQueryDesignerGuiEditor::beforeSwitchTo(Kexi::ViewMode mode, bool &dontStore) | ||
599 | { | 599 | { | ||
600 | kDebug() << mode; | 600 | kDebug() << mode; | ||
601 | 601 | | |||
602 | if (!d->dataTable->dataAwareObject()->acceptRowEdit()) | 602 | if (!d->dataTable->dataAwareObject()->acceptRowEdit()) | ||
603 | return cancelled; | 603 | return cancelled; | ||
604 | 604 | | |||
605 | kDebug() << "queryChangedInPreviousView:" << tempData()->queryChangedInPreviousView(); | 605 | kDebug() << "queryChangedInView:" << tempData()->queryChangedInView(); | ||
606 | 606 | | |||
607 | if (mode == Kexi::DesignViewMode) { | 607 | if (mode == Kexi::DesignViewMode) { | ||
608 | return true; | 608 | return true; | ||
609 | } | 609 | } | ||
610 | else if (mode == Kexi::DataViewMode) { | 610 | else if (mode == Kexi::DataViewMode) { | ||
611 | if (!isDirty() && window()->neverSaved()) { | 611 | if (!isDirty() && window()->neverSaved()) { | ||
612 | KMessageBox::information(this, msgCannotSwitch_EmptyDesign()); | 612 | KMessageBox::information(this, msgCannotSwitch_EmptyDesign()); | ||
613 | return cancelled; | 613 | return cancelled; | ||
614 | } | 614 | } | ||
615 | if (tempData()->queryChangedInPreviousView() || !tempData()->query()) { | 615 | if (tempData()->queryChangedInView() != Kexi::NoViewMode || !tempData()->query()) { | ||
616 | //remember current design in a temporary structure | 616 | //remember current design in a temporary structure | ||
617 | QString errMsg; | 617 | QString errMsg; | ||
618 | //build schema; problems are not allowed | 618 | //build schema; problems are not allowed | ||
619 | if (!buildSchema(&errMsg)) { | 619 | if (!buildSchema(&errMsg)) { | ||
620 | KMessageBox::sorry(this, errMsg); | 620 | KMessageBox::sorry(this, errMsg); | ||
621 | return cancelled; | 621 | return cancelled; | ||
622 | } | 622 | } | ||
623 | } | 623 | } | ||
624 | dontStore = true; | 624 | dontStore = true; | ||
625 | //! @todo | 625 | //! @todo | ||
626 | return true; | 626 | return true; | ||
627 | } else if (mode == Kexi::TextViewMode) { | 627 | } else if (mode == Kexi::TextViewMode) { | ||
628 | dontStore = true; | 628 | dontStore = true; | ||
629 | if (tempData()->queryChangedInPreviousView() || !tempData()->query()) { | 629 | if (tempData()->queryChangedInView() != Kexi::NoViewMode || !tempData()->query()) { | ||
630 | //remember current design in a temporary structure | 630 | //remember current design in a temporary structure | ||
631 | //build schema; ignore problems | 631 | //build schema; ignore problems | ||
632 | buildSchema(); | 632 | buildSchema(); | ||
633 | } | 633 | } | ||
634 | /* if (tempData()->query && tempData()->query->fieldCount()==0) { | 634 | /* if (tempData()->query && tempData()->query->fieldCount()==0) { | ||
635 | //no fields selected: let's add "*" (all-tables asterisk), | 635 | //no fields selected: let's add "*" (all-tables asterisk), | ||
636 | // otherwise SQL statement will be invalid | 636 | // otherwise SQL statement will be invalid | ||
637 | tempData()->query->addAsterisk( new KexiDB::QueryAsterisk( tempData()->query ) ); | 637 | tempData()->query->addAsterisk( new KexiDB::QueryAsterisk( tempData()->query ) ); | ||
Show All 33 Lines | 668 | if (!result.success) { | |||
671 | return false; | 671 | return false; | ||
672 | } | 672 | } | ||
673 | } | 673 | } | ||
674 | //! @todo load global query properties | 674 | //! @todo load global query properties | ||
675 | } | 675 | } | ||
676 | } else if (mode == Kexi::TextViewMode || mode == Kexi::DataViewMode) { | 676 | } else if (mode == Kexi::TextViewMode || mode == Kexi::DataViewMode) { | ||
677 | // Switch from text or data view. In the second case, the design could be changed as well | 677 | // Switch from text or data view. In the second case, the design could be changed as well | ||
678 | // because there could be changes made in the text view before switching to the data view. | 678 | // because there could be changes made in the text view before switching to the data view. | ||
679 | if (tempData()->queryChangedInPreviousView()) { | 679 | if (tempData()->queryChangedInView() == Kexi::TextViewMode) { | ||
680 | //previous view changed query data | 680 | //SQL view changed the query design | ||
681 | //-clear and regenerate GUI items | 681 | //-clear and regenerate GUI items | ||
682 | initTableRows(); | 682 | initTableRows(); | ||
683 | //! @todo | 683 | //! @todo | ||
684 | if (tempData()->query()) { | 684 | if (tempData()->query()) { | ||
685 | //there is a query schema to show | 685 | //there is a query schema to show | ||
686 | showTablesForQuery(tempData()->query()); | 686 | showTablesForQuery(tempData()->query()); | ||
687 | //-show fields | 687 | //-show fields | ||
688 | KexiDB::ResultInfo result; | 688 | KexiDB::ResultInfo result; | ||
Show All 17 Lines | 704 | if (d->dataTable->dataAwareObject()->currentRow() < 0 | |||
706 | d->dataTable->dataAwareObject()->ensureCellVisible(0, 0); | 706 | d->dataTable->dataAwareObject()->ensureCellVisible(0, 0); | ||
707 | d->dataTable->dataAwareObject()->setCursorPosition(0, 0); | 707 | d->dataTable->dataAwareObject()->setCursorPosition(0, 0); | ||
708 | } | 708 | } | ||
709 | } | 709 | } | ||
710 | if (d->sets->size() > 0) { | 710 | if (d->sets->size() > 0) { | ||
711 | d->dataTable->tableView()->adjustColumnWidthToContents(COLUMN_ID_COLUMN); | 711 | d->dataTable->tableView()->adjustColumnWidthToContents(COLUMN_ID_COLUMN); | ||
712 | d->dataTable->tableView()->adjustColumnWidthToContents(COLUMN_ID_TABLE); | 712 | d->dataTable->tableView()->adjustColumnWidthToContents(COLUMN_ID_TABLE); | ||
713 | } | 713 | } | ||
714 | tempData()->setQueryChangedInPreviousView(false); | 714 | tempData()->setQueryChangedInView(false); | ||
715 | setFocus(); //to allow shared actions proper update | 715 | setFocus(); //to allow shared actions proper update | ||
716 | return true; | 716 | return true; | ||
717 | } | 717 | } | ||
718 | 718 | | |||
719 | 719 | | |||
720 | KexiDB::SchemaData* | 720 | KexiDB::SchemaData* | ||
721 | KexiQueryDesignerGuiEditor::storeNewData(const KexiDB::SchemaData& sdata, | 721 | KexiQueryDesignerGuiEditor::storeNewData(const KexiDB::SchemaData& sdata, | ||
722 | KexiView::StoreNewDataOptions options, | 722 | KexiView::StoreNewDataOptions options, | ||
723 | bool &cancel) | 723 | bool &cancel) | ||
724 | { | 724 | { | ||
725 | Q_UNUSED(options); | 725 | Q_UNUSED(options); | ||
726 | if (!d->dataTable->dataAwareObject()->acceptRowEdit()) { | 726 | if (!d->dataTable->dataAwareObject()->acceptRowEdit()) { | ||
727 | cancel = true; | 727 | cancel = true; | ||
728 | return 0; | 728 | return 0; | ||
729 | } | 729 | } | ||
730 | QString errMsg; | 730 | QString errMsg; | ||
731 | KexiQueryPart::TempData * temp = tempData(); | 731 | KexiQueryPart::TempData * temp = tempData(); | ||
732 | if (!temp->query() || !(viewMode() == Kexi::DesignViewMode && !temp->queryChangedInPreviousView())) { | 732 | if (!temp->query() || !(viewMode() == Kexi::DesignViewMode && temp->queryChangedInView() == Kexi::NoViewMode)) { | ||
733 | //only rebuild schema if it has not been rebuilt previously | 733 | //only rebuild schema if it has not been rebuilt previously | ||
734 | if (!buildSchema(&errMsg)) { | 734 | if (!buildSchema(&errMsg)) { | ||
735 | KMessageBox::sorry(this, errMsg); | 735 | KMessageBox::sorry(this, errMsg); | ||
736 | cancel = true; | 736 | cancel = true; | ||
737 | return 0; | 737 | return 0; | ||
738 | } | 738 | } | ||
739 | } | 739 | } | ||
740 | (KexiDB::SchemaData&)*temp->query() = sdata; //copy main attributes | 740 | (KexiDB::SchemaData&)*temp->query() = sdata; //copy main attributes | ||
▲ Show 20 Lines • Show All 508 Lines • ▼ Show 20 Line(s) | |||||
1249 | 1249 | | |||
1250 | void KexiQueryDesignerGuiEditor::slotRowInserted(KexiDB::RecordData* record, uint row, bool /*repaint*/) | 1250 | void KexiQueryDesignerGuiEditor::slotRowInserted(KexiDB::RecordData* record, uint row, bool /*repaint*/) | ||
1251 | { | 1251 | { | ||
1252 | if (d->droppedNewRecord && d->droppedNewRecord == record) { | 1252 | if (d->droppedNewRecord && d->droppedNewRecord == record) { | ||
1253 | createPropertySet(row, d->droppedNewTable, d->droppedNewField, true); | 1253 | createPropertySet(row, d->droppedNewTable, d->droppedNewField, true); | ||
1254 | propertySetSwitched(); | 1254 | propertySetSwitched(); | ||
1255 | d->droppedNewRecord = 0; | 1255 | d->droppedNewRecord = 0; | ||
1256 | } | 1256 | } | ||
1257 | tempData()->setQueryChangedInPreviousView(true); | 1257 | tempData()->setQueryChangedInView(true); | ||
1258 | } | 1258 | } | ||
1259 | 1259 | | |||
1260 | void KexiQueryDesignerGuiEditor::slotTableAdded(KexiDB::TableSchema & /*t*/) | 1260 | void KexiQueryDesignerGuiEditor::slotTableAdded(KexiDB::TableSchema & /*t*/) | ||
1261 | { | 1261 | { | ||
1262 | if (!d->slotTableAdded_enabled) | 1262 | if (!d->slotTableAdded_enabled) | ||
1263 | return; | 1263 | return; | ||
1264 | updateColumnsData(); | 1264 | updateColumnsData(); | ||
1265 | setDirty(); | 1265 | setDirty(); | ||
1266 | tempData()->setQueryChangedInPreviousView(true); | 1266 | tempData()->setQueryChangedInView(true); | ||
1267 | d->dataTable->setFocus(); | 1267 | d->dataTable->setFocus(); | ||
1268 | } | 1268 | } | ||
1269 | 1269 | | |||
1270 | void KexiQueryDesignerGuiEditor::slotTableHidden(KexiDB::TableSchema & /*t*/) | 1270 | void KexiQueryDesignerGuiEditor::slotTableHidden(KexiDB::TableSchema & /*t*/) | ||
1271 | { | 1271 | { | ||
1272 | updateColumnsData(); | 1272 | updateColumnsData(); | ||
1273 | setDirty(); | 1273 | setDirty(); | ||
1274 | tempData()->setQueryChangedInPreviousView(true); | 1274 | tempData()->setQueryChangedInView(true); | ||
1275 | } | 1275 | } | ||
1276 | 1276 | | |||
1277 | QByteArray KexiQueryDesignerGuiEditor::generateUniqueAlias() const | 1277 | QByteArray KexiQueryDesignerGuiEditor::generateUniqueAlias() const | ||
1278 | { | 1278 | { | ||
1279 | //! @todo add option for using non-i18n'd "expr" prefix? | 1279 | //! @todo add option for using non-i18n'd "expr" prefix? | ||
1280 | const QByteArray expStr( | 1280 | const QByteArray expStr( | ||
1281 | i18nc("short for 'expression' word (only latin letters, please)", "expr").toLatin1()); | 1281 | i18nc("short for 'expression' word (only latin letters, please)", "expr").toLatin1()); | ||
1282 | //! @todo optimization: cache it? | 1282 | //! @todo optimization: cache it? | ||
▲ Show 20 Lines • Show All 336 Lines • ▼ Show 20 Line(s) | |||||
1619 | { | 1619 | { | ||
1620 | #ifdef KEXI_NO_QUERY_TOTALS | 1620 | #ifdef KEXI_NO_QUERY_TOTALS | ||
1621 | Q_UNUSED(record) | 1621 | Q_UNUSED(record) | ||
1622 | Q_UNUSED(newValue) | 1622 | Q_UNUSED(newValue) | ||
1623 | Q_UNUSED(result) | 1623 | Q_UNUSED(result) | ||
1624 | #else | 1624 | #else | ||
1625 | //! @todo unused yet | 1625 | //! @todo unused yet | ||
1626 | setDirty(true); | 1626 | setDirty(true); | ||
1627 | tempData()->setQueryChangedInPreviousView(true); | 1627 | tempData()->setQueryChangedInView(true); | ||
1628 | #endif | 1628 | #endif | ||
1629 | } | 1629 | } | ||
1630 | 1630 | | |||
1631 | void KexiQueryDesignerGuiEditor::slotBeforeSortingCellChanged(KexiDB::RecordData *record, | 1631 | void KexiQueryDesignerGuiEditor::slotBeforeSortingCellChanged(KexiDB::RecordData *record, | ||
1632 | QVariant& newValue, KexiDB::ResultInfo* result) | 1632 | QVariant& newValue, KexiDB::ResultInfo* result) | ||
1633 | { | 1633 | { | ||
1634 | bool saveOldValue = true; | 1634 | bool saveOldValue = true; | ||
1635 | KoProperty::Set *set = d->sets->findPropertySetForItem(*record); | 1635 | KoProperty::Set *set = d->sets->findPropertySetForItem(*record); | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 1697 | if (set) { | |||
1698 | (*set)["criteria"] = QString(tokenStr + e->toString(0)); //print it prettier | 1698 | (*set)["criteria"] = QString(tokenStr + e->toString(0)); //print it prettier | ||
1699 | } | 1699 | } | ||
1700 | //this is just checking: destroy expr. object | 1700 | //this is just checking: destroy expr. object | ||
1701 | delete e; | 1701 | delete e; | ||
1702 | } else if (set && str.isEmpty()) { | 1702 | } else if (set && str.isEmpty()) { | ||
1703 | (*set)["criteria"] = QVariant(); //clear it | 1703 | (*set)["criteria"] = QVariant(); //clear it | ||
1704 | } | 1704 | } | ||
1705 | setDirty(true); | 1705 | setDirty(true); | ||
1706 | tempData()->setQueryChangedInPreviousView(true); | 1706 | tempData()->setQueryChangedInView(true); | ||
1707 | } | 1707 | } | ||
1708 | else { | 1708 | else { | ||
1709 | result->success = false; | 1709 | result->success = false; | ||
1710 | result->allowToDiscardChanges = true; | 1710 | result->allowToDiscardChanges = true; | ||
1711 | result->column = COLUMN_ID_CRITERIA; | 1711 | result->column = COLUMN_ID_CRITERIA; | ||
1712 | result->msg = i18n("Invalid criteria \"%1\"", newValue.toString()); | 1712 | result->msg = i18n("Invalid criteria \"%1\"", newValue.toString()); | ||
1713 | } | 1713 | } | ||
1714 | } | 1714 | } | ||
1715 | 1715 | | |||
1716 | void KexiQueryDesignerGuiEditor::slotTablePositionChanged(KexiRelationsTableContainer*) | 1716 | void KexiQueryDesignerGuiEditor::slotTablePositionChanged(KexiRelationsTableContainer*) | ||
1717 | { | 1717 | { | ||
1718 | setDirty(true); | 1718 | setDirty(true); | ||
1719 | // this is not needed here because only position has changed: tempData()->setQueryChangedInPreviousView(true); | 1719 | // this is not needed here because only position has changed: tempData()->setQueryChangedInView(true); | ||
1720 | } | 1720 | } | ||
1721 | 1721 | | |||
1722 | void KexiQueryDesignerGuiEditor::slotAboutConnectionRemove(KexiRelationsConnection*) | 1722 | void KexiQueryDesignerGuiEditor::slotAboutConnectionRemove(KexiRelationsConnection*) | ||
1723 | { | 1723 | { | ||
1724 | setDirty(true); | 1724 | setDirty(true); | ||
1725 | tempData()->setQueryChangedInPreviousView(true); | 1725 | tempData()->setQueryChangedInView(true); | ||
1726 | } | 1726 | } | ||
1727 | 1727 | | |||
1728 | void KexiQueryDesignerGuiEditor::slotAppendFields( | 1728 | void KexiQueryDesignerGuiEditor::slotAppendFields( | ||
1729 | KexiDB::TableOrQuerySchema& tableOrQuery, const QStringList& fieldNames) | 1729 | KexiDB::TableOrQuerySchema& tableOrQuery, const QStringList& fieldNames) | ||
1730 | { | 1730 | { | ||
1731 | //! @todo how about query columns and multiple fields? | 1731 | //! @todo how about query columns and multiple fields? | ||
1732 | KexiDB::TableSchema *table = tableOrQuery.table(); | 1732 | KexiDB::TableSchema *table = tableOrQuery.table(); | ||
1733 | if (!table || fieldNames.isEmpty()) | 1733 | if (!table || fieldNames.isEmpty()) | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | 1846 | if (set["isExpression"].value().toBool() == true) { | |||
1848 | d->dataTable->dataAwareObject()->acceptEditor(); | 1848 | d->dataTable->dataAwareObject()->acceptEditor(); | ||
1849 | d->data->updateRowEditBuffer(d->dataTable->dataAwareObject()->selectedItem(), | 1849 | d->data->updateRowEditBuffer(d->dataTable->dataAwareObject()->selectedItem(), | ||
1850 | 0, QVariant(set["alias"].value().toString() | 1850 | 0, QVariant(set["alias"].value().toString() | ||
1851 | + ": " + set["field"].value().toString())); | 1851 | + ": " + set["field"].value().toString())); | ||
1852 | d->data->saveRowChanges(*d->dataTable->dataAwareObject()->selectedItem(), true); | 1852 | d->data->saveRowChanges(*d->dataTable->dataAwareObject()->selectedItem(), true); | ||
1853 | } | 1853 | } | ||
1854 | } | 1854 | } | ||
1855 | } | 1855 | } | ||
1856 | tempData()->setQueryChangedInPreviousView(true); | 1856 | tempData()->setQueryChangedInView(true); | ||
1857 | } | 1857 | } | ||
1858 | 1858 | | |||
1859 | void KexiQueryDesignerGuiEditor::slotNewItemStored(KexiPart::Item& item) | 1859 | void KexiQueryDesignerGuiEditor::slotNewItemStored(KexiPart::Item& item) | ||
1860 | { | 1860 | { | ||
1861 | d->relations->objectCreated(item.partClass(), item.name()); | 1861 | d->relations->objectCreated(item.partClass(), item.name()); | ||
1862 | } | 1862 | } | ||
1863 | 1863 | | |||
1864 | void KexiQueryDesignerGuiEditor::slotItemRemoved(const KexiPart::Item& item) | 1864 | void KexiQueryDesignerGuiEditor::slotItemRemoved(const KexiPart::Item& item) | ||
Show All 10 Lines |