24 #include <ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/ui_EditDefaultValueDialog.h>
26 #include <QFileDialog>
29 #include <QMessageBox>
39 typeString(typeString),
40 communicator(communicator)
44 std::string verboseJson = json.toUtf8().data();
45 std::string compressedJson;
52 compressedJson = verboseJson;
53 ui->labelParseResult->setStyleSheet(
"QLabel { color : red; }");
54 ui->labelParseResult->setText(QString::fromUtf8(ex.what()));
57 connect(ui->textEditJson, SIGNAL(textChanged()), SLOT(onJsonTextChanged()));
58 connect(ui->pushButtonFormat, SIGNAL(clicked()), SLOT(onFormat()));
59 connect(ui->pushButtonShowInternalFormat, SIGNAL(clicked()), SLOT(onShowInternalJson()));
60 connect(ui->pushButtonImport, SIGNAL(clicked(
bool)), SLOT(onImportInternalJson()));
61 ui->textEditJson->setText(QString::fromUtf8(compressedJson.c_str()));
71 std::string compressedJson = ui->textEditJson->toPlainText().toUtf8().data();
74 return QString::fromUtf8(verboseJson.c_str());
77 void EditDefaultValueDialog::onJsonTextChanged()
79 std::string compressedJson = ui->textEditJson->toPlainText().toUtf8().data();
81 bool iserr = r.
iserr();
84 ui->labelParseResult->setStyleSheet(
"QLabel { color : red; }");
85 ui->labelParseResult->setText(QString::fromUtf8(r.
geterr().c_str()));
89 ui->labelParseResult->setStyleSheet(
"QLabel { color : green }");
90 ui->labelParseResult->setText(
"Input is valid.");
92 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!iserr);
93 ui->pushButtonShowInternalFormat->setEnabled(!iserr);
96 void EditDefaultValueDialog::onFormat()
98 std::string compressedJson = ui->textEditJson->toPlainText().toUtf8().data();
103 msgBox.setText(QString::fromStdString(r.geterr()));
108 ui->textEditJson->setText(QString::fromUtf8(compressedJson.c_str()));
112 void EditDefaultValueDialog::onShowInternalJson()
120 catch (VariantJsonException& ex)
122 text = QString(
"Error: ") + QString::fromStdString(ex.what());
125 msgBox.setText(text);
129 void EditDefaultValueDialog::onImportInternalJson()
131 QDialog editDefaultDialog;
132 editDefaultDialog.setWindowTitle(
"JSON Import");
133 editDefaultDialog.resize(QSize(600, 400));
134 QTextEdit* dialogTextEdit =
new QTextEdit();
135 dialogTextEdit->setAcceptRichText(
false);
136 dialogTextEdit->setPlainText(
"");
138 QVBoxLayout* layout =
new QVBoxLayout;
139 layout->addWidget(dialogTextEdit);
140 QDialogButtonBox* buttonBox =
new QDialogButtonBox(dialogTextEdit);
141 buttonBox->setOrientation(Qt::Horizontal);
142 buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
143 layout->addWidget(buttonBox);
144 editDefaultDialog.setLayout(layout);
146 connect(buttonBox, SIGNAL(accepted()), &editDefaultDialog, SLOT(accept()));
147 connect(buttonBox, SIGNAL(rejected()), &editDefaultDialog, SLOT(reject()));
149 if (editDefaultDialog.exec() == QDialog::Accepted)
151 std::string json(dialogTextEdit->toPlainText().toUtf8().data());
152 std::string compressedJson;
156 ui->textEditJson->setText(QString::fromUtf8(compressedJson.c_str()));
158 catch (VariantJsonException& ex)
161 msgBox.setText(QString(
"Error: ") + QString::fromStdString(ex.getReason()));
164 catch (LocalException& ex)
168 msgBox.setText(QString(
"Error: ") + QString::fromStdString(ex.getReason()));