17 QQuickPaintedItem(parent),
24 currentSelectedPlotter(nullptr)
26 setFlag(ItemHasContents,
true);
28 setAcceptedMouseButtons(Qt::AllButtons);
29 setRenderTarget(QQuickPaintedItem::FramebufferObject);
31 connect(
this,
SIGNAL(widthChanged()),
this, SLOT(updateCustomPlotSize()) );
32 connect(
this,
SIGNAL(heightChanged()),
this, SLOT(updateCustomPlotSize()));
45 for (
auto graph :
static_cast<Plotter*
> (pltr)->graphList)
49 static_cast<Graph*
> (graph)->getConnection()->freeResources();
66 if (!
yarp.checkNetwork()) {
67 qCritical(
"Cannot connect to yarp network");
72 connect(plotManager,
SIGNAL(requestRepaint()),
this,SLOT(onRepaint()),Qt::QueuedConnection);
81 int c = params.count();
83 v = (
char**)malloc(
sizeof(
char*) * c);
84 for(
int i=0;i<params.count();i++){
85 v[i] = strdup(params.at(i).toLatin1().data());
90 for(
int i=0;i<params.count();i++) {
99 if (rf.
check(
"help")) {
101 for(
int i=0;i<params.count();i++) {
108 for(
int i=0;i<params.count();i++) {
115 if (rf.
check(
"local")) {
116 qWarning() <<
"--local option is deprecated. YARPScope now uses \"${YARP_PORT_PREFIX}/YARPScope/${REMOTE_PORT_NAME}\"";
120 if (rf.
check(
"rows")) {
121 qWarning() <<
"--rows option is deprecated. Use XML mode if you need more than one plot in a single window\"";
125 if (rf.
check(
"cols")) {
126 qWarning() <<
"--cols option is deprecated. Use XML mode if you need more than one plot in a single window\"";
152 if (rf.
check(
"xml")) {
154 const std::string &filename = rf.
findFile(
"xml");
155 QString f = QString(
"%1").arg(filename.data());
156 loader =
new XmlLoader(f,plotManager,
this);
157 qDebug(
"Loading file %s",filename.c_str());
160 qDebug(
"Loading from command line");
171 updateCustomPlotSize();
187 plotManager->
clear();
208 qDebug(
"Usage: yarpscope [OPTIONS]\n");
211 qDebug(
" --help Print this help and exit.\n");
213 qDebug(
" --title [string] Title of the window (default \"YARP Port Scope\")");
214 qDebug(
" --x [uint] Initial X position of the window.");
215 qDebug(
" --y [uint] Initial Y position of the window.");
216 qDebug(
" --dx [uint] Initial width of the window.");
217 qDebug(
" --dy [uint] Initial height of the window.\n");
219 qDebug(
" --interval [int] Initial refresh interval in milliseconds. (default = 50ms)\n");
222 qDebug(
" --xml [path] Path to the xml with the description of the scene (all the");
223 qDebug(
" \"simple mode\" options are discarded).\n");
225 qDebug(
"SIMPLE MODE (single remote):");
226 qDebug(
" --remote [string] Remote port to connect to.");
227 qDebug(
" --carrier [string] YARP Carrier used for connections (default \"mcast\")");
228 qDebug(
" --persistent, Make normal or persistent connections (default persistent)");
229 qDebug(
" --no-persistent");
230 qDebug(
" --index [...] Index(es) of the vector to plot.");
231 qDebug(
" It can be an [uint] or an array of [uint]s");
232 qDebug(
" --plot_title [string] Plot title (default = remote)");
233 qDebug(
" --min [float] Minimum value for the X axis (default -100)");
234 qDebug(
" --max [float] Maximum value for the X axis (default 100)");
235 qDebug(
" --size [uint] Plot size (Number of samples to plot) (default 201)");
236 qDebug(
" --bgcolor [string] Background color.");
242 qDebug(
" --color [...] Graph color(s).");
243 qDebug(
" Depending on index it must be a [string] or an array of [string]s.");
244 qDebug(R
"( --type [...] Graph type(s). Accepted values are "points", "lines" and "bars" (default = "lines"))");
245 qDebug(" Depending on index it must be a [string] or an array of [string]s.");
246 qDebug(
" --graph_size [...] Graph size(s) (thickness of the points) (default = 1)");
247 qDebug(
" Depending on index it must be a [uint] or an array of [uint]s.\n");
252 qDebug(
"LEGACY OPTIONS (deprecated and unused):");
253 qDebug(
" --local [string] Use YARP_PORT_PREFIX environment variable to modify default value.");
254 qDebug(
" --rows [uint] Only one plot is supported from command line. Use XML mode instead.");
255 qDebug(
" --cols [uint] Only one plot is supported from command line. Use XML mode instead.");
259void QtYARPScope::onRepaint()
275 int w = painter->device()->width();
276 int h = painter->device()->height();
278 for (
int i=0; i<plotManager->
getPlotters()->count();i++)
280 painter->beginNativePainting();
283 int hSpan = plotter->hspan;
284 int vSpan = plotter->vspan;
285 int plotterWidth = (w/cols) * hSpan;
286 int plotterHeight = (h/rows) * vSpan;
288 QPixmap picture(QSize(plotter->customPlot.width() * plotter->customPlot.devicePixelRatio(),
289 plotter->customPlot.height() * plotter->customPlot.devicePixelRatio()));
291 QCPPainter qcpPainter( &picture );
292 plotter->customPlot.toPainter( &qcpPainter );
293 QRectF r = QRectF(plotter->gridx * plotterWidth/hSpan,
294 plotter->gridy * plotterHeight/vSpan,
295 picture.rect().width(),picture.rect().height());
296 plotter->setPaintGeometry(r);
297 painter->drawPixmap(r,picture,QRectF(0,0,plotterWidth,plotterHeight) );
299 painter->endNativePainting();
347void QtYARPScope::graphClicked( QCPAbstractPlottable* plottable )
362 for (
int i=0; i<plotManager->
getPlotters()->count();i++)
365 QRectF r = plotter->paintRectGeometry;
368 QPoint pos = QPoint(x - r.x(), y - r.y());
369 QMouseEvent* newEvent =
new QMouseEvent( event->type(), pos, event->button(), event->buttons(), event->modifiers() );
370 QCoreApplication::postEvent( &plotter->customPlot, newEvent,Qt::HighEventPriority );
383#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
384 int x =
event->position().x();
385 int y =
event->position().y();
391 for (
int i=0; i<plotManager->
getPlotters()->count();i++)
394 QRectF r = plotter->paintRectGeometry;
397 QPoint pos = QPoint(x - r.x(), y - r.y());
398#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
399 QWheelEvent* newEvent =
new QWheelEvent(pos,
400 event->globalPosition(),
409 QWheelEvent* newEvent =
new QWheelEvent(pos, event->angleDelta().y(), event->buttons(), event->modifiers() );
411 QCoreApplication::postEvent( &plotter->customPlot, newEvent );
421void QtYARPScope::updateCustomPlotSize()
424 if(loader ==
nullptr){
432 int plottersCount = plotManager->
getPlotters()->count();
433 for(
int i=0; i<plottersCount; i++){
436 int hSpan = plotter->hspan;
437 int vSpan = plotter->vspan;
438 int plotterWidth = (w/cols) * hSpan;
439 int plotterHeight = (h/rows) * vSpan;
441 plotter->customPlot.setGeometry(0,0,plotterWidth,plotterHeight);
int SIGNAL(int pid, int signum)
Class representing a Graph.
The Manager of the plotters.
void playPressed(bool check)
Sets the play or pause state.
void setInterval(int interval)
Sets the refresh interval.
void clear()
Clear all plotters datas.
QList< QObject * > * getPlotters()
Returns a list of all plotters.
void rescale()
Rescale all plotters.
Class representing a Plotter.
void mouseMoveEvent(QMouseEvent *event) override
the mouse move event
void intervalLoaded(int interval)
void mouseDoubleClickEvent(QMouseEvent *event) override
the mouse double click event
void usage()
Prints the help menu.
Q_INVOKABLE bool parseParameters(QStringList params)
parse the parameters received from the main container in QstringList form
void paint(QPainter *painter) override
paint method.
Q_INVOKABLE void rescale()
rescales the graphs in order to contains the maximum and minimum value visible in the window
Q_INVOKABLE void changeInterval(int interval)
changes the refresh interval
void routeMouseEvents(QMouseEvent *event)
this function is used to route the mouse events on the core plugin to the relative QCustomPlot.
Q_INVOKABLE void clear()
clears the data in the current window
QtYARPScope(QQuickItem *parent=0)
void setWindowSize(int w, int h)
void setWindowTitle(QString title)
void mouseReleaseEvent(QMouseEvent *event) override
the mouse release event
void setWindowPosition(int x, int y)
void mousePressEvent(QMouseEvent *event) override
the mouse press event
Q_INVOKABLE void playPressed(int check)
plays or pauses the data flow
void wheelEvent(QWheelEvent *event) override
the wheel mouse event
Reads a configuration from a xml file.
Reads a configuration from a xml file.
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
std::string toString() const override
Return a standard text representation of the content of the object.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
std::string findFile(const std::string &name)
Find the full path to a file.
bool setDefaultConfigFile(const std::string &fname)
Provide a default value for the configuration file (can be overridden from command line with the –fro...
virtual bool isString() const
Checks if value is a string.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual bool isInt32() const
Checks if value is a 32-bit integer.
virtual std::string asString() const
Get string value.
The main, catch-all namespace for YARP.