diff --git a/kexi/plugins/queries/kexiquerydesignerguieditor.h b/kexi/plugins/queries/kexiquerydesignerguieditor.h --- a/kexi/plugins/queries/kexiquerydesignerguieditor.h +++ b/kexi/plugins/queries/kexiquerydesignerguieditor.h @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2004 Lucijan Busch - Copyright (C) 2004-2015 Jarosław Staniek + Copyright (C) 2004-2016 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/kexi/plugins/queries/kexiquerydesignerguieditor.cpp b/kexi/plugins/queries/kexiquerydesignerguieditor.cpp --- a/kexi/plugins/queries/kexiquerydesignerguieditor.cpp +++ b/kexi/plugins/queries/kexiquerydesignerguieditor.cpp @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2004 Lucijan Busch - Copyright (C) 2004-2015 Jarosław Staniek + Copyright (C) 2004-2016 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -602,7 +602,7 @@ if (!d->dataTable->dataAwareObject()->acceptRowEdit()) return cancelled; - kDebug() << "queryChangedInPreviousView:" << tempData()->queryChangedInPreviousView(); + kDebug() << "queryChangedInView:" << tempData()->queryChangedInView(); if (mode == Kexi::DesignViewMode) { return true; @@ -612,7 +612,7 @@ KMessageBox::information(this, msgCannotSwitch_EmptyDesign()); return cancelled; } - if (tempData()->queryChangedInPreviousView() || !tempData()->query()) { + if (tempData()->queryChangedInView() != Kexi::NoViewMode || !tempData()->query()) { //remember current design in a temporary structure QString errMsg; //build schema; problems are not allowed @@ -626,7 +626,7 @@ return true; } else if (mode == Kexi::TextViewMode) { dontStore = true; - if (tempData()->queryChangedInPreviousView() || !tempData()->query()) { + if (tempData()->queryChangedInView() != Kexi::NoViewMode || !tempData()->query()) { //remember current design in a temporary structure //build schema; ignore problems buildSchema(); @@ -676,8 +676,8 @@ } else if (mode == Kexi::TextViewMode || mode == Kexi::DataViewMode) { // Switch from text or data view. In the second case, the design could be changed as well // because there could be changes made in the text view before switching to the data view. - if (tempData()->queryChangedInPreviousView()) { - //previous view changed query data + if (tempData()->queryChangedInView() == Kexi::TextViewMode) { + //SQL view changed the query design //-clear and regenerate GUI items initTableRows(); //! @todo @@ -711,7 +711,7 @@ d->dataTable->tableView()->adjustColumnWidthToContents(COLUMN_ID_COLUMN); d->dataTable->tableView()->adjustColumnWidthToContents(COLUMN_ID_TABLE); } - tempData()->setQueryChangedInPreviousView(false); + tempData()->setQueryChangedInView(false); setFocus(); //to allow shared actions proper update return true; } @@ -729,7 +729,7 @@ } QString errMsg; KexiQueryPart::TempData * temp = tempData(); - if (!temp->query() || !(viewMode() == Kexi::DesignViewMode && !temp->queryChangedInPreviousView())) { + if (!temp->query() || !(viewMode() == Kexi::DesignViewMode && temp->queryChangedInView() == Kexi::NoViewMode)) { //only rebuild schema if it has not been rebuilt previously if (!buildSchema(&errMsg)) { KMessageBox::sorry(this, errMsg); @@ -1254,24 +1254,24 @@ propertySetSwitched(); d->droppedNewRecord = 0; } - tempData()->setQueryChangedInPreviousView(true); + tempData()->setQueryChangedInView(true); } void KexiQueryDesignerGuiEditor::slotTableAdded(KexiDB::TableSchema & /*t*/) { if (!d->slotTableAdded_enabled) return; updateColumnsData(); setDirty(); - tempData()->setQueryChangedInPreviousView(true); + tempData()->setQueryChangedInView(true); d->dataTable->setFocus(); } void KexiQueryDesignerGuiEditor::slotTableHidden(KexiDB::TableSchema & /*t*/) { updateColumnsData(); setDirty(); - tempData()->setQueryChangedInPreviousView(true); + tempData()->setQueryChangedInView(true); } QByteArray KexiQueryDesignerGuiEditor::generateUniqueAlias() const @@ -1624,7 +1624,7 @@ #else //! @todo unused yet setDirty(true); - tempData()->setQueryChangedInPreviousView(true); + tempData()->setQueryChangedInView(true); #endif } @@ -1703,7 +1703,7 @@ (*set)["criteria"] = QVariant(); //clear it } setDirty(true); - tempData()->setQueryChangedInPreviousView(true); + tempData()->setQueryChangedInView(true); } else { result->success = false; @@ -1716,13 +1716,13 @@ void KexiQueryDesignerGuiEditor::slotTablePositionChanged(KexiRelationsTableContainer*) { setDirty(true); - // this is not needed here because only position has changed: tempData()->setQueryChangedInPreviousView(true); + // this is not needed here because only position has changed: tempData()->setQueryChangedInView(true); } void KexiQueryDesignerGuiEditor::slotAboutConnectionRemove(KexiRelationsConnection*) { setDirty(true); - tempData()->setQueryChangedInPreviousView(true); + tempData()->setQueryChangedInView(true); } void KexiQueryDesignerGuiEditor::slotAppendFields( @@ -1853,7 +1853,7 @@ } } } - tempData()->setQueryChangedInPreviousView(true); + tempData()->setQueryChangedInView(true); } void KexiQueryDesignerGuiEditor::slotNewItemStored(KexiPart::Item& item) diff --git a/kexi/plugins/queries/kexiquerydesignersql.h b/kexi/plugins/queries/kexiquerydesignersql.h --- a/kexi/plugins/queries/kexiquerydesignersql.h +++ b/kexi/plugins/queries/kexiquerydesignersql.h @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2004-2012 Jarosław Staniek + Copyright (C) 2004-2016 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/kexi/plugins/queries/kexiquerydesignersql.cpp b/kexi/plugins/queries/kexiquerydesignersql.cpp --- a/kexi/plugins/queries/kexiquerydesignersql.cpp +++ b/kexi/plugins/queries/kexiquerydesignersql.cpp @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2004-2014 Jarosław Staniek + Copyright (C) 2004-2016 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -18,6 +18,11 @@ * Boston, MA 02110-1301, USA. */ +#include "kexiquerydesignersql.h" +#include "kexiquerydesignersqleditor.h" +#include "kexiquerypart.h" +#include "kexisectionheader.h" + #include #include #include @@ -41,13 +46,6 @@ #include #include -#include "kexiquerydesignersqleditor.h" -#include "kexiquerydesignersql.h" -#include "kexiquerypart.h" - -#include "kexisectionheader.h" - - static bool compareSQL(const QString& sql1, const QString& sql2) { //! @todo use reformatting functions here @@ -211,7 +209,7 @@ if (sqlTextIsEmpty && mode == Kexi::DesignViewMode) { //special case: empty SQL text, allow to switch to the design view if (temp->query()) { - temp->setQueryChangedInPreviousView(true); //query changed + temp->setQueryChangedInView(true); //query changed temp->setQuery(0); } } @@ -224,7 +222,7 @@ && compareSQL(d->origStatement, d->editor->text())) { //statement unchanged! - nothing to do - temp->setQueryChangedInPreviousView(false); + temp->setQueryChangedInView(false); } else { //yes: parse SQL text if (sqlTextIsEmpty || !slotCheckQuery()) { @@ -235,7 +233,7 @@ return cancelled; } //do not change original query - it's invalid - temp->setQueryChangedInPreviousView(false); + temp->setQueryChangedInView(false); //this view is no longer _just_ switched from "NoViewMode" d->justSwitchedFromNoViewMode = false; return true; @@ -245,7 +243,7 @@ //replace old query schema with new one temp->setQuery(d->parsedQuery); //this will also delete temp->query() d->parsedQuery = 0; - temp->setQueryChangedInPreviousView(true); + temp->setQueryChangedInView(true); } } d->origStatement = d->editor->text(); @@ -279,7 +277,7 @@ if (query) { // Use query with Kexi keywords (but not driver-specific keywords) escaped. temp->setQuery(query); - if (temp->queryChangedInPreviousView()) { + if (temp->queryChangedInView() != Kexi::NoViewMode) { KexiDB::Connection::SelectStatementOptions options; options.identifierEscaping = KexiDB::Driver::EscapeKexi; options.addVisibleLookupColumns = false; @@ -293,10 +291,19 @@ return false; } - if (!compareSQL(d->origStatement, d->editor->text())) { - d->slotTextChangedEnabled = false; - d->editor->setText(d->origStatement); - d->slotTextChangedEnabled = true; + if (temp->queryChangedInView() == Kexi::DesignViewMode /* true in this scenario: + - user switched from SQL to Design, + - changed the design, + - switched to Data + - switched back to SQL */ + || mode != Kexi::DataViewMode) /* true in this scenario: user switched from No-view + or Design view */ + { + if (!compareSQL(d->origStatement, d->editor->text())) { + d->slotTextChangedEnabled = false; + d->editor->setText(d->origStatement); + d->slotTextChangedEnabled = true; + } } QTimer::singleShot(100, d->editor, SLOT(setFocus())); return true; diff --git a/kexi/plugins/queries/kexiquerypart.h b/kexi/plugins/queries/kexiquerypart.h --- a/kexi/plugins/queries/kexiquerypart.h +++ b/kexi/plugins/queries/kexiquerypart.h @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2004-2010 Jarosław Staniek + Copyright (C) 2004-2016 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -79,19 +79,22 @@ //! Connection used for retrieving definition of the query KexiDB::Connection *conn; - /*! @return true if \a query member has changed in previous view. + /*! @return view mode if which the query member has changed. + It's possibly one of previously visited views. Kexi::NoViewMode is the default, + what means that query was not changed. Used on view switching. We're checking this flag to see if we should rebuild internal structure for DesignViewMode of regenerated sql text in TextViewMode after switch from other view. */ - bool queryChangedInPreviousView() const; + Kexi::ViewMode queryChangedInView() const; - /*! Sets the queryChangedInPreviousView flag. - @see queryChangedInPreviousView() */ - void setQueryChangedInPreviousView(bool set); + /*! Sets the queryChangedInView flag. If @a set is true, then the flag is changed + to the current view mode. If @a set is false, the flag is changed to Kexi::NoViewMode. + @see queryChangedInView() */ + void setQueryChangedInView(bool set); private: KexiDB::QuerySchema *m_query; - bool m_queryChangedInPreviousView; + Kexi::ViewMode m_queryChangedInView; }; virtual KLocalizedString i18nMessage(const QString& englishMessage, diff --git a/kexi/plugins/queries/kexiquerypart.cpp b/kexi/plugins/queries/kexiquerypart.cpp --- a/kexi/plugins/queries/kexiquerypart.cpp +++ b/kexi/plugins/queries/kexiquerypart.cpp @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2004 Lucijan Busch - Copyright (C) 2004-2010 Jarosław Staniek + Copyright (C) 2004-2016 Jarosław Staniek This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -178,7 +178,7 @@ : KexiWindowData(window) , KexiDB::Connection::TableSchemaChangeListenerInterface() , m_query(0) - , m_queryChangedInPreviousView(false) + , m_queryChangedInView(Kexi::NoViewMode) { this->conn = conn; } @@ -236,14 +236,15 @@ m_query = query; } -bool KexiQueryPart::TempData::queryChangedInPreviousView() const +Kexi::ViewMode KexiQueryPart::TempData::queryChangedInView() const { - return m_queryChangedInPreviousView; + return m_queryChangedInView; } -void KexiQueryPart::TempData::setQueryChangedInPreviousView(bool set) +void KexiQueryPart::TempData::setQueryChangedInView(bool set) { - m_queryChangedInPreviousView = set; + m_queryChangedInView = set ? qobject_cast(parent())->currentViewMode() + : Kexi::NoViewMode; } //----------------