forked from qt-creator/qt-creator
Debugger: Remove WatchModel double sorting
Change-Id: Ia26cdcddf086546650525c779c21b0100a616af3 Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -131,8 +131,7 @@ WatchData::WatchData() :
|
|||||||
elided(0),
|
elided(0),
|
||||||
wantsChildren(false),
|
wantsChildren(false),
|
||||||
valueEnabled(true),
|
valueEnabled(true),
|
||||||
valueEditable(true),
|
valueEditable(true)
|
||||||
sortId(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +274,6 @@ QString WatchData::toString() const
|
|||||||
str << QLatin1Char('{');
|
str << QLatin1Char('{');
|
||||||
if (!iname.isEmpty())
|
if (!iname.isEmpty())
|
||||||
str << "iname=\"" << iname << doubleQuoteComma;
|
str << "iname=\"" << iname << doubleQuoteComma;
|
||||||
str << "sortId=\"" << sortId << doubleQuoteComma;
|
|
||||||
if (!name.isEmpty() && name != QLatin1String(iname))
|
if (!name.isEmpty() && name != QLatin1String(iname))
|
||||||
str << "name=\"" << name << doubleQuoteComma;
|
str << "name=\"" << name << doubleQuoteComma;
|
||||||
if (address) {
|
if (address) {
|
||||||
@@ -492,7 +490,6 @@ void decodeArrayHelper(std::function<void(const WatchData &)> itemHandler, const
|
|||||||
const QByteArray exp = "*(" + gdbQuoteTypes(tmplate.type) + "*)0x";
|
const QByteArray exp = "*(" + gdbQuoteTypes(tmplate.type) + "*)0x";
|
||||||
for (int i = 0, n = ba.size() / sizeof(T); i < n; ++i) {
|
for (int i = 0, n = ba.size() / sizeof(T); i < n; ++i) {
|
||||||
data = tmplate;
|
data = tmplate;
|
||||||
data.sortId = i;
|
|
||||||
data.iname += QByteArray::number(i);
|
data.iname += QByteArray::number(i);
|
||||||
data.name = QString::fromLatin1("[%1]").arg(i);
|
data.name = QString::fromLatin1("[%1]").arg(i);
|
||||||
data.value = decodeItemHelper(p[i]);
|
data.value = decodeItemHelper(p[i]);
|
||||||
@@ -610,7 +607,6 @@ void parseChildrenData(const WatchData &data0, const GdbMi &item,
|
|||||||
for (int i = 0, n = int(children.children().size()); i != n; ++i) {
|
for (int i = 0, n = int(children.children().size()); i != n; ++i) {
|
||||||
const GdbMi &child = children.children().at(i);
|
const GdbMi &child = children.children().at(i);
|
||||||
WatchData data1 = childtemplate;
|
WatchData data1 = childtemplate;
|
||||||
data1.sortId = i;
|
|
||||||
GdbMi name = child["name"];
|
GdbMi name = child["name"];
|
||||||
if (name.isValid())
|
if (name.isValid())
|
||||||
data1.name = QString::fromLatin1(name.data());
|
data1.name = QString::fromLatin1(name.data());
|
||||||
|
|||||||
@@ -126,7 +126,6 @@ public:
|
|||||||
bool wantsChildren;
|
bool wantsChildren;
|
||||||
bool valueEnabled; // Value will be enabled or not
|
bool valueEnabled; // Value will be enabled or not
|
||||||
bool valueEditable; // Value will be editable
|
bool valueEditable; // Value will be editable
|
||||||
qint32 sortId;
|
|
||||||
|
|
||||||
Q_DECLARE_TR_FUNCTIONS(Debugger::Internal::WatchHandler)
|
Q_DECLARE_TR_FUNCTIONS(Debugger::Internal::WatchHandler)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -271,8 +271,6 @@ public:
|
|||||||
QVariant data(const QModelIndex &idx, int role) const;
|
QVariant data(const QModelIndex &idx, int role) const;
|
||||||
bool setData(const QModelIndex &idx, const QVariant &value, int role);
|
bool setData(const QModelIndex &idx, const QVariant &value, int role);
|
||||||
|
|
||||||
void reinsertAllData();
|
|
||||||
void reinsertAllDataHelper(WatchItem *item, QList<WatchData> *data);
|
|
||||||
QString displayForAutoTest(const QByteArray &iname) const;
|
QString displayForAutoTest(const QByteArray &iname) const;
|
||||||
void reinitialize(bool includeInspectData = false);
|
void reinitialize(bool includeInspectData = false);
|
||||||
|
|
||||||
@@ -333,11 +331,11 @@ WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine)
|
|||||||
this, &WatchModel::updateStarted);
|
this, &WatchModel::updateStarted);
|
||||||
|
|
||||||
connect(action(SortStructMembers), &SavedAction::valueChanged,
|
connect(action(SortStructMembers), &SavedAction::valueChanged,
|
||||||
this, &WatchModel::reinsertAllData);
|
m_engine, &DebuggerEngine::updateAll);
|
||||||
connect(action(ShowStdNamespace), &SavedAction::valueChanged,
|
connect(action(ShowStdNamespace), &SavedAction::valueChanged,
|
||||||
this, &WatchModel::reinsertAllData);
|
m_engine, &DebuggerEngine::updateAll);
|
||||||
connect(action(ShowQtNamespace), &SavedAction::valueChanged,
|
connect(action(ShowQtNamespace), &SavedAction::valueChanged,
|
||||||
this, &WatchModel::reinsertAllData);
|
m_engine, &DebuggerEngine::updateAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchModel::reinitialize(bool includeInspectData)
|
void WatchModel::reinitialize(bool includeInspectData)
|
||||||
@@ -369,14 +367,6 @@ WatchItem *WatchItem::findItem(const QByteArray &iname)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchModel::reinsertAllDataHelper(WatchItem *item, QList<WatchData> *data)
|
|
||||||
{
|
|
||||||
data->append(*item); // Slices intentionally.
|
|
||||||
data->back().setAllUnneeded();
|
|
||||||
foreach (TreeItem *child, item->children())
|
|
||||||
reinsertAllDataHelper(static_cast<WatchItem *>(child), data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QByteArray parentName(const QByteArray &iname)
|
static QByteArray parentName(const QByteArray &iname)
|
||||||
{
|
{
|
||||||
const int pos = iname.lastIndexOf('.');
|
const int pos = iname.lastIndexOf('.');
|
||||||
@@ -1125,78 +1115,6 @@ DisplayFormats WatchItem::typeFormatList() const
|
|||||||
return formats;
|
return formats;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine sort order of watch items by sort order or alphabetical inames
|
|
||||||
// according to setting 'SortStructMembers'. We need a map key for insertBulkData
|
|
||||||
// and a predicate for finding the insertion position of a single item.
|
|
||||||
|
|
||||||
// Set this before using any of the below according to action
|
|
||||||
static bool sortWatchDataAlphabetically = true;
|
|
||||||
|
|
||||||
static bool watchDataLessThan(const QByteArray &iname1, int sortId1,
|
|
||||||
const QByteArray &iname2, int sortId2)
|
|
||||||
{
|
|
||||||
if (!sortWatchDataAlphabetically)
|
|
||||||
return sortId1 < sortId2;
|
|
||||||
// Get positions of last part of iname 'local.this.i1" -> "i1"
|
|
||||||
int cmpPos1 = iname1.lastIndexOf('.');
|
|
||||||
if (cmpPos1 == -1)
|
|
||||||
cmpPos1 = 0;
|
|
||||||
else
|
|
||||||
cmpPos1++;
|
|
||||||
int cmpPos2 = iname2.lastIndexOf('.');
|
|
||||||
if (cmpPos2 == -1)
|
|
||||||
cmpPos2 = 0;
|
|
||||||
else
|
|
||||||
cmpPos2++;
|
|
||||||
// Are we looking at an array with numerical inames 'local.this.i1.0" ->
|
|
||||||
// Go by sort id.
|
|
||||||
if (cmpPos1 < iname1.size() && cmpPos2 < iname2.size()
|
|
||||||
&& isdigit(iname1.at(cmpPos1)) && isdigit(iname2.at(cmpPos2)))
|
|
||||||
return sortId1 < sortId2;
|
|
||||||
// Alphabetically
|
|
||||||
return qstrcmp(iname1.constData() + cmpPos1, iname2.constData() + cmpPos2) < 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool watchItemSorter(const TreeItem *item1, const TreeItem *item2)
|
|
||||||
{
|
|
||||||
const WatchItem *it1 = static_cast<const WatchItem *>(item1);
|
|
||||||
const WatchItem *it2 = static_cast<const WatchItem *>(item2);
|
|
||||||
return watchDataLessThan(it1->iname, it1->sortId, it2->iname, it2->sortId);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int findInsertPosition(const QVector<TreeItem *> &list, const WatchItem *item)
|
|
||||||
{
|
|
||||||
sortWatchDataAlphabetically = boolSetting(SortStructMembers);
|
|
||||||
const auto it = qLowerBound(list.begin(), list.end(), item, watchItemSorter);
|
|
||||||
return it - list.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WatchModel::reinsertAllData()
|
|
||||||
{
|
|
||||||
QList<WatchData> list;
|
|
||||||
foreach (TreeItem *child, rootItem()->children())
|
|
||||||
reinsertAllDataHelper(static_cast<WatchItem *>(child), &list);
|
|
||||||
|
|
||||||
reinitialize(true);
|
|
||||||
|
|
||||||
for (int i = 0, n = list.size(); i != n; ++i) {
|
|
||||||
const WatchData &data = list.at(i);
|
|
||||||
QTC_ASSERT(!data.iname.isEmpty(), qDebug() << data.toString(); return);
|
|
||||||
// Add new entry.
|
|
||||||
WatchItem *parent = findItem(parentName(data.iname));
|
|
||||||
QTC_ASSERT(parent, return);
|
|
||||||
WatchItem *newItem = new WatchItem(data);
|
|
||||||
newItem->sortChildren(&watchItemSorter);
|
|
||||||
const int row = findInsertPosition(parent->children(), newItem);
|
|
||||||
parent->insertChild(row, newItem);
|
|
||||||
if (m_expandedINames.contains(parent->iname)) {
|
|
||||||
emit inameIsExpanded(parent->iname);
|
|
||||||
emit itemIsExpanded(indexForItem(parent));
|
|
||||||
}
|
|
||||||
showEditValue(newItem); // FIXME: Needed?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int WatchItem::requestedFormat() const
|
int WatchItem::requestedFormat() const
|
||||||
{
|
{
|
||||||
int format = theIndividualFormats.value(iname, AutomaticFormat);
|
int format = theIndividualFormats.value(iname, AutomaticFormat);
|
||||||
@@ -1244,14 +1162,13 @@ void WatchModel::insertItem(WatchItem *item)
|
|||||||
WatchItem *parent = findItem(parentName(item->iname));
|
WatchItem *parent = findItem(parentName(item->iname));
|
||||||
QTC_ASSERT(parent, return);
|
QTC_ASSERT(parent, return);
|
||||||
|
|
||||||
if (WatchItem *existing = parent->findItem(item->iname))
|
if (WatchItem *existing = parent->findItem(item->iname)) {
|
||||||
|
int row = parent->children().indexOf(existing);
|
||||||
takeItem(existing);
|
takeItem(existing);
|
||||||
|
|
||||||
//item->walkTree([item](TreeItem *sub) { sub->sortChildren(&watchItemSorter); });
|
|
||||||
item->sortChildren(&watchItemSorter);
|
|
||||||
|
|
||||||
const int row = findInsertPosition(parent->children(), item);
|
|
||||||
parent->insertChild(row, item);
|
parent->insertChild(row, item);
|
||||||
|
} else {
|
||||||
|
parent->appendChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
item->walkTree([this](TreeItem *sub) { showEditValue(static_cast<WatchItem *>(sub)); });
|
item->walkTree([this](TreeItem *sub) { showEditValue(static_cast<WatchItem *>(sub)); });
|
||||||
}
|
}
|
||||||
@@ -1572,7 +1489,7 @@ void WatchModel::setTypeFormat(const QByteArray &type0, int format)
|
|||||||
else
|
else
|
||||||
theTypeFormats[type] = format;
|
theTypeFormats[type] = format;
|
||||||
saveFormats();
|
saveFormats();
|
||||||
reinsertAllData();
|
m_engine->updateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchModel::setIndividualFormat(const QByteArray &iname, int format)
|
void WatchModel::setIndividualFormat(const QByteArray &iname, int format)
|
||||||
|
|||||||
Reference in New Issue
Block a user