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
36 QWidget* parent,
37 const visionx::imrec::ChannelConfig& channel_config,
38 const visionx::imrec::ChannelPreferences& channel_prefs) :
39 QWidget(parent), m_channel_name{channel_config.name}, 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 =
53 QString::fromStdString(imrec::format2hrstr(imrec::str2format(channel_config.format)));
54 m_widget.file_format->setCurrentText(q_format_str);
55
56 update_file_formats(channel_prefs.requiresLossless);
57 set_visible_file_fps(m_widget.file_format->currentText());
58
59 connect(m_widget.name, SIGNAL(textEdited(QString)), this, SLOT(channel_name_changed(QString)));
60 connect(m_widget.file_format,
61 SIGNAL(currentTextChanged(QString)),
62 this,
63 SLOT(file_format_changed(QString)));
64
65 m_widget.lossless->setChecked(channel_prefs.requiresLossless);
66 connect(m_widget.lossless, SIGNAL(stateChanged(int)), this, SLOT(lossless_state_changed(int)));
67}
68
72
73const std::string&
75{
76 return m_channel_name;
77}
78
79void
81{
82 m_widget.channels_config->setTitle(QString::fromStdString("Channel: " + new_name));
83 m_channel_name = new_name;
84}
85
86void
88{
89 // TODO: Display fancy graphics.
90 ARMARX_WARNING << "Invalid name '" << new_name << "' for channel (already taken).";
91}
92
93void
94visionx::ChannelConfigWidget::setChannelPreferences(const imrec::ChannelPreferences& channel_prefs)
95{
96 update_file_formats(channel_prefs.requiresLossless);
97}
98
99visionx::imrec::ChannelConfig
101{
102 imrec::ChannelConfig cc;
103 cc.name = m_channel_name;
104 cc.disabled = disabled or not m_widget.channels_config->isChecked();
105 const imrec::Format format =
106 imrec::str2format(m_widget.file_format->currentText().toStdString());
107 cc.format = imrec::format2hrstr(format);
108 cc.fps = m_widget.file_fps->value();
109 return cc;
110}
111
112void
113visionx::ChannelConfigWidget::update_file_formats(bool require_lossless)
114{
115 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(m_widget.file_format->model());
116 for (int i = 0; i < m_widget.file_format->count(); ++i)
117 {
118 QStandardItem* item = model->item(i);
119 const imrec::Format format = imrec::str2format(item->text().toStdString());
120 const bool disabled = require_lossless and not imrec::isFormatLossless(format);
121 item->setFlags(disabled ? item->flags() & ~Qt::ItemIsEnabled
122 : item->flags() | Qt::ItemIsEnabled);
123 }
124
125 // If require_lossless is set and current selected value is lossy, choose bmp image sequence.
126 if (require_lossless)
127 {
128 const std::string format_str = m_widget.file_format->currentText().toStdString();
129 const imrec::Format format = imrec::str2format(format_str);
130 if (not imrec::isFormatLossless(format))
131 {
132 const QString q_format_str =
133 QString::fromStdString(imrec::format2hrstr(imrec::Format::bmp_img_seq));
134 m_widget.file_format->setCurrentText(q_format_str);
135 }
136 }
137}
138
139void
140visionx::ChannelConfigWidget::set_visible_file_fps(const QString& q_format_str)
141{
142 const std::string format_str = q_format_str.toStdString();
143 const imrec::Format format = imrec::str2format(format_str);
144 set_visible_file_fps(not imrec::isFormatDynamicFramerate(format));
145}
146
147void
148visionx::ChannelConfigWidget::set_visible_file_fps(bool visible)
149{
150 m_widget.file_fps->setVisible(visible);
151 m_widget.label_file_fps->setVisible(visible);
152}
153
154void
155visionx::ChannelConfigWidget::channel_name_changed(const QString& q_new_name)
156{
157 const std::string new_name = simox::alg::trim_copy(q_new_name.toStdString());
158 const std::string old_name = m_channel_name;
159 if (new_name != old_name)
160 {
161 emit channelRenamed(old_name, new_name);
162 }
163}
164
165void
166visionx::ChannelConfigWidget::lossless_state_changed(int state)
167{
168 update_file_formats(state == Qt::Checked);
169}
170
171void
172visionx::ChannelConfigWidget::file_format_changed(const QString& new_format_str)
173{
174 set_visible_file_fps(new_format_str);
175}
imrec::ChannelConfig toChannelConfig(bool disabled) const
ChannelConfigWidget(QWidget *parent, const visionx::imrec::ChannelConfig &channel_config, const visionx::imrec::ChannelPreferences &channel_prefs)
void rejectChannelName(const std::string &new_name)
void setChannelPreferences(const imrec::ChannelPreferences &channel_prefs)
void confirmChannelName(const std::string &new_name)
const std::string & getChannelName() const
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
bool isFormatDynamicFramerate(Format format)
std::map< Format, RegistryEntry > getFormatsMap()
Format str2format(const std::string &format_str)
const std::string & format2hrstr(const Format format)
Format
Supported recording Formats.
Definition public_api.h:54
bool isFormatLossless(Format format)