From 1a6b62a2b03b29bae7f900c77df785eefc8707b3 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Mon, 18 Jan 2016 09:22:49 +0100 Subject: [PATCH] Clang: Fix text format for completion details The tooltip text right to the completion list item is prepared for rich text (html) interpretation, but the QLabel the text will finally be displayed with has no explicit text format set and thus defaults to auto detection. The auto detection works fine for e.g. "int optionalArg" but fails for "const Foo&". Task-number: QTCREATORBUG-15630 Change-Id: Ia58d65ee542730e4823c69150d452cdde98112f8 Reviewed-by: Marco Bubke --- .../clangcodemodel/clangassistproposalmodel.cpp | 5 +++++ src/plugins/clangcodemodel/clangassistproposalmodel.h | 2 ++ .../texteditor/codeassist/genericproposalmodel.cpp | 11 +++++++++++ .../texteditor/codeassist/genericproposalmodel.h | 4 ++++ .../texteditor/codeassist/genericproposalwidget.cpp | 6 ++++++ 5 files changed, 28 insertions(+) diff --git a/src/plugins/clangcodemodel/clangassistproposalmodel.cpp b/src/plugins/clangcodemodel/clangassistproposalmodel.cpp index d4085b39298..4b7ac93b16f 100644 --- a/src/plugins/clangcodemodel/clangassistproposalmodel.cpp +++ b/src/plugins/clangcodemodel/clangassistproposalmodel.cpp @@ -39,6 +39,11 @@ namespace ClangCodeModel { namespace Internal { +ClangAssistProposalModel::ClangAssistProposalModel() +{ + setDetailTextFormat(Qt::RichText); +} + bool ClangAssistProposalModel::isSortable(const QString &/*prefix*/) const { return true; diff --git a/src/plugins/clangcodemodel/clangassistproposalmodel.h b/src/plugins/clangcodemodel/clangassistproposalmodel.h index 5f7b1f502a0..90ef4a2f202 100644 --- a/src/plugins/clangcodemodel/clangassistproposalmodel.h +++ b/src/plugins/clangcodemodel/clangassistproposalmodel.h @@ -41,6 +41,8 @@ namespace Internal { class ClangAssistProposalModel : public TextEditor::GenericProposalModel { public: + ClangAssistProposalModel(); + bool isSortable(const QString &prefix) const override; void sort(const QString &prefix) override; }; diff --git a/src/plugins/texteditor/codeassist/genericproposalmodel.cpp b/src/plugins/texteditor/codeassist/genericproposalmodel.cpp index 3881775bc8a..e7839d97eb7 100644 --- a/src/plugins/texteditor/codeassist/genericproposalmodel.cpp +++ b/src/plugins/texteditor/codeassist/genericproposalmodel.cpp @@ -135,6 +135,7 @@ private: } // Anonymous GenericProposalModel::GenericProposalModel() + : m_detailTextFormat(Qt::AutoText) {} GenericProposalModel::~GenericProposalModel() @@ -150,6 +151,16 @@ void GenericProposalModel::loadContent(const QList &items) m_idByText.insert(m_originalItems.at(i)->text(), i); } +Qt::TextFormat GenericProposalModel::detailTextFormat() const +{ + return m_detailTextFormat; +} + +void GenericProposalModel::setDetailTextFormat(Qt::TextFormat detailTextFormat) +{ + m_detailTextFormat = detailTextFormat; +} + void GenericProposalModel::reset() { m_currentItems = m_originalItems; diff --git a/src/plugins/texteditor/codeassist/genericproposalmodel.h b/src/plugins/texteditor/codeassist/genericproposalmodel.h index a68bf21134e..b97a23869ea 100644 --- a/src/plugins/texteditor/codeassist/genericproposalmodel.h +++ b/src/plugins/texteditor/codeassist/genericproposalmodel.h @@ -72,12 +72,16 @@ public: void setSortingAllowed(bool isAllowed); bool isSortingAllowed() const; + Qt::TextFormat detailTextFormat() const; + void setDetailTextFormat(Qt::TextFormat detailTextFormat); + protected: QList m_currentItems; private: QHash m_idByText; QList m_originalItems; + Qt::TextFormat m_detailTextFormat; }; } // TextEditor diff --git a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp index 063bedb9565..777e1a8b3f4 100644 --- a/src/plugins/texteditor/codeassist/genericproposalwidget.cpp +++ b/src/plugins/texteditor/codeassist/genericproposalwidget.cpp @@ -168,6 +168,11 @@ public: m_label->setText(text); } + void setTextFormat(Qt::TextFormat textFormat) + { + m_label->setTextFormat(textFormat); + } + // Workaround QTCREATORBUG-11653 void calculateMaximumWidth() { @@ -312,6 +317,7 @@ void GenericProposalWidgetPrivate::maybeShowInfoTip() m_infoFrame->move(m_completionListView->infoFramePos()); m_infoFrame->setText(infoTip); + m_infoFrame->setTextFormat(m_model->detailTextFormat()); m_infoFrame->calculateMaximumWidth(); m_infoFrame->adjustSize(); m_infoFrame->show();