forked from qt-creator/qt-creator
TextEditor: make the format of completion item detail text adjustable
Instead of always assuming content in the form of rich text allow each item individually to define it's text format for the detail text that is shown as a tooltip of a completion item. Fixes: QTCREATORBUG-22429 Change-Id: I9fa71373a743c26fa06d48acc5f0509584830ca0 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -495,6 +495,11 @@ bool ClangAssistProposalItem::isKeyword() const
|
|||||||
return m_codeCompletions[0].completionKind == CodeCompletion::KeywordCompletionKind;
|
return m_codeCompletions[0].completionKind == CodeCompletion::KeywordCompletionKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::TextFormat ClangAssistProposalItem::detailFormat() const
|
||||||
|
{
|
||||||
|
return Qt::RichText;
|
||||||
|
}
|
||||||
|
|
||||||
bool ClangAssistProposalItem::isSnippet() const
|
bool ClangAssistProposalItem::isSnippet() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
QIcon icon() const final;
|
QIcon icon() const final;
|
||||||
QString detail() const final;
|
QString detail() const final;
|
||||||
bool isKeyword() const final;
|
bool isKeyword() const final;
|
||||||
|
Qt::TextFormat detailFormat() const final;
|
||||||
bool isSnippet() const final;
|
bool isSnippet() const final;
|
||||||
bool isValid() const final;
|
bool isValid() const final;
|
||||||
quint64 hash() const final;
|
quint64 hash() const final;
|
||||||
|
|||||||
@@ -131,6 +131,11 @@ QString ClangPreprocessorAssistProposalItem::detail() const
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::TextFormat ClangPreprocessorAssistProposalItem::detailFormat() const
|
||||||
|
{
|
||||||
|
return Qt::RichText;
|
||||||
|
}
|
||||||
|
|
||||||
bool ClangPreprocessorAssistProposalItem::isSnippet() const
|
bool ClangPreprocessorAssistProposalItem::isSnippet() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ public:
|
|||||||
void setDetail(const QString &detail);
|
void setDetail(const QString &detail);
|
||||||
QString detail() const final;
|
QString detail() const final;
|
||||||
|
|
||||||
|
Qt::TextFormat detailFormat() const final;
|
||||||
|
|
||||||
bool isSnippet() const final;
|
bool isSnippet() const final;
|
||||||
bool isValid() const final;
|
bool isValid() const final;
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ public:
|
|||||||
virtual void apply(TextDocumentManipulatorInterface &manipulator, int basePosition) const = 0;
|
virtual void apply(TextDocumentManipulatorInterface &manipulator, int basePosition) const = 0;
|
||||||
virtual QIcon icon() const = 0;
|
virtual QIcon icon() const = 0;
|
||||||
virtual QString detail() const = 0;
|
virtual QString detail() const = 0;
|
||||||
virtual bool isKeyword() const { return false; };
|
virtual bool isKeyword() const { return false; }
|
||||||
|
virtual Qt::TextFormat detailFormat() const { return Qt::AutoText; }
|
||||||
virtual bool isSnippet() const = 0;
|
virtual bool isSnippet() const = 0;
|
||||||
virtual bool isValid() const = 0;
|
virtual bool isValid() const = 0;
|
||||||
virtual quint64 hash() const = 0; // it is only for removing duplicates
|
virtual quint64 hash() const = 0; // it is only for removing duplicates
|
||||||
|
|||||||
@@ -262,6 +262,11 @@ QString GenericProposalModel::detail(int index) const
|
|||||||
return m_currentItems.at(index)->detail();
|
return m_currentItems.at(index)->detail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::TextFormat GenericProposalModel::detailFormat(int index) const
|
||||||
|
{
|
||||||
|
return m_currentItems.at(index)->detailFormat();
|
||||||
|
}
|
||||||
|
|
||||||
void GenericProposalModel::removeDuplicates()
|
void GenericProposalModel::removeDuplicates()
|
||||||
{
|
{
|
||||||
if (m_duplicatesRemoved)
|
if (m_duplicatesRemoved)
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public:
|
|||||||
|
|
||||||
virtual QIcon icon(int index) const;
|
virtual QIcon icon(int index) const;
|
||||||
virtual QString detail(int index) const;
|
virtual QString detail(int index) const;
|
||||||
|
virtual Qt::TextFormat detailFormat(int index) const;
|
||||||
virtual int persistentId(int index) const;
|
virtual int persistentId(int index) const;
|
||||||
virtual bool containsDuplicates() const;
|
virtual bool containsDuplicates() const;
|
||||||
virtual void removeDuplicates();
|
virtual void removeDuplicates();
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public:
|
|||||||
int rowCount(const QModelIndex &) const override;
|
int rowCount(const QModelIndex &) const override;
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
|
enum UserRoles{ FixItRole = Qt::UserRole, DetailTextFormatRole };
|
||||||
private:
|
private:
|
||||||
GenericProposalModelPtr m_completionModel;
|
GenericProposalModelPtr m_completionModel;
|
||||||
};
|
};
|
||||||
@@ -99,7 +100,9 @@ QVariant ModelAdapter::data(const QModelIndex &index, int role) const
|
|||||||
return m_completionModel->icon(index.row());
|
return m_completionModel->icon(index.row());
|
||||||
} else if (role == Qt::WhatsThisRole) {
|
} else if (role == Qt::WhatsThisRole) {
|
||||||
return m_completionModel->detail(index.row());
|
return m_completionModel->detail(index.row());
|
||||||
} else if (role == Qt::UserRole) {
|
} else if (role == DetailTextFormatRole) {
|
||||||
|
return m_completionModel->detailFormat(index.row());
|
||||||
|
} else if (role == FixItRole) {
|
||||||
return m_completionModel->proposalItem(index.row())->requiresFixIts();
|
return m_completionModel->proposalItem(index.row())->requiresFixIts();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +126,6 @@ public:
|
|||||||
// Limit horizontal width
|
// Limit horizontal width
|
||||||
m_label->setSizePolicy(QSizePolicy::Fixed, m_label->sizePolicy().verticalPolicy());
|
m_label->setSizePolicy(QSizePolicy::Fixed, m_label->sizePolicy().verticalPolicy());
|
||||||
|
|
||||||
m_label->setTextFormat(Qt::RichText);
|
|
||||||
m_label->setForegroundRole(QPalette::ToolTipText);
|
m_label->setForegroundRole(QPalette::ToolTipText);
|
||||||
m_label->setBackgroundRole(QPalette::ToolTipBase);
|
m_label->setBackgroundRole(QPalette::ToolTipBase);
|
||||||
}
|
}
|
||||||
@@ -133,6 +135,11 @@ public:
|
|||||||
m_label->setText(text);
|
m_label->setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTextFormat(Qt::TextFormat format)
|
||||||
|
{
|
||||||
|
m_label->setTextFormat(format);
|
||||||
|
}
|
||||||
|
|
||||||
// Workaround QTCREATORBUG-11653
|
// Workaround QTCREATORBUG-11653
|
||||||
void calculateMaximumWidth()
|
void calculateMaximumWidth()
|
||||||
{
|
{
|
||||||
@@ -189,7 +196,7 @@ public:
|
|||||||
|
|
||||||
QStyledItemDelegate::paint(painter, option, index);
|
QStyledItemDelegate::paint(painter, option, index);
|
||||||
|
|
||||||
if (m_parent->model()->data(index, Qt::UserRole).toBool()) {
|
if (m_parent->model()->data(index, ModelAdapter::FixItRole).toBool()) {
|
||||||
const QRect itemRect = m_parent->rectForIndex(index);
|
const QRect itemRect = m_parent->rectForIndex(index);
|
||||||
const QScrollBar *verticalScrollBar = m_parent->verticalScrollBar();
|
const QScrollBar *verticalScrollBar = m_parent->verticalScrollBar();
|
||||||
|
|
||||||
@@ -205,7 +212,7 @@ public:
|
|||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
|
||||||
{
|
{
|
||||||
QSize size(QStyledItemDelegate::sizeHint(option, index));
|
QSize size(QStyledItemDelegate::sizeHint(option, index));
|
||||||
if (m_parent->model()->data(index, Qt::UserRole).toBool())
|
if (m_parent->model()->data(index, ModelAdapter::FixItRole).toBool())
|
||||||
size.setWidth(size.width() + m_parent->rectForIndex(index).height() - 5);
|
size.setWidth(size.width() + m_parent->rectForIndex(index).height() - 5);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
@@ -313,6 +320,8 @@ void GenericProposalWidgetPrivate::maybeShowInfoTip()
|
|||||||
m_infoFrame = new GenericProposalInfoFrame(m_completionListView);
|
m_infoFrame = new GenericProposalInfoFrame(m_completionListView);
|
||||||
|
|
||||||
m_infoFrame->move(m_completionListView->infoFramePos());
|
m_infoFrame->move(m_completionListView->infoFramePos());
|
||||||
|
m_infoFrame->setTextFormat(
|
||||||
|
current.data(ModelAdapter::DetailTextFormatRole).value<Qt::TextFormat>());
|
||||||
m_infoFrame->setText(infoTip);
|
m_infoFrame->setText(infoTip);
|
||||||
m_infoFrame->calculateMaximumWidth();
|
m_infoFrame->calculateMaximumWidth();
|
||||||
m_infoFrame->adjustSize();
|
m_infoFrame->adjustSize();
|
||||||
|
|||||||
Reference in New Issue
Block a user