I ended up writing a Python script after all. It's available here:
https://github.com/hexamon/qgispythonprocessing/blob/master/math_on_all_fields.py
If someone answers with a non-Python solution that works I will accept that instead.
Here is the relevant logic in the script:
op = self.parameterAsEnum(parameters, self.OPERATION,context) #Math operation type fetched from enumerated list parameter
col = self.parameterAsFields(parameters, self.DIVCOL,context)[0] #Column for operation
for current, feature in enumerate(features):
# Stop the algorithm if cancel button has been clicked
if feedback.isCanceled():
break
#Iterate over all fields
for current, attr in enumerate(feature.fields()):
#Don't process the column used for the operation
if current != feature.fieldNameIndex(col):
#Current attribute in iteration
c = feature.attribute(feature.fieldNameIndex(attr.name()))
#Column to use for operation
d = feature.attribute(feature.fieldNameIndex(col))
if(attr.isNumeric() == TRUE):
if(op == 0):
newVal = c * d
elif(op == 1):
newVal = c / d
elif(op == 2):
newVal = c + d
elif(op == 3):
newVal = c - d
feature.setAttribute(current, newVal)
vector field
inputs as the maximum possible number of fields, then manually select them when you run the model. – csk Oct 17 '19 at 16:08