MCPcopy Create free account
hub / github.com/MiniZinc/MiniZincIDE / onStdOutLine

Method onStdOutLine

MiniZincIDE/process.cpp:535–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

533}
534
535void MznProcess::onStdOutLine(const QString& line)
536{
537 emit outputStdOut(line);
538
539 if (!parse) {
540 // Not running with --json-stream, so cannot parse output
541 emit unknownOutput(line);
542 return;
543 }
544
545 QJsonParseError error;
546 auto json = QJsonDocument::fromJson(line.toUtf8(), &error);
547 if (!json.isNull()) {
548 auto msg = json.object();
549 auto msg_type = msg["type"].toString();
550 if (msg_type == "solution") {
551 auto sections = msg["output"].toObject().toVariantMap();
552 QStringList order;
553 if (msg["sections"].isArray()) {
554 for (auto it : msg["sections"].toArray()) {
555 order << it.toString();
556 }
557 } else {
558 order = sections.keys();
559 }
560 qint64 time = msg["time"].isDouble() ? static_cast<qint64>(msg["time"].toDouble()) : -1;
561 emit solutionOutput(sections, order, time);
562 } else if (msg_type == "checker") {
563 auto checkerSol = [&] (QJsonObject& msg) {
564 auto sections = msg["output"].toObject().toVariantMap();
565 QStringList order;
566 if (msg["sections"].isArray()) {
567 for (auto it : msg["sections"].toArray()) {
568 order << it.toString();
569 }
570 } else {
571 order = sections.keys();
572 }
573 qint64 time = msg["time"].isDouble() ? static_cast<qint64>(msg["time"].toDouble()) : -1;
574 emit checkerOutput(sections, order, time);
575 };
576
577 if (msg["messages"].isArray()) {
578 for (auto it : msg["messages"].toArray()) {
579 auto msg = it.toObject();
580 auto msg_type = msg["type"].toString();
581 if (msg_type == "solution") {
582 checkerSol(msg);
583 } else if (msg_type == "trace") {
584 auto section = msg["section"].toString();
585 qint64 time = msg["time"].isDouble() ? static_cast<qint64>(msg["time"].toDouble()) : -1;
586 emit checkerOutput({{section, msg["message"].toString()}}, {section}, time);
587 } else if (msg_type == "comment") {
588 auto comment = msg["comment"].toString();
589 emit commentOutput(comment);
590 } else if (msg_type == "warning") {
591 emit warningOutput(msg, true);
592 } else if (msg_type == "error") {

Callers

nothing calls this directly

Calls 2

toVariantMapMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected