MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / getIcon

Method getIcon

src/Gui/ViewProviderFeaturePython.cpp:97–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95#define FC_PY_CALL_CHECK(_name) _FC_PY_CALL_CHECK(_name, return (NotImplemented))
96
97QIcon ViewProviderFeaturePythonImp::getIcon() const
98{
99 _FC_PY_CALL_CHECK(getIcon, return (QIcon()));
100
101 // Run the getIcon method of the proxy object.
102 Base::PyGILStateLocker lock;
103 try {
104 Py::Object ret(Base::pyCall(py_getIcon.ptr()));
105 if (ret.isNone()) {
106 return {};
107 }
108
109 if (ret.isString()) {
110 std::string content = Py::String(ret).as_std_string("utf-8");
111 QPixmap icon;
112 if (BitmapFactory().findPixmapInCache(content.c_str(), icon)) {
113 return icon;
114 }
115
116 // Check if the passed string is a filename, otherwise treat as xpm data
117 QFileInfo fi(QString::fromUtf8(content.c_str()));
118 if (fi.isFile() && fi.exists()) {
119 icon.load(fi.absoluteFilePath());
120 }
121 else {
122 QByteArray ary;
123 int strlen = (int)content.size();
124 ary.resize(strlen);
125 for (int j = 0; j < strlen; j++) {
126 ary[j] = content[j];
127 }
128 // Make sure to remove crap around the XPM data
129 QList<QByteArray> lines = ary.split('\n');
130 QByteArray buffer;
131 buffer.reserve(ary.size() + lines.size());
132 for (const auto& line : lines) {
133 QByteArray trim = line.trimmed();
134 if (!trim.isEmpty()) {
135 buffer.append(trim);
136 buffer.append('\n');
137 }
138 }
139 icon.loadFromData(buffer, "XPM");
140 }
141 if (!icon.isNull()) {
142 return icon;
143 }
144 }
145 else {
146 PythonWrapper wrap;
147 wrap.loadGuiModule();
148 wrap.loadWidgetsModule();
149 QIcon* picon = wrap.toQIcon(ret.ptr());
150 if (picon) {
151 return *picon;
152 }
153 }
154 }

Callers

nothing calls this directly

Calls 15

QIconClass · 0.85
pyCallFunction · 0.85
isNoneMethod · 0.80
as_std_stringMethod · 0.80
findPixmapInCacheMethod · 0.80
isFileMethod · 0.80
reserveMethod · 0.80
loadGuiModuleMethod · 0.80
loadWidgetsModuleMethod · 0.80
toQIconMethod · 0.80
StringClass · 0.70
ptrMethod · 0.45

Tested by

no test coverage detected