29 #include <QFileDialog> 30 #include <QMessageBox> 39 : QWidget(parent), _signal_helper(signal_helper), _rpc_client(rpc)
41 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
48 qRegisterMetaType<messages::Signal>(
"messages::Signal");
61 QVBoxLayout* layout =
new QVBoxLayout(
this);
63 layout->setAlignment(Qt::AlignTop);
74 layout->addSpacing(20);
75 QFrame* hline =
new QFrame;
76 hline->setFrameShape(QFrame::HLine);
77 hline->setFrameShadow(QFrame::Sunken);
78 hline->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
79 layout->addWidget(hline);
81 layout->addSpacing(20);
83 QHBoxLayout* btn_layout =
new QHBoxLayout;
89 layout->addLayout(btn_layout);
104 namespace p = google::protobuf;
106 int num_fields = desc->field_count();
107 for (
int i = 0; i < num_fields; ++i)
109 const p::FieldDescriptor* field = desc->field(i);
110 if (field->cpp_type() != p::FieldDescriptor::CPPTYPE_MESSAGE)
113 "ToolboxWidget::createToolboxContent(): non-message-field found in parameter message. Only message fields are allowed in top-level");
117 QString name = QString::fromStdString(field->name());
118 name[0] = name[0].toUpper();
121 _toolbox->addItem(param_widget, name);
134 namespace p = google::protobuf;
136 int num_fields = desc->field_count();
140 PRINT_ERROR(
"ToolboxWidget::updateParameterWidgets(): Number of fields does not match number of ParameterWidgets.");
146 for (
int i = 0; i < num_fields; ++i)
148 const p::FieldDescriptor* field = desc->field(i);
150 if (field->cpp_type() != p::FieldDescriptor::CPPTYPE_MESSAGE)
152 PRINT_ERROR(
"ToolboxWidget::fromMessage(): non-message-field found in parameter message. Only message fields are allowed in top-level");
185 status +=
"Cannot connect to RPC client / connection lost\n";
186 if (!suppress_warning) QMessageBox::warning(
this, tr(
"RPC Connection Error"), status);
193 if (!status_msg.ok())
195 status += QString::fromStdString(status_msg.text()) +
"\n";
200 if (ret_val ==
false && !suppress_warning) QMessageBox::warning(
this, tr(
"Invalid Configuration"), status);
225 connect(rpc_worker, SIGNAL(taskFinished(
bool,
const QString&)),
this, SLOT(
rpcTaskFinished(
bool,
const QString&)));
226 connect(&
_rpc_task_thread, SIGNAL(finished()), rpc_worker, SLOT(deleteLater()));
252 QMessageBox::warning(
this, tr(
"Something went wrong..."), msg);
272 auto signal_feedback = [
this](
const messages::Signal& signal) {
_signal_helper->addSignal(signal); };
278 std::unique_ptr<google::protobuf::Message> cached_msg =
_task_cache.
fromCache(std::to_string(task_id));
295 std::unique_ptr<google::protobuf::Message> cached_msg =
_task_cache.
fromCache(std::to_string(task_id));
299 QMessageBox::warning(
this,
"Warning",
"Cannot save parameters to file, since not found in cache.");
304 QString default_filter = tr(
"Parameter file (*.cparams)");
306 QString
filename = QFileDialog::getSaveFileName(
this, tr(
"Export Parameters"),
"parameters.cparams",
307 tr(
"Parameter file (*.cparams);;All files (*.*)"), &default_filter);
310 QFileDialog::getSaveFileName(
this, tr(
"Export Parameters"),
"parameters", tr(
"Parameter file (*.cparams);;All files (*.*)"), &default_filter);
312 if (filename.isEmpty())
return;
315 std::ofstream file(filename.toStdString(), std::ofstream::binary | std::ofstream::trunc);
319 QMessageBox::warning(
this,
"Warning",
"Cannot open file with write-permissions for exporting parameters.");
322 params.SerializeToOstream(&file);
329 QString default_filter = tr(
"Parameter file (*.cparams)");
331 QFileDialog::getOpenFileName(
this, tr(
"Import Parameters"),
"parameters", tr(
"Parameter file (*.cparams);;All files (*.*)"), &default_filter);
339 QMessageBox::warning(
this,
"Warning",
"Cannot load parameter before RPC client is configured.");
343 if (filepath.isEmpty())
return;
345 std::ifstream file(filepath.toStdString());
349 QMessageBox::warning(
this,
"Warning",
"Cannot open file with read-permissions for importing parameters.");
void toCache(const std::string &key, const google::protobuf::Message &message)
void feedback(const messages::Signal &signal)
std::shared_ptr< SignalHelper > Ptr
void erase(const std::string &key)
void setRpcClient(std::shared_ptr< MasterServiceClient > client)
std::unique_ptr< google::protobuf::Message > fromCache(const std::string &key) const
#define PRINT_ERROR(msg)
Print msg-stream as error msg.