A Lagrangian method for indefinite q-integrals