Skip to content

Commit 0b3882e

Browse files
committed
Fix broken LBP visualization
1 parent 55d98de commit 0b3882e

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Bug fixes:
1313

1414
* Fix velocity interpolation not undo'ed
1515

16+
* Fix broken LBP visualization
17+
1618
Other:
1719

1820
* Busy wait in PlayerWorker for higher precision

src/application/models/note_column_model.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ void NoteColumnModel::notifyDataChanged(int startLine, int endLine, const QList<
181181

182182
void NoteColumnModel::updateIndexHighlights()
183183
{
184-
notifyDataChanged(0, rowCount() - 1, { static_cast<int>(DataRole::Color), static_cast<int>(DataRole::Border) });
184+
if (!m_lines.empty()) {
185+
notifyDataChanged(0, static_cast<int>(m_lines.size()) - 1, { static_cast<int>(DataRole::Color), static_cast<int>(DataRole::Border) });
186+
}
185187
}
186188

187189
void NoteColumnModel::updateIndexHighlightAtPosition(quint64 line)

src/unit_tests/note_column_model_test/note_column_model_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,37 @@ void NoteColumnModelTest::test_setLineFocused_shouldUpdateData()
106106
QCOMPARE(model.data(idx, static_cast<int>(NoteColumnModel::DataRole::LineColumn)).toInt(), 1);
107107
}
108108

109+
void NoteColumnModelTest::test_updateIndexHighlights_shouldEmitDataChangedWithCorrectRange()
110+
{
111+
const auto automationService { std::make_shared<AutomationService>() };
112+
const auto selectionService { std::make_shared<SelectionService>() };
113+
const auto settingsService { std::make_shared<SettingsService>() };
114+
const auto editorService { std::make_shared<EditorService>(selectionService, settingsService) };
115+
const auto utilService { std::make_shared<UtilService>() };
116+
const auto helper { std::make_shared<NoteColumnLineContainerHelper>(automationService, editorService, selectionService, utilService) };
117+
118+
NoteColumnModel model { { 0, 0, 0 }, editorService, helper, settingsService };
119+
120+
const int lineCount = 10;
121+
NoteColumnModel::LineList lines;
122+
for (int i = 0; i < lineCount; ++i) {
123+
lines.push_back(std::make_shared<Line>(static_cast<size_t>(i)));
124+
}
125+
model.setColumnData(lines);
126+
127+
QSignalSpy spy { &model, &NoteColumnModel::dataChanged };
128+
model.updateIndexHighlights();
129+
130+
QCOMPARE(spy.count(), 1);
131+
const auto arguments = spy.takeFirst();
132+
const auto topLeft = arguments.at(0).value<QModelIndex>();
133+
const auto bottomRight = arguments.at(1).value<QModelIndex>();
134+
135+
const int barLine = static_cast<int>(editorService->positionBarLine());
136+
QCOMPARE(topLeft.row(), barLine);
137+
QCOMPARE(bottomRight.row(), barLine + lineCount - 1);
138+
}
139+
109140
} // namespace noteahead
110141

111142
QTEST_GUILESS_MAIN(noteahead::NoteColumnModelTest)

src/unit_tests/note_column_model_test/note_column_model_test.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ private slots:
3131
void test_rowCount_shouldReturnCorrectValue();
3232
void test_data_shouldReturnCorrectValues();
3333
void test_setLineFocused_shouldUpdateData();
34+
void test_updateIndexHighlights_shouldEmitDataChangedWithCorrectRange();
3435
};
3536

3637
} // namespace noteahead

0 commit comments

Comments
 (0)