Commit bc54bad2 authored by Jarosław Staniek's avatar Jarosław Staniek
Browse files

Fix state of 'modification' flag while switching from SQL view to Query Data view and back

Summary:
A general change in the logic of the Query Designer is that now we remember the view mode that was in use while the modification to design happened, not just the fact that the modification happened previously (since the last saving changes).

BUG:278379

Also fixes this:
Changes in query design not retained after changes in SQL view and switching to Data view
BUG:358413

FIXED-IN:2.9.11

Test Plan: Follow the scenarios of the both bugs for any simple query such as "SELECT * FROM T ORDER BY F".

Reviewers: piggz, wicik

Projects: #kexi, #calligra:_3.0

Differential Revision: https://phabricator.kde.org/D856

ported from calligra.git e8262276d8888e9
parent 00dd676e
/* This file is part of the KDE project
Copyright (C) 2004 Lucijan Busch <lucijan@kde.org>
Copyright (C) 2004-2015 Jarosław Staniek <staniek@kde.org>
Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -611,7 +611,7 @@ KexiQueryDesignerGuiEditor::beforeSwitchTo(Kexi::ViewMode mode, bool *dontStore)
if (!d->dataTable->dataAwareObject()->acceptRecordEditing())
return cancelled;
qDebug() << "queryChangedInPreviousView:" << tempData()->queryChangedInPreviousView();
qDebug() << "queryChangedInView:" << tempData()->queryChangedInView();
if (mode == Kexi::DesignViewMode) {
return true;
......@@ -621,7 +621,7 @@ KexiQueryDesignerGuiEditor::beforeSwitchTo(Kexi::ViewMode mode, bool *dontStore)
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
......@@ -635,7 +635,7 @@ KexiQueryDesignerGuiEditor::beforeSwitchTo(Kexi::ViewMode mode, bool *dontStore)
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();
......@@ -689,8 +689,8 @@ KexiQueryDesignerGuiEditor::afterSwitchFrom(Kexi::ViewMode mode)
} 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
......@@ -724,7 +724,7 @@ KexiQueryDesignerGuiEditor::afterSwitchFrom(Kexi::ViewMode mode)
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;
}
......@@ -743,7 +743,7 @@ KexiQueryDesignerGuiEditor::storeNewData(const KDbObject& object,
}
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);
......@@ -1269,7 +1269,7 @@ void KexiQueryDesignerGuiEditor::slotRecordInserted(KDbRecordData* data, int rec
propertySetSwitched();
d->droppedNewRecord = 0;
}
tempData()->setQueryChangedInPreviousView(true);
tempData()->setQueryChangedInView(true);
}
void KexiQueryDesignerGuiEditor::slotTableAdded(KDbTableSchema* /*t*/)
......@@ -1278,7 +1278,7 @@ void KexiQueryDesignerGuiEditor::slotTableAdded(KDbTableSchema* /*t*/)
return;
updateColumnsData();
setDirty();
tempData()->setQueryChangedInPreviousView(true);
tempData()->setQueryChangedInView(true);
d->dataTable->setFocus();
}
......@@ -1286,7 +1286,7 @@ void KexiQueryDesignerGuiEditor::slotTableHidden(KDbTableSchema* /*t*/)
{
updateColumnsData();
setDirty();
tempData()->setQueryChangedInPreviousView(true);
tempData()->setQueryChangedInView(true);
}
QByteArray KexiQueryDesignerGuiEditor::generateUniqueAlias() const
......@@ -1640,7 +1640,7 @@ void KexiQueryDesignerGuiEditor::slotBeforeTotalsCellChanged(KDbRecordData *data
#else
//! @todo unused yet
setDirty(true);
tempData()->setQueryChangedInPreviousView(true);
tempData()->setQueryChangedInView(true);
#endif
}
......@@ -1717,7 +1717,7 @@ void KexiQueryDesignerGuiEditor::slotBeforeCriteriaCellChanged(KDbRecordData *da
(*set)["criteria"] = QVariant(); //clear it
}
setDirty(true);
tempData()->setQueryChangedInPreviousView(true);
tempData()->setQueryChangedInView(true);
}
else {
result->success = false;
......@@ -1730,13 +1730,13 @@ void KexiQueryDesignerGuiEditor::slotBeforeCriteriaCellChanged(KDbRecordData *da
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(
......@@ -1867,7 +1867,7 @@ void KexiQueryDesignerGuiEditor::slotPropertyChanged(KPropertySet& set, KPropert
}
}
}
tempData()->setQueryChangedInPreviousView(true);
tempData()->setQueryChangedInView(true);
}
void KexiQueryDesignerGuiEditor::slotNewItemStored(KexiPart::Item* item)
......
/* This file is part of the KDE project
Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
Copyright (C) 2004-2014 Jarosław Staniek <staniek@kde.org>
Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -208,7 +208,7 @@ tristate KexiQueryDesignerSQLView::beforeSwitchTo(Kexi::ViewMode mode, bool *don
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);
}
}
......@@ -221,7 +221,7 @@ tristate KexiQueryDesignerSQLView::beforeSwitchTo(Kexi::ViewMode mode, bool *don
&& compareSQL(d->origStatement.toString(), d->editor->text()))
{
//statement unchanged! - nothing to do
temp->setQueryChangedInPreviousView(false);
temp->setQueryChangedInView(false);
} else {
//yes: parse SQL text
if (sqlTextIsEmpty || !slotCheckQuery()) {
......@@ -232,7 +232,7 @@ tristate KexiQueryDesignerSQLView::beforeSwitchTo(Kexi::ViewMode mode, bool *don
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;
......@@ -242,7 +242,7 @@ tristate KexiQueryDesignerSQLView::beforeSwitchTo(Kexi::ViewMode mode, bool *don
//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 = KDbEscapedString(d->editor->text());
......@@ -276,7 +276,7 @@ KexiQueryDesignerSQLView::afterSwitchFrom(Kexi::ViewMode mode)
if (query) {
// Use query with Kexi keywords (but not driver-specific keywords) escaped.
temp->setQuery(query);
if (temp->queryChangedInPreviousView()) {
if (temp->queryChangedInView() != Kexi::NoViewMode) {
KDbSelectStatementOptions options;
options.addVisibleLookupColumns = false;
KDbNativeStatementBuilder builder(KexiMainWindowIface::global()->project()->dbConnection());
......@@ -296,10 +296,19 @@ KexiQueryDesignerSQLView::afterSwitchFrom(Kexi::ViewMode mode)
d->origStatement = KDbEscapedString(sql);
}
if (!compareSQL(d->origStatement.toString(), d->editor->text())) {
d->slotTextChangedEnabled = false;
d->editor->setText(d->origStatement.toString());
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.toString(), d->editor->text())) {
d->slotTextChangedEnabled = false;
d->editor->setText(d->origStatement.toString());
d->slotTextChangedEnabled = true;
}
}
QTimer::singleShot(100, d->editor, SLOT(setFocus()));
return true;
......
/* This file is part of the KDE project
Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
Copyright (C) 2004-2012 Jarosław Staniek <staniek@kde.org>
Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......
/* This file is part of the KDE project
Copyright (C) 2004 Lucijan Busch <lucijan@kde.org>
Copyright (C) 2004-2010 Jarosław Staniek <staniek@kde.org>
Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -194,7 +194,7 @@ KexiQueryPart::TempData::TempData(KexiWindow* window, KDbConnection *conn)
: KexiWindowData(window)
, KDbConnection::TableSchemaChangeListenerInterface()
, m_query(0)
, m_queryChangedInPreviousView(false)
, m_queryChangedInView(Kexi::NoViewMode)
{
this->conn = conn;
}
......@@ -252,14 +252,15 @@ void KexiQueryPart::TempData::setQuery(KDbQuerySchema *query)
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<KexiWindow*>(parent())->currentViewMode()
: Kexi::NoViewMode;
}
#include "kexiquerypart.moc"
/* This file is part of the KDE project
Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
Copyright (C) 2004-2010 Jarosław Staniek <staniek@kde.org>
Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -76,19 +76,22 @@ public:
//! Connection used for retrieving definition of the query
KDbConnection *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:
KDbQuerySchema *m_query;
bool m_queryChangedInPreviousView;
Kexi::ViewMode m_queryChangedInView;
};
//! Implemented for KexiPart::Part.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment