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

imported into gitlab version 2.2.1

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 375 additions and 0 deletions
This diff is collapsed.
This diff is collapsed.
# new generation cumbia-qtcontrols
## Installation
### Dependencies
Qt libraries
### Download build and install
> git clone https://github.com/ELETTRA-SincrotroneTrieste/cumbia-qtcontrols-ng.git
> cd cumbia-qtcontrols-ng
> qmake && make && make install
### Options
You can either edit cumbia-qtcontrols-ng.pri to change the *INSTALL_ROOT* installation prefix or pass the *INSTALL_ROOT=path/to/qumbia-svg* to qmake:
> qmake INSTALL_ROOT=/my/custom/dir
#### Default prefix
The default prefix is */usr/local/cumbia-libs* (includes in */usr/local/cumbia-libs/include/cumbia-qtcontrols-ng/*, libs in */usr/local/cumbia-libs/lib/* and so forth)
### Important advice
Please make sure the installation prefix is the same as that used for the *cumbia* library. This ensures proper library interoperability.
### Are you ready?
Start reading the <a href="https://elettra-sincrotronetrieste.github.io/cumbia-qtcontrols-ng/">cumbia svg library documentation</a>.
# cumbia-qtcontrols-ng
artwork/circularplots.png

277 KiB

artwork/class-diagram.png

58 KiB

artwork/old-quapplynumeric.png

2.9 KiB

artwork/qgraphicplot-zoom.png

30.9 KiB

artwork/qgraphicsplot-zoom.png

15.8 KiB

artwork/qgraphicsplot.png

23.8 KiB

artwork/qgraphicsplot2.png

27.5 KiB

artwork/quarrayplot.png

15 KiB

artwork/qucircularplot-edit.png

47.3 KiB

artwork/qunumeric-1.png

14.1 KiB

artwork/quscalarplot.png

15 KiB

#include "out_of_bounds_distortions.h"
double OOBDistort::x_distort(double x, const double &, const double &,
const double &, const double &) const {
return x;
}
double OOBDistort::y_distort(double y, const double &, const double &,
const double &, const double &) const {
return y;
}
void OOBDistort::bounds_distort(double *x, double *X, double *y, double *Y,
const double &xlb, const double &xub, const double &ylb, const double &yub,
const double &xmin, const double &xmax, const double &ymin, const double &ymax) const {
double xx = (xmax - xmin) * 0.4;
double yy = (ymax - ymin) * 0.4;
*x = xlb <= xmin ? xlb : xlb - xx;
*X = xub >= xmax ? xub : xub + xx;
*y = ylb <= ymin ? ylb : ylb - yy;
*Y = yub >= ymax ? yub : yub + yy;
}
double OOBLogDistort::x_distort(double x, const double &, const double &,
const double &, const double &) const {
return x;
}
double OOBLogDistort::y_distort(double y, const double &ylb, const double &yub,
const double &ymin, const double &ymax) const {
(void) ymin; (void) ymax;
if(y < ylb) y = ylb - log(ylb - y);
if(y > yub) y = yub + log(y - yub);
return y;
}
void OOBLogDistort::bounds_distort(double *x, double *X, double *y, double *Y,
const double &xlb, const double &xub, const double &ylb, const double &yub,
const double &xmin, const double &xmax, const double &ymin, const double &ymax) const {
double xx = (xmax - xmin) * 1.1; // x extra
double yy = (ymax - ymin) * 1.1;
double dY = ymax + yy;
double dy = ymin - yy;
double dX = xmax + xx;
double dx = xmin - xx;
*x = xlb <= xmin ? xlb : xlb - (dx > 0 ? log(dx) : log(-dx));
*X = xub >= xmax ? xub : xub + (dX > 0 ? log(dX) : log(-dX));
*y = ylb <= ymin ? ylb : ylb - (dy > 0 ? log(dy) : log(-dy));
*Y = yub >= ymax ? yub : yub + (dY > 0 ? log(dY) : log(-dY));
}
#ifndef OOBDISTORT_H
#define OOBDISTORT_H
#include <math.h>
/*!
* \brief The OOBDistort class linearly distorts (no distortion) x and y when out of bounds.
*/
class OOBDistort {
public:
virtual ~OOBDistort() {}
virtual double x_distort(double v, const double &xlb, const double& xub,
const double& xmin, const double& xmax) const;
virtual double y_distort(double v, const double &ylb, const double& yub,
const double& ymin, const double& ymax) const;
virtual void bounds_distort(double *x, double *X, double *y, double *Y, const double &xlb, const double &xub, const double &ylb, const double &yub, const double &xmin, const double &xmax, const double &ymin, const double &ymax) const;
};
/*!
* \brief Applies a logarithmic distortion to x and y values when they are out of bounds
*/
class OOBLogDistort : public OOBDistort {
public:
OOBLogDistort(float base = M_E) { m_base = base; }
virtual ~OOBLogDistort() {}
virtual double x_distort(double v, const double &xlb, const double& xub,
const double& xmin, const double& xmax) const;
virtual double y_distort(double v, const double &ylb, const double& yub,
const double& ymin, const double& ymax) const;
virtual void bounds_distort(double *x, double *X, double *y, double *Y, const double &xlb, const double &xub, const double &ylb, const double &yub, const double &xmin, const double &xmax, const double &ymin, const double &ymax) const;
float m_base;
};
#endif // OOBDISTORT_H
#ifndef QUCIRCULARPLOT_DRAWABLE_I_H
#define QUCIRCULARPLOT_DRAWABLE_I_H
class QPainter;
class QRectF;
class QWidget;
class QuCircularPlotEngine;
class QuCircularPlotDrawable_I {
public:
/*!
* \brief returns true if the drawable scales with zooming
*
* \return true the drawable scales according to the zoom. It will be painted with the painter *transform* applied
* false the drawable does not scale with the zoom. It will be painted after the painter is *restored* or
* before the transformation is applied, according to the z value
* \see z
*/
virtual bool scales() = 0;
/*!
* \brief z defines the z order of the element that is drawn
* \return the z order
*
* Drawable elements with a lower z value are drawn before.
*
* \par Important note
* Axes, curves, baseline and bounds are assumed to have z equal to 0.
* Drawables with z less than or *equal to* 0 will be drawn *before* the axes and the curves. Drawables with z greater than
* zero will be drawn *after* axes, bounds and curves.
*/
virtual int z() const = 0;
/*!
* \brief paint the drawable on the provided painter.
*
* Draw a custom shape on the painter.
* The plot engine can be used to get the plot configuration
*
* \par Note
* Inner and outer radiuses correspond to the *axes bounds*.
* The *valid* area for curves is defined between the inner_radius and the outer_radius.
* Outside this section, curves may be drawn deformed.
*
* Drawables can paint anywhere.
*
* \param p the active painter
* \param plot_e the plot engine
* \param inner_radius start of valid scale section
* \param outer_radius end of valid scale section
* \param rect the drawing area, directly from QGraphicsItem::paint
* \param widget pointer to QWidget, directly from QGraphicsItem::paint
*/
virtual void draw(QPainter *p,
const QuCircularPlotEngine *plot_e,
double inner_radius,
double outer_radius,
const QRectF &rect,
QWidget *widget) = 0;
};
#endif // QUCIRCULARPLOT_DRAWABLE_I_H
#ifndef QUCIRCULARPLOTATTRIBUTES_H
#define QUCIRCULARPLOTATTRIBUTES_H
#include <QColor>
class OOBDistort;
/*!
* \brief Holds QuCircularPlot options
*
* This struct hierarchically stores the characteristics of the plot
*
* \section axes
* Defines the axes configuration
*
* \subsection x
* Defines the x axis configuration
* - baseline
* - autoscale
* - lower bound
* - upper bound
*
* \subsection y
* Defines the y axis configuration:
* - scale_inverted
* - autoscale
* - lower bound
* - upper bound
*
* \section geom
* Defines the geometrical characteristics of the plot: the inner and outer radius representing the
* axis limits (lower and upper) and the kind of distortion that shall be applied to curves when
* their points exceed the (non automatic) Y bounds.
*
* \subsection selection
* Geometry for the selection (movable selection area and selected point on the curve)
*
* \section paint
* Contains drawing options (show hide elements) and *colors* in the dedicated section
*
* \subsection colors
* Define colors for several elements
*
* \section Note
* Whenever you change one or more attributes, you may want to trigger an immediate *update*
* on the plot (either item or widget)
*
* \section Example
*
* \code
QuCircularPlotI *ni = new QuCircularPlotI(nullptr, QSize(300, 300));
QuCircularPlotEngine *pie = ni->engine();
qucircularplot_attributes &a = pie->a;
a.axes.y.autoscale = true; // enable y axis autoscale
a.geom.inner_radius_factor = 0.1; // widen inter axes area
a.paint.colors.background = QColor(Qt::white); // light color scheme
ni->update();
* \endcode
*
*/
struct qucircularplot_attributes
{
struct {
struct {
float baseline = 0.0f;
bool autoscale = true;
double lb = -1000;
double ub = 1000; // "axis" bounds, either manual or auto
} x;
struct {
bool autoscale = true;
bool scale_inverted = false;
double lb = -1000;
double ub = 1000;
} y;
} axes;
struct {
double inner_radius_factor = 0.2; //!< where (geometrically) the lower bound is
double outer_radius_factor = 0.8; //!< where (geometrically) the upper bound is
OOBDistort *oob_distortion = nullptr; //!< "out of bounds" curve distortion
//!< defines how curves are distorted when points
//!< exceed Y axis upper and lower bounds
//!< Default must be initialized (QuCircularPlotEngine)
struct {
float aradius = 3.5; //!< radius of the (moving) circular selection area
float yp_radius = 1.2; //!< radius of the point selected on the curve
} selection; //!< selection attributes
} geom; //!< geometry attributes: inner and outer radius, radius factor
struct {
bool show_values = false; //!< show values on the plot. Default: false. OK when there's little data
bool show_points = false; //!< show data points (default: false, while show_curves is true by default)
bool show_bounds = true; //!< draw one circle on the lower bound and one on the upper (default: yes)
bool show_curves = true; //!< show the curves (lines connecting the data points): default true
bool show_xax = true; //!< show the "X" axis: default: yes on the baseline
bool show_origin = true; //!< show the "origin" at 9 o'clock default: true
int y_axes = 0; //!< number of "Y" axes to show default: 0
struct {
QColor background = QColor(Qt::white); //!< background color
QColor axes = QColor(Qt::lightGray); //!< axes color
} colors;
} paint; //!< "paint" attributes: show or hide things
};
#endif // QUCIRCULARPLOTATTRIBUTES_H
#include "qucircularplotconfigurator.h"
#include <QApplication>
#include <QSettings>
#include <QString>
#include <QPen>
#include <qucircularplotcurve.h>
#include <qupalette.h>
#include <cumacros.h>
QuCircularPlotConfigurator::QuCircularPlotConfigurator()
{
}
void QuCircularPlotConfigurator::configure(QuCircularPlotCurve *c, int curves_cnt)
{
QSettings s("elettra.eu", qApp->applicationName());
const QString& id = m_get_id(c);
QStringList groups = s.childGroups();
int idx = groups.indexOf(id);
if(c != nullptr && idx >= 0) {
s.beginGroup(id);
printf("\e[1,33m loading from settings %s\e[0m\n", qstoc(id));
/* choose a nice curve color or load it from QSettings, if defined for the application name and
* curve name.
*/
QColor curveColor = s.value("pen/color", c->pen().color()).value<QColor>();
int alpha = s.value("pen/color/alpha", c->pen().color().alpha()).toInt();
// int curveStyle = s.value("pen/style", c->style()).toInt();
double penWidth = s.value("pen/width", c->pen().widthF()).toDouble();
// bool displayYValues = s.value(id + "/show-values", false).toBool();
curveColor.setAlpha(alpha);
QPen curvePen(curveColor);
curvePen.setWidth(penWidth);
pretty_pri("pen width %f", penWidth);
c->setPen(curvePen);
// c->setProperty("showYValuesEnabled", displayYValues);
s.endGroup();
}
else if(c != nullptr) {
QuPalette palette;
QStringList colors = QStringList() << "dark_green" << "blue" << "violet"
<< "red" << "black" << "light_gray" << "yellow" << "green" << "gray"
<< "orange" << "pink" << "dark_red";
QString color_nam = colors.at(curves_cnt % colors.size());
QColor curveColor = palette.value(color_nam);
QPen curvePen(curveColor, 0.0);
c->setPen(curvePen);
}
}
QString QuCircularPlotConfigurator::m_get_id(const QuCircularPlotCurve *c) {
return c->source().replace("/", ".");
}
#ifndef QUCIRCULARPLOTCONFIGURATOR_H
#define QUCIRCULARPLOTCONFIGURATOR_H
class QuCircularPlotCurve;
#include <QString>
class QuCircularPlotConfigurator
{
public:
QuCircularPlotConfigurator();
void configure(QuCircularPlotCurve *c, int curvecnt);
QString m_get_id(const QuCircularPlotCurve *c);
};
#endif // QUCIRCULARPLOTCONFIGURATOR_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