[ImageGallery] Do not fill intrinsics model until it has been instantiated

In some cases, like when opening the most recent file from the command
line, switching the color palette or hot reloading, the intrinsics
might be parsed and ready to populate the intrinsics' `TableModel` while
the model itself is being instantiated.

To prevent crashes, we forbid operations on the `TableModel` until it has
been fully instantiated.
This commit is contained in:
Candice Bentéjac 2025-01-22 20:09:23 +01:00
parent 935f5d07db
commit f1a83628a6

View file

@ -75,6 +75,11 @@ Panel {
}
function populate_model() {
if (!intrinsicModel.ready) {
// If the TableModel is not done being instantiated, do nothing
return
}
intrinsicModel.clear()
for (var intr in parsedIntrinsic) {
intrinsicModel.appendRow(parsedIntrinsic[intr])
@ -569,6 +574,8 @@ Panel {
TableModel {
id : intrinsicModel
property bool ready: false
// Hardcoded default width per column
property var columnWidths: [105, 75, 75, 75, 60, 60, 60, 60, 200, 60, 60, 60]
property var columnNames: [
@ -599,6 +606,13 @@ Panel {
TableModelColumn { display: function(modelIndex){return parsedIntrinsic[modelIndex.row][intrinsicModel.columnNames[10]]} }
TableModelColumn { display: function(modelIndex){return parsedIntrinsic[modelIndex.row][intrinsicModel.columnNames[11]]} }
//https://doc.qt.io/qt-5/qml-qt-labs-qmlmodels-tablemodel.html#appendRow-method
Component.onCompleted: {
ready = true
// Triggers "populate_model" in case the intrinsics have been filled while the model was
// being instantiated
root.populate_model()
}
}
//CODE FOR HEADERS