Truncate resource names that are unreasonably long. Closes #1832

This commit is contained in:
baldurk
2020-04-21 17:09:33 +01:00
parent 75da714a85
commit f57709366a
2 changed files with 22 additions and 7 deletions
+19 -7
View File
@@ -159,6 +159,15 @@ rdcstr DoStringise(const PointerVal &el)
}
}
QString GetTruncatedResourceName(ICaptureContext &ctx, ResourceId id)
{
rdcstr name = ctx.GetResourceName(id);
if(name.length() > 64)
return name.substr(0, 64) + "...";
return name;
}
// this is an opaque struct that contains the data to render, hit-test, etc for some text that
// contains links to resources. It will update and cache the names of the resources.
struct RichResourceText
@@ -213,7 +222,7 @@ struct RichResourceText
{
if(v.userType() == qMetaTypeId<ResourceId>())
{
QString resname = QString(ctx.GetResourceName(v.value<ResourceId>())).toHtmlEscaped();
QString resname = GetTruncatedResourceName(ctx, v.value<ResourceId>()).toHtmlEscaped();
html += lit("<td valign=\"middle\"><b>%1</b></td>"
"<td><img width=\"16\" src=':/link%3.png'></td>")
.arg(resname)
@@ -458,7 +467,7 @@ void RichResourceTextPaint(const QWidget *owner, QPainter *painter, QRect rect,
valid = (id != ResourceId());
if(ctxptr)
name = ctxptr->GetResourceName(id);
name = GetTruncatedResourceName(*ctxptr, id);
else
name = ToQStr(id);
}
@@ -474,7 +483,8 @@ void RichResourceTextPaint(const QWidget *owner, QPainter *painter, QRect rect,
{
if(ptr->base != ResourceId())
{
name = QFormatStr("%1+%2").arg(ptr->ctxptr->GetResourceName(ptr->base)).arg(ptr->offset);
name =
QFormatStr("%1+%2").arg(GetTruncatedResourceName(*ptr->ctxptr, ptr->base)).arg(ptr->offset);
}
else
{
@@ -608,7 +618,7 @@ int RichResourceTextWidthHint(const QWidget *owner, const QFont &font, const QVa
ResourceId id = var.value<ResourceId>();
if(ctxptr)
name = ctxptr->GetResourceName(id);
name = GetTruncatedResourceName(*ctxptr, id);
else
name = ToQStr(id);
}
@@ -619,7 +629,8 @@ int RichResourceTextWidthHint(const QWidget *owner, const QFont &font, const QVa
ptr->cacheAddress(owner);
if(ptr->val.pointer != 0)
name = QFormatStr("%1+%2").arg(ptr->ctxptr->GetResourceName(ptr->base)).arg(ptr->offset);
name =
QFormatStr("%1+%2").arg(GetTruncatedResourceName(*ptr->ctxptr, ptr->base)).arg(ptr->offset);
else
name = lit("NULL");
}
@@ -685,7 +696,7 @@ bool RichResourceTextMouseEvent(const QWidget *owner, const QVariant &var, QRect
ctxptr = getCaptureContext(owner);
if(ctxptr)
name = ctxptr->GetResourceName(id);
name = GetTruncatedResourceName(*ctxptr, id);
else
name = ToQStr(id);
}
@@ -693,7 +704,8 @@ bool RichResourceTextMouseEvent(const QWidget *owner, const QVariant &var, QRect
{
ctxptr = ptr->ctxptr;
name = QFormatStr("%1+%2").arg(ptr->ctxptr->GetResourceName(ptr->base)).arg(ptr->offset);
name =
QFormatStr("%1+%2").arg(GetTruncatedResourceName(*ptr->ctxptr, ptr->base)).arg(ptr->offset);
}
QRect textRect = QFontMetrics(f).boundingRect(rect, Qt::AlignLeft | Qt::AlignVCenter, name);
+3
View File
@@ -165,6 +165,9 @@
<property name="text">
<string>Resource Name Here</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>