Commit 984a6eca authored by Alessandro Portale's avatar Alessandro Portale

cplusplus: Make functions of Icons static

This avoids multiple instatiations and reloading of the same image files.

Change-Id: I4d0bb955e23c1cb817671c25bff4e74fb7b3d0f4
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 44aaec76
......@@ -33,46 +33,19 @@
using namespace CPlusPlus;
using CPlusPlus::Icons;
Icons::Icons()
: _classIcon(QLatin1String(":/codemodel/images/class.png")),
_structIcon(QLatin1String(":/codemodel/images/struct.png")),
_enumIcon(QLatin1String(":/codemodel/images/enum.png")),
_enumeratorIcon(QLatin1String(":/codemodel/images/enumerator.png")),
_funcPublicIcon(QLatin1String(":/codemodel/images/func.png")),
_funcProtectedIcon(QLatin1String(":/codemodel/images/func_prot.png")),
_funcPrivateIcon(QLatin1String(":/codemodel/images/func_priv.png")),
_funcPublicStaticIcon(QLatin1String(":/codemodel/images/func_st.png")),
_funcProtectedStaticIcon(QLatin1String(":/codemodel/images/func_prot_st.png")),
_funcPrivateStaticIcon(QLatin1String(":/codemodel/images/func_priv_st.png")),
_namespaceIcon(QLatin1String(":/codemodel/images/namespace.png")),
_varPublicIcon(QLatin1String(":/codemodel/images/var.png")),
_varProtectedIcon(QLatin1String(":/codemodel/images/var_prot.png")),
_varPrivateIcon(QLatin1String(":/codemodel/images/var_priv.png")),
_varPublicStaticIcon(QLatin1String(":/codemodel/images/var_st.png")),
_varProtectedStaticIcon(QLatin1String(":/codemodel/images/var_prot_st.png")),
_varPrivateStaticIcon(QLatin1String(":/codemodel/images/var_priv_st.png")),
_signalIcon(QLatin1String(":/codemodel/images/signal.png")),
_slotPublicIcon(QLatin1String(":/codemodel/images/slot.png")),
_slotProtectedIcon(QLatin1String(":/codemodel/images/slot_prot.png")),
_slotPrivateIcon(QLatin1String(":/codemodel/images/slot_priv.png")),
_keywordIcon(QLatin1String(":/codemodel/images/keyword.png")),
_macroIcon(QLatin1String(":/codemodel/images/macro.png"))
{
}
QIcon Icons::iconForSymbol(const Symbol *symbol) const
QIcon Icons::iconForSymbol(const Symbol *symbol)
{
return iconForType(iconTypeForSymbol(symbol));
}
QIcon Icons::keywordIcon() const
QIcon Icons::keywordIcon()
{
return _keywordIcon;
return iconForType(KeywordIconType);
}
QIcon Icons::macroIcon() const
QIcon Icons::macroIcon()
{
return _macroIcon;
return iconForType(MacroIconType);
}
Icons::IconType Icons::iconTypeForSymbol(const Symbol *symbol)
......@@ -141,55 +114,101 @@ Icons::IconType Icons::iconTypeForSymbol(const Symbol *symbol)
return UnknownIconType;
}
QIcon Icons::iconForType(IconType type) const
QIcon Icons::iconForType(IconType type)
{
switch (type) {
case ClassIconType:
return _classIcon;
case StructIconType:
return _structIcon;
case EnumIconType:
return _enumIcon;
case EnumeratorIconType:
return _enumeratorIcon;
case FuncPublicIconType:
return _funcPublicIcon;
case FuncProtectedIconType:
return _funcProtectedIcon;
case FuncPrivateIconType:
return _funcPrivateIcon;
case FuncPublicStaticIconType:
return _funcPublicStaticIcon;
case FuncProtectedStaticIconType:
return _funcProtectedStaticIcon;
case FuncPrivateStaticIconType:
return _funcPrivateStaticIcon;
case NamespaceIconType:
return _namespaceIcon;
case VarPublicIconType:
return _varPublicIcon;
case VarProtectedIconType:
return _varProtectedIcon;
case VarPrivateIconType:
return _varPrivateIcon;
case VarPublicStaticIconType:
return _varPublicStaticIcon;
case VarProtectedStaticIconType:
return _varProtectedStaticIcon;
case VarPrivateStaticIconType:
return _varPrivateStaticIcon;
case SignalIconType:
return _signalIcon;
case SlotPublicIconType:
return _slotPublicIcon;
case SlotProtectedIconType:
return _slotProtectedIcon;
case SlotPrivateIconType:
return _slotPrivateIcon;
case KeywordIconType:
return _keywordIcon;
case MacroIconType:
return _macroIcon;
case ClassIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/class.png"));
return icon;
}
case StructIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/struct.png"));
return icon;
}
case EnumIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/enum.png"));
return icon;
}
case EnumeratorIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/enumerator.png"));
return icon;
}
case FuncPublicIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/func.png"));
return icon;
}
case FuncProtectedIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/func_prot.png"));
return icon;
}
case FuncPrivateIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/func_priv.png"));
return icon;
}
case FuncPublicStaticIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/func_st.png"));
return icon;
}
case FuncProtectedStaticIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/func_prot_st.png"));
return icon;
}
case FuncPrivateStaticIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/func_priv_st.png"));
return icon;
}
case NamespaceIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/namespace.png"));
return icon;
}
case VarPublicIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/var.png"));
return icon;
}
case VarProtectedIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/var_prot.png"));
return icon;
}
case VarPrivateIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/var_priv.png"));
return icon;
}
case VarPublicStaticIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/var_st.png"));
return icon;
}
case VarProtectedStaticIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/var_prot_st.png"));
return icon;
}
case VarPrivateStaticIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/var_priv_st.png"));
return icon;
}
case SignalIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/signal.png"));
return icon;
}
case SlotPublicIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/slot.png"));
return icon;
}
case SlotProtectedIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/slot_prot.png"));
return icon;
}
case SlotPrivateIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/slot_priv.png"));
return icon;
}
case KeywordIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/keyword.png"));
return icon;
}
case MacroIconType: {
const static QIcon icon(QLatin1String(":/codemodel/images/macro.png"));
return icon;
}
default:
break;
}
......
......@@ -37,12 +37,10 @@ class Symbol;
class CPLUSPLUS_EXPORT Icons
{
public:
Icons();
static QIcon iconForSymbol(const Symbol *symbol);
QIcon iconForSymbol(const Symbol *symbol) const;
QIcon keywordIcon() const;
QIcon macroIcon() const;
static QIcon keywordIcon();
static QIcon macroIcon();
enum IconType {
ClassIconType = 0,
......@@ -72,32 +70,10 @@ public:
};
static IconType iconTypeForSymbol(const Symbol *symbol);
QIcon iconForType(IconType type) const;
static QIcon iconForType(IconType type);
private:
QIcon _classIcon;
QIcon _structIcon;
QIcon _enumIcon;
QIcon _enumeratorIcon;
QIcon _funcPublicIcon;
QIcon _funcProtectedIcon;
QIcon _funcPrivateIcon;
QIcon _funcPublicStaticIcon;
QIcon _funcProtectedStaticIcon;
QIcon _funcPrivateStaticIcon;
QIcon _namespaceIcon;
QIcon _varPublicIcon;
QIcon _varProtectedIcon;
QIcon _varPrivateIcon;
QIcon _varPublicStaticIcon;
QIcon _varProtectedStaticIcon;
QIcon _varPrivateStaticIcon;
QIcon _signalIcon;
QIcon _slotPublicIcon;
QIcon _slotProtectedIcon;
QIcon _slotPrivateIcon;
QIcon _keywordIcon;
QIcon _macroIcon;
Icons() {}
};
} // namespace CPlusPlus
......
......@@ -27,6 +27,7 @@
#include "Overview.h"
#include <cplusplus/Icons.h>
#include <cplusplus/Scope.h>
#include <cplusplus/Literals.h>
#include <cplusplus/Symbols.h>
......@@ -210,7 +211,7 @@ QVariant OverviewModel::data(const QModelIndex &index, int role) const
case Qt::DecorationRole: {
Symbol *symbol = static_cast<Symbol *>(index.internalPointer());
return _icons.iconForSymbol(symbol);
return Icons::iconForSymbol(symbol);
} break;
case FileNameRole: {
......
......@@ -28,7 +28,6 @@
#include "CppDocument.h"
#include "Overview.h"
#include "Icons.h"
#include <QAbstractItemModel>
......@@ -73,7 +72,6 @@ private:
private:
Document::Ptr _cppDocument;
Overview _overview;
Icons _icons;
};
} // namespace CPlusPlus
......
......@@ -219,7 +219,6 @@ QString ClangAssistProposalItem::text() const
QIcon ClangAssistProposalItem::icon() const
{
using CPlusPlus::Icons;
static const CPlusPlus::Icons m_icons;
static const char SNIPPET_ICON_PATH[] = ":/texteditor/images/snippet.png";
static const QIcon snippetIcon = QIcon(QLatin1String(SNIPPET_ICON_PATH));
......@@ -227,11 +226,11 @@ QIcon ClangAssistProposalItem::icon() const
case CodeCompletion::ClassCompletionKind:
case CodeCompletion::TemplateClassCompletionKind:
case CodeCompletion::TypeAliasCompletionKind:
return m_icons.iconForType(Icons::ClassIconType);
return Icons::iconForType(Icons::ClassIconType);
case CodeCompletion::EnumerationCompletionKind:
return m_icons.iconForType(Icons::EnumIconType);
return Icons::iconForType(Icons::EnumIconType);
case CodeCompletion::EnumeratorCompletionKind:
return m_icons.iconForType(Icons::EnumeratorIconType);
return Icons::iconForType(Icons::EnumeratorIconType);
case CodeCompletion::ConstructorCompletionKind:
case CodeCompletion::DestructorCompletionKind:
case CodeCompletion::FunctionCompletionKind:
......@@ -240,39 +239,39 @@ QIcon ClangAssistProposalItem::icon() const
switch (m_codeCompletion.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
return m_icons.iconForType(Icons::FuncPublicIconType);
return Icons::iconForType(Icons::FuncPublicIconType);
default:
return m_icons.iconForType(Icons::FuncPrivateIconType);
return Icons::iconForType(Icons::FuncPrivateIconType);
}
case CodeCompletion::SignalCompletionKind:
return m_icons.iconForType(Icons::SignalIconType);
return Icons::iconForType(Icons::SignalIconType);
case CodeCompletion::SlotCompletionKind:
switch (m_codeCompletion.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
return m_icons.iconForType(Icons::SlotPublicIconType);
return Icons::iconForType(Icons::SlotPublicIconType);
case CodeCompletion::NotAccessible:
case CodeCompletion::NotAvailable:
return m_icons.iconForType(Icons::SlotPrivateIconType);
return Icons::iconForType(Icons::SlotPrivateIconType);
}
case CodeCompletion::NamespaceCompletionKind:
return m_icons.iconForType(Icons::NamespaceIconType);
return Icons::iconForType(Icons::NamespaceIconType);
case CodeCompletion::PreProcessorCompletionKind:
return m_icons.iconForType(Icons::MacroIconType);
return Icons::iconForType(Icons::MacroIconType);
case CodeCompletion::VariableCompletionKind:
switch (m_codeCompletion.availability()) {
case CodeCompletion::Available:
case CodeCompletion::Deprecated:
return m_icons.iconForType(Icons::VarPublicIconType);
return Icons::iconForType(Icons::VarPublicIconType);
default:
return m_icons.iconForType(Icons::VarPrivateIconType);
return Icons::iconForType(Icons::VarPrivateIconType);
}
case CodeCompletion::KeywordCompletionKind:
return m_icons.iconForType(Icons::KeywordIconType);
return Icons::iconForType(Icons::KeywordIconType);
case CodeCompletion::ClangSnippetKind:
return snippetIcon;
case CodeCompletion::Other:
return m_icons.iconForType(Icons::UnknownIconType);
return Icons::iconForType(Icons::UnknownIconType);
}
return QIcon();
......
......@@ -46,6 +46,7 @@
#include <cplusplus/BackwardsScanner.h>
#include <cplusplus/ExpressionUnderCursor.h>
#include <cplusplus/Icons.h>
#include <cplusplus/SimpleLexer.h>
#include <clangbackendipc/filecontainer.h>
......@@ -454,7 +455,7 @@ void ClangCompletionAssistProcessor::completeIncludePath(const QString &realPath
auto *item = new ClangPreprocessorAssistProposalItem;
item->setText(text);
item->setDetail(hint);
item->setIcon(m_icons.keywordIcon());
item->setIcon(Icons::keywordIcon());
item->setCompletionOperator(m_completionOperator);
m_completions.append(item);
}
......@@ -465,11 +466,11 @@ bool ClangCompletionAssistProcessor::completePreprocessorDirectives()
{
foreach (const QString &preprocessorCompletion, m_preprocessorCompletions)
addCompletionItem(preprocessorCompletion,
m_icons.iconForType(Icons::MacroIconType));
Icons::iconForType(Icons::MacroIconType));
if (m_interface->objcEnabled())
addCompletionItem(QLatin1String("import"),
m_icons.iconForType(Icons::MacroIconType));
Icons::iconForType(Icons::MacroIconType));
return !m_completions.isEmpty();
}
......@@ -477,7 +478,7 @@ bool ClangCompletionAssistProcessor::completePreprocessorDirectives()
bool ClangCompletionAssistProcessor::completeDoxygenKeywords()
{
for (int i = 1; i < CppTools::T_DOXY_LAST_TAG; ++i)
addCompletionItem(QString::fromLatin1(CppTools::doxygenTagSpell(i)), m_icons.keywordIcon());
addCompletionItem(QString::fromLatin1(CppTools::doxygenTagSpell(i)), Icons::keywordIcon());
return !m_completions.isEmpty();
}
......
......@@ -34,21 +34,6 @@
namespace ClassView {
namespace Internal {
///////////////////////////////// TreeItemModelPrivate //////////////////////////////////
/*!
\class TreeItemModelPrivate
\brief The TreeItemModelPrivate class contains private class data for
the TreeItemModel class.
\sa TreeItemModel
*/
class TreeItemModelPrivate
{
public:
//! icon provider
CPlusPlus::Icons icons;
};
///////////////////////////////// TreeItemModel //////////////////////////////////
/*!
......@@ -57,14 +42,12 @@ public:
*/
TreeItemModel::TreeItemModel(QObject *parent)
: QStandardItemModel(parent),
d(new TreeItemModelPrivate())
: QStandardItemModel(parent)
{
}
TreeItemModel::~TreeItemModel()
{
delete d;
}
QVariant TreeItemModel::data(const QModelIndex &index, int role) const
......@@ -79,7 +62,7 @@ QVariant TreeItemModel::data(const QModelIndex &index, int role) const
bool ok = false;
int type = iconType.toInt(&ok);
if (ok && type >= 0)
return d->icons.iconForType(static_cast<CPlusPlus::Icons::IconType>(type));
return CPlusPlus::Icons::iconForType(static_cast<CPlusPlus::Icons::IconType>(type));
}
}
break;
......
......@@ -284,7 +284,7 @@ CppMacro::CppMacro(const Macro &macro)
CppDeclarableElement::CppDeclarableElement(Symbol *declaration)
: CppElement()
, declaration(declaration)
, icon(Icons().iconForSymbol(declaration))
, icon(Icons::iconForSymbol(declaration))
{
Overview overview;
overview.showArgumentNames = true;
......
......@@ -182,14 +182,13 @@ private:
auto *item = new VirtualFunctionProposalItem(link, m_params.openInNextSplit);
item->setText(text);
item->setIcon(m_icons.iconForSymbol(func));
item->setIcon(Icons::iconForSymbol(func));
return item;
}
VirtualFunctionAssistProvider::Parameters m_params;
Overview m_overview;
Icons m_icons;
mutable SymbolFinder m_finder;
};
......
......@@ -1010,7 +1010,7 @@ int InternalCppCompletionAssistProcessor::startCompletionHelper()
if (m_model->m_completionOperator == T_DOXY_COMMENT) {
for (int i = 1; i < T_DOXY_LAST_TAG; ++i)
addCompletionItem(QString::fromLatin1(doxygenTagSpell(i)), m_icons.keywordIcon());
addCompletionItem(QString::fromLatin1(doxygenTagSpell(i)), Icons::keywordIcon());
return m_positionForProposal;
}
......@@ -1193,7 +1193,7 @@ void InternalCppCompletionAssistProcessor::addCompletionItem(Symbol *symbol, int
ConvertToCompletionItem toCompletionItem;
AssistProposalItem *item = toCompletionItem(symbol);
if (item) {
item->setIcon(m_icons.iconForSymbol(symbol));
item->setIcon(Icons::iconForSymbol(symbol));
item->setOrder(order);
m_completions.append(item);
}
......@@ -1300,7 +1300,7 @@ void InternalCppCompletionAssistProcessor::completeInclude(const QString &realPa
QString text = fileName.mid(realPath.length() + 1);
if (fileInfo.isDir())
text += QLatin1Char('/');
addCompletionItem(text, m_icons.keywordIcon());
addCompletionItem(text, Icons::keywordIcon());
}
}
}
......@@ -1814,7 +1814,7 @@ bool InternalCppCompletionAssistProcessor::completeQtMethod(const QList<LookupIt
break;
signatures.insert(completionText);
ci->setText(completionText); // fix the completion item.
ci->setIcon(m_icons.iconForSymbol(fun));
ci->setIcon(Icons::iconForSymbol(fun));
if (wantQt5SignalOrSlot && fun->isSlot())
ci->setOrder(1);
m_completions.append(ci);
......@@ -1841,7 +1841,7 @@ bool InternalCppCompletionAssistProcessor::completeQtMethodClassName(
return false;
const LookupContext &context = m_model->m_typeOfExpression->context();
const QIcon classIcon = m_icons.iconForType(Icons::ClassIconType);
const QIcon classIcon = Icons::iconForType(Icons::ClassIconType);
Overview overview;
foreach (const LookupItem &lookupItem, results) {
......@@ -1866,16 +1866,16 @@ void InternalCppCompletionAssistProcessor::addKeywords()
// keyword completion items.
for (int i = T_FIRST_KEYWORD; i < keywordLimit; ++i)
addCompletionItem(QLatin1String(Token::name(i)), m_icons.keywordIcon(), KeywordsOrder);
addCompletionItem(QLatin1String(Token::name(i)), Icons::keywordIcon(), KeywordsOrder);
// primitive type completion items.
for (int i = T_FIRST_PRIMITIVE; i <= T_LAST_PRIMITIVE; ++i)
addCompletionItem(QLatin1String(Token::name(i)), m_icons.keywordIcon(), KeywordsOrder);
addCompletionItem(QLatin1String(Token::name(i)), Icons::keywordIcon(), KeywordsOrder);
// "Identifiers with special meaning"
if (m_interface->languageFeatures().cxx11Enabled) {
addCompletionItem(QLatin1String("override"), m_icons.keywordIcon(), KeywordsOrder);
addCompletionItem(QLatin1String("final"), m_icons.keywordIcon(), KeywordsOrder);
addCompletionItem(QLatin1String("override"), Icons::keywordIcon(), KeywordsOrder);
addCompletionItem(QLatin1String("final"), Icons::keywordIcon(), KeywordsOrder);
}
}
......@@ -1888,7 +1888,7 @@ void InternalCppCompletionAssistProcessor::addMacros(const QString &fileName,
addMacros_helper(snapshot, fileName, &processed, &definedMacros);
foreach (const QString &macroName, definedMacros)
addCompletionItem(macroName, m_icons.macroIcon(), MacrosOrder);
addCompletionItem(macroName, Icons::macroIcon(), MacrosOrder);
}
void InternalCppCompletionAssistProcessor::addMacros_helper(const Snapshot &snapshot,
......
......@@ -31,8 +31,6 @@
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/snippets/snippetassistcollector.h>
#include <cplusplus/Icons.h>
#include <functional>
QT_BEGIN_NAMESPACE
......@@ -67,7 +65,6 @@ protected:
QList<TextEditor::AssistProposalItemInterface *> m_completions;
QStringList m_preprocessorCompletions;
TextEditor::IAssistProposal *m_hintProposal;
CPlusPlus::Icons m_icons;
private:
TextEditor::SnippetAssistCollector m_snippetCollector;
......
......@@ -25,6 +25,7 @@
#include "searchsymbols.h"
#include <cplusplus/Icons.h>
#include <cplusplus/LookupContext.h>
#include <utils/qtcassert.h>
#include <utils/scopedswap.h>
......@@ -292,7 +293,7 @@ IndexItem::Ptr SearchSymbols::addChildItem(const QString &symbolName, const QStr
m_paths.insert(symbol->fileId(), path);
}
const QIcon icon = icons.iconForSymbol(symbol);
const QIcon icon = Icons::iconForSymbol(symbol);
IndexItem::Ptr newItem = IndexItem::create(findOrInsert(symbolName),
findOrInsert(symbolType),
findOrInsert(symbolScope),
......
......@@ -32,7 +32,6 @@
#include "stringtable.h"
#include <cplusplus/CppDocument.h>
#include <cplusplus/Icons.h>
#include <cplusplus/Overview.h>
#include <QString>
......@@ -108,7 +107,6 @@ private:
IndexItem::Ptr _parent;
QString _scope;
CPlusPlus::Overview overview;
CPlusPlus::Icons icons;
SymbolTypes symbolsToSearchFor;
QHash<const CPlusPlus::StringLiteral *, QString> m_paths;
};
......
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