| 95 | #define FC_PY_CALL_CHECK(_name) _FC_PY_CALL_CHECK(_name, return (NotImplemented)) |
| 96 | |
| 97 | QIcon 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 | } |
nothing calls this directly
no test coverage detected