Bug 473485

Summary: QAbstractItemModel::endInsertColumns: Invalid index
Product: [Applications] krita Reporter: grum999
Component: AnimationAssignee: Emmet O'Neill <emmetoneill.pdx>
Status: RESOLVED FIXED    
Severity: normal CC: alvin, dimula73, emmetoneill.pdx
Priority: NOR Keywords: regression, release_blocker
Version: 5.2.0-beta2   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description grum999 2023-08-17 17:40:58 UTC
SUMMARY
The first file I open in Krita, whatever the format (jpg, png, kra) generate the following message in terminal:
```
QAbstractItemModel::endInsertColumns:  Invalid index ( 0 , 101 ) in model KisAnimTimelineFramesModel(0x5607b0855610)
```

STEPS TO REPRODUCE
1. Start Krita from terminal
2. Open a file

OBSERVED RESULT
- An invalid index message related to KisAnimTimelineFramesModel is displayed
- Next files opened don't generate message

Note: if Animation Timeline docker is visible, there's no error message 

EXPECTED RESULT
- No error message?

SOFTWARE/OS VERSIONS
Krita
 Version: 5.2.0-beta2
 Hidpi: false
Qt
  Version (compiled): 5.15.7
  Version (loaded): 5.15.7
OS Information
  Build ABI: x86_64-little_endian-lp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: linux
  Kernel Version: 5.19.0-45-generic
  Pretty Productname: KDE neon 5.27
  Product Type: neon
  Product Version: 22.04
  Desktop: KDE
  Appimage build: Yes
Comment 1 grum999 2023-08-17 17:57:23 UTC
Opening an animation file with 75 frames (0 to 74)  generate a different message :)
```
QAbstractItemModel::endInsertColumns:  Invalid index ( 1 , 75 ) in model KisAnimTimelineFramesModel(0x55f8e4ef8380)
```
Comment 2 Emmet O'Neill 2023-08-18 21:30:17 UTC
Yep, you're right. 

I'm not sure why this is happening yet, but it'll be on my list of things to look into next week.

Thanks for the report as always grum!
Comment 3 Freya Lupen 2023-08-20 13:22:34 UTC
*** Bug 473282 has been marked as a duplicate of this bug. ***
Comment 4 grum999 2023-08-20 15:09:38 UTC
Ah thanks!

Didn't saw the bug 473282 as I didn't searched in resolved... :-/
Comment 5 Dmitry Kazakov 2023-08-23 09:25:44 UTC
Git commit 2157e5c8a4d36c13f7b69be739f136639faeb2ca by Dmitry Kazakov.
Committed on 23/08/2023 at 11:24.
Pushed by dkazakov into branch 'master'.

Fix a model warning in KisTimeBasedItemModel

There were two issues:

1) KisTimeBasedItemModel::columnCount() could return the value that
   has already changed in the image without calling to
   begin/endInsertColumns. That is not really welcome by Qt.

2) In KisTimeBasedItemModel::setImage() we reset the model (and therefore
   updated its columns list), but didn't update m_d->numFramesOverride,
   which caused double insertion of the columns in
   slotPlaybackRangeChanged() a bit later.

M  +2    -1    plugins/dockers/animation/KisTimeBasedItemModel.cpp

https://invent.kde.org/graphics/krita/-/commit/2157e5c8a4d36c13f7b69be739f136639faeb2ca
Comment 6 Dmitry Kazakov 2023-08-23 09:27:00 UTC
Git commit de673feee8f20079e54b51f7799d48e267703035 by Dmitry Kazakov.
Committed on 23/08/2023 at 11:26.
Pushed by dkazakov into branch 'krita/5.2'.

Fix a model warning in KisTimeBasedItemModel

There were two issues:

1) KisTimeBasedItemModel::columnCount() could return the value that
   has already changed in the image without calling to
   begin/endInsertColumns. That is not really welcome by Qt.

2) In KisTimeBasedItemModel::setImage() we reset the model (and therefore
   updated its columns list), but didn't update m_d->numFramesOverride,
   which caused double insertion of the columns in
   slotPlaybackRangeChanged() a bit later.

M  +2    -1    plugins/dockers/animation/KisTimeBasedItemModel.cpp

https://invent.kde.org/graphics/krita/-/commit/de673feee8f20079e54b51f7799d48e267703035