Skip to content
Snippets Groups Projects
Commit 917ec06d authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

github -> gitlab migration

parents
No related branches found
No related tags found
No related merge requests found
v1.0: first release
This diff is collapsed.
### Adds a "Copy source" action to the right click menu of cumbia-qtcontrols widget supporting contextual menus
cumbia-qtcontrols widgets that use CuContextMenu to provide a right click menu will add a *Copy source* action
that copies the source (or target) of the widget into the *clipboard*.
The source (target) is copied as plain text.
To install the plugin, execute
- qmake
- make
- make install
after checking that the line
```
include(/usr/local/cumbia-libs/include/cumbia-qtcontrols/cumbia-qtcontrols.pri)
```
in the file cumbia-copy-source-context-menu-actions.pro is correct (in the default case,
cumbia-qtcontrols is installed under /usr/local/cumbia-libs)
Have fun.
{
"Keys" : [ ]
}
#-------------------------------------------------
#
# Project created by QtCreator 2019-09-03T15:28:56
#
#-------------------------------------------------
isEmpty(INSTALL_ROOT) {
INSTALL_ROOT = /usr/local/cumbia-libs
}
isEmpty(prefix) {
prefix = $${INSTALL_ROOT}
}
include($${INSTALL_ROOT}/include/cumbia-qtcontrols/cumbia-qtcontrols.pri)
QUMBIA_PLUGINS_LIBDIR=$${INSTALL_ROOT}/lib/qumbia-plugins
QT += core gui datavisualization
TARGET = cumbia-viewtrend-context-menu-actions
TEMPLATE = lib
CONFIG += plugin
isEmpty(buildtype) {
buildtype = release
} else {
equals(buildtype, debug) {
message("")
message("debug build")
message("")
}
}
CONFIG += $${buildtype}
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
cumbia-viewtrend-ctx-menu-action.cpp \
qutrendwidget.cpp
HEADERS += \
cumbia-viewtrend-ctx-menu-action.h \
qutrendwidget.h
DISTFILES += cumbia-viewtrend-context-menu-action.json \
README.md
unix {
target.path = $${QUMBIA_PLUGINS_LIBDIR}
INSTALLS += target
}
#include "cumbia-viewtrend-ctx-menu-action.h"
#include <cucontrolsreader_abs.h>
#include <QApplication>
#include <cucontext.h>
#include <cucontexti.h>
#include "qutrendwidget.h"
class CuViewTrendContextMenuActionPluginPrivate {
public:
QList<QAction *>m_actions;
const CuContext *m_ctx;
QPoint m_pos;
};
CuViewTrendContextMenuActionPlugin::CuViewTrendContextMenuActionPlugin(QObject *parent) : QObject(parent)
{
d = new CuViewTrendContextMenuActionPluginPrivate;
d->m_ctx = nullptr;
}
CuViewTrendContextMenuActionPlugin::~CuViewTrendContextMenuActionPlugin()
{
delete d;
}
void CuViewTrendContextMenuActionPlugin::setup(QWidget *widget, const CuContextI *cuctx)
{
d->m_pos = widget->rect().topRight();
d->m_ctx = cuctx->getContext();
if(d->m_ctx && d->m_actions.isEmpty() && cuctx && d->m_ctx->getReader()) {
QAction *a = new QAction("View Trend", this);
connect(a, SIGNAL(triggered()), this, SLOT(onActionTriggered()));
d->m_actions << a;
}
}
QList<QAction *> CuViewTrendContextMenuActionPlugin::getActions() const
{
return d->m_actions;
}
int CuViewTrendContextMenuActionPlugin::order() const
{
return -10;
}
void CuViewTrendContextMenuActionPlugin::onActionTriggered()
{
if(d->m_ctx) {
QuTrendWidget *t = new QuTrendWidget(nullptr, d->m_ctx);
t->move(d->m_pos);
t->show();
}
else
perr("CuCopySourceContextMenuActionPlugin.onActionTriggered: neither a reader nor a writer are configured");
}
#ifndef CUMBIACOPYSOURCECTXMENUACTION_H
#define CUMBIACOPYSOURCECTXMENUACTION_H
#include <cucontextmenuactionsplugin_i.h>
#include <QAction>
#include <QList>
#include <QObject>
class CuViewTrendContextMenuActionPluginPrivate;
class CuContextI;
class CuViewTrendContextMenuActionPlugin : public QObject, public CuContextMenuActionsPlugin_I
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "cumbia-viewtrend-context-menu-actions.json")
public:
explicit CuViewTrendContextMenuActionPlugin(QObject *parent = nullptr);
~CuViewTrendContextMenuActionPlugin();
Q_INTERFACES(CuContextMenuActionsPlugin_I)
// CuContextMenuActionsPlugin_I interface
public:
void setup(QWidget *widget, const CuContextI *cuctx);
QList<QAction *> getActions() const;
int order() const;
protected slots:
void onActionTriggered();
private:
CuViewTrendContextMenuActionPluginPrivate *d;
};
#endif // CUMBIACOPYSOURCECTXMENUACTION_H
#include "qutrendwidget.h"
#include <qutrendplot.h>
#include <quwatcher.h>
#include <cucontext.h>
#include <QLabel>
#include <QGridLayout>
#include <cumacros.h>
#include <QDialog>
// spectrum - 3D?
#include <cupluginloader.h>
#include <qutimearray3dplotplugin_i.h>
#include <QPushButton>
class QuTrendDialogPrivate {
public:
QWindow *m_surface;
};
QuTrendWidget::QuTrendWidget(QWidget *parent, const CuContext *ctx) : QWidget(parent) {
d = new QuTrendDialogPrivate;
d->m_surface = nullptr;
resize(700, 500);
setAttribute(Qt::WA_DeleteOnClose, true);
QGridLayout *lo = new QGridLayout(this);
QLabel *l = new QLabel("source", this);
l->setObjectName("lsrc");
QFont f = l->font();
f.setBold(true);
l->setFont(f);
l->setAlignment(Qt::AlignHCenter);
QuTrendPlot *plot = nullptr;
if(ctx && ctx->cumbia())
plot = new QuTrendPlot(this, ctx->cumbia(), *ctx->getReaderFactoryI());
else if(ctx && ctx->cumbiaPool())
plot = new QuTrendPlot(this, ctx->cumbiaPool(), ctx->getControlsFactoryPool());
lo->addWidget(l, 0, 0, 1, 7);
QPushButton *b = new QPushButton("Configure", this);
lo->addWidget(b, 0, 6, 1, 1);
if(plot) {
lo->addWidget(plot, lo->rowCount(), 0, 5, lo->columnCount());
connect(plot, SIGNAL(newData(const CuData&)), this, SLOT(onNewData(const CuData&)));
connect(findChild<QPushButton *>(), SIGNAL(clicked()), this, SLOT(showConfig()));
if(ctx->getReader()) plot->setSource(ctx->getReader()->source());
// label text and window title
l->setText(plot->source());
setWindowTitle(l->text() + " - trend");
}
}
QuTrendWidget::~QuTrendWidget() {
delete d;
}
void QuTrendWidget::onNewData(const CuData &da) {
QGridLayout *glo = findChild<QGridLayout *>();
if(da["err"].toBool()) {
}
if(da.has("data_format_str", "vector")) {
if(!d->m_surface) {
QHBoxLayout *hlo = new QHBoxLayout(this);
CuContext *ctx = nullptr;
QuTrendPlot *p = findChild<QuTrendPlot *>();
if(p) {
p->setVisible(false); // hide scalar trend plot
glo->removeWidget(p); // remove scalar trend plot from layout
glo->addLayout(hlo, glo->rowCount(), 0, 6, glo->columnCount()); // add hor layout for 3D plot
ctx = p->getContext();
CuPluginLoader ploader;
QObject *pl_obj;
QuTimeArray3DPlotPlugin_I *pi = ploader.get<QuTimeArray3DPlotPlugin_I>("qutimearray3dplotplugin.so", &pl_obj);
if(pi) {
d->m_surface = pi->create("QuTimeArray3DPlot", 0);
// d->m_surface->setFlags(d->m_surface->flags() ^ Qt::FramelessWindowHint);
d->m_surface->setProperty("maxNumRows", 100);
d->m_surface->resize(800, 800);
QWidget *container = QWidget::createWindowContainer(d->m_surface, this);
hlo->addWidget(container);
findChild<QPushButton *>()->setCheckable(true);
disconnect(findChild<QPushButton *>(), SIGNAL(clicked()), this, SLOT(showConfig()));
connect(findChild<QPushButton *>(), SIGNAL(toggled(bool)), this, SLOT(showConfig(bool)));
QuWatcher *w = nullptr;
if(ctx->cumbia() && ctx->getReaderFactoryI())
w = new QuWatcher(this, ctx->cumbia(), *ctx->getReaderFactoryI());
else if(ctx->cumbiaPool())
w = new QuWatcher(this, ctx->cumbiaPool(), ctx->getControlsFactoryPool());
if(w && ctx->getReader()) {
connect(w, SIGNAL(newData(CuData)), this, SLOT(onNewData(CuData)));
w->setSource(ctx->getReader()->source());
}
}
delete p;
}
}
double x;
CuVariant ts = da["timestamp_ms"];
ts.getType() == CuVariant::LongInt ? x = static_cast<qint64>(ts.toLongInt()) : x = ts.toDouble();
const std::vector<double> &v = da["value"].toDoubleVector();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QVector<double> qv(v.begin(), v.end()), qvx;
#else
QVector<double> qv = QVector<double>::fromStdVector(v), qvx;
#endif
for(int i = 0; i < qv.size(); i++) qvx.push_back(i);
printf("QuTrendWidget::onNewData: invoking addTimeArray wit date time %s siz %d\n",
QDateTime::fromMSecsSinceEpoch(x).toString().toStdString().c_str(), qv.size());
QMetaObject::invokeMethod(d->m_surface, "addTimeArray", Q_ARG(QString, da["src"].toString().c_str()),
Q_ARG(double, x),
Q_ARG(QVector<double>, qvx), Q_ARG(QVector<double>, qv));
}
}
void QuTrendWidget::showConfig(bool show) {
if(d->m_surface && show) {
CuPluginLoader ploader;
QObject *pl_obj;
QuTimeArray3DPlotPlugin_I *pi = ploader.get<QuTimeArray3DPlotPlugin_I>("qutimearray3dplotplugin.so", &pl_obj);
if(pi) {
QWidget *m_configW = pi->plotConfigurationWidget(d->m_surface);
m_configW->setObjectName("3dconfw");
QHBoxLayout *hlo = findChild<QHBoxLayout *>();
hlo->addWidget(m_configW);
}
}
else if(!show && d->m_surface && findChild<QWidget *>("3dconfw")) {
printf("QuTrendWidget::showConfig: deleting 3dconfw\n");
delete findChild<QWidget *>("3dconfw");
}
else if(findChild<QuTrendPlot *>()) {
QDialog *di = findChild<QuTrendPlot *>()->createConfigureDialog();
di->exec();
delete di;
}
}
#ifndef QUTRENDWIDGET_H
#define QUTRENDWIDGET_H
#include <QWidget>
#include <cucontrolsfactories_i.h>
#include <cucontrolsreader_abs.h>
class CuContext;
class QuTrendDialogPrivate;
class QuTrendWidget : public QWidget
{
Q_OBJECT
public:
explicit QuTrendWidget(QWidget *parent, const CuContext *ctx);
~QuTrendWidget();
signals:
public slots:
void onNewData(const CuData& da);
void showConfig(bool show = true);
private:
QuTrendDialogPrivate *d;
};
#endif // QUTRENDDIALOG_H
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment