Interesting that Madrid was not on your list at first, and now it is. 4-1/2 weeks (a month and a day) seems like a lot, until you start to actually block out the trip, day by day and destination by destination. Travel days allow you breakfast in once place and dinner in another - and perhaps not much in-between depending whether you fly, go by train, or drive.
Just for grins ...
ARR: Barcelona
4 nights (3 days) in Barcelona
4 nights (3 days) Madrid
3 nights (2 days) Granada (I know, this is one day less than you mention)
3 nights (2 days) Cordoba
3 nights (2 days) Sevilla (Cordoba to Sevilla is pretty easy, so this is not a day where you lose much)
4 nights (3 days) Lisboa
3 nights (2 days) Porto
2 nights (1 day) San Sebastian
NEXT MORNING: Back to Madrid or Barcelona for one night, then fly home
27 nights or 28 days of traveling in Europe, 30 days when you include the flights to and from Europe, of which only 18 full days are spent in any one place. 10 days are partially or largely spent getting from one place to another on the Iberian Peninsula, plus two more getting there and getting back home. Of course, you can add in 1 or 2 more days into the itinerary above to get to 4-1/2 weeks. Sounds like a good trip. No "white towns" in Andalucia, but you could add that in, perhaps. If you are driving in Andalucia, that could be fairly easy, for example by detouring on your way from Cordoba to Sevilla. Or just add that extra day and night in Granada back to the plan. Or, you could add in a day and a night in Toledo on your way from Madrid to Andalucia.
Still, the travel day consideration is food for thought. The only ones who can answer if that is too much are you and your companion.