Barcelona has many public toilets, especially in parks and areas with few restaurants.

Museums, markets and other public institutions in Barcelona are obligated by law to provide public toilets.
Opening hours are important. If a market makes siesta, the toilet of that market often is closed at that time too.