bool QmlConsoleItemModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    ConsoleItem *item = getItem(index);
    bool result = false;
    if (role == Qt::DisplayRole) {
        item->setText(value.toString());
        result = true;
    } else if (role == QmlConsoleItemModel::TypeRole) {
        item->itemType = (ConsoleItem::ItemType)value.toInt();
        result = true;
    } else if (role == QmlConsoleItemModel::FileRole) {
        item->file = value.toString();
        result = true;
    } else if (role == QmlConsoleItemModel::LineRole) {
        item->line = value.toInt();
        result = true;
    }

    if (result)
        emit dataChanged(index, index);

    return result;
}
ConsoleItem *constructLogItemTree(ConsoleItem *parent, const QVariant &result,
                                     const QString &key = QString())
{
    if (!result.isValid())
        return 0;

    ConsoleItem *item = new ConsoleItem(parent);
    if (result.type() == QVariant::Map) {
        if (key.isEmpty())
            item->setText(QLatin1String("Object"));
        else
            item->setText(key + QLatin1String(" : Object"));

        QMapIterator<QString, QVariant> i(result.toMap());
        while (i.hasNext()) {
            i.next();
            ConsoleItem *child = constructLogItemTree(item, i.value(), i.key());
            if (child)
                item->insertChild(child, true);
        }
    } else if (result.type() == QVariant::List) {
        if (key.isEmpty())
            item->setText(QLatin1String("List"));
        else
            item->setText(QString(QLatin1String("[%1] : List")).arg(key));
        QVariantList resultList = result.toList();
        for (int i = 0; i < resultList.count(); i++) {
            ConsoleItem *child = constructLogItemTree(item, resultList.at(i),
                                                          QString::number(i));
            if (child)
                item->insertChild(child, true);
        }
    } else if (result.canConvert(QVariant::String)) {
        item->setText(result.toString());
    } else {
        item->setText(QLatin1String("Unknown Value"));
    }

    return item;
}