SqliteTableModel: Do a few fixes and add sorting again

Fix empty rows being shown in the main window when changing to a table
with less rows than the old one.

Add sorting in the browse tab again.

Do some minor clean ups.