forked from qt-creator/qt-creator
Debugger: Move struct sorting logic to generic parser
Backends only have to specify whether an object members are sortable in principle (e.g. all structs), and some numeric 'sortgroup' value for member items (higher values are always sorted on top). Change-Id: I10ce94580374fed48a35f058a575a1408d6801af Reviewed-by: David Schulz <david.schulz@theqtcompany.com> Reviewed-by: Christian Stenger <christian.stenger@theqtcompany.com>
This commit is contained in:
@@ -118,6 +118,7 @@ WatchItem::WatchItem() :
|
||||
bitsize(0),
|
||||
elided(0),
|
||||
arrayIndex(-1),
|
||||
sortGroup(0),
|
||||
wantsChildren(false),
|
||||
valueEnabled(true),
|
||||
valueEditable(true),
|
||||
@@ -380,7 +381,18 @@ static void decodeArrayData(WatchItem *item, const QByteArray &rawData,
|
||||
qDebug() << "ENCODING ERROR: " << encoding.toString();
|
||||
}
|
||||
|
||||
void WatchItem::parseHelper(const GdbMi &input)
|
||||
static bool sortByName(const Utils::TreeItem *a, const Utils::TreeItem *b)
|
||||
{
|
||||
auto aa = static_cast<const WatchItem *>(a);
|
||||
auto bb = static_cast<const WatchItem *>(b);
|
||||
|
||||
if (aa->sortGroup != bb->sortGroup)
|
||||
return aa->sortGroup > bb->sortGroup;
|
||||
|
||||
return aa->name < bb->name;
|
||||
}
|
||||
|
||||
void WatchItem::parseHelper(const GdbMi &input, bool maySort)
|
||||
{
|
||||
setChildrenUnneeded();
|
||||
|
||||
@@ -437,6 +449,10 @@ void WatchItem::parseHelper(const GdbMi &input)
|
||||
if (mi.isValid())
|
||||
exp = mi.data();
|
||||
|
||||
mi = input["sortgroup"];
|
||||
if (mi.isValid())
|
||||
sortGroup = mi.toInt();
|
||||
|
||||
mi = input["valueenabled"];
|
||||
if (mi.data() == "true")
|
||||
valueEnabled = true;
|
||||
@@ -500,14 +516,17 @@ void WatchItem::parseHelper(const GdbMi &input)
|
||||
QByteArray key = subinput["key"].data();
|
||||
if (!key.isEmpty())
|
||||
child->name = decodeData(key, subinput["keyencoded"].data());
|
||||
child->parseHelper(subinput);
|
||||
child->parseHelper(subinput, maySort);
|
||||
appendChild(child);
|
||||
}
|
||||
|
||||
if (maySort && input["sortable"].toInt())
|
||||
sortChildren(&sortByName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WatchItem::parse(const GdbMi &data)
|
||||
void WatchItem::parse(const GdbMi &data, bool maySort)
|
||||
{
|
||||
iname = data["iname"].data();
|
||||
|
||||
@@ -517,7 +536,7 @@ void WatchItem::parse(const GdbMi &data)
|
||||
else
|
||||
name = QString::fromLatin1(data["name"].data());
|
||||
|
||||
parseHelper(data);
|
||||
parseHelper(data, maySort);
|
||||
|
||||
if (wname.isValid())
|
||||
exp = name.toUtf8();
|
||||
|
||||
Reference in New Issue
Block a user