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 #include <QLabel>
25 #include <QPushButton>
26 #include <QToolButton>
29 #include <QAction>
30 #include <QApplication>
31 #include <QClipboard>
32 #include <QToolBar>
33 namespace armarx
34 {
35  DataFieldPropertiesWidget::DataFieldPropertiesWidget(std::string description, DatafieldRefPtr dataFieldIdentifier, VariantPtr variant, IceManagerPtr iceManager, QWidget* parent, Qt::WindowFlags f)
36  : PropertiesWidget(parent, f),
37  plotter(new PlotterController {this})
38  {
39  qRegisterMetaType<VariantPtr>("VariantPtr");
40  plotter->setIceManager(iceManager);
41  this->variant = variant;
42  this->dataFieldIdentifier = dataFieldIdentifier;
43  this->description = description;
44 
45  createUi();
47  updateTask->start();
48  // startTimer(200);
49  setEnableEdit(false);
50  }
51 
53  {
54  updateTask->stop();
55  ARMARX_DEBUG << "~DataFieldPropertiesWidget()";
56  }
57 
59  {
60  variantWidget->setEnableEdit(enableEdit);
61  }
62 
63 
65  {
66  return variantWidget->getEnableEdit();
67  }
68 
70  {
71  return dataFieldIdentifier->getDataFieldIdentifier();
72  }
73 
75  {
76  return variant;
77  }
78 
80  {
81  if (toggled)
82  {
83  updateTask->start();
84  }
85  else
86  {
87  updateTask->stop();
88  }
89  plotter->plottingPaused(!toggled);
90  }
91 
93  {
94  QClipboard* clipboard = QApplication::clipboard();
95  if (clipboard)
96  {
97  clipboard->setText(variantWidget->getValueText());
98  }
99  else
100  {
101  ARMARX_ERROR << "Could not copy text to clipboard";
102  }
103  }
104 
105  void DataFieldPropertiesWidget::createUi()
106  {
107  // create property entries
108  setPropertiesTitle("Datafield");
109  addProperty("Identifier", dataFieldIdentifier->getDataFieldIdentifier()->getIdentifierStr().c_str());
110  addProperty("Description", description.c_str());
111 
112  variantWidget = new VariantWidget(variant);
113  addProperty("Type", variant->getTypeName().c_str());
114  TimedVariantPtr tvar = TimedVariantPtr::dynamicCast(variant);
115  if (tvar)
116  {
117  auto simestampStr = tvar->getTime().toDateTime() + " (" + std::to_string((TimeUtil::GetTime() - tvar->getTime()).toMilliSeconds()) + " ms old)";
118  addProperty("Timestamp", simestampStr.c_str());
119  }
120  addProperty("Value", "");
121 
122  addWidget(variantWidget);
123  plotter->setPollingInterval(40);
124  plotter->setUpdateInterval(40);
125  plotter->setShownInterval(30);
126  plotter->setSelectedDatafields(QStringList(QString::fromStdString(dataFieldIdentifier->getDataFieldIdentifier()->getIdentifierStr())), 100);
127 
128  addWidget(plotter->getPlotterWidget());
129  QToolBar* bar = new QToolBar();
130  bar->setIconSize(QSize(16, 16));
131  QAction* refreshButton = new QAction(bar);
132  refreshButton->setIcon(QIcon(":/icons/view-refresh-7.png"));
133  refreshButton->setCheckable(true);
134  refreshButton->setToolTip("Refresh value continuously");
135  refreshButton->setChecked(true);
136  connect(refreshButton, SIGNAL(toggled(bool)), this, SLOT(toggleAutoRefresh(bool)));
137  bar->addAction(refreshButton);
138 
139  QAction* copyButton = new QAction("Copy", bar);
140  copyButton->setToolTip("Copy value to clipboard");
141  copyButton->setIcon(QIcon(":/icons/edit-copy-4.svg"));
142 
143  connect(copyButton, SIGNAL(triggered()), this, SLOT(copyValueToClipboard()));
144  bar->addAction(copyButton);
145  getContentLayout()->addWidget(bar, 5, 1);
146  }
147 
149  {
150  try
151  {
152  variant = dataFieldIdentifier->getDataField();
153  if (variant)
154  {
155  QMetaObject::invokeMethod(variantWidget, "setValue", Q_ARG(VariantPtr, variant)); //->setValue(variant);
156  TimedVariantPtr tvar = TimedVariantPtr::dynamicCast(variant);
157  if (tvar)
158  {
159  auto simestampStr = tvar->getTime().toDateTime() + " (" + std::to_string((TimeUtil::GetTime() - tvar->getTime()).toMilliSeconds()) + " ms old)";
160  QString dateString = tvar->getInitialized() ?
161  QString::fromStdString(simestampStr) :
162  "not initialized";
163 
164  QMetaObject::invokeMethod(this, "setProperty", Q_ARG(QString, "Timestamp"), Q_ARG(QString, dateString)); //->setValue(variant);
165  }
166 
167  }
168  }
169  catch (...)
170  {
171  ARMARX_INFO << deactivateSpam(10) << "Failed to get current value for datafield " << dataFieldIdentifier->getDataFieldIdentifier() << " - Is the Observer still running?";
172  }
173 
174  }
175 }
armarx::PlotterController::setPollingInterval
void setPollingInterval(int value)
Definition: PlotterController.cpp:866
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:35
armarx::PropertiesWidget::addProperty
void addProperty(const QString &label, QWidget *propertyWidget)
Definition: PropertiesWidget.h:72
armarx::PlotterController::getPlotterWidget
QWidget * getPlotterWidget()
Definition: PlotterController.cpp:113
armarx::DataFieldPropertiesWidget::getVariant
VariantPtr getVariant()
Definition: DataFieldPropertiesWidget.cpp:74
armarx::DataFieldPropertiesWidget::updateValue
void updateValue()
Definition: DataFieldPropertiesWidget.cpp:148
armarx::DataFieldPropertiesWidget::copyValueToClipboard
void copyValueToClipboard()
Definition: DataFieldPropertiesWidget.cpp:92
armarx::DataFieldPropertiesWidget::setEnableEdit
void setEnableEdit(bool enableEdit)
Definition: DataFieldPropertiesWidget.cpp:58
DataFieldPropertiesWidget.h
IceInternal::Handle< DatafieldRef >
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::VariantWidget::getEnableEdit
bool getEnableEdit()
Definition: VariantWidget.cpp:117
armarx::DataFieldPropertiesWidget::toggleAutoRefresh
void toggleAutoRefresh(bool)
Definition: DataFieldPropertiesWidget.cpp:79
armarx::PlotterController::setUpdateInterval
void setUpdateInterval(int value)
Definition: PlotterController.cpp:880
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::DataFieldPropertiesWidget::getDatafieldIdentifier
DataFieldIdentifierPtr getDatafieldIdentifier() const
Definition: DataFieldPropertiesWidget.cpp:69
PlotterController.h
armarx::PlotterController::plottingPaused
void plottingPaused(bool toggled)
Definition: PlotterController.cpp:330
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::PropertiesWidget::setPropertiesTitle
void setPropertiesTitle(const QString &title)
Definition: PropertiesWidget.h:65
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:174
armarx::DataFieldPropertiesWidget::~DataFieldPropertiesWidget
~DataFieldPropertiesWidget() override
Definition: DataFieldPropertiesWidget.cpp:52
IceUtil::Handle< IceManager >
armarx::VariantWidget::setEnableEdit
void setEnableEdit(bool enableEdit)
Definition: VariantWidget.cpp:105
armarx::PropertiesWidget::addWidget
void addWidget(QWidget *widget)
Definition: PropertiesWidget.h:136
armarx::DataFieldPropertiesWidget::getEnableEdit
bool getEnableEdit()
Definition: DataFieldPropertiesWidget.cpp:64
armarx::PeriodicTask
Definition: ArmarXManager.h:70
armarx::PlotterController::setShownInterval
void setShownInterval(int value)
Definition: PlotterController.cpp:931
armarx::PlotterController::setSelectedDatafields
void setSelectedDatafields(const QStringList &value, int samplingIntervalMs=-1)
Changes the datafields that are plotted.
Definition: PlotterController.cpp:848
armarx::VariantWidget::getValueText
QString getValueText()
Definition: VariantWidget.cpp:127
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PropertiesWidget::getContentLayout
QGridLayout * getContentLayout() const
Definition: PropertiesWidget.h:143
armarx::VariantWidget
Definition: VariantWidget.h:38
armarx::PropertiesWidget
Definition: PropertiesWidget.h:37