Skip to content

Commit

Permalink
Refactor parsed output display in RequestBuilder.cpp (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Jan 30, 2024
1 parent 211c869 commit 5473755
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/ui/RequestBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,41 @@ void RequestBuilder::show_response_dialog(const request_data_handler_response &r
QVBoxLayout *parsedOutputLayout = new QVBoxLayout;
parsedOutputGroupBox->setLayout(parsedOutputLayout);
if (response.body_parts_parsed.size() > 1) {
// Add a QTabWidget to show the parsed output parts
QTabWidget *tabWidget = new QTabWidget;
parsedOutputLayout->addWidget(tabWidget);
for (auto &parsedOutput : response.body_parts_parsed) {
// label each tab {outputN} where N is the index of the output part
tabWidget->addTab(
new QLabel(QString::fromStdString(parsedOutput)),
QString::fromStdString("{output" +
std::to_string(tabWidget->count()) +
"}"));
if (response.body_parts_parsed.size() > 3) {
// Use a dropdown to select the parsed output to show
QComboBox *parsedOutputComboBox = new QComboBox;
parsedOutputLayout->addWidget(parsedOutputComboBox);
for (size_t i = 0; i < response.body_parts_parsed.size(); i++) {
// add each parsed output to the dropdown
parsedOutputComboBox->addItem(
QString::number(i) + ": " +
QString::fromStdString(
response.body_parts_parsed[i]),
QVariant(QString::fromStdString(
response.body_parts_parsed[i])));
}
// Add a QLabel to show the selected parsed output
QLabel *parsedOutputLabel = new QLabel;
parsedOutputLayout->addWidget(parsedOutputLabel);
// Show the selected parsed output
connect(parsedOutputComboBox, &QComboBox::currentTextChanged, this,
[=]() {
parsedOutputLabel->setText(
parsedOutputComboBox->currentData()
.toString());
});
} else {
// Add a QTabWidget to show the parsed output parts
QTabWidget *tabWidget = new QTabWidget;
parsedOutputLayout->addWidget(tabWidget);
for (auto &parsedOutput : response.body_parts_parsed) {
// label each tab {outputN} where N is the index of the output part
tabWidget->addTab(
new QLabel(QString::fromStdString(parsedOutput)),
QString::fromStdString(
"{output" +
std::to_string(tabWidget->count()) + "}"));
}
}
} else {
QString parsed_output =
Expand Down

0 comments on commit 5473755

Please sign in to comment.