That's 10 nights, 5 places. Might be a bit tight to sleep in all of them. I'd suggest Cordoba as a day trip on the way from Madrid to Seville, or between Seville and Granada, again as a day trip. I'd go in this order:
Madrid ---Cordoba for a few hour day trip ---Seville---Granada---Barcelona.
Of these, my least favorite is Madrid. The art museums are wonderful, and you should go, but with kids you can't spend all day looking at art. Ditto for the palace. It's not a bad city by any means, but not quite as interesting as the others. So here's a rough idea.
FLy into Madrid on the 5, expect this day to be very low key (jet lag). Do a full day in Madrid on the 6, then on the 7 take a very early train to Cordoba, spend several hours at the mesquita/lunch/wandering, and take a PM train to Seville.
On the 8 and 9 explore Seville.
on the 10 go to Granada in the AM. Explore Granada on the 10, and do the Alhambra on the 11.
On the 12 go to Barcelona. 13 and 14 in Barcelona
Fly home.
FYI Granada to Barcelona is long. There are trains, including a night train which might make sense for you. I'd just fly, though. Flights should be cheap.
Both Seville and Granada could benefit from another night, but this is the best balance IMO.