File indexing completed on 2024-04-28 05:41:24
0001 /* 0002 This file is part of KCachegrind. 0003 0004 SPDX-FileCopyrightText: 2002-2016 Josef Weidendorfer <Josef.Weidendorfer@gmx.de> 0005 0006 SPDX-License-Identifier: GPL-2.0-only 0007 */ 0008 0009 #include "context.h" 0010 0011 #include <QObject> 0012 0013 //--------------------------------------------------- 0014 // ProfileContext 0015 0016 ProfileContext* ProfileContext::_contexts = nullptr; 0017 QString* ProfileContext::_typeName = nullptr; 0018 QString* ProfileContext::_i18nTypeName = nullptr; 0019 0020 0021 ProfileContext::ProfileContext(ProfileContext::Type t) 0022 { 0023 _type = t; 0024 } 0025 0026 ProfileContext* ProfileContext::context(ProfileContext::Type t) 0027 { 0028 if (!_contexts) { 0029 _contexts = new ProfileContext[MaxType+1]; 0030 for(int i=0;i<=MaxType;i++) 0031 _contexts[i] = ProfileContext((ProfileContext::Type)i); 0032 } 0033 return &(_contexts[t]); 0034 } 0035 0036 void ProfileContext::cleanup() 0037 { 0038 if (_typeName) { 0039 delete [] _typeName; 0040 _typeName = nullptr; 0041 } 0042 if (_i18nTypeName) { 0043 delete [] _i18nTypeName; 0044 _i18nTypeName = nullptr; 0045 } 0046 if (_contexts) { 0047 delete [] _contexts; 0048 _contexts = nullptr; 0049 } 0050 } 0051 0052 QString ProfileContext::typeName(ProfileContext::Type t) 0053 { 0054 if (!_typeName) { 0055 _typeName = new QString [MaxType+1]; 0056 QString* strs = _typeName; 0057 for(int i=0;i<=MaxType;i++) 0058 strs[i] = QStringLiteral("?"); 0059 0060 strs[InvalidType] = QT_TR_NOOP("Invalid Context"); 0061 strs[UnknownType] = QT_TR_NOOP("Unknown Context"); 0062 strs[PartLine] = QT_TR_NOOP("Part Source Line"); 0063 strs[Line] = QT_TR_NOOP("Source Line"); 0064 strs[PartLineCall] = QT_TR_NOOP("Part Line Call"); 0065 strs[LineCall] = QT_TR_NOOP("Line Call"); 0066 strs[PartLineJump] = QT_TR_NOOP("Part Jump"); 0067 strs[LineJump] = QT_TR_NOOP("Jump"); 0068 strs[PartInstr] = QT_TR_NOOP("Part Instruction"); 0069 strs[Instr] = QT_TR_NOOP("Instruction"); 0070 strs[PartInstrJump] = QT_TR_NOOP("Part Instruction Jump"); 0071 strs[InstrJump] = QT_TR_NOOP("Instruction Jump"); 0072 strs[PartInstrCall] = QT_TR_NOOP("Part Instruction Call"); 0073 strs[InstrCall] = QT_TR_NOOP("Instruction Call"); 0074 strs[PartCall] = QT_TR_NOOP("Part Call"); 0075 strs[Call] = QT_TR_NOOP("Call"); 0076 strs[PartFunction] = QT_TR_NOOP("Part Function"); 0077 strs[FunctionSource] = QT_TR_NOOP("Function Source File"); 0078 strs[Function] = QT_TR_NOOP("Function"); 0079 strs[FunctionCycle] = QT_TR_NOOP("Function Cycle"); 0080 strs[PartClass] = QT_TR_NOOP("Part Class"); 0081 strs[Class] = QT_TR_NOOP("Class"); 0082 strs[PartFile] = QT_TR_NOOP("Part Source File"); 0083 strs[File] = QT_TR_NOOP("Source File"); 0084 strs[PartObject] = QT_TR_NOOP("Part ELF Object"); 0085 strs[Object] = QT_TR_NOOP("ELF Object"); 0086 strs[Part] = QT_TR_NOOP("Profile Part"); 0087 strs[Data] = QT_TR_NOOP("Program Trace"); 0088 } 0089 if (t<0 || t> MaxType) t = MaxType; 0090 return _typeName[t]; 0091 } 0092 0093 ProfileContext::Type ProfileContext::type(const QString& s) 0094 { 0095 // This is the default context type 0096 if (s.isEmpty()) return Function; 0097 0098 Type type; 0099 for (int i=0; i<MaxType;i++) { 0100 type = (Type) i; 0101 if (typeName(type) == s) 0102 return type; 0103 } 0104 return UnknownType; 0105 } 0106 0107 // all strings of typeName() are translatable because of QT_TR_NOOP there 0108 QString ProfileContext::i18nTypeName(Type t) 0109 { 0110 if (!_i18nTypeName) { 0111 _i18nTypeName = new QString [MaxType+1]; 0112 for(int i=0;i<=MaxType;i++) 0113 _i18nTypeName[i] = QObject::tr(typeName((Type)i).toUtf8()); 0114 } 0115 if (t<0 || t> MaxType) t = MaxType; 0116 return _i18nTypeName[t]; 0117 } 0118 0119 ProfileContext::Type ProfileContext::i18nType(const QString& s) 0120 { 0121 // This is the default context type 0122 if (s.isEmpty()) return Function; 0123 0124 Type type; 0125 for (int i=0; i<MaxType;i++) { 0126 type = (Type) i; 0127 if (i18nTypeName(type) == s) 0128 return type; 0129 } 0130 return UnknownType; 0131 }