Rory McIlroy won the Scottish Open to become the first player to win all three British National Opens.