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  setEnabled(false);
12  emit closed();
13  });
14 }
15 
17 {
18  delete _dialog;
19 }
20 
21 void PublisherVideo::updateState(double current_time)
22 {
23  if (_dialog->isHidden())
24  {
25  return;
26  }
27  QString ref_curve = _dialog->referenceCurve();
28  if (ref_curve.isEmpty())
29  {
30  return;
31  }
32  auto it = _datamap->numeric.find(ref_curve.toStdString());
33  if (it == _datamap->numeric.end())
34  {
35  return;
36  }
37  const auto& data = it->second;
38  auto position = data.getYfromX(current_time);
39  if (position)
40  {
41  if (!_dialog->isPaused())
42  {
43  _dialog->pause(true);
44  }
45  _dialog->seekByValue(position.value());
46  }
47 }
48 
49 void PublisherVideo::play(double current_time)
50 {
51  updateState(current_time);
52 }
53 
54 bool PublisherVideo::xmlSaveState(QDomDocument& doc, QDomElement& parent_element) const
55 {
56  QDomElement config = doc.createElement("config");
57  config.setAttribute("video_file", _dialog->ui->lineFilename->text());
58  config.setAttribute("curve_name", _dialog->ui->lineEditReference->text());
59  config.setAttribute("use_frame",
60  _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  {
81  _dialog->ui->radioButtonTime->setChecked(true);
82  }
83  _xml_loaded = true;
84  return true;
85 }
86 
87 void PublisherVideo::setEnabled(bool enabled)
88 {
89  QSettings settings;
90  auto ui = _dialog->ui;
91  if (enabled)
92  {
93  if (!_xml_loaded)
94  {
95  QString filename = settings.value("VideoDialog::video_file", "").toString();
96  if (filename != ui->lineFilename->text())
97  {
98  _dialog->loadFile(filename);
99  }
100 
101  auto curve_name = settings.value("VideoDialog::curve_name", "").toString();
102  ui->lineEditReference->setText(curve_name);
103  _dialog->restoreGeometry(settings.value("VideoDialog::geometry").toByteArray());
104  }
105  _dialog->show();
106  }
107  else
108  {
109  settings.setValue("VideoDialog::video_file", ui->lineFilename->text());
110  settings.setValue("VideoDialog::curve_name", ui->lineEditReference->text());
111  settings.setValue("VideoDialog::geometry", _dialog->saveGeometry());
112  _dialog->hide();
113  }
114 }
PublisherVideo::enabled
bool enabled() const override
True if started.
Definition: video_viewer.h:28
VideoDialog::seekByValue
void seekByValue(double value)
Definition: video_dialog.cpp:213
VideoDialog::isPaused
bool isPaused() const
Definition: video_dialog.cpp:127
PublisherVideo::setEnabled
virtual void setEnabled(bool enabled) override
Definition: video_viewer.cpp:87
VideoDialog::ui
Ui::VideoDialog * ui
Definition: video_dialog.h:47
PublisherVideo::_dialog
VideoDialog * _dialog
Definition: video_viewer.h:48
PublisherVideo::_xml_loaded
bool _xml_loaded
Definition: video_viewer.h:46
PublisherVideo::play
void play(double current_time) override
Definition: video_viewer.cpp:49
PublisherVideo::~PublisherVideo
virtual ~PublisherVideo()
Definition: video_viewer.cpp:16
PublisherVideo::xmlSaveState
bool xmlSaveState(QDomDocument &doc, QDomElement &parent_element) const override
Override this method to save the status of the plugin to XML.
Definition: video_viewer.cpp:54
PJ::StatePublisher::closed
void closed()
signal to be emitted when the plugin disable itself.
VideoDialog::closed
void closed()
PJ::PlotDataMapRef::numeric
TimeseriesMap numeric
Numerical timeseries.
Definition: plotdata.h:39
PublisherVideo::PublisherVideo
PublisherVideo()
Definition: video_viewer.cpp:7
VideoDialog::referenceCurve
QString referenceCurve() const
Definition: video_dialog.cpp:117
VideoDialog::pause
void pause(bool paused)
Definition: video_dialog.cpp:122
PublisherVideo::updateState
void updateState(double current_time) override
Method called when the timetracker is moved manually to a certain position.
Definition: video_viewer.cpp:21
VideoDialog
Definition: video_dialog.h:33
PublisherVideo::xmlLoadState
bool xmlLoadState(const QDomElement &parent_element) override
Override this method to load the status of the plugin from XML.
Definition: video_viewer.cpp:66
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
VideoDialog::loadFile
bool loadFile(QString filename)
Definition: video_dialog.cpp:95
video_viewer.h
PJ::StatePublisher::_datamap
const PlotDataMapRef * _datamap
Definition: statepublisher_base.h:52


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:48