I know, it's boring, but it seems important to me.
As I see now item quality is stored "as is"—if you have 5 Q32 apples, then it means that it's stored (in DB) as 5×32×Apple_ID. Adding 5 Q31 apples will make pile of 10 Q31 apples (quality rounded down). Adding 5 more Q33 apples will make a pile of 15 Q31 apples.
If you will store total quality we will get different picture.
- 5 Q32 items => (total)Q 160 / 5 = 32 (per item, rounded down)
- Adding 5 Q31 to the pile => (total)Q 315 / 10 = 31 (per item, rounded down)
- Adding 5 Q33 to the pile => (total)Q 480 / 15 = 32 (per item, rounded down)