Commit 3d1f5bd8 authored by Aurindam Jana's avatar Aurindam Jana
Browse files

QtMessageLogHandler: Fix crash



Set a parent when creating QtMessageLogItem.

Change-Id: I8faf76059dcc517794a4eb3d202bc14cd1632ca8
Reviewed-by: default avatarKai Koehne <kai.koehne@nokia.com>
parent 39cb4e95
......@@ -1045,13 +1045,15 @@ void QmlEngine::onDebugQueryStateChanged(
qobject_cast<QmlJsDebugClient::QDeclarativeDebugExpressionQuery *>(
sender());
if (query && state != QmlJsDebugClient::QDeclarativeDebugQuery::Error) {
QtMessageLogItem *item = constructLogItemTree(query->result());
QtMessageLogItem *item = constructLogItemTree(qtMessageLogHandler()->root(),
query->result());
if (item)
qtMessageLogHandler()->appendItem(item);
} else
qtMessageLogHandler()->
appendItem(new QtMessageLogItem(QtMessageLogHandler::ErrorType,
_("Error evaluating expression.")));
appendItem(new QtMessageLogItem(qtMessageLogHandler()->root(),
QtMessageLogHandler::ErrorType,
_("Error evaluating expression.")));
delete query;
}
......@@ -1122,7 +1124,8 @@ void QmlEngine::appendDebugOutput(QtMsgType type, const QString &message,
//This case is not possible
return;
}
QtMessageLogItem *item = new QtMessageLogItem(itemType, message);
QtMessageLogItem *item = new QtMessageLogItem(qtMessageLogHandler()->root(),
itemType, message);
item->file = info.file;
item->line = info.line;
qtMessageLogHandler()->appendItem(item);
......@@ -1175,8 +1178,9 @@ bool QmlEngine::evaluateScriptExpression(const QString& expression)
//Incase of invalid context, show Error message
qtMessageLogHandler()->
appendItem(new QtMessageLogItem(
qtMessageLogHandler()->root(),
QtMessageLogHandler::ErrorType,
_("Cannot evaluate without"
_("Cannot evaluate without "
"a valid QML/JS Context.")),
qtMessageLogHandler()->rowCount());
}
......@@ -1287,12 +1291,12 @@ bool QmlEngine::canEvaluateScript(const QString &script)
}
QtMessageLogItem *QmlEngine::constructLogItemTree(
const QVariant &result, const QString &key)
QtMessageLogItem *parent, const QVariant &result, const QString &key)
{
if (!result.isValid())
return 0;
QtMessageLogItem *item = new QtMessageLogItem();
QtMessageLogItem *item = new QtMessageLogItem(parent);
if (result.type() == QVariant::Map) {
if (key.isEmpty())
item->text = _("Object");
......@@ -1302,7 +1306,8 @@ QtMessageLogItem *QmlEngine::constructLogItemTree(
QMapIterator<QString, QVariant> i(result.toMap());
while (i.hasNext()) {
i.next();
QtMessageLogItem *child = constructLogItemTree(i.value(), i.key());
QtMessageLogItem *child = constructLogItemTree(item,
i.value(), i.key());
if (child)
item->insertChild(item->childCount(), child);
}
......@@ -1313,7 +1318,7 @@ QtMessageLogItem *QmlEngine::constructLogItemTree(
item->text = QString(_("[%1] : List")).arg(key);
QVariantList resultList = result.toList();
for (int i = 0; i < resultList.count(); i++) {
QtMessageLogItem *child = constructLogItemTree(resultList.at(i),
QtMessageLogItem *child = constructLogItemTree(item, resultList.at(i),
QString::number(i));
if (child)
item->insertChild(item->childCount(), child);
......
......@@ -187,7 +187,8 @@ private:
void updateEditor(Core::IEditor *editor, const QTextDocument *document);
bool canEvaluateScript(const QString &script);
QtMessageLogItem *constructLogItemTree(const QVariant &result,
QtMessageLogItem *constructLogItemTree(QtMessageLogItem *parent,
const QVariant &result,
const QString &key = QString());
bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line,
quint32 *column, bool *valid);
......
......@@ -128,8 +128,8 @@ public:
//TODO:: remove this method
void reformatRequest(QByteArray &request);
QtMessageLogItem *constructLogItemTree(const QmlV8ObjectData &objectData,
const QVariant &refsVal);
QtMessageLogItem *constructLogItemTree(QtMessageLogItem *parent,
const QmlV8ObjectData &objectData, const QVariant &refsVal);
private:
QByteArray packMessage(const QByteArray &type, const QByteArray &message = QByteArray());
QScriptValue initObject();
......@@ -974,6 +974,7 @@ void QmlV8DebuggerClientPrivate::reformatRequest(QByteArray &request)
}
QtMessageLogItem *QmlV8DebuggerClientPrivate::constructLogItemTree(
QtMessageLogItem *parent,
const QmlV8ObjectData &objectData,
const QVariant &refsVal)
{
......@@ -987,12 +988,12 @@ QtMessageLogItem *QmlV8DebuggerClientPrivate::constructLogItemTree(
text = QString(_("%1: %2")).arg(QString::fromAscii(objectData.name))
.arg(objectData.value.toString());
QtMessageLogItem *item = new QtMessageLogItem(
QtMessageLogHandler::UndefinedType, text);
QtMessageLogItem *item = new QtMessageLogItem(parent,
QtMessageLogHandler::UndefinedType, text);
foreach (const QVariant &property, objectData.properties) {
QtMessageLogItem *child = constructLogItemTree(
extractData(property, refsVal), refsVal);
item, extractData(property, refsVal), refsVal);
if (child)
item->insertChild(item->childCount(), child);
}
......@@ -1837,7 +1838,8 @@ void QmlV8DebuggerClient::updateEvaluationResult(int sequence, bool success, con
} else if (d->debuggerCommands.contains(sequence)) {
d->updateLocalsAndWatchers.removeOne(sequence);
QmlV8ObjectData body = d->extractData(bodyVal, refsVal);
QtMessageLogItem *item = d->constructLogItemTree(body, refsVal);
QtMessageLogItem *item = d->constructLogItemTree(d->engine->qtMessageLogHandler()->root(),
body, refsVal);
if (item)
d->engine->qtMessageLogHandler()->appendItem(item);
//Update the locals
......
......@@ -45,8 +45,8 @@ namespace Internal {
//
///////////////////////////////////////////////////////////////////////
QtMessageLogItem::QtMessageLogItem(QtMessageLogHandler::ItemType itemType,
const QString &text, QtMessageLogItem *parent)
QtMessageLogItem::QtMessageLogItem(QtMessageLogItem *parent,
QtMessageLogHandler::ItemType itemType, const QString &text)
: m_parentItem(parent),
text(text),
itemType(itemType),
......@@ -86,8 +86,8 @@ bool QtMessageLogItem::insertChildren(int position, int count)
for (int row = 0; row < count; ++row) {
QtMessageLogItem *item = new
QtMessageLogItem(QtMessageLogHandler::UndefinedType, QString(),
this);
QtMessageLogItem(this , QtMessageLogHandler::UndefinedType,
QString());
m_childItems.insert(position, item);
}
......@@ -99,10 +99,6 @@ bool QtMessageLogItem::insertChild(int position, QtMessageLogItem *item)
if (position < 0 || position > m_childItems.size())
return false;
if (item->parent())
item->parent()->detachChild(item->childNumber());
item->m_parentItem = this;
m_childItems.insert(position, item);
return true;
......@@ -143,7 +139,7 @@ bool QtMessageLogItem::detachChild(int position)
QtMessageLogHandler::QtMessageLogHandler(QObject *parent) :
QAbstractItemModel(parent),
m_hasEditableRow(false),
m_rootItem(new QtMessageLogItem()),
m_rootItem(new QtMessageLogItem(0)),
m_maxSizeOfFileName(0)
{
}
......@@ -157,8 +153,8 @@ void QtMessageLogHandler::clear()
{
beginResetModel();
reset();
delete m_rootItem;
m_rootItem = new QtMessageLogItem();
qDeleteAll(m_rootItem->m_childItems);
m_rootItem->m_childItems.clear();
endResetModel();
if (m_hasEditableRow)
......@@ -180,7 +176,7 @@ bool QtMessageLogHandler::appendItem(QtMessageLogItem *item, int position)
bool QtMessageLogHandler::appendMessage(QtMessageLogHandler::ItemType itemType,
const QString &message, int position)
{
return appendItem(new QtMessageLogItem(itemType, message), position);
return appendItem(new QtMessageLogItem(m_rootItem, itemType, message), position);
}
void QtMessageLogHandler::setHasEditableRow(bool hasEditableRow)
......@@ -202,7 +198,7 @@ bool QtMessageLogHandler::hasEditableRow() const
void QtMessageLogHandler::appendEditableRow()
{
int position = m_rootItem->childCount();
if (appendItem(new QtMessageLogItem(QtMessageLogHandler::InputType), position))
if (appendItem(new QtMessageLogItem(m_rootItem, QtMessageLogHandler::InputType), position))
emit selectEditableRow(index(position, 0),
QItemSelectionModel::ClearAndSelect);
}
......@@ -289,7 +285,8 @@ QModelIndex QtMessageLogHandler::parent(const QModelIndex &index) const
return QModelIndex();
//can parentItem be 0?
QTC_ASSERT(parentItem, qDebug("Parent is Null!!"));
if (!parentItem)
return QModelIndex();
return createIndex(parentItem->childNumber(), 0, parentItem);
}
......
......@@ -78,6 +78,8 @@ public:
int sizeOfFile(const QFont &font);
int sizeOfLineNumber(const QFont &font);
QtMessageLogItem *root() const { return m_rootItem; }
public slots:
void clear();
......@@ -116,9 +118,9 @@ private:
class QtMessageLogItem
{
public:
QtMessageLogItem(QtMessageLogHandler::ItemType type = QtMessageLogHandler::UndefinedType,
const QString &data = QString(),
QtMessageLogItem *parent = 0);
QtMessageLogItem(QtMessageLogItem *parent,
QtMessageLogHandler::ItemType type = QtMessageLogHandler::UndefinedType,
const QString &data = QString());
~QtMessageLogItem();
QtMessageLogItem *child(int number);
......@@ -139,6 +141,9 @@ public:
QtMessageLogHandler::ItemType itemType;
QString file;
int line;
private:
friend class QtMessageLogHandler;
};
} //Internal
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment