1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #include "Icons.h" 27 28 #include <cplusplus/FullySpecifiedType.h> 29 #include <cplusplus/Scope.h> 30 #include <cplusplus/Symbols.h> 31 #include <cplusplus/Type.h> 32 33 namespace CPlusPlus { 34 namespace Icons { 35 iconForSymbol(const Symbol * symbol)36QIcon iconForSymbol(const Symbol *symbol) 37 { 38 return iconForType(iconTypeForSymbol(symbol)); 39 } 40 keywordIcon()41QIcon keywordIcon() 42 { 43 return iconForType(Utils::CodeModelIcon::Keyword); 44 } 45 macroIcon()46QIcon macroIcon() 47 { 48 return iconForType(Utils::CodeModelIcon::Macro); 49 } 50 iconTypeForSymbol(const Symbol * symbol)51Utils::CodeModelIcon::Type iconTypeForSymbol(const Symbol *symbol) 52 { 53 using namespace Utils::CodeModelIcon; 54 if (const Template *templ = symbol->asTemplate()) { 55 if (Symbol *decl = templ->declaration()) 56 return iconTypeForSymbol(decl); 57 } 58 59 FullySpecifiedType symbolType = symbol->type(); 60 if (symbol->isFunction() || (symbol->isDeclaration() && symbolType && 61 symbolType->isFunctionType())) 62 { 63 const Function *function = symbol->asFunction(); 64 if (!function) 65 function = symbol->type()->asFunctionType(); 66 67 if (function->isSlot()) { 68 if (function->isPublic()) 69 return SlotPublic; 70 else if (function->isProtected()) 71 return SlotProtected; 72 else if (function->isPrivate()) 73 return SlotPrivate; 74 } else if (function->isSignal()) { 75 return Signal; 76 } else if (symbol->isPublic()) { 77 return symbol->isStatic() ? FuncPublicStatic : FuncPublic; 78 } else if (symbol->isProtected()) { 79 return symbol->isStatic() ? FuncProtectedStatic : FuncProtected; 80 } else if (symbol->isPrivate()) { 81 return symbol->isStatic() ? FuncPrivateStatic : FuncPrivate; 82 } 83 } else if (symbol->enclosingScope() && symbol->enclosingScope()->isEnum()) { 84 return Enumerator; 85 } else if (symbol->isDeclaration() || symbol->isArgument()) { 86 if (symbol->isPublic()) { 87 return symbol->isStatic() ? VarPublicStatic : VarPublic; 88 } else if (symbol->isProtected()) { 89 return symbol->isStatic() ? VarProtectedStatic : VarProtected; 90 } else if (symbol->isPrivate()) { 91 return symbol->isStatic() ? VarPrivateStatic : VarPrivate; 92 } 93 } else if (symbol->isEnum()) { 94 return Utils::CodeModelIcon::Enum; 95 } else if (symbol->isForwardClassDeclaration()) { 96 return Utils::CodeModelIcon::Class; // TODO: Store class key in ForwardClassDeclaration 97 } else if (const Class *klass = symbol->asClass()) { 98 return klass->isStruct() ? Struct : Utils::CodeModelIcon::Class; 99 } else if (symbol->isObjCClass() || symbol->isObjCForwardClassDeclaration()) { 100 return Utils::CodeModelIcon::Class; 101 } else if (symbol->isObjCProtocol() || symbol->isObjCForwardProtocolDeclaration()) { 102 return Utils::CodeModelIcon::Class; 103 } else if (symbol->isObjCMethod()) { 104 return FuncPublic; 105 } else if (symbol->isNamespace()) { 106 return Utils::CodeModelIcon::Namespace; 107 } else if (symbol->isTypenameArgument()) { 108 return Utils::CodeModelIcon::Class; 109 } else if (symbol->isQtPropertyDeclaration() || symbol->isObjCPropertyDeclaration()) { 110 return Property; 111 } else if (symbol->isUsingNamespaceDirective() || 112 symbol->isUsingDeclaration()) { 113 // TODO: Might be nice to have a different icons for these things 114 return Utils::CodeModelIcon::Namespace; 115 } 116 117 return Unknown; 118 } 119 120 } // Icons 121 } // CPlusPlus 122