@@ -54,6 +54,46 @@ void SelectionServiceTest::test_selectedPositions_reversed_shouldReturnCorrectRa
5454 QCOMPARE (positions.at (2 ).line , 6 );
5555}
5656
57+ void SelectionServiceTest::test_selectedPositions_reorderedColumns_shouldFollowDisplayOrder ()
58+ {
59+ SelectionService service;
60+
61+ // A track that had columns 0, 1, 2 and then got a new one inserted on the left. The new column
62+ // takes the next free index, 3, and sits at display position 0: an index is an identity, not a
63+ // place on screen, so after an insert the two stop agreeing.
64+ service.setColumnOrderResolver ([](size_t ) { return SelectionService::ColumnIndexList { 3 , 0 , 1 , 2 }; });
65+
66+ // Dragging across the first three columns on screen, which are indices 3, 0 and 1.
67+ service.requestSelectionStart (0 , 0 , 3 , 0 );
68+ service.requestSelectionEnd (0 , 0 , 1 , 0 );
69+
70+ QVERIFY (service.isSelected (0 , 0 , 3 , 0 ));
71+ QVERIFY (service.isSelected (0 , 0 , 0 , 0 ));
72+ QVERIFY (service.isSelected (0 , 0 , 1 , 0 ));
73+
74+ // Index 2 is the fourth column on screen, past the end of the drag. Walking indices numerically
75+ // from 1 to 3 would have taken it in and left out index 0, which is what made the rectangle
76+ // cover the wrong columns.
77+ QVERIFY (!service.isSelected (0 , 0 , 2 , 0 ));
78+
79+ // Left to right on screen, which is what anything walking the selection has to follow.
80+ const SelectionService::ColumnIndexList expected { 3 , 0 , 1 };
81+ QCOMPARE (service.selectedColumns (), expected);
82+ }
83+
84+ void SelectionServiceTest::test_selectedPositions_noResolver_shouldFallBackOnIndexOrder ()
85+ {
86+ // Without a resolver there is nothing to say what the display order is, so the indices are the
87+ // only order there is. Keeps a bare SelectionService behaving as it always did.
88+ SelectionService service;
89+ service.requestSelectionStart (0 , 0 , 1 , 0 );
90+ service.requestSelectionEnd (0 , 0 , 3 , 0 );
91+
92+ QVERIFY (service.isSelected (0 , 0 , 1 , 0 ));
93+ QVERIFY (service.isSelected (0 , 0 , 2 , 0 ));
94+ QVERIFY (service.isSelected (0 , 0 , 3 , 0 ));
95+ }
96+
5797void SelectionServiceTest::test_isValidSelection_shouldReturnFalseForIncompleteSelection ()
5898{
5999 SelectionService service;
0 commit comments