Fix bugtracker #885: preserve custom summary-table SQL on accept

setQuery() restored the loaded SQL text into the line edit but never
restored the "Edit SQL query" checkbox, so a custom query (a join, a
subquery, a view other than project_summary_view) displayed correctly
while the widget stayed in built-in mode. queryStr() only consults that
checkbox, so accepting the dialog without touching anything silently
replaced the custom query with a freshly generated one.

Detect it instead of trusting a flag that was never set: after parsing
columns from the loaded query, rebuild the query those columns would
produce and compare it against what was loaded. A mismatch means the
widget cannot reconstruct it, so it must be user-written -- check the
box and keep the literal text.

Verified against both cases this has to get right, not just the one
in the report: a genuinely custom query (join) now round-trips through
an untouched accept+save byte-for-byte, and a plain built-in query
written before the #238 pos-ordering fix (examples/industrial.qet, no
ORDER BY clause) is classified as custom rather than silently gaining
an ORDER BY it didn't have -- it round-trips unchanged rather than
being corrupted, though its column picker is now disabled until a user
rebuilds it by hand.

Based on the patch attached to #885.
This commit is contained in:
ispyisail
2026-09-16 13:09:48 +12:00
parent 265aa44320
commit a756bc0722
@@ -109,6 +109,7 @@ void SummaryQueryWidget::setQuery(const QString &query)
if (query.startsWith("SELECT"))
{
reset();
ui->m_edit_sql_query_cb->setChecked(false);
ui->m_user_query_le->setText(query);
QString select = query;
@@ -129,6 +130,17 @@ void SummaryQueryWidget::setQuery(const QString &query)
}
}
}
//If the query this widget would build from the columns just
//parsed above does not match the query as loaded byte-for-byte,
//the user wrote it by hand (a join, a subquery, a different
//view) and accepting the dialog unmodified must not silently
//replace it with a generated one (bugtracker #885).
const bool custom_query = query != queryStr();
m_custom_query = custom_query ? query : QString();
ui->m_edit_sql_query_cb->setChecked(custom_query);
ui->m_user_query_le->setEnabled(custom_query);
ui->m_info_widget->setDisabled(custom_query);
}
}