If you want to go to the south I'd consider going first - go from Barcelona to Seville on the first or second day, spend time there or elsewhere in the south, including the coast, then to Madrid, finishing in Barcelona. The reason for this is twofold - mid June is starting to get hot in the south but by July it is more likely to be unpleasant. Also I prefer to end my trip in the city I am flying out of - otherwise you would probably need to fly from Granada or Seville or Malaga the night before your flight home, requiring a not-all-that useful one night in Barcelona. End in Barcelona and you can stay your week there as planned and just get a cab or train to the airport from your hotel on departure day.
I did 15 days covering Granada/Nerja, Toledo and Barcelona last year with similar age kids. They loved the Albayzin and looking at the Alhambra in Granada - especially the fort, less into the palace. We found a ruined castle in Lanjarron that they still talk about wandering through. Nerja was a fun beach break. In Barcelona they especially liked Casa Batllo (they give you an interactive ipad guide that was a hit), the beach, and the cable car to Montjuic.
General kid-travel words of wisdom :
You can take them to museums and cathedrals - mine did well because if you expect your kids to participate and enjoy an activity for a reasonable amount of time they likely will. Especially if they know that the next thing will be ice cream or a park.
Food - Spanish food and restaurants are pretty kid friendly. Buy some proscuitto at home to introduce them to the idea of jamon (or buy Spanish jamon if you want, but it's hard to find and pricey, and proscuitto is similar enough for a kid to get the idea) - if they like this then no matter what else is on the menu they won't starve! And croquetas and paella are pretty popular.
Hotels - apartments are great for families with kids. A two bedroom is usually less than a mid-range quad hotel room and you have more space and a kitchen. I think barcelona has some restrictions on airbnb but there are apartment hotels and licensed agencies.
Heat - yes. It's hot. Drink lots of water and follow the siesta custom when possible. Go to your hotel or air conditioned museums during the heat of the day. It shouldn't derail your trip unless you are intent on a death march to sight after sight after sight each day (bad idea no matter the weather!). With time for breaks in parks or cafes, going back to the hotel for rest, and avoiding the hottest times you should be fine.