To make the shortcrust pastry, sift the flour into a large bowl, add the cold butter cut into cubes, and use your fingertips to rub them together until they resemble breadcrumbs.
Beat the egg lightly, then add it to the bowl together with the cold water.
Knead the dough well until it's elastic and does not stick to the hands.
Cover the dough with clingfilm, and refrigerate for 20 minutes.
Use a rolling pin to roll it to about ½ cm thickness, then arrange the dough over a pie dish, removing the extra dough from the edges.
Use a fork to prick the dough in a few places, then cover it with kitchen foil or non-stick paper.
Fill the pie crust with baking ceramic beans or dry pulses for the blind baking.
Bake it for 10 minutes at 190 degrees Celsius (375 Fahrenheit), then remove the foil and beans/pulses and bake for a further 10 minutes until golden.
Remove from the oven, and set aside.
To make the filling, peel and chop the potatoes, then add them to a pan with salted cold water, then boil for 15-20 minutes until tender, then drain the water and set aside.
In a large frying pan, melt the butter, and add the peeled and chopped onion - fry on a low to medium heat until golden.
Add the peeled and chopped garlic, together with the chopped leeks.
Sauté for 10-15 minutes until the leeks are soft, then add the potatoes, breaking them slightly, half of the cheese, and all the cream.
Mix well, season with salt and pepper, then fill the pastry with this filling.
Top with the remaining cheese, and bake for 25 minutes until golden and bubbling hot.
Serve hot or cold.