| 409 | } |
| 410 | |
| 411 | void ThemeEditorDialog::loadFromFile() |
| 412 | { |
| 413 | const QString path = QFileDialog::getOpenFileName( |
| 414 | this, tr("Load theme"), QString(), tr("JSON files (*.json);;All files (*)")); |
| 415 | if (path.isEmpty()) |
| 416 | return; |
| 417 | |
| 418 | QFile file(path); |
| 419 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 420 | QMessageBox::warning(this, tr("Load failed"), tr("Could not open file:\n%1").arg(path)); |
| 421 | return; |
| 422 | } |
| 423 | |
| 424 | QJsonParseError err; |
| 425 | const QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &err); |
| 426 | if (doc.isNull()) { |
| 427 | QMessageBox::warning(this, tr("Load failed"), tr("Invalid JSON:\n%1").arg(err.errorString())); |
| 428 | return; |
| 429 | } |
| 430 | if (!doc.isObject()) { |
| 431 | QMessageBox::warning(this, tr("Load failed"), tr("Expected a JSON object.")); |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | params = normalizeThemeJson(doc.object()); |
| 436 | syncMetaFromParams(); |
| 437 | tree->clear(); |
| 438 | populate(nullptr, params, { }); |
| 439 | tree->expandAll(); |
| 440 | emit themeJsonChanged(params); |
| 441 | } |
| 442 | |
| 443 | void ThemeEditorDialog::identifyPressed() |
| 444 | { |
nothing calls this directly
no test coverage detected