video_viewer.cpp
Go to the documentation of this file.
1 #include <QTextStream>
2 #include <QFile>
3 #include <QMessageBox>
4 #include <QSettings>
5 #include "video_viewer.h"
6 
8 {
9  _dialog = new VideoDialog(nullptr);
10  connect(_dialog, &VideoDialog::closed, this, [this]()
11  {
12  setEnabled(false);
13  emit closed();
14  });
15 }
16 
18 {
19  delete _dialog;
20 }
21 
22 void PublisherVideo::updateState(double current_time)
23 {
24  if(_dialog->isHidden())
25  {
26  return;
27  }
28  QString ref_curve = _dialog->referenceCurve();
29  if(ref_curve.isEmpty())
30  {
31  return;
32  }
33  auto it = _datamap->numeric.find(ref_curve.toStdString());
34  if( it == _datamap->numeric.end() )
35  {
36  return;
37  }
38  const auto& data = it->second;
39  auto position = data.getYfromX(current_time);
40  if( position )
41  {
42  if( !_dialog->isPaused() )
43  {
44  _dialog->pause(true);
45  }
46  _dialog->seekByValue(position.value());
47  }
48 }
49 
50 void PublisherVideo::play(double current_time)
51 {
52  updateState(current_time);
53 }
54 
55 bool PublisherVideo::xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const
56 {
57  QDomElement config = doc.createElement("config");
58  config.setAttribute("video_file", _dialog->ui->lineFilename->text());
59  config.setAttribute("curve_name", _dialog->ui->lineEditReference->text());
60  config.setAttribute("use_frame", _dialog->ui->radioButtonFrame->isChecked() ? "true" : "false");
61 
62  parent_element.appendChild(config);
63  return true;
64 }
65 
66 bool PublisherVideo::xmlLoadState(const QDomElement &parent_element)
67 {
68  QDomElement config = parent_element.firstChildElement("config");
69  if( config.isNull() )
70  {
71  return false;
72  }
73  _dialog->loadFile( config.attribute("video_file") );
74  _dialog->ui->lineEditReference->setText( config.attribute("curve_name") );
75  if( config.attribute("use_frame") == "true" )
76  {
77  _dialog->ui->radioButtonFrame->setChecked(true);
78  }
79  else{
80  _dialog->ui->radioButtonTime->setChecked(true);
81  }
82  _xml_loaded = true;
83  return true;
84 }
85 
87 {
88  QSettings settings;
89  auto ui = _dialog->ui;
90  if(enabled)
91  {
92  if( !_xml_loaded )
93  {
94  QString filename = settings.value("VideoDialog::video_file", "").toString();
95  if(filename != ui->lineFilename->text())
96  {
97  _dialog->loadFile(filename);
98  }
99 
100  auto curve_name = settings.value("VideoDialog::curve_name", "").toString();
101  ui->lineEditReference->setText(curve_name);
102  _dialog->restoreGeometry(settings.value("VideoDialog::geometry").toByteArray());
103  }
104  _dialog->show();
105  }
106  else
107  {
108  settings.setValue("VideoDialog::video_file", ui->lineFilename->text());
109  settings.setValue("VideoDialog::curve_name", ui->lineEditReference->text());
110  settings.setValue("VideoDialog::geometry", _dialog->saveGeometry());
111  _dialog->hide();
112  }
113 }
const PlotDataMapRef * _datamap
bool loadFile(QString filename)
bool enabled() const override
True if started.
Definition: video_viewer.h:28
void closed()
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
void updateState(double current_time) override
Method called when the timetracker is moved manually to a certain position.
QString referenceCurve() const
TimeseriesMap numeric
Numerical timeseries.
Definition: plotdata.h:38
void pause(bool paused)
virtual ~PublisherVideo()
virtual void setEnabled(bool enabled) override
VideoDialog * _dialog
Definition: video_viewer.h:49
void seekByValue(double value)
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Ui::VideoDialog * ui
Definition: video_dialog.h:48
Definition: format.h:895
void closed()
signal to be emitted when the plugin disable itself.
void play(double current_time) override
bool isPaused() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:12:53