TaskGroup* AbstractGroupingStrategy::createGroup(ItemList items)
{
    GroupPtr oldGroup;
    if (!items.isEmpty() && items.first()->isGrouped()) {
        oldGroup = items.first()->parentGroup();
    } else {
        oldGroup = rootGroup();
    }

    TaskGroup *newGroup = new TaskGroup(d->groupManager);
    ItemList oldGroupMembers = oldGroup->members();
    int index = oldGroupMembers.count();
    d->createdGroups.append(newGroup);
    //kDebug() << "added group" << d->createdGroups.count();
    // NOTE: Queued is vital to make sure groups only get removed after their children, for
    // correct QAbstractItemModel (TasksModel) transaction semantics.
    connect(newGroup, SIGNAL(itemRemoved(AbstractGroupableItem*)), this, SLOT(checkGroup()), Qt::QueuedConnection);
    foreach (AbstractGroupableItem * item, items) {
        int idx = oldGroupMembers.indexOf(item);
        if (idx >= 0 && idx < index) {
            index = idx;
        }
        newGroup->add(item);
    }