Surgery principles for the spectral analysis of quantum graphs