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 
37 namespace 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
armarx::PlotterController::setPollingInterval
void setPollingInterval(int value)
Definition: PlotterController.cpp:900
armarx::PlotterController
Definition: PlotterController.h:75
armarx::DataFieldPropertiesWidget::DataFieldPropertiesWidget
DataFieldPropertiesWidget(std::string description, DatafieldRefPtr dataFieldIdentifier, VariantPtr variant, IceManagerPtr iceManager, QWidget *parent=0, Qt::WindowFlags f=0)
Definition: DataFieldPropertiesWidget.cpp:39
armarx::PropertiesWidget::addProperty
void addProperty(const QString &label, QWidget *propertyWidget)
Definition: PropertiesWidget.h:79
armarx::PlotterController::getPlotterWidget
QWidget * getPlotterWidget()
Definition: PlotterController.cpp:114
armarx::DataFieldPropertiesWidget::getVariant
VariantPtr getVariant()
Definition: DataFieldPropertiesWidget.cpp:86
armarx::DataFieldPropertiesWidget::updateValue
void updateValue()
Definition: DataFieldPropertiesWidget.cpp:171
armarx::DataFieldPropertiesWidget::copyValueToClipboard
void copyValueToClipboard()
Definition: DataFieldPropertiesWidget.cpp:106
armarx::DataFieldPropertiesWidget::setEnableEdit
void setEnableEdit(bool enableEdit)
Definition: DataFieldPropertiesWidget.cpp:68
DataFieldPropertiesWidget.h
IceInternal::Handle< DatafieldRef >
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:75
armarx::VariantWidget::getEnableEdit
bool getEnableEdit()
Definition: VariantWidget.cpp:121
armarx::DataFieldPropertiesWidget::toggleAutoRefresh
void toggleAutoRefresh(bool)
Definition: DataFieldPropertiesWidget.cpp:92
armarx::PlotterController::setUpdateInterval
void setUpdateInterval(int value)
Definition: PlotterController.cpp:916
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
armarx::DataFieldPropertiesWidget::getDatafieldIdentifier
DataFieldIdentifierPtr getDatafieldIdentifier() const
Definition: DataFieldPropertiesWidget.cpp:80
PlotterController.h
armarx::PlotterController::plottingPaused
void plottingPaused(bool toggled)
Definition: PlotterController.cpp:338
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
armarx::PropertiesWidget::setPropertiesTitle
void setPropertiesTitle(const QString &title)
Definition: PropertiesWidget.h:71
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
TimedVariant.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::DataFieldPropertiesWidget::~DataFieldPropertiesWidget
~DataFieldPropertiesWidget() override
Definition: DataFieldPropertiesWidget.cpp:61
IceUtil::Handle< IceManager >
armarx::VariantWidget::setEnableEdit
void setEnableEdit(bool enableEdit)
Definition: VariantWidget.cpp:107
armarx::PropertiesWidget::addWidget
void addWidget(QWidget *widget)
Definition: PropertiesWidget.h:150
armarx::DataFieldPropertiesWidget::getEnableEdit
bool getEnableEdit()
Definition: DataFieldPropertiesWidget.cpp:74
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::PlotterController::setShownInterval
void setShownInterval(int value)
Definition: PlotterController.cpp:973
armarx::PlotterController::setSelectedDatafields
void setSelectedDatafields(const QStringList &value, int samplingIntervalMs=-1)
Changes the datafields that are plotted.
Definition: PlotterController.cpp:880
armarx::VariantWidget::getValueText
QString getValueText()
Definition: VariantWidget.cpp:133
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::PropertiesWidget::getContentLayout
QGridLayout * getContentLayout() const
Definition: PropertiesWidget.h:160
armarx::VariantWidget
Definition: VariantWidget.h:40
armarx::PropertiesWidget
Definition: PropertiesWidget.h:37