DataFieldPropertiesWidget.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::Gui
17* @author Kai Welke (welke@kit.edu)
18* @copyright 2012 Humanoids Group, IAIM, IFA
19* @license http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
24
25#include <QAction>
26#include <QApplication>
27#include <QClipboard>
28#include <QLabel>
29#include <QPushButton>
30#include <QToolBar>
31#include <QToolButton>
32
34
36
37namespace armarx
38{
40 DatafieldRefPtr dataFieldIdentifier,
41 VariantPtr variant,
42 IceManagerPtr iceManager,
43 QWidget* parent,
44 Qt::WindowFlags f) :
45 PropertiesWidget(parent, f), plotter(new PlotterController{this})
46 {
47 qRegisterMetaType<VariantPtr>("VariantPtr");
48 plotter->setIceManager(iceManager);
49 this->variant = variant;
50 this->dataFieldIdentifier = dataFieldIdentifier;
51 this->description = description;
52
53 createUi();
56 updateTask->start();
57 // startTimer(200);
58 setEnableEdit(false);
59 }
60
62 {
63 updateTask->stop();
64 ARMARX_DEBUG << "~DataFieldPropertiesWidget()";
65 }
66
67 void
69 {
70 variantWidget->setEnableEdit(enableEdit);
71 }
72
73 bool
75 {
76 return variantWidget->getEnableEdit();
77 }
78
81 {
82 return dataFieldIdentifier->getDataFieldIdentifier();
83 }
84
87 {
88 return variant;
89 }
90
91 void
93 {
94 if (toggled)
95 {
96 updateTask->start();
97 }
98 else
99 {
100 updateTask->stop();
101 }
102 plotter->plottingPaused(!toggled);
103 }
104
105 void
107 {
108 QClipboard* clipboard = QApplication::clipboard();
109 if (clipboard)
110 {
111 clipboard->setText(variantWidget->getValueText());
112 }
113 else
114 {
115 ARMARX_ERROR << "Could not copy text to clipboard";
116 }
117 }
118
119 void
120 DataFieldPropertiesWidget::createUi()
121 {
122 // create property entries
123 setPropertiesTitle("Datafield");
124 addProperty("Identifier",
125 dataFieldIdentifier->getDataFieldIdentifier()->getIdentifierStr().c_str());
126 addProperty("Description", description.c_str());
127
128 variantWidget = new VariantWidget(variant);
129 addProperty("Type", variant->getTypeName().c_str());
130 TimedVariantPtr tvar = TimedVariantPtr::dynamicCast(variant);
131 if (tvar)
132 {
133 auto simestampStr =
134 tvar->getTime().toDateTime() + " (" +
135 std::to_string((TimeUtil::GetTime() - tvar->getTime()).toMilliSeconds()) +
136 " ms old)";
137 addProperty("Timestamp", simestampStr.c_str());
138 }
139 addProperty("Value", "");
140
141 addWidget(variantWidget);
142 plotter->setPollingInterval(40);
143 plotter->setUpdateInterval(40);
144 plotter->setShownInterval(30);
145 plotter->setSelectedDatafields(
146 QStringList(QString::fromStdString(
147 dataFieldIdentifier->getDataFieldIdentifier()->getIdentifierStr())),
148 100);
149
150 addWidget(plotter->getPlotterWidget());
151 QToolBar* bar = new QToolBar();
152 bar->setIconSize(QSize(16, 16));
153 QAction* refreshButton = new QAction(bar);
154 refreshButton->setIcon(QIcon(":/icons/view-refresh-7.png"));
155 refreshButton->setCheckable(true);
156 refreshButton->setToolTip("Refresh value continuously");
157 refreshButton->setChecked(true);
158 connect(refreshButton, SIGNAL(toggled(bool)), this, SLOT(toggleAutoRefresh(bool)));
159 bar->addAction(refreshButton);
160
161 QAction* copyButton = new QAction("Copy", bar);
162 copyButton->setToolTip("Copy value to clipboard");
163 copyButton->setIcon(QIcon(":/icons/edit-copy-4.svg"));
164
165 connect(copyButton, SIGNAL(triggered()), this, SLOT(copyValueToClipboard()));
166 bar->addAction(copyButton);
167 getContentLayout()->addWidget(bar, 5, 1);
168 }
169
170 void
172 {
173 try
174 {
175 variant = dataFieldIdentifier->getDataField();
176 if (variant)
177 {
178 QMetaObject::invokeMethod(
179 variantWidget, "setValue", Q_ARG(VariantPtr, variant)); //->setValue(variant);
180 TimedVariantPtr tvar = TimedVariantPtr::dynamicCast(variant);
181 if (tvar)
182 {
183 auto simestampStr =
184 tvar->getTime().toDateTime() + " (" +
185 std::to_string((TimeUtil::GetTime() - tvar->getTime()).toMilliSeconds()) +
186 " ms old)";
187 QString dateString = tvar->getInitialized()
188 ? QString::fromStdString(simestampStr)
189 : "not initialized";
190
191 QMetaObject::invokeMethod(this,
192 "setProperty",
193 Q_ARG(QString, "Timestamp"),
194 Q_ARG(QString, dateString)); //->setValue(variant);
195 }
196 }
197 }
198 catch (...)
199 {
200 ARMARX_INFO << deactivateSpam(10) << "Failed to get current value for datafield "
201 << dataFieldIdentifier->getDataFieldIdentifier()
202 << " - Is the Observer still running?";
203 }
204 }
205} // namespace armarx
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
DataFieldIdentifierPtr getDatafieldIdentifier() const
DataFieldPropertiesWidget(std::string description, DatafieldRefPtr dataFieldIdentifier, VariantPtr variant, IceManagerPtr iceManager, QWidget *parent=0, Qt::WindowFlags f=0)
The periodic task executes one thread method repeatedly using the time period specified in the constr...
void setSelectedDatafields(const QStringList &value, int samplingIntervalMs=-1)
Changes the datafields that are plotted.
void addWidget(QWidget *widget)
void addProperty(const QString &label, QWidget *propertyWidget)
void setPropertiesTitle(const QString &title)
QGridLayout * getContentLayout() const
PropertiesWidget(QWidget *parent=0, Qt::WindowFlags f=0)
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< TimedVariant > TimedVariantPtr
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
IceInternal::Handle< DatafieldRef > DatafieldRefPtr
Definition Observer.h:43
IceUtil::Handle< IceManager > IceManagerPtr
IceManager smart pointer.
Definition ArmarXFwd.h:39
IceInternal::Handle< DataFieldIdentifier > DataFieldIdentifierPtr
Typedef of DataFieldIdentifierPtr as IceInternal::Handle<DataFieldIdentifier> for convenience.