ChannelConfigWidget.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX::gui-plugins::ImageRecorder
19  * @author Christian R. G. Dreher <c.dreher@kit.edu>
20  * @date 2020
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
27 
28 
29 // Qt
30 #include <QStandardItemModel>
31 
32 // Simox
33 #include <SimoxUtility/algorithm/string/string_tools.h>
34 
35 
36 visionx::ChannelConfigWidget::ChannelConfigWidget(QWidget* parent, const visionx::imrec::ChannelConfig& channel_config, const visionx::imrec::ChannelPreferences& channel_prefs)
37  : QWidget(parent),
38  m_channel_name{channel_config.name},
39  m_channel_prefs{channel_prefs}
40 {
41  m_widget.setupUi(this);
42 
43  const QString q_channel_name = QString::fromStdString(channel_config.name);
44  m_widget.channels_config->setTitle(QString{"Channel: "} + q_channel_name);
45  m_widget.channels_config->setChecked(not channel_config.disabled);
46  m_widget.name->setText(q_channel_name);
47 
48  for (const auto& [format, reg_entry] : visionx::imrec::getFormatsMap())
49  {
50  m_widget.file_format->addItem(QString::fromStdString(reg_entry.hr_name));
51  }
52  const QString q_format_str = QString::fromStdString(imrec::format2hrstr(imrec::str2format(channel_config.format)));
53  m_widget.file_format->setCurrentText(q_format_str);
54 
55  update_file_formats(channel_prefs.requiresLossless);
56  set_visible_file_fps(m_widget.file_format->currentText());
57 
58  connect(m_widget.name, SIGNAL(textEdited(QString)), this, SLOT(channel_name_changed(QString)));
59  connect(m_widget.file_format, SIGNAL(currentTextChanged(QString)), this, SLOT(file_format_changed(QString)));
60 
61  m_widget.lossless->setChecked(channel_prefs.requiresLossless);
62  connect(m_widget.lossless, SIGNAL(stateChanged(int)), this, SLOT(lossless_state_changed(int)));
63 }
64 
65 
67 {
68 
69 }
70 
71 
72 const std::string&
74 {
75  return m_channel_name;
76 }
77 
78 
79 void
81 {
82  m_widget.channels_config->setTitle(QString::fromStdString("Channel: " + new_name));
83  m_channel_name = new_name;
84 }
85 
86 
87 void
89 {
90  // TODO: Display fancy graphics.
91  ARMARX_WARNING << "Invalid name '" << new_name << "' for channel (already taken).";
92 }
93 
94 
95 void
96 visionx::ChannelConfigWidget::setChannelPreferences(const imrec::ChannelPreferences& channel_prefs)
97 {
98  update_file_formats(channel_prefs.requiresLossless);
99 }
100 
101 
102 visionx::imrec::ChannelConfig
104 {
105  imrec::ChannelConfig cc;
106  cc.name = m_channel_name;
107  cc.disabled = disabled or not m_widget.channels_config->isChecked();
108  const imrec::Format format = imrec::str2format(m_widget.file_format->currentText().toStdString());
109  cc.format = imrec::format2hrstr(format);
110  cc.fps = m_widget.file_fps->value();
111  return cc;
112 }
113 
114 
115 void
116 visionx::ChannelConfigWidget::update_file_formats(bool require_lossless)
117 {
118  QStandardItemModel* model = qobject_cast<QStandardItemModel*>(m_widget.file_format->model());
119  for (int i = 0; i < m_widget.file_format->count(); ++i)
120  {
121  QStandardItem* item = model->item(i);
122  const imrec::Format format = imrec::str2format(item->text().toStdString());
123  const bool disabled = require_lossless and not imrec::isFormatLossless(format);
124  item->setFlags(disabled ? item->flags() & ~Qt::ItemIsEnabled : item->flags() | Qt::ItemIsEnabled);
125  }
126 
127  // If require_lossless is set and current selected value is lossy, choose bmp image sequence.
128  if (require_lossless)
129  {
130  const std::string format_str = m_widget.file_format->currentText().toStdString();
131  const imrec::Format format = imrec::str2format(format_str);
132  if (not imrec::isFormatLossless(format))
133  {
134  const QString q_format_str = QString::fromStdString(imrec::format2hrstr(imrec::Format::bmp_img_seq));
135  m_widget.file_format->setCurrentText(q_format_str);
136  }
137  }
138 }
139 
140 
141 void
142 visionx::ChannelConfigWidget::set_visible_file_fps(const QString& q_format_str)
143 {
144  const std::string format_str = q_format_str.toStdString();
145  const imrec::Format format = imrec::str2format(format_str);
146  set_visible_file_fps(not imrec::isFormatDynamicFramerate(format));
147 }
148 
149 
150 void
151 visionx::ChannelConfigWidget::set_visible_file_fps(bool visible)
152 {
153  m_widget.file_fps->setVisible(visible);
154  m_widget.label_file_fps->setVisible(visible);
155 }
156 
157 
158 void
159 visionx::ChannelConfigWidget::channel_name_changed(const QString& q_new_name)
160 {
161  const std::string new_name = simox::alg::trim_copy(q_new_name.toStdString());
162  const std::string old_name = m_channel_name;
163  if (new_name != old_name)
164  {
165  emit channelRenamed(old_name, new_name);
166  }
167 }
168 
169 
170 void
171 visionx::ChannelConfigWidget::lossless_state_changed(int state)
172 {
173  update_file_formats(state == Qt::Checked);
174 }
175 
176 
177 void
178 visionx::ChannelConfigWidget::file_format_changed(const QString& new_format_str)
179 {
180  set_visible_file_fps(new_format_str);
181 }
visionx::imrec::Format::bmp_img_seq
@ bmp_img_seq
visionx::imrec::getFormatsMap
std::map< Format, RegistryEntry > getFormatsMap()
Definition: public_api.cpp:184
visionx::ChannelConfigWidget::toChannelConfig
imrec::ChannelConfig toChannelConfig(bool disabled) const
Definition: ChannelConfigWidget.cpp:103
visionx::imrec::Format
Format
Supported recording Formats.
Definition: public_api.h:55
visionx::ChannelConfigWidget::getChannelName
const std::string & getChannelName() const
Definition: ChannelConfigWidget.cpp:73
visionx::imrec::isFormatLossless
bool isFormatLossless(Format format)
Definition: public_api.cpp:191
visionx::ChannelConfigWidget::ChannelConfigWidget
ChannelConfigWidget(QWidget *parent, const visionx::imrec::ChannelConfig &channel_config, const visionx::imrec::ChannelPreferences &channel_prefs)
Definition: ChannelConfigWidget.cpp:36
ChannelConfigWidget.h
visionx::ChannelConfigWidget::~ChannelConfigWidget
virtual ~ChannelConfigWidget()
Definition: ChannelConfigWidget.cpp:66
visionx::imrec::format2hrstr
const std::string & format2hrstr(const Format format)
Definition: public_api.cpp:152
visionx::ChannelConfigWidget::rejectChannelName
void rejectChannelName(const std::string &new_name)
Definition: ChannelConfigWidget.cpp:88
visionx::imrec::str2format
Format str2format(const std::string &format_str)
Definition: public_api.cpp:159
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
visionx::imrec::isFormatDynamicFramerate
bool isFormatDynamicFramerate(Format format)
Definition: public_api.cpp:198
visionx::ChannelConfigWidget::setChannelPreferences
void setChannelPreferences(const imrec::ChannelPreferences &channel_prefs)
Definition: ChannelConfigWidget.cpp:96
visionx::ChannelConfigWidget::confirmChannelName
void confirmChannelName(const std::string &new_name)
Definition: ChannelConfigWidget.cpp:80