Instead of always creating the `terrainsVariant` and then checking whether it is empty, you could wrap the whole thing in `if (tileset->terrainCount() > 0)`.