Commit 653757e7 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Fixed HTML escaping issues in the function argument widget

HTML escaping was moved out of the TypePrettyPrinter since it interferes
with other logic there. Instead, the region to mark is now available
from the Overview and used by the FunctionArgumentWidget to put the
current argument in bold.
parent 8c45eb57
...@@ -35,27 +35,18 @@ ...@@ -35,27 +35,18 @@
using namespace CPlusPlus; using namespace CPlusPlus;
Overview::Overview() Overview::Overview()
: _markArgument(0), : _markedArgument(0),
_markedArgumentBegin(0),
_markedArgumentEnd(0),
_showArgumentNames(false), _showArgumentNames(false),
_showReturnTypes(false), _showReturnTypes(false),
_showFunctionSignatures(true), _showFunctionSignatures(true),
_showFullyQualifiedNames(false), _showFullyQualifiedNames(false)
_richText(false)
{ } { }
Overview::~Overview() Overview::~Overview()
{ } { }
bool Overview::richText() const
{
return _richText;
}
void Overview::setRichText(bool richText)
{
_richText = richText;
}
bool Overview::showArgumentNames() const bool Overview::showArgumentNames() const
{ {
return _showArgumentNames; return _showArgumentNames;
...@@ -76,14 +67,34 @@ bool Overview::showReturnTypes() const ...@@ -76,14 +67,34 @@ bool Overview::showReturnTypes() const
return _showReturnTypes; return _showReturnTypes;
} }
unsigned Overview::markArgument() const unsigned Overview::markedArgument() const
{
return _markedArgument;
}
void Overview::setMarkedArgument(unsigned position)
{
_markedArgument = position;
}
int Overview::markedArgumentBegin() const
{
return _markedArgumentBegin;
}
void Overview::setMarkedArgumentBegin(int begin)
{
_markedArgumentBegin = begin;
}
int Overview::markedArgumentEnd() const
{ {
return _markArgument; return _markedArgumentEnd;
} }
void Overview::setMarkArgument(unsigned position) void Overview::setMarkedArgumentEnd(int end)
{ {
_markArgument = position; _markedArgumentEnd = end;
} }
bool Overview::showFunctionSignatures() const bool Overview::showFunctionSignatures() const
......
...@@ -44,9 +44,6 @@ public: ...@@ -44,9 +44,6 @@ public:
Overview(); Overview();
~Overview(); ~Overview();
bool richText() const;
void setRichText(bool richText);
bool showArgumentNames() const; bool showArgumentNames() const;
void setShowArgumentNames(bool showArgumentNames); void setShowArgumentNames(bool showArgumentNames);
...@@ -59,10 +56,15 @@ public: ...@@ -59,10 +56,15 @@ public:
bool showFullyQualifiedNames() const; bool showFullyQualifiedNames() const;
void setShowFullyQualifiedNamed(bool showFullyQualifiedNames); void setShowFullyQualifiedNamed(bool showFullyQualifiedNames);
// 1-based // argument index that you want to mark
// ### rename unsigned markedArgument() const;
unsigned markArgument() const; void setMarkedArgument(unsigned position);
void setMarkArgument(unsigned position);
int markedArgumentBegin() const;
void setMarkedArgumentBegin(int begin);
int markedArgumentEnd() const;
void setMarkedArgumentEnd(int end);
QString operator()(Name *name) const QString operator()(Name *name) const
{ return prettyName(name); } { return prettyName(name); }
...@@ -75,12 +77,13 @@ public: ...@@ -75,12 +77,13 @@ public:
QString prettyType(const FullySpecifiedType &type, const QString &name) const; QString prettyType(const FullySpecifiedType &type, const QString &name) const;
private: private:
unsigned _markArgument; unsigned _markedArgument;
int _markedArgumentBegin;
int _markedArgumentEnd;
bool _showArgumentNames: 1; bool _showArgumentNames: 1;
bool _showReturnTypes: 1; bool _showReturnTypes: 1;
bool _showFunctionSignatures: 1; bool _showFunctionSignatures: 1;
bool _showFullyQualifiedNames: 1; bool _showFullyQualifiedNames: 1;
bool _richText: 1;
}; };
} // end of namespace CPlusPlus } // end of namespace CPlusPlus
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include <Scope.h> #include <Scope.h>
#include <QStringList> #include <QStringList>
#include <QtDebug> #include <QtDebug>
#include <QTextDocument> // Qt::escape()
using namespace CPlusPlus; using namespace CPlusPlus;
...@@ -107,10 +106,10 @@ QString TypePrettyPrinter::operator()(const FullySpecifiedType &type, const QStr ...@@ -107,10 +106,10 @@ QString TypePrettyPrinter::operator()(const FullySpecifiedType &type, const QStr
void TypePrettyPrinter::acceptType(const FullySpecifiedType &ty) void TypePrettyPrinter::acceptType(const FullySpecifiedType &ty)
{ {
if (ty.isSigned()) if (ty.isSigned())
out(QLatin1String("signed ")); _text += QLatin1String("signed ");
else if (ty.isUnsigned()) else if (ty.isUnsigned())
out(QLatin1String("unsigned ")); _text += QLatin1String("unsigned ");
const FullySpecifiedType previousFullySpecifiedType = _fullySpecifiedType; const FullySpecifiedType previousFullySpecifiedType = _fullySpecifiedType;
_fullySpecifiedType = ty; _fullySpecifiedType = ty;
...@@ -148,14 +147,14 @@ void TypePrettyPrinter::applyPtrOperators(bool wantSpace) ...@@ -148,14 +147,14 @@ void TypePrettyPrinter::applyPtrOperators(bool wantSpace)
space(); space();
if (op->isPointerType()) { if (op->isPointerType()) {
out(QLatin1Char('*')); _text += QLatin1Char('*');
outCV(op); outCV(op);
} else if (op->isReferenceType()) { } else if (op->isReferenceType()) {
out(QLatin1Char('&')); _text += QLatin1Char('&');
} else if (const PointerToMemberType *memPtrTy = op->asPointerToMemberType()) { } else if (const PointerToMemberType *memPtrTy = op->asPointerToMemberType()) {
space(); space();
out(_overview->prettyName(memPtrTy->memberName())); _text += _overview->prettyName(memPtrTy->memberName());
out(QLatin1Char('*')); _text += QLatin1Char('*');
outCV(op); outCV(op);
} }
} }
...@@ -163,13 +162,13 @@ void TypePrettyPrinter::applyPtrOperators(bool wantSpace) ...@@ -163,13 +162,13 @@ void TypePrettyPrinter::applyPtrOperators(bool wantSpace)
void TypePrettyPrinter::visit(VoidType *) void TypePrettyPrinter::visit(VoidType *)
{ {
out(QLatin1String("void")); _text += QLatin1String("void");
applyPtrOperators(); applyPtrOperators();
} }
void TypePrettyPrinter::visit(NamedType *type) void TypePrettyPrinter::visit(NamedType *type)
{ {
out(overview()->prettyName(type->name())); _text += overview()->prettyName(type->name());
applyPtrOperators(); applyPtrOperators();
} }
...@@ -206,25 +205,25 @@ void TypePrettyPrinter::visit(IntegerType *type) ...@@ -206,25 +205,25 @@ void TypePrettyPrinter::visit(IntegerType *type)
{ {
switch (type->kind()) { switch (type->kind()) {
case IntegerType::Char: case IntegerType::Char:
out(QLatin1String("char")); _text += QLatin1String("char");
break; break;
case IntegerType::WideChar: case IntegerType::WideChar:
out(QLatin1String("wchar_t")); _text += QLatin1String("wchar_t");
break; break;
case IntegerType::Bool: case IntegerType::Bool:
out(QLatin1String("bool")); _text += QLatin1String("bool");
break; break;
case IntegerType::Short: case IntegerType::Short:
out(QLatin1String("short")); _text += QLatin1String("short");
break; break;
case IntegerType::Int: case IntegerType::Int:
out(QLatin1String("int")); _text += QLatin1String("int");
break; break;
case IntegerType::Long: case IntegerType::Long:
out(QLatin1String("long")); _text += QLatin1String("long");
break; break;
case IntegerType::LongLong: case IntegerType::LongLong:
out(QLatin1String("long long")); _text += QLatin1String("long long");
break; break;
} }
...@@ -235,13 +234,13 @@ void TypePrettyPrinter::visit(FloatType *type) ...@@ -235,13 +234,13 @@ void TypePrettyPrinter::visit(FloatType *type)
{ {
switch (type->kind()) { switch (type->kind()) {
case FloatType::Float: case FloatType::Float:
out(QLatin1String("float")); _text += QLatin1String("float");
break; break;
case FloatType::Double: case FloatType::Double:
out(QLatin1String("double")); _text += QLatin1String("double");
break; break;
case FloatType::LongDouble: case FloatType::LongDouble:
out(QLatin1String("long double")); _text += QLatin1String("long double");
break; break;
} }
...@@ -277,26 +276,26 @@ void TypePrettyPrinter::visit(ReferenceType *type) ...@@ -277,26 +276,26 @@ void TypePrettyPrinter::visit(ReferenceType *type)
void TypePrettyPrinter::visit(ArrayType *type) void TypePrettyPrinter::visit(ArrayType *type)
{ {
out(overview()->prettyType(type->elementType())); _text += overview()->prettyType(type->elementType());
if (! _ptrOperators.isEmpty()) { if (! _ptrOperators.isEmpty()) {
out(QLatin1Char('(')); _text += QLatin1Char('(');
applyPtrOperators(false); applyPtrOperators(false);
if (! _name.isEmpty()) { if (! _name.isEmpty()) {
out(_name); _text += _name;
_name.clear(); _name.clear();
} }
out(QLatin1Char(')')); _text += QLatin1Char(')');
} }
out(QLatin1String("[]")); _text += QLatin1String("[]");
} }
void TypePrettyPrinter::visit(Function *type) void TypePrettyPrinter::visit(Function *type)
{ {
if (_overview->showReturnTypes()) if (_overview->showReturnTypes())
out(_overview->prettyType(type->returnType())); _text += _overview->prettyType(type->returnType());
if (! _ptrOperators.isEmpty()) { if (! _ptrOperators.isEmpty()) {
out(QLatin1Char('(')); _text += QLatin1Char('(');
applyPtrOperators(false); applyPtrOperators(false);
if (! _name.isEmpty()) { if (! _name.isEmpty()) {
...@@ -304,11 +303,11 @@ void TypePrettyPrinter::visit(Function *type) ...@@ -304,11 +303,11 @@ void TypePrettyPrinter::visit(Function *type)
_name.clear(); _name.clear();
} }
out(QLatin1Char(')')); _text += QLatin1Char(')');
} else if (! _name.isEmpty() && _overview->showFunctionSignatures()) { } else if (! _name.isEmpty() && _overview->showFunctionSignatures()) {
space(); space();
out(_name); _text += _name;
_name.clear(); _name.clear();
} }
...@@ -318,41 +317,41 @@ void TypePrettyPrinter::visit(Function *type) ...@@ -318,41 +317,41 @@ void TypePrettyPrinter::visit(Function *type)
argumentText.setShowArgumentNames(false); argumentText.setShowArgumentNames(false);
argumentText.setShowFunctionSignatures(true); argumentText.setShowFunctionSignatures(true);
out(QLatin1Char('(')); _text += QLatin1Char('(');
for (unsigned index = 0; index < type->argumentCount(); ++index) { for (unsigned index = 0; index < type->argumentCount(); ++index) {
if (index != 0) if (index != 0)
out(QLatin1String(", ")); _text += QLatin1String(", ");
if (Argument *arg = type->argumentAt(index)->asArgument()) { if (Argument *arg = type->argumentAt(index)->asArgument()) {
if (index + 1 == _overview->markArgument()) if (index + 1 == _overview->markedArgument())
outPlain(QLatin1String("<b>")); const_cast<Overview*>(_overview)->setMarkedArgumentBegin(_text.length());
Name *name = 0; Name *name = 0;
if (_overview->showArgumentNames()) if (_overview->showArgumentNames())
name = arg->name(); name = arg->name();
out(argumentText(arg->type(), name)); _text += argumentText(arg->type(), name);
if (index + 1 == _overview->markArgument()) if (index + 1 == _overview->markedArgument())
outPlain(QLatin1String("</b>")); const_cast<Overview*>(_overview)->setMarkedArgumentEnd(_text.length());
} }
} }
if (type->isVariadic()) if (type->isVariadic())
out(QLatin1String("...")); _text += QLatin1String("...");
out(QLatin1Char(')')); _text += QLatin1Char(')');
if (type->isConst() && type->isVolatile()) { if (type->isConst() && type->isVolatile()) {
space(); space();
out("const volatile"); _text += "const volatile";
} else if (type->isConst()) { } else if (type->isConst()) {
space(); space();
out("const"); _text += "const";
} else if (type->isVolatile()) { } else if (type->isVolatile()) {
space(); space();
out("volatile"); _text += "volatile";
} }
} }
} }
...@@ -369,28 +368,14 @@ void TypePrettyPrinter::space() ...@@ -369,28 +368,14 @@ void TypePrettyPrinter::space()
_text += QLatin1Char(' '); _text += QLatin1Char(' ');
} }
void TypePrettyPrinter::outPlain(const QString &text)
{ _text += text; }
void TypePrettyPrinter::out(const QString &text)
{
if (overview()->richText())
_text += Qt::escape(text);
else
_text += text;
}
void TypePrettyPrinter::out(const QChar &ch)
{ _text += ch; }
void TypePrettyPrinter::outCV(const FullySpecifiedType &ty) void TypePrettyPrinter::outCV(const FullySpecifiedType &ty)
{ {
if (ty.isConst() && ty.isVolatile()) if (ty.isConst() && ty.isVolatile())
out(QLatin1String("const volatile")); _text += QLatin1String("const volatile");
else if (ty.isConst()) else if (ty.isConst())
out(QLatin1String("const")); _text += QLatin1String("const");
else if (ty.isVolatile()) else if (ty.isVolatile())
out(QLatin1String("volatile")); _text += QLatin1String("volatile");
} }
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include <QtGui/QToolButton> #include <QtGui/QToolButton>
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtGui/QTextDocument> // Qt::escape()
using namespace CPlusPlus; using namespace CPlusPlus;
...@@ -382,13 +383,23 @@ bool FunctionArgumentWidget::eventFilter(QObject *obj, QEvent *e) ...@@ -382,13 +383,23 @@ bool FunctionArgumentWidget::eventFilter(QObject *obj, QEvent *e)
void FunctionArgumentWidget::updateHintText() void FunctionArgumentWidget::updateHintText()
{ {
Overview overview; Overview overview;
overview.setRichText(true);
overview.setShowReturnTypes(true); overview.setShowReturnTypes(true);
overview.setShowArgumentNames(true); overview.setShowArgumentNames(true);
overview.setMarkArgument(m_currentarg + 1); overview.setMarkedArgument(m_currentarg + 1);
Function *f = currentFunction(); Function *f = currentFunction();
setText(overview(f->type(), f->name())); const QString prettyMethod = overview(f->type(), f->name());
const int begin = overview.markedArgumentBegin();
const int end = overview.markedArgumentEnd();
QString hintText;
hintText += Qt::escape(prettyMethod.left(begin));
hintText += "<b>";
hintText += Qt::escape(prettyMethod.mid(begin, end - begin));
hintText += "</b>";
hintText += Qt::escape(prettyMethod.mid(end));
setText(hintText);
m_numberLabel->setText(tr("%1 of %2").arg(m_current + 1).arg(m_items.size())); m_numberLabel->setText(tr("%1 of %2").arg(m_current + 1).arg(m_items.size()));
m_popupFrame->setFixedWidth(m_popupFrame->minimumSizeHint().width()); m_popupFrame->setFixedWidth(m_popupFrame->minimumSizeHint().width());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment