The Post Office has settled a long-running dispute with sub-postmasters over its Horizon IT system.