In 1840 , their chieftains entered into a compact with Britain , the Treaty of Waitangi , in which they ceded sovereignty to Queen Victoria while retaining territorial rights .