diff --git a/sources/dataBase/ui/summaryquerywidget.cpp b/sources/dataBase/ui/summaryquerywidget.cpp index 468c51821..a49e4a646 100644 --- a/sources/dataBase/ui/summaryquerywidget.cpp +++ b/sources/dataBase/ui/summaryquerywidget.cpp @@ -63,7 +63,6 @@ QString SummaryQueryWidget::queryStr() const QStringList keys = selectedKeys(); QString select ="SELECT "; - QString order_by = " ORDER BY "; QString column; bool first = true; @@ -72,14 +71,29 @@ QString SummaryQueryWidget::queryStr() const first = false; } else { column += ", "; - order_by +=", "; } column += key; - order_by += key; } QString from = " FROM project_summary_view"; + //Always ordered by the folio's own position, never by the columns + //the user happened to choose to display. This is a table of + //contents: it lists the folios of the project and its order is the + //project's order. Ordering by the displayed columns instead meant + //that choosing, say, Title as the first column silently sorted the + //summary alphabetically (bugtracker #238). + // + //project_summary_view exposes the position as "pos", from + //diagram.pos, which is an INTEGER -- so this sorts numerically and + //folio 10 does not land between folio 1 and folio 2. One row per + //folio means pos fully determines the order and no secondary key is + //needed. + // + //A user who wants a different order can still write the query by + //hand; that path returns above, untouched. + QString order_by = " ORDER BY pos"; + QString q(select + column + from + order_by); return q; }