debugger: remember format settings also for individual variables

Task-number: QTCREATORBUG-6944
Change-Id: I98c803e64a6a1ac2c07a0d0b0f31c6d7756faffc
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
hjk
2012-03-14 12:26:27 +01:00
committed by hjk
parent bd28997385
commit d014c2ca4b
2 changed files with 41 additions and 39 deletions

View File

@@ -72,8 +72,11 @@ enum { debugModel = 0 };
#define MODEL_DEBUG(s) do { if (debugModel) qDebug() << s; } while (0)
#define MODEL_DEBUGX(s) qDebug() << s
QHash<QByteArray, int> WatchHandler::m_watcherNames;
QHash<QByteArray, int> WatchHandler::m_typeFormats;
static QHash<QByteArray, int> theWatcherNames;
static QHash<QByteArray, int> theTypeFormats;
static QHash<QByteArray, int> theIndividualFormats;
static int theUnprintableBase = -1;
static QByteArray stripForFormat(const QByteArray &ba)
{
@@ -97,17 +100,15 @@ static QByteArray stripForFormat(const QByteArray &ba)
return res;
}
static int m_unprintableBase = -1;
void WatchHandler::setUnprintableBase(int base)
{
m_unprintableBase = base;
theUnprintableBase = base;
emitAllChanged();
}
int WatchHandler::unprintableBase()
{
return m_unprintableBase;
return theUnprintableBase;
}
////////////////////////////////////////////////////////////////////
@@ -706,10 +707,10 @@ static QString truncateValue(QString v)
int WatchModel::itemFormat(const WatchData &data) const
{
const int individualFormat = m_handler->m_individualFormats.value(data.iname, -1);
const int individualFormat = theIndividualFormats.value(data.iname, -1);
if (individualFormat != -1)
return individualFormat;
return m_handler->m_typeFormats.value(stripForFormat(data.type), -1);
return theTypeFormats.value(stripForFormat(data.type), -1);
}
static inline QString expression(const WatchItem *item)
@@ -837,10 +838,10 @@ QVariant WatchModel::data(const QModelIndex &idx, int role) const
return QString::fromLatin1(data.type);
case LocalsTypeFormatRole:
return m_handler->m_typeFormats.value(stripForFormat(data.type), -1);
return theTypeFormats.value(stripForFormat(data.type), -1);
case LocalsIndividualFormatRole:
return m_handler->m_individualFormats.value(data.iname, -1);
return theIndividualFormats.value(data.iname, -1);
case LocalsRawValueRole:
return data.value;
@@ -911,9 +912,9 @@ bool WatchModel::setData(const QModelIndex &index, const QVariant &value, int ro
case LocalsIndividualFormatRole: {
const int format = value.toInt();
if (format == -1) {
m_handler->m_individualFormats.remove(data.iname);
theIndividualFormats.remove(data.iname);
} else {
m_handler->m_individualFormats[data.iname] = format;
theIndividualFormats[data.iname] = format;
}
engine()->updateWatchData(data);
break;
@@ -1249,9 +1250,9 @@ QDebug operator<<(QDebug d, const WatchModel &m)
void WatchModel::formatRequests(QByteArray *out, const WatchItem *item) const
{
int format = m_handler->m_individualFormats.value(item->iname, -1);
int format = theIndividualFormats.value(item->iname, -1);
if (format == -1)
format = m_handler->m_typeFormats.value(stripForFormat(item->type), -1);
format = theTypeFormats.value(stripForFormat(item->type), -1);
if (format != -1)
*out += item->iname + ":format=" + QByteArray::number(format) + ',';
foreach (const WatchItem *child, item->children)
@@ -1311,7 +1312,7 @@ void WatchHandler::endCycle()
void WatchHandler::cleanup()
{
m_expandedINames.clear();
m_watcherNames.remove(QByteArray());
theWatcherNames.remove(QByteArray());
m_return->reinitialize();
m_locals->reinitialize();
m_tooltips->reinitialize();
@@ -1429,21 +1430,21 @@ void WatchHandler::removeData(const QByteArray &iname)
QByteArray WatchHandler::watcherName(const QByteArray &exp)
{
return "watch." + QByteArray::number(m_watcherNames[exp]);
return "watch." + QByteArray::number(theWatcherNames[exp]);
}
void WatchHandler::watchExpression(const QString &exp)
{
QTC_ASSERT(m_engine, return);
// Do not insert the same entry more then once.
if (m_watcherNames.value(exp.toLatin1()))
if (theWatcherNames.value(exp.toLatin1()))
return;
// FIXME: 'exp' can contain illegal characters
WatchData data;
data.exp = exp.toLatin1();
data.name = exp;
m_watcherNames[data.exp] = m_watcherCounter++;
theWatcherNames[data.exp] = m_watcherCounter++;
saveWatchers();
if (exp.isEmpty())
@@ -1560,12 +1561,12 @@ void WatchHandler::showEditValue(const WatchData &data)
void WatchHandler::clearWatches()
{
if (m_watcherNames.isEmpty())
if (theWatcherNames.isEmpty())
return;
const QList<WatchItem *> watches = m_watchers->rootItem()->children;
for (int i = watches.size() - 1; i >= 0; i--)
m_watchers->destroyItem(watches.at(i));
m_watcherNames.clear();
theWatcherNames.clear();
m_watcherCounter = 0;
updateWatchersWindow();
emitAllChanged();
@@ -1576,7 +1577,7 @@ void WatchHandler::removeWatchExpression(const QString &exp0)
{
QByteArray exp = exp0.toLatin1();
MODEL_DEBUG("REMOVE WATCH: " << exp);
m_watcherNames.remove(exp);
theWatcherNames.remove(exp);
foreach (WatchItem *item, m_watchers->rootItem()->children) {
if (item->exp == exp) {
m_watchers->destroyItem(item);
@@ -1598,7 +1599,7 @@ QStringList WatchHandler::watchedExpressions()
{
// Filter out invalid watchers.
QStringList watcherNames;
QHashIterator<QByteArray, int> it(m_watcherNames);
QHashIterator<QByteArray, int> it(theWatcherNames);
while (it.hasNext()) {
it.next();
const QByteArray &watcherName = it.key();
@@ -1621,14 +1622,14 @@ void WatchHandler::loadTypeFormats()
while (it.hasNext()) {
it.next();
if (!it.key().isEmpty())
m_typeFormats.insert(it.key().toUtf8(), it.value().toInt());
theTypeFormats.insert(it.key().toUtf8(), it.value().toInt());
}
}
void WatchHandler::saveTypeFormats()
{
QMap<QString, QVariant> typeFormats;
QHashIterator<QByteArray, int> it(m_typeFormats);
QHashIterator<QByteArray, int> it(theTypeFormats);
while (it.hasNext()) {
it.next();
const int format = it.value();
@@ -1651,7 +1652,7 @@ void WatchHandler::saveSessionData()
void WatchHandler::loadSessionData()
{
loadTypeFormats();
m_watcherNames.clear();
theWatcherNames.clear();
m_watcherCounter = 0;
QVariant value = debuggerCore()->sessionValue(QLatin1String("Watchers"));
foreach (WatchItem *item, m_watchers->rootItem()->children)
@@ -1667,7 +1668,7 @@ void WatchHandler::updateWatchers()
foreach (WatchItem *item, m_watchers->rootItem()->children)
m_watchers->destroyItem(item);
// Copy over all watchers and mark all watchers as incomplete.
foreach (const QByteArray &exp, m_watcherNames.keys()) {
foreach (const QByteArray &exp, theWatcherNames.keys()) {
WatchData data;
data.iname = watcherName(exp);
data.setAllNeeded();
@@ -1737,9 +1738,9 @@ void WatchHandler::setFormat(const QByteArray &type0, int format)
{
const QByteArray type = stripForFormat(type0);
if (format == -1)
m_typeFormats.remove(type);
theTypeFormats.remove(type);
else
m_typeFormats[type] = format;
theTypeFormats[type] = format;
saveTypeFormats();
m_return->emitDataChanged(1);
m_locals->emitDataChanged(1);
@@ -1751,9 +1752,9 @@ int WatchHandler::format(const QByteArray &iname) const
{
int result = -1;
if (const WatchData *item = findItem(iname)) {
int result = m_individualFormats.value(item->iname, -1);
int result = theIndividualFormats.value(item->iname, -1);
if (result == -1)
result = m_typeFormats.value(stripForFormat(item->type), -1);
result = theTypeFormats.value(stripForFormat(item->type), -1);
}
return result;
}
@@ -1778,8 +1779,8 @@ QByteArray WatchHandler::expansionRequests() const
QByteArray WatchHandler::typeFormatRequests() const
{
QByteArray ba;
if (!m_typeFormats.isEmpty()) {
QHashIterator<QByteArray, int> it(m_typeFormats);
if (!theTypeFormats.isEmpty()) {
QHashIterator<QByteArray, int> it(theTypeFormats);
while (it.hasNext()) {
it.next();
ba.append(it.key().toHex());
@@ -1795,8 +1796,8 @@ QByteArray WatchHandler::typeFormatRequests() const
QByteArray WatchHandler::individualFormatRequests() const
{
QByteArray ba;
if (!m_individualFormats.isEmpty()) {
QHashIterator<QByteArray, int> it(m_individualFormats);
if (!theIndividualFormats.isEmpty()) {
QHashIterator<QByteArray, int> it(theIndividualFormats);
while (it.hasNext()) {
it.next();
ba.append(it.key());
@@ -1911,5 +1912,10 @@ bool WatchHandler::isValidToolTip(const QByteArray &iname) const
return item && !item->type.trimmed().isEmpty();
}
QHash<QByteArray, int> WatchHandler::watcherNames()
{
return theWatcherNames;
}
} // namespace Internal
} // namespace Debugger

View File

@@ -179,8 +179,7 @@ public:
QSet<QByteArray> expandedINames() const
{ return m_expandedINames; }
static QStringList watchedExpressions();
static QHash<QByteArray, int> watcherNames()
{ return m_watcherNames; }
static QHash<QByteArray, int> watcherNames();
QByteArray expansionRequests() const;
QByteArray typeFormatRequests() const;
@@ -222,9 +221,6 @@ private:
typedef QMap<QByteArray, QPointer<QObject> > EditHandlers;
EditHandlers m_editHandlers;
static QHash<QByteArray, int> m_watcherNames;
static QHash<QByteArray, int> m_typeFormats;
QHash<QByteArray, int> m_individualFormats; // Indexed by iname.
TypeFormats m_reportedTypeFormats;
// Items expanded in the Locals & Watchers view.