Debugger: Remove dead code that persisted tooltips at some time

This was not in use since 2fe69b60 in  2015 without anyone complaining.

Change-Id: Iccc4a230a008b8dff5b08faa5cb1ae513c4c0360
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2024-07-15 11:30:14 +02:00
parent 5cc47bc232
commit 4367737012
2 changed files with 0 additions and 250 deletions

View File

@@ -33,21 +33,13 @@
#include <utils/utilsicons.h>
#include <QAbstractItemModel>
#include <QApplication>
#include <QClipboard>
#include <QDebug>
#include <QFileInfo>
#include <QLabel>
#include <QScreen>
#include <QScrollBar>
#include <QSortFilterProxyModel>
#include <QStack>
#include <QStandardItemModel>
#include <QToolBar>
#include <QToolButton>
#include <QVBoxLayout>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
using namespace Core;
using namespace ProjectExplorer;
@@ -59,32 +51,6 @@ namespace Debugger::Internal {
//#define DEBUG(x) qDebug() << x
#define DEBUG(x)
// Expire tooltips after n days on (no longer load them) in order
// to avoid them piling up.
enum { toolTipsExpiryDays = 6 };
const char sessionSettingsKeyC[] = "DebuggerToolTips";
const char sessionDocumentC[] = "DebuggerToolTips";
const char sessionVersionAttributeC[] = "version";
const char toolTipElementC[] = "DebuggerToolTip";
//const char toolTipClassAttributeC[] = "class";
const char fileNameAttributeC[] = "name";
const char functionAttributeC[] = "function";
const char textPositionAttributeC[] = "position";
const char textLineAttributeC[] = "line";
const char textColumnAttributeC[] = "column";
const char offsetXAttributeC[] = "offset_x";
const char offsetYAttributeC[] = "offset_y";
const char engineTypeAttributeC[] = "engine";
const char dateAttributeC[] = "date";
const char treeElementC[] = "tree";
const char treeExpressionAttributeC[] = "expression";
const char treeInameAttributeC[] = "iname";
// const char modelElementC[] = "model";
// const char modelColumnCountAttributeC[] = "columncount";
// const char modelRowElementC[] = "row";
const char modelItemElementC[] = "item";
class DebuggerToolTipHolder;
class DebuggerToolTipManagerPrivate : public QObject
@@ -115,8 +81,6 @@ public:
void leavingDebugMode();
void sessionAboutToChange();
void loadSessionData();
void saveSessionData();
void updateVisibleToolTips();
void closeAllToolTips();
@@ -129,27 +93,6 @@ public:
bool m_debugModeActive = false;
};
// Forward a stream reader across end elements looking for the
// next start element of a desired type.
static bool readStartElement(QXmlStreamReader &r, const char *name)
{
while (r.tokenType() != QXmlStreamReader::StartElement
|| r.name() != QLatin1String(name))
switch (r.readNext()) {
case QXmlStreamReader::EndDocument:
return false;
case QXmlStreamReader::NoToken:
case QXmlStreamReader::Invalid:
qWarning("'%s'/'%s' encountered while looking for start element '%s'.",
qPrintable(r.tokenString()),
qPrintable(r.name().toString()), name);
return false;
default:
break;
}
return true;
}
// A label that can be dragged to drag something else.
class DraggableLabel : public QLabel
@@ -286,8 +229,6 @@ public:
m_expandedINames.remove(idx.data(LocalsINameRole).toString());
}
void restoreTreeModel(QXmlStreamReader &r);
QPointer<DebuggerEngine> m_engine;
QSet<QString> m_expandedINames;
bool m_enabled;
@@ -325,51 +266,6 @@ QVariant ToolTipWatchItem::data(int column, int role) const
return QVariant();
}
void ToolTipModel::restoreTreeModel(QXmlStreamReader &r)
{
Q_UNUSED(r)
#if 0
// Helper for building a QStandardItemModel of a tree form (see TreeModelVisitor).
// The recursion/building is based on the scheme: \code
// <row><item1><item2>
// <row><item11><item12></row>
// </row>
// \endcode
bool withinModel = true;
while (withinModel && !r.atEnd()) {
const QXmlStreamReader::TokenType token = r.readNext();
switch (token) {
case QXmlStreamReader::StartElement: {
const QStringRef element = r.name();
// Root model element with column count.
if (element == QLatin1String(modelElementC)) {
if (const int cc = r.attributes().value(QLatin1String(modelColumnCountAttributeC)).toString().toInt())
columnCount = cc;
m->setColumnCount(columnCount);
} else if (element == QLatin1String(modelRowElementC)) {
builder.startRow();
} else if (element == QLatin1String(modelItemElementC)) {
builder.addItem(r.readElementText());
}
}
break; // StartElement
case QXmlStreamReader::EndElement: {
const QStringRef element = r.name();
// Row closing: pop off parent.
if (element == QLatin1String(modelRowElementC))
builder.endRow();
else if (element == QLatin1String(modelElementC))
withinModel = false;
}
break; // EndElement
default:
break;
} // switch
} // while
#endif
}
/*!
\class Debugger::Internal::DebuggerToolTipTreeView
@@ -642,8 +538,6 @@ public:
void acquireEngine(DebuggerEngine *engine);
void releaseEngine();
void saveSessionData(QXmlStreamWriter &w) const;
void positionShow(const TextEditorWidget *editorWidget);
void updateTooltip(DebuggerEngine *engine);
@@ -724,11 +618,8 @@ QDebug operator<<(QDebug d, const DebuggerToolTipContext &c)
The debugger tooltip goes from the unpinned state (button
showing 'Pin') to the pinned state (button showing 'Close').
It consists of a title toolbar and a vertical main layout.
The widget has the ability to save/restore tree model contents to XML.
With the engine acquired, it sets a filter model (by expression) on
one of the engine's models (debuggerModel).
On release, it serializes and restores the data to a QStandardItemModel
(defaultModel) and displays that.
It is associated with file name and position with functionality to
acquire and release the engine. When the debugger stops at a file, all
@@ -737,14 +628,6 @@ QDebug operator<<(QDebug d, const DebuggerToolTipContext &c)
engine, that is, store the data internally and keep displaying them
marked as 'previous'.
When restoring the data from a session, all tooltips start in 'released' mode.
Stored tooltips expire after toolTipsExpiryDays while loading to prevent
them accumulating.
In addition, if the stored line number diverges too much from the current line
number in positionShow(), the tooltip is also closed/discarded.
The widget is that is first shown by the TextEditor's tooltip
class and typically closed by it unless the user pins it.
In that case, it is removed from the tip's layout, added to the DebuggerToolTipManager's
@@ -759,7 +642,6 @@ DebuggerToolTipHolder::DebuggerToolTipHolder(const DebuggerToolTipContext &conte
widget->setObjectName("DebuggerTreeViewToolTipWidget: " + context_.iname);
context = context_;
context.creationDate = QDate::currentDate();
state = New;
@@ -894,52 +776,6 @@ void DebuggerToolTipHolder::positionShow(const TextEditorWidget *editorWidget)
}
}
//// Parse a 'yyyyMMdd' date
static QDate dateFromString(const QString &date)
{
return date.size() == 8
? QDate(date.left(4).toInt(), date.mid(4, 2).toInt(), date.mid(6, 2).toInt())
: QDate();
}
void DebuggerToolTipHolder::saveSessionData(QXmlStreamWriter &w) const
{
w.writeStartElement(toolTipElementC);
QXmlStreamAttributes attributes;
// attributes.append(toolTipClassAttributeC, QString::fromLatin1(metaObject()->className()));
attributes.append(fileNameAttributeC, context.fileName.toString());
if (!context.function.isEmpty())
attributes.append(functionAttributeC, context.function);
attributes.append(textPositionAttributeC, QString::number(context.position));
attributes.append(textLineAttributeC, QString::number(context.line));
attributes.append(textColumnAttributeC, QString::number(context.column));
attributes.append(dateAttributeC, creationDate.toString("yyyyMMdd"));
QPoint offset = widget->titleLabel->m_offset;
if (offset.x())
attributes.append(offsetXAttributeC, QString::number(offset.x()));
if (offset.y())
attributes.append(offsetYAttributeC, QString::number(offset.y()));
attributes.append(engineTypeAttributeC, context.engineType);
attributes.append(treeExpressionAttributeC, context.expression);
attributes.append(treeInameAttributeC, context.iname);
w.writeAttributes(attributes);
w.writeStartElement(treeElementC);
widget->model.forAllItems([&w](ToolTipWatchItem *item) {
const QString modelItemElement(modelItemElementC);
for (int i = 0; i < 3; ++i) {
const QString value = item->data(i, Qt::DisplayRole).toString();
if (value.isEmpty())
w.writeEmptyElement(modelItemElement);
else
w.writeTextElement(modelItemElement, value);
}
});
w.writeEndElement();
w.writeEndElement();
}
/*!
\class Debugger::Internal::DebuggerToolTipManager
@@ -1019,8 +855,6 @@ void DebuggerToolTipManager::deregisterEngine()
if (tooltip->context.engineType == d->m_engine->objectName())
tooltip->releaseEngine();
d->saveSessionData();
// FIXME: For now remove all.
for (DebuggerToolTipHolder *tooltip : std::as_const(d->m_tooltips))
tooltip->destroy();
@@ -1037,81 +871,6 @@ void DebuggerToolTipManagerPrivate::sessionAboutToChange()
closeAllToolTips();
}
void DebuggerToolTipManagerPrivate::loadSessionData()
{
closeAllToolTips();
const QString data = SessionManager::value(sessionSettingsKeyC).toString();
QXmlStreamReader r(data);
if (r.readNextStartElement() && r.name() == QLatin1String(sessionDocumentC)) {
while (!r.atEnd()) {
if (readStartElement(r, toolTipElementC)) {
const QXmlStreamAttributes attributes = r.attributes();
DebuggerToolTipContext context;
context.fileName = FilePath::fromString(
attributes.value(fileNameAttributeC).toString());
context.position = attributes.value(textPositionAttributeC).toString().toInt();
context.line = attributes.value(textLineAttributeC).toString().toInt();
context.column = attributes.value(textColumnAttributeC).toString().toInt();
context.function = attributes.value(functionAttributeC).toString();
QPoint offset;
const QString offsetXAttribute(offsetXAttributeC);
const QString offsetYAttribute(offsetYAttributeC);
if (attributes.hasAttribute(offsetXAttribute))
offset.setX(attributes.value(offsetXAttribute).toString().toInt());
if (attributes.hasAttribute(offsetYAttribute))
offset.setY(attributes.value(offsetYAttribute).toString().toInt());
context.mousePosition = offset;
context.iname = attributes.value(treeInameAttributeC).toString();
context.expression = attributes.value(treeExpressionAttributeC).toString();
// const QStringRef className = attributes.value(toolTipClassAttributeC);
context.engineType = attributes.value(engineTypeAttributeC).toString();
context.creationDate = dateFromString(attributes.value(dateAttributeC).toString());
bool readTree = context.isValid();
if (!context.creationDate.isValid() || context.creationDate.daysTo(QDate::currentDate()) > toolTipsExpiryDays) {
// DEBUG("Expiring tooltip " << context.fileName << '@' << context.position << " from " << creationDate)
//readTree = false;
} else { //if (className != "Debugger::Internal::DebuggerToolTipWidget") {
//qWarning("Unable to create debugger tool tip widget of class %s", qPrintable(className.toString()));
//readTree = false;
}
if (readTree) {
auto tw = new DebuggerToolTipHolder(context);
m_tooltips.push_back(tw);
tw->widget->model.restoreTreeModel(r);
tw->widget->pin();
tw->widget->titleLabel->setText(Tr::tr("%1 (Restored)").arg(context.expression));
tw->widget->treeView->expandAll();
} else {
r.readElementText(QXmlStreamReader::SkipChildElements); // Skip
}
r.readNext(); // Skip </tree>
}
}
}
}
void DebuggerToolTipManagerPrivate::saveSessionData()
{
QString data;
purgeClosedToolTips();
QXmlStreamWriter w(&data);
w.writeStartDocument();
w.writeStartElement(sessionDocumentC);
w.writeAttribute(sessionVersionAttributeC, "1.0");
for (DebuggerToolTipHolder *tooltip : std::as_const(m_tooltips))
if (tooltip->widget->isPinned)
tooltip->saveSessionData(w);
w.writeEndDocument();
return; // FIXME
// setSessionValue(sessionSettingsKeyC, QVariant(data));
}
void DebuggerToolTipManager::closeAllToolTips()
{
d->closeAllToolTips();
@@ -1136,10 +895,6 @@ DebuggerToolTipManagerPrivate::DebuggerToolTipManagerPrivate(DebuggerEngine *eng
{
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
this, &DebuggerToolTipManagerPrivate::onModeChanged);
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
this, &DebuggerToolTipManagerPrivate::loadSessionData);
connect(SessionManager::instance(), &SessionManager::aboutToSaveSession,
this, &DebuggerToolTipManagerPrivate::saveSessionData);
connect(SessionManager::instance(), &SessionManager::aboutToUnloadSession,
this, &DebuggerToolTipManagerPrivate::sessionAboutToChange);
debugModeEntered();