+void DecodeTrace::export_annotations(vector<Annotation> *annotations) const
+{
+ using namespace pv::data::decode;
+
+ GlobalSettings settings;
+ const QString dir = settings.value("MainWindow/SaveDirectory").toString();
+
+ const QString file_name = QFileDialog::getSaveFileName(
+ owner_->view(), tr("Export annotations"), dir, tr("Text Files (*.txt);;All Files (*)"));
+
+ if (file_name.isEmpty())
+ return;
+
+ QString format = settings.value(GlobalSettings::Key_Dec_ExportFormat).toString();
+ const QString quote = format.contains("%q") ? "\"" : "";
+ format = format.remove("%q");
+
+ QFile file(file_name);
+ if (file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
+ QTextStream out_stream(&file);
+
+ for (Annotation &ann : *annotations) {
+ const QString sample_range = QString("%1-%2") \
+ .arg(QString::number(ann.start_sample()), QString::number(ann.end_sample()));
+
+ const QString class_name = quote + ann.row()->class_name() + quote;
+
+ QString all_ann_text;
+ for (const QString &s : ann.annotations())
+ all_ann_text = all_ann_text + quote + s + quote + ",";
+ all_ann_text.chop(1);
+
+ const QString first_ann_text = quote + ann.annotations().front() + quote;
+
+ 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("%c", class_name);
+ out_text = out_text.replace("%1", first_ann_text);
+ out_text = out_text.replace("%a", all_ann_text);
+ out_stream << out_text << '\n';
+ }
+
+ if (out_stream.status() == QTextStream::Ok)
+ return;
+ }
+
+ QMessageBox msg(owner_->view());
+ msg.setText(tr("Error") + "\n\n" + tr("File %1 could not be written to.").arg(file_name));
+ msg.setStandardButtons(QMessageBox::Ok);
+ msg.setIcon(QMessageBox::Warning);
+ msg.exec();
+}
+
+void DecodeTrace::update_rows()
+{
+ lock_guard<mutex> lock(row_modification_mutex_);
+
+ QFontMetrics m(QApplication::font());
+
+ for (RowData& r : rows_)
+ r.exists = false;
+
+ for (const Row& decode_row : decode_signal_->get_rows()) {
+ // Find row in our list
+ auto r_it = find_if(rows_.begin(), rows_.end(),
+ [&](RowData& r){ return r.decode_row == decode_row; });
+
+ RowData* r = nullptr;
+ if (r_it == rows_.end()) {
+ // Row doesn't exist yet, create and append it
+ RowData nr;
+ nr.decode_row = decode_row;
+ nr.height = default_row_height_;
+ nr.currently_visible = false;
+ nr.expand_marker_highlighted = false;
+ nr.expanded = false;
+
+ rows_.push_back(nr);
+ r = &rows_.back();
+ } else
+ r = &(*r_it);
+
+ r->exists = true;
+
+ const int w = m.boundingRect(r->decode_row.title()).width() + RowTitleMargin;
+ r->title_width = w;
+ }
+
+ // Remove any rows that no longer exist, obeying that iterators are invalidated
+ bool any_exists;
+ do {
+ any_exists = false;
+
+ for (unsigned int i = 0; i < rows_.size(); i++)
+ if (!rows_[i].exists) {
+ rows_.erase(rows_.begin() + i);
+ any_exists = true;
+ break;
+ }
+ } while (any_exists);
+}
+
+void DecodeTrace::on_setting_changed(const QString &key, const QVariant &value)
+{
+ Trace::on_setting_changed(key, value);
+
+ if (key == GlobalSettings::Key_Dec_AlwaysShowAllRows) {
+ max_visible_rows_ = 0;
+ always_show_all_rows_ = value.toBool();
+ }
+}
+