9 namespace gp = google::protobuf;
14 ui =
new Ui::ProtobufLoader;
23 QString theme = settings.value(
"Preferences::theme",
"light").toString();
24 ui->pushButtonRemove->setIcon(
LoadSvg(
":/resources/svg/trash.svg", theme));
26 connect(
ui->pushButtonInclude, &QPushButton::clicked,
this,
28 connect(
ui->pushButtonLoad, &QPushButton::clicked,
this,
30 connect(
ui->pushButtonRemove, &QPushButton::clicked,
this,
33 QString last_type = settings.value(
"ProtobufParserCreator.lastType").toString();
34 int combo_index =
ui->comboBox->findText(last_type, Qt::MatchExactly);
35 if (!last_type.isEmpty() && combo_index != -1)
37 ui->comboBox->setCurrentIndex(combo_index);
41 connect(
ui->comboBox, qOverload<const QString&>(&QComboBox::currentIndexChanged),
this,
50 QMessageBox::warning(
nullptr, tr(
"Error loading file"),
51 tr(
"File %1 does not exist").
arg(filename), QMessageBox::Cancel);
54 file.open(QIODevice::ReadOnly);
56 QFileInfo fileinfo(filename);
57 QString file_basename = fileinfo.fileName();
63 _source_tree.MapPath(
"", fileinfo.absolutePath().toStdString());
72 if (error_collector.
errors().size() > 0)
74 QMessageBox::warning(
nullptr,
"Error parsing Proto file",
75 error_collector.
errors().front(), QMessageBox::Cancel);
80 ui->loadedProto->setText(file_basename);
82 ui->comboBox->clear();
88 QString type_qname = QString::fromStdString(
type_name);
89 info.
descriptors.insert({ type_qname, descriptor });
90 ui->comboBox->addItem(type_qname);
97 ui->listWidget->clear();
98 ui->protoPreview->clear();
102 auto include_list = settings.value(
"ProtobufParserCreator.include_dirs").toStringList();
103 for (
const auto& include_dir : include_list)
105 QDir path_dir(include_dir);
106 if (path_dir.exists())
108 ui->listWidget->addItem(include_dir);
112 ui->listWidget->sortItems();
114 auto filename = settings.value(
"ProtobufParserCreator.protofile").toString();
115 if (!filename.isEmpty())
124 QStringList include_list;
125 for (
int row = 0; row <
ui->listWidget->count(); row++)
127 include_list +=
ui->listWidget->item(row)->text();
129 settings.setValue(
"ProtobufParserCreator.include_dirs", include_list);
140 const std::string& schema,
143 QString descriptor_name =
150 throw std::runtime_error(
"ParserFactoryProtobuf: can't find the descriptor");
152 auto selected_descriptor = descr_it->second;
153 return std::make_shared<ProtobufParser>(topic_name, selected_descriptor,
data);
157 gp::FileDescriptorSet field_set;
158 if (!field_set.ParseFromArray(schema.data(), schema.size()))
160 throw std::runtime_error(
"failed to parse schema data");
163 return std::make_shared<ProtobufParser>(topic_name,
type_name, field_set,
data);
170 QString directory_path =
171 settings.value(
"ProtobufParserCreator.loadDirectory", QDir::currentPath())
175 QFileDialog::getExistingDirectory(
_widget, tr(
"Load StyleSheet"), directory_path);
176 if (dirname.isEmpty())
180 settings.setValue(
"ProtobufParserCreator.loadDirectory", dirname);
181 if (
ui->listWidget->findItems(dirname, Qt::MatchExactly).empty())
183 ui->listWidget->addItem(dirname);
184 ui->listWidget->sortItems();
192 QString directory_path =
193 settings.value(
"ProtobufParserCreator.loadDirectory", QDir::currentPath())
196 QString filename = QFileDialog::getOpenFileName(
_widget, tr(
"Load StyleSheet"),
197 directory_path, tr(
"(*.proto)"));
198 if (filename.isEmpty())
205 directory_path = QFileInfo(filename).absolutePath();
206 settings.setValue(
"ProtobufParserCreator.loadDirectory", directory_path);
213 auto selected =
ui->listWidget->selectedItems();
215 while (!selected.isEmpty())
217 auto item = selected.front();
218 delete ui->listWidget->takeItem(
ui->listWidget->row(item));
219 selected.pop_front();
231 settings.setValue(
"ProtobufParserCreator.lastType", text);