Showing the changes to interface/src/scripting/TestScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -160,3 +160,30 @@ void TestScriptingInterface::clearCaches() { · 159 unmodified lines | ||
| 160 | 160 | qApp->reloadResourceCaches(); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | +// Writes a JSON object from javascript to a file | |
| 164 | +void TestScriptingInterface::saveObject(QVariant variant, const QString& filename) { | |
| 165 | + QString testResultsLocation = qApp->getTestResultsLocation(); | |
| 166 | + if (testResultsLocation.isNull()) { | |
| 167 | + return; | |
| 168 | + } | |
| 169 | + | |
| 170 | + QJsonDocument jsonDocument; | |
| 171 | + jsonDocument = QJsonDocument::fromVariant(variant); | |
| 172 | + if (jsonDocument.isNull()) { | |
| 173 | + return; | |
| 174 | + } | |
| 175 | + | |
| 176 | + QByteArray jsonData = jsonDocument.toJson(); | |
| 177 | + | |
| 178 | + // Append trailing slash if needed | |
| 179 | + if (testResultsLocation.right(1) != "/") { | |
| 180 | + testResultsLocation += "/"; | |
| 181 | + } | |
| 182 | + | |
| 183 | + QString filepath = QDir::cleanPath(testResultsLocation + filename); | |
| 184 | + QFile file(filepath); | |
| 185 | + | |
| 186 | + file.open(QFile::WriteOnly); | |
| 187 | + file.write(jsonData); | |
| 188 | + file.close(); | |
| 189 | +} | |