connect(ann_export_format_, SIGNAL(textChanged(const QString&)),
this, SLOT(on_dec_exportFormat_changed(const QString&)));
decoder_layout->addRow(tr("Annotation export format"), ann_export_format_);
- QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %r: row name; %q: use quotation marks"));
+ QLabel *description_1 = new QLabel(tr("%s = sample range; %d: decoder name; %r: row name; %c: class name"));
description_1->setAlignment(Qt::AlignRight);
decoder_layout->addRow(description_1);
- QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts"));
+ QLabel *description_2 = new QLabel(tr("%1: longest annotation text; %a: all annotation texts; %q: use quotation marks"));
description_2->setAlignment(Qt::AlignRight);
decoder_layout->addRow(description_2);
const QString quote = format.contains("%q") ? "\"" : "";
format = format.remove("%q");
+ const bool has_sample_range = format.contains("%s");
+ const bool has_row_name = format.contains("%r");
+ const bool has_dec_name = format.contains("%d");
+ const bool has_class_name = format.contains("%c");
+ const bool has_first_ann_text = format.contains("%1");
+ const bool has_all_ann_text = format.contains("%a");
+
QFile file(file_name);
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
QTextStream out_stream(&file);
for (const Annotation* ann : annotations) {
- const QString sample_range = QString("%1-%2") \
- .arg(QString::number(ann->start_sample()), QString::number(ann->end_sample()));
+ QString out_text = format;
- const QString row_name = quote + ann->row()->description() + quote;
+ if (has_sample_range) {
+ const QString sample_range = QString("%1-%2") \
+ .arg(QString::number(ann->start_sample()), QString::number(ann->end_sample()));
+ out_text = out_text.replace("%s", sample_range);
+ }
- QString all_ann_text;
- for (const QString &s : *(ann->annotations()))
- all_ann_text = all_ann_text + quote + s + quote + ",";
- all_ann_text.chop(1);
+ if (has_dec_name)
+ out_text = out_text.replace("%d",
+ quote + QString::fromUtf8(ann->row()->decoder()->name()) + quote);
- const QString first_ann_text = quote + ann->annotations()->front() + quote;
+ if (has_row_name) {
+ const QString row_name = quote + ann->row()->description() + quote;
+ out_text = out_text.replace("%r", row_name);
+ }
+
+ if (has_class_name) {
+ const QString class_name = quote + ann->ann_class_name() + quote;
+ out_text = out_text.replace("%c", class_name);
+ }
+
+ if (has_first_ann_text) {
+ const QString first_ann_text = quote + ann->annotations()->front() + quote;
+ out_text = out_text.replace("%1", first_ann_text);
+ }
+
+ if (has_all_ann_text) {
+ QString all_ann_text;
+ for (const QString &s : *(ann->annotations()))
+ all_ann_text = all_ann_text + quote + s + quote + ",";
+ all_ann_text.chop(1);
+
+ out_text = out_text.replace("%a", all_ann_text);
+ }
- QString out_text = format;
- out_text = out_text.replace("%s", sample_range);
- out_text = out_text.replace("%d",
- quote + QString::fromUtf8(ann->row()->decoder()->name()) + quote);
- out_text = out_text.replace("%r", row_name);
- out_text = out_text.replace("%1", first_ann_text);
- out_text = out_text.replace("%a", all_ann_text);
out_stream << out_text << '\n';
}