You can just integrate your angular velocity to get angular position (as Euler angles), convert the Euler angles to Quaternion, then multiply the Quaternion to accumulate the orientation.
Suppose your input is given by a 3D vector of angular velocity: omega = (alpha, beta, gamma), given by degrees per second. To get the Euler angles, E, in degrees, multiply omega by the change in time, which we can call dt. This results to:
Vector3D omega = new Vector3D(alpha, beta, gamma);
Vector3D E = omega * dt;
You can get dt by subtracting the current time by the time of your previous update. After getting the 3D Euler angles from gyroscope data, convert it into a Quaternion (w,x,y,z) through this equation (from Wikipedia):
float w = cos(E.x/2) * cos(E.y/2) * cos(E.z/2) + sin(E.x/2) * sin(E.y/2) * sin(E.z/2);
float x = sin(E.x/2) * cos(E.y/2) * cos(E.z/2) - cos(E.x/2) * sin(E.y/2) * sin(E.z/2);
float y = cos(E.x/2) * sin(E.y/2) * cos(E.z/2) + sin(E.x/2) * cos(E.y/2) * sin(E.z/2);
float z = cos(E.x/2) * cos(E.y/2) * sin(E.z/2) - sin(E.x/2) * sin(E.y/2) * cos(E.z/2);
Quaternion q = new Quaternion(w, x, y, z);
Just copy-paste the two code snippets above into your Q.update() method then return the Quaternion. If you want to know how the equation works, just check the Wiki link and read through it.