Barcelona is a wonderful place for architecture, Madrid not so much. Madrid is mostly about European painting. Unless you want to spend hours in the top-notch are museums, skip it. Fly to Barcelona for 4 nights (3 full days) and take a couple walking tours that concentrate on architecture and book some of the major architectural sights. Then fly to either Venice or Naples. Venice is usually the least convenient airport to fly out of, since getting to the airport can be very time consuming, and either very difficult or very expensive if you have an early morning flight departure. Then fly home from either Rome or Naples.
Before you make decisions about what you want to see in southern Italy, you need to understand travel times. You can get fast trains from Venice and Rome to Naples and Salerno but not to any of your other places. For the rest, you need the local Circumvesuviana or the Campania Express train (a ground-level metro train), buses and ferries. If you go in high season, they will be crowded, chances are you won't get a seat with a view and you may have to wait in line for a long time. Flying between Naples and Venice may save you an hour or two over taking the train.
I was in Sorrento in late winter and found it charming (there were hardly any tourists) but without any sights. It's well-positioned for day-tripping to Pompeii and Herculaneum by local train, Capri by ferry, and the Amalfi Coast (Positano, Amalfi, . . . . ) by bus or (in season) by ferry. OTOH, I was in Salerno in late winter (different trip) and thought it was an interesting place to visit with several sights, a large sandy beach, and a well-preserved medieval center, as well as a good selection of restaurants. Salerno has better train connections than Sorrento and is somewhat better for day-tripping to the AC by bus or ferry.