25 #include <QFileDialog>
26 #include <QMessageBox>
33 #include <ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/ui_EditDefaultValueDialog.h>
43 typeString(typeString),
44 communicator(communicator)
48 std::string verboseJson = json.toUtf8().data();
49 std::string compressedJson;
57 compressedJson = verboseJson;
58 ui->labelParseResult->setStyleSheet(
"QLabel { color : red; }");
59 ui->labelParseResult->setText(QString::fromUtf8(ex.what()));
62 connect(ui->textEditJson, SIGNAL(textChanged()), SLOT(onJsonTextChanged()));
63 connect(ui->pushButtonFormat, SIGNAL(clicked()), SLOT(onFormat()));
64 connect(ui->pushButtonShowInternalFormat, SIGNAL(clicked()), SLOT(onShowInternalJson()));
65 connect(ui->pushButtonImport, SIGNAL(clicked(
bool)), SLOT(onImportInternalJson()));
66 ui->textEditJson->setText(QString::fromUtf8(compressedJson.c_str()));
76 std::string compressedJson = ui->textEditJson->toPlainText().toUtf8().data();
77 std::string verboseJson =
80 return QString::fromUtf8(verboseJson.c_str());
84 EditDefaultValueDialog::onJsonTextChanged()
86 std::string compressedJson = ui->textEditJson->toPlainText().toUtf8().data();
88 compressedJson, typeString.toUtf8().data(), communicator);
89 bool iserr = r.
iserr();
92 ui->labelParseResult->setStyleSheet(
"QLabel { color : red; }");
93 ui->labelParseResult->setText(QString::fromUtf8(r.
geterr().c_str()));
97 ui->labelParseResult->setStyleSheet(
"QLabel { color : green }");
98 ui->labelParseResult->setText(
"Input is valid.");
100 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!iserr);
101 ui->pushButtonShowInternalFormat->setEnabled(!iserr);
105 EditDefaultValueDialog::onFormat()
107 std::string compressedJson = ui->textEditJson->toPlainText().toUtf8().data();
112 msgBox.setText(QString::fromStdString(r.geterr()));
117 ui->textEditJson->setText(QString::fromUtf8(compressedJson.c_str()));
122 EditDefaultValueDialog::onShowInternalJson()
130 catch (VariantJsonException& ex)
132 text = QString(
"Error: ") + QString::fromStdString(ex.what());
135 msgBox.setText(text);
140 EditDefaultValueDialog::onImportInternalJson()
142 QDialog editDefaultDialog;
143 editDefaultDialog.setWindowTitle(
"JSON Import");
144 editDefaultDialog.resize(QSize(600, 400));
145 QTextEdit* dialogTextEdit =
new QTextEdit();
146 dialogTextEdit->setAcceptRichText(
false);
147 dialogTextEdit->setPlainText(
"");
149 QVBoxLayout* layout =
new QVBoxLayout;
150 layout->addWidget(dialogTextEdit);
151 QDialogButtonBox* buttonBox =
new QDialogButtonBox(dialogTextEdit);
152 buttonBox->setOrientation(Qt::Horizontal);
153 buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
154 layout->addWidget(buttonBox);
155 editDefaultDialog.setLayout(layout);
157 connect(buttonBox, SIGNAL(accepted()), &editDefaultDialog, SLOT(accept()));
158 connect(buttonBox, SIGNAL(rejected()), &editDefaultDialog, SLOT(reject()));
160 if (editDefaultDialog.exec() == QDialog::Accepted)
162 std::string json(dialogTextEdit->toPlainText().toUtf8().data());
163 std::string compressedJson;
167 ui->textEditJson->setText(QString::fromUtf8(compressedJson.c_str()));
169 catch (VariantJsonException& ex)
172 msgBox.setText(QString(
"Error: ") + QString::fromStdString(ex.getReason()));
175 catch (LocalException& ex)
179 msgBox.setText(QString(
"Error: ") + QString::fromStdString(ex.getReason()));