fix(qt): a selection anchor finds numeric ids, and ranges skip header rows
controls/SelectionModel.qml kept the anchor in a string property and then looked it up with a strict comparison, so a list whose rows carry numeric ids never found its anchor again and every Shift-click there degraded to a plain toggle. Ids now compare as strings, which is what the selection map keys already were. The range fill also wrote `m[rows[i].id]` for every row in the span, so a list that mixes group headers into its rows gained an "undefined" key and a count one above the ticks on screen. Rows without an id are skipped. `idKey` names the identifying field for rows that do not call it `id`. scripts/qml-tests/tst_multi_select.qml starts with the rule's own cases and joins qt-runtime-gate.sh and test-crates.yml. cc
This commit is contained in:
5 files changed
+118
-13
No files matched your search
@@ -88,6 +88,7 @@ on:
|
||||
- "scripts/test-library-folders-qml.sh"
|
||||
- "scripts/test-array-model-qml.sh"
|
||||
- "scripts/test-keyed-model-qml.sh"
|
||||
- "scripts/test-multi-select-qml.sh"
|
||||
- "scripts/test-wallpaper-field-qml.sh"
|
||||
- "scripts/test-card-menu-qml.sh"
|
||||
- "scripts/test-orbit-daemon.py"
|
||||
@@ -120,6 +121,7 @@ on:
|
||||
- "scripts/test-library-folders-qml.sh"
|
||||
- "scripts/test-array-model-qml.sh"
|
||||
- "scripts/test-keyed-model-qml.sh"
|
||||
- "scripts/test-multi-select-qml.sh"
|
||||
- "scripts/test-wallpaper-field-qml.sh"
|
||||
- "scripts/test-card-menu-qml.sh"
|
||||
- "scripts/test-orbit-daemon.py"
|
||||
|
||||
@@ -40,6 +40,20 @@
|
||||
//
|
||||
// A NEW object is always returned: mutating a `var` map in place notifies
|
||||
// nothing, and every binding on it would go stale.
|
||||
//
|
||||
// ── EVERY CLICK TARGET MUST HAND ITS MODIFIERS OVER ───────────────────────
|
||||
// The rule only sees what the click target passes in. A select-mode surface
|
||||
// has more targets than its row body — the checkbox disc, the checkbox
|
||||
// controls, a whole album card, the name links drawn on a row — and each one
|
||||
// that called its host with no modifiers turned every Shift-click there into
|
||||
// a plain toggle. `scripts/qml-tests/tst_multi_select.qml` clicks all of them
|
||||
// through the real components.
|
||||
//
|
||||
// ── IDS COMPARE AS STRINGS ────────────────────────────────────────────────
|
||||
// `anchorId` is a string property, so a numeric id (an offline track id, a
|
||||
// settings folder id) was stored as "42" and then never found again among
|
||||
// rows carrying 42 — Shift silently degraded to a toggle. The selection map
|
||||
// keys are strings anyway, so comparing as strings is the same identity.
|
||||
|
||||
import QtQuick
|
||||
|
||||
@@ -49,40 +63,59 @@ QtObject {
|
||||
/// The row a shift-range measures from. "" = no anchor yet. Hosts clear
|
||||
/// it when they leave select mode.
|
||||
property string anchorId: ""
|
||||
/// The row field that identifies a row. Track and album rows use `id`;
|
||||
/// the offline manager's rows carry `trackId`, the explorer facets `key`.
|
||||
property string idKey: "id"
|
||||
|
||||
function _idOf(row) {
|
||||
if (!row)
|
||||
return ""
|
||||
var value = row[root.idKey]
|
||||
return value === undefined || value === null ? "" : String(value)
|
||||
}
|
||||
|
||||
function _indexOf(rows, id) {
|
||||
var wanted = String(id)
|
||||
for (var i = 0; i < rows.length; i++)
|
||||
if (rows[i] && rows[i].id === id)
|
||||
if (root._idOf(rows[i]) === wanted)
|
||||
return i
|
||||
return -1
|
||||
}
|
||||
|
||||
/// Adds every identified row between the anchor and `id` to `into`.
|
||||
/// Rows without an id (group headers riding in the same list) are skipped.
|
||||
function _fillRange(into, rows, anchorAt, here) {
|
||||
var lo = Math.min(anchorAt, here)
|
||||
var hi = Math.max(anchorAt, here)
|
||||
for (var i = lo; i <= hi; i++) {
|
||||
var rowId = root._idOf(rows[i])
|
||||
if (rowId !== "")
|
||||
into[rowId] = true
|
||||
}
|
||||
return into
|
||||
}
|
||||
|
||||
/// The selection map after clicking `id`, given the ordered `rows` the
|
||||
/// user is looking at and the `modifiers` off the mouse event.
|
||||
///
|
||||
/// Pass the FILTERED rows when a view is filtered: a range over rows the
|
||||
/// user cannot see is not a range they asked for.
|
||||
function next(current, id, rows, modifiers) {
|
||||
var shift = (modifiers & Qt.ShiftModifier) !== 0
|
||||
var shift = ((modifiers || 0) & Qt.ShiftModifier) !== 0
|
||||
var anchorAt = root.anchorId !== "" ? root._indexOf(rows, root.anchorId) : -1
|
||||
|
||||
if (shift && anchorAt >= 0) {
|
||||
var here = root._indexOf(rows, id)
|
||||
if (here >= 0) {
|
||||
var lo = Math.min(anchorAt, here)
|
||||
var hi = Math.max(anchorAt, here)
|
||||
var m = Object.assign({}, current)
|
||||
for (var i = lo; i <= hi; i++)
|
||||
m[rows[i].id] = true
|
||||
if (here >= 0)
|
||||
// The anchor STAYS, so the same range can be re-dragged.
|
||||
return m
|
||||
}
|
||||
return root._fillRange(Object.assign({}, current), rows, anchorAt, here)
|
||||
}
|
||||
|
||||
var key = String(id)
|
||||
var out = Object.assign({}, current)
|
||||
if (out[id] === true) delete out[id]
|
||||
else out[id] = true
|
||||
root.anchorId = id
|
||||
if (out[key] === true) delete out[key]
|
||||
else out[key] = true
|
||||
root.anchorId = key
|
||||
return out
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Excel-style multi-select regression suite: the shared selection rule
|
||||
// (controls/SelectionModel.qml) and the REAL row, card, checkbox and rail
|
||||
// components of the select-mode surfaces. Every click target a select-mode
|
||||
// surface offers must deliver Shift (a range from the anchor) and Ctrl (one
|
||||
// more row) to the selection; a target that swallows the modifier, or that
|
||||
// navigates away instead of selecting, is exactly the regression this guards.
|
||||
import QtQuick
|
||||
import QtTest
|
||||
import com.blitzfc.qbz
|
||||
import "../../crates/qbz-qt/qml/controls"
|
||||
|
||||
Item {
|
||||
id: root
|
||||
width: 1200; height: 1400
|
||||
|
||||
// ---- the selection rule itself ---------------------------------------------
|
||||
SelectionModel { id: rule }
|
||||
SelectionModel { id: keyedRule; idKey: "trackId" }
|
||||
TestCase {
|
||||
name: "SelectionRule"
|
||||
|
||||
function init() {
|
||||
rule.anchorId = ""
|
||||
keyedRule.anchorId = ""
|
||||
}
|
||||
|
||||
function test_numeric_ids_range() {
|
||||
var rows = [{ "id": 11 }, { "id": 12 }, { "id": 13 }, { "id": 14 }]
|
||||
var m = rule.next({}, 11, rows, Qt.NoModifier)
|
||||
m = rule.next(m, 13, rows, Qt.ShiftModifier)
|
||||
compare(Object.keys(m).sort().join(","), "11,12,13")
|
||||
}
|
||||
|
||||
function test_rows_without_id_are_skipped() {
|
||||
var rows = [{ "id": "a" }, { "kind": "header" }, { "id": "b" }]
|
||||
var m = rule.next({}, "a", rows, Qt.NoModifier)
|
||||
m = rule.next(m, "b", rows, Qt.ShiftModifier)
|
||||
compare(Object.keys(m).sort().join(","), "a,b")
|
||||
}
|
||||
|
||||
function test_id_key() {
|
||||
var rows = [{ "trackId": 7 }, { "trackId": 8 }, { "trackId": 9 }]
|
||||
var m = keyedRule.next({}, 9, rows, Qt.NoModifier)
|
||||
m = keyedRule.next(m, 7, rows, Qt.ShiftModifier)
|
||||
compare(Object.keys(m).sort().join(","), "7,8,9")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ bash scripts/test-compact-seek-qml.sh
|
||||
bash scripts/test-library-folders-qml.sh
|
||||
bash scripts/test-array-model-qml.sh
|
||||
bash scripts/test-keyed-model-qml.sh
|
||||
bash scripts/test-multi-select-qml.sh
|
||||
bash scripts/test-wallpaper-field-qml.sh
|
||||
bash scripts/test-card-menu-qml.sh
|
||||
bash scripts/test-orbit-qml.sh
|
||||
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
# Excel-style multi-select regression: every select-mode click target — row
|
||||
# body, checkbox disc, checkbox controls, album cards, the name links on a
|
||||
# row, the My QBZ rows, the folder rail and the settings folder table — hands
|
||||
# Shift / Ctrl to the selection rule, and the rule itself ranges over string
|
||||
# and numeric ids alike. Same run in CI and locally.
|
||||
set -euo pipefail
|
||||
cd "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
|
||||
if [[ -n "${QT_ROOT_DIR:-}" ]]; then
|
||||
qt_multi_select_bins="$QT_ROOT_DIR/bin"
|
||||
else
|
||||
qt_multi_select_qmake="${QMAKE:-}"
|
||||
if [[ -z "$qt_multi_select_qmake" ]]; then
|
||||
qt_multi_select_qmake="$(command -v qmake6 || command -v qmake)"
|
||||
fi
|
||||
qt_multi_select_bins="$("$qt_multi_select_qmake" -query QT_INSTALL_BINS)"
|
||||
fi
|
||||
QT_QPA_PLATFORM=offscreen QT_QUICK_BACKEND=software \
|
||||
"$qt_multi_select_bins/qmltestrunner" \
|
||||
-input scripts/qml-tests/tst_multi_select.qml \
|
||||
-import scripts/qml-tests/imports
|
||||
Reference in new issue
Block a user