Implemented possibility of custom count query in QueryObject

Feel free to discuss this pull request. I do not think it is perfect solution but it should work correctly.