mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-1474 Added Axis labels to curves.
This commit is contained in:
parent
e4d6171f2c
commit
25cf7fcaf5
@ -150,6 +150,9 @@ ConfigMultiRotorWidget::ConfigMultiRotorWidget(QWidget *parent) :
|
||||
|
||||
// Connect the multirotor motor reverse checkbox
|
||||
connect(m_aircraft->MultirotorRevMixerCheckBox, SIGNAL(clicked(bool)), this, SLOT(reverseMultirotorMotor()));
|
||||
|
||||
m_aircraft->multiThrottleCurve->setXAxisLabel(tr("Input"));
|
||||
m_aircraft->multiThrottleCurve->setYAxisLabel(tr("Output"));
|
||||
updateEnableControls();
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ GUIConfigDataUnion VehicleConfig::getConfigData()
|
||||
}
|
||||
|
||||
// sanity check
|
||||
//Q_ASSERT(SystemSettings::GUICONFIGDATA_NUMELEM == (sizeof(configData.UAVObject) / sizeof(configData.UAVObject[0])));
|
||||
// Q_ASSERT(SystemSettings::GUICONFIGDATA_NUMELEM == (sizeof(configData.UAVObject) / sizeof(configData.UAVObject[0])));
|
||||
|
||||
return configData;
|
||||
}
|
||||
|
@ -129,14 +129,15 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa
|
||||
connect(ui->enableThrustPIDScalingCheckBox, SIGNAL(toggled(bool)), ui->ThrustPIDTarget, SLOT(setEnabled(bool)));
|
||||
connect(ui->enableThrustPIDScalingCheckBox, SIGNAL(toggled(bool)), ui->ThrustPIDAxis, SLOT(setEnabled(bool)));
|
||||
connect(ui->enableThrustPIDScalingCheckBox, SIGNAL(toggled(bool)), ui->thrustPIDScalingCurve, SLOT(setEnabled(bool)));
|
||||
ui->thrustPIDScalingCurve->setMixerType(MixerCurve::MIXERCURVE_TPA);
|
||||
ui->thrustPIDScalingCurve->setMin(-1);
|
||||
ui->thrustPIDScalingCurve->setMax(1);
|
||||
ui->thrustPIDScalingCurve->setXAxisLabel(tr("Thrust"));
|
||||
ui->thrustPIDScalingCurve->setYAxisLabel(tr("Scaling factor"));
|
||||
ui->thrustPIDScalingCurve->setMin(-0.5);
|
||||
ui->thrustPIDScalingCurve->setMax(0.5);
|
||||
|
||||
addWidget(ui->defaultThrottleCurveButton);
|
||||
addWidget(ui->enableThrustPIDScalingCheckBox);
|
||||
addWidget(ui->thrustPIDScalingCurve);
|
||||
addWidget(ui->thrustPIDScalingCurve->getCurveWidget());
|
||||
addWidget(ui->thrustPIDScalingCurve);
|
||||
connect(this, SIGNAL(widgetContentsChanged(QWidget *)), this, SLOT(processLinkedWidgets(QWidget *)));
|
||||
|
||||
connect(this, SIGNAL(autoPilotConnected()), this, SLOT(onBoardConnected()));
|
||||
@ -169,6 +170,7 @@ void ConfigStabilizationWidget::updateObjectsFromWidgets()
|
||||
void ConfigStabilizationWidget::updateThrottleCurveFromObject()
|
||||
{
|
||||
UAVObject *stabBank = getObjectManager()->getObject(QString(m_pidTabBars.at(0)->tabData(m_currentPIDBank).toString()));
|
||||
|
||||
Q_ASSERT(stabBank);
|
||||
qDebug() << "updatingCurveFromObject" << stabBank->getName();
|
||||
|
||||
@ -194,13 +196,14 @@ void ConfigStabilizationWidget::updateThrottleCurveFromObject()
|
||||
void ConfigStabilizationWidget::updateObjectFromThrottleCurve()
|
||||
{
|
||||
UAVObject *stabBank = getObjectManager()->getObject(QString(m_pidTabBars.at(0)->tabData(m_currentPIDBank).toString()));
|
||||
|
||||
Q_ASSERT(stabBank);
|
||||
qDebug() << "updatingObjectFromCurve" << stabBank->getName();
|
||||
|
||||
UAVObjectField *field = stabBank->getField("ThrustPIDScaleCurve");
|
||||
Q_ASSERT(field);
|
||||
|
||||
QList<double> curve = ui->thrustPIDScalingCurve->getCurve();
|
||||
QList<double> curve = ui->thrustPIDScalingCurve->getCurve();
|
||||
for (quint32 i = 0; i < field->getNumElements(); i++) {
|
||||
field->setValue(curve.at(i), i);
|
||||
qDebug() << field->getName() << field->getElementNames().at(i) << "<=" << curve.at(i);
|
||||
@ -213,7 +216,8 @@ void ConfigStabilizationWidget::updateObjectFromThrottleCurve()
|
||||
|
||||
void ConfigStabilizationWidget::resetThrottleCurveToDefault()
|
||||
{
|
||||
UAVDataObject *defaultStabBank = (UAVDataObject*)getObjectManager()->getObject(QString(m_pidTabBars.at(0)->tabData(m_currentPIDBank).toString()));
|
||||
UAVDataObject *defaultStabBank = (UAVDataObject *)getObjectManager()->getObject(QString(m_pidTabBars.at(0)->tabData(m_currentPIDBank).toString()));
|
||||
|
||||
Q_ASSERT(defaultStabBank);
|
||||
defaultStabBank = defaultStabBank->dirtyClone();
|
||||
|
||||
|
@ -96,14 +96,6 @@ void MixerCurve::setMixerType(MixerCurveType curveType)
|
||||
m_mixerUI->CurveMax->setMinimum(-1.0);
|
||||
break;
|
||||
}
|
||||
case MixerCurve::MIXERCURVE_TPA:
|
||||
{
|
||||
m_mixerUI->SettingsGroup->setTitle("Thrust PID Scale");
|
||||
m_mixerUI->buttonGroup->hide();
|
||||
m_curve->setRange(-1.0, 1.0);
|
||||
m_mixerUI->CurveMin->setMinimum(-1.0);
|
||||
m_mixerUI->CurveMax->setMinimum(-1.0);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -304,6 +296,16 @@ double MixerCurve::setRange(double min, double max)
|
||||
return m_curve->setRange(min, max);
|
||||
}
|
||||
|
||||
void MixerCurve::setXAxisLabel(QString label)
|
||||
{
|
||||
m_curve->setXAxisLabel(label);
|
||||
}
|
||||
|
||||
void MixerCurve::setYAxisLabel(QString label)
|
||||
{
|
||||
m_curve->setYAxisLabel(label);
|
||||
}
|
||||
|
||||
double MixerCurve::getCurveMin()
|
||||
{
|
||||
return m_mixerUI->CurveMin->value();
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
|
||||
|
||||
/* Enumeration options for ThrottleCurves */
|
||||
typedef enum { MIXERCURVE_THROTTLE = 0, MIXERCURVE_PITCH = 1, MIXERCURVE_TPA = 2 } MixerCurveType;
|
||||
typedef enum { MIXERCURVE_THROTTLE = 0, MIXERCURVE_PITCH = 1 } MixerCurveType;
|
||||
|
||||
void setMixerType(MixerCurveType curveType);
|
||||
void initCurve(const QList<double> *points);
|
||||
@ -68,6 +68,9 @@ public:
|
||||
double getCurveStep();
|
||||
double setRange(double min, double max);
|
||||
|
||||
void setXAxisLabel(QString label);
|
||||
void setYAxisLabel(QString label);
|
||||
|
||||
MixerCurveWidget *getCurveWidget()
|
||||
{
|
||||
return m_curve;
|
||||
|
@ -136,8 +136,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>860</width>
|
||||
<height>703</height>
|
||||
<width>844</width>
|
||||
<height>726</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
@ -7836,7 +7836,7 @@ border-radius: 5;</string>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<y>-295</y>
|
||||
<width>844</width>
|
||||
<height>998</height>
|
||||
</rect>
|
||||
@ -16192,7 +16192,7 @@ border-radius: 5;</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_27">
|
||||
<item row="0" column="1">
|
||||
<widget class="MixerCurve" name="thrustPIDScalingCurve" native="true">
|
||||
<widget class="MixerCurveWidget" name="thrustPIDScalingCurve" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
@ -16205,6 +16205,11 @@ border-radius: 5;</string>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>7</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3" rowspan="3" alignment="Qt::AlignTop">
|
||||
@ -27072,9 +27077,9 @@ Useful if you have accidentally changed some settings.</string>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>MixerCurve</class>
|
||||
<class>MixerCurveWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">mixercurve.h</header>
|
||||
<header location="global">mixercurvewidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
@ -37,32 +37,33 @@
|
||||
#include "mixercurvewidget.h"
|
||||
|
||||
MixerNode::MixerNode(MixerCurveWidget *graphWidget)
|
||||
: graph(graphWidget)
|
||||
: m_graph(graphWidget)
|
||||
{
|
||||
setFlag(ItemIsMovable);
|
||||
setFlag(ItemSendsGeometryChanges);
|
||||
setCacheMode(DeviceCoordinateCache);
|
||||
setZValue(-1);
|
||||
vertical = false;
|
||||
drawNode = true;
|
||||
drawText = true;
|
||||
m_vertical = false;
|
||||
m_drawNode = true;
|
||||
m_drawText = true;
|
||||
|
||||
positiveColor = "#609FF2"; // blueish?
|
||||
neutralColor = "#14CE24"; // greenish?
|
||||
negativeColor = "#EF5F5F"; // redish?
|
||||
disabledColor = "#dddddd";
|
||||
disabledTextColor = "#aaaaaa";
|
||||
m_alpha = 0.7;
|
||||
m_positiveColor = "#609FF2"; // blueish?
|
||||
m_neutralColor = "#14CE24"; // greenish?
|
||||
m_negativeColor = "#EF5F5F"; // redish?
|
||||
m_disabledColor = "#dddddd";
|
||||
m_disabledTextColor = "#aaaaaa";
|
||||
}
|
||||
|
||||
void MixerNode::addEdge(Edge *edge)
|
||||
{
|
||||
edgeList << edge;
|
||||
m_edgeList << edge;
|
||||
edge->adjust();
|
||||
}
|
||||
|
||||
QList<Edge *> MixerNode::edges() const
|
||||
{
|
||||
return edgeList;
|
||||
return m_edgeList;
|
||||
}
|
||||
|
||||
|
||||
@ -83,18 +84,19 @@ void MixerNode::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
{
|
||||
QString text = QString().sprintf("%.2f", value());
|
||||
|
||||
painter->setFont(graph->font());
|
||||
if (drawNode) {
|
||||
painter->setFont(m_graph->font());
|
||||
if (m_drawNode) {
|
||||
QRadialGradient gradient(-3, -3, 10);
|
||||
|
||||
QColor color;
|
||||
if (value() < 0) {
|
||||
color = negativeColor;
|
||||
color = m_negativeColor;
|
||||
} else if (value() == 0) {
|
||||
color = neutralColor;
|
||||
color = m_neutralColor;
|
||||
} else {
|
||||
color = positiveColor;
|
||||
color = m_positiveColor;
|
||||
}
|
||||
color.setAlphaF(m_alpha);
|
||||
|
||||
if (option->state & QStyle::State_Sunken) {
|
||||
gradient.setCenter(3, 3);
|
||||
@ -104,23 +106,23 @@ void MixerNode::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
gradient.setColorAt(1, selColor.darker());
|
||||
gradient.setColorAt(0, selColor);
|
||||
} else {
|
||||
gradient.setColorAt(0, graph->isEnabled() ? color : disabledColor);
|
||||
gradient.setColorAt(1, graph->isEnabled() ? color.darker() : disabledColor);
|
||||
gradient.setColorAt(0, m_graph->isEnabled() ? color : m_disabledColor);
|
||||
gradient.setColorAt(1, m_graph->isEnabled() ? color.darker() : m_disabledColor);
|
||||
}
|
||||
painter->setBrush(gradient);
|
||||
painter->setPen(graph->isEnabled() ? QPen(Qt::black, 0) : QPen(disabledTextColor));
|
||||
painter->setPen(m_graph->isEnabled() ? QPen(Qt::black, 0) : QPen(m_disabledTextColor));
|
||||
painter->drawEllipse(boundingRect());
|
||||
|
||||
if (!image.isNull()) {
|
||||
painter->drawImage(boundingRect().adjusted(1, 1, -1, -1), image);
|
||||
if (!m_image.isNull()) {
|
||||
painter->drawImage(boundingRect().adjusted(1, 1, -1, -1), m_image);
|
||||
}
|
||||
}
|
||||
|
||||
if (drawText) {
|
||||
if (graph->isEnabled()) {
|
||||
painter->setPen(QPen(drawNode ? Qt::white : Qt::black, 0));
|
||||
if (m_drawText) {
|
||||
if (m_graph->isEnabled()) {
|
||||
painter->setPen(QPen(m_drawNode ? Qt::white : Qt::black, 0));
|
||||
} else {
|
||||
painter->setPen(QPen(disabledTextColor));
|
||||
painter->setPen(QPen(m_disabledTextColor));
|
||||
}
|
||||
|
||||
painter->drawText((value() < 0) ? -10 : -8, 3, text);
|
||||
@ -129,27 +131,27 @@ void MixerNode::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
||||
void MixerNode::verticalMove(bool flag)
|
||||
{
|
||||
vertical = flag;
|
||||
m_vertical = flag;
|
||||
}
|
||||
|
||||
double MixerNode::value()
|
||||
{
|
||||
double h = graph->sceneRect().height();
|
||||
double h = m_graph->sceneRect().height();
|
||||
double ratio = (h - pos().y()) / h;
|
||||
|
||||
return ((graph->getMax() - graph->getMin()) * ratio) + graph->getMin();
|
||||
return ((m_graph->getMax() - m_graph->getMin()) * ratio) + m_graph->getMin();
|
||||
}
|
||||
|
||||
|
||||
QVariant MixerNode::itemChange(GraphicsItemChange change, const QVariant &val)
|
||||
{
|
||||
QPointF newPos = val.toPointF();
|
||||
double h = graph->sceneRect().height();
|
||||
double h = m_graph->sceneRect().height();
|
||||
|
||||
switch (change) {
|
||||
case ItemPositionChange:
|
||||
{
|
||||
if (!vertical) {
|
||||
if (!m_vertical) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -169,12 +171,12 @@ QVariant MixerNode::itemChange(GraphicsItemChange change, const QVariant &val)
|
||||
}
|
||||
case ItemPositionHasChanged:
|
||||
{
|
||||
foreach(Edge * edge, edgeList)
|
||||
foreach(Edge * edge, m_edgeList)
|
||||
edge->adjust();
|
||||
|
||||
update();
|
||||
|
||||
graph->itemMoved(value());
|
||||
m_graph->itemMoved(value());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -59,27 +59,32 @@ public:
|
||||
|
||||
void setPositiveColor(QColor color = "#609FF2")
|
||||
{
|
||||
positiveColor = color;
|
||||
m_positiveColor = color;
|
||||
}
|
||||
|
||||
void setNegativeColor(QColor color = "#EF5F5F")
|
||||
{
|
||||
negativeColor = color;
|
||||
m_negativeColor = color;
|
||||
}
|
||||
|
||||
void setAlpha(qreal alpha)
|
||||
{
|
||||
m_alpha = alpha;
|
||||
}
|
||||
|
||||
void setImage(QImage img)
|
||||
{
|
||||
image = img;
|
||||
m_image = img;
|
||||
}
|
||||
|
||||
void setDrawNode(bool draw)
|
||||
{
|
||||
drawNode = draw;
|
||||
m_drawNode = draw;
|
||||
}
|
||||
|
||||
void setDrawText(bool draw)
|
||||
{
|
||||
drawText = draw;
|
||||
m_drawText = draw;
|
||||
}
|
||||
|
||||
QRectF boundingRect() const;
|
||||
@ -95,22 +100,23 @@ protected:
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
private:
|
||||
QList<Edge *> edgeList;
|
||||
QPointF newPos;
|
||||
MixerCurveWidget *graph;
|
||||
QList<Edge *> m_edgeList;
|
||||
QPointF m_newPos;
|
||||
MixerCurveWidget *m_graph;
|
||||
|
||||
QColor positiveColor;
|
||||
QColor neutralColor;
|
||||
QColor negativeColor;
|
||||
QColor disabledColor;
|
||||
QColor disabledTextColor;
|
||||
qreal m_alpha;
|
||||
QColor m_positiveColor;
|
||||
QColor m_neutralColor;
|
||||
QColor m_negativeColor;
|
||||
QColor m_disabledColor;
|
||||
QColor m_disabledTextColor;
|
||||
|
||||
QImage image;
|
||||
QImage m_image;
|
||||
|
||||
bool vertical;
|
||||
bool drawNode;
|
||||
bool drawText;
|
||||
int index;
|
||||
bool m_vertical;
|
||||
bool m_drawNode;
|
||||
bool m_drawText;
|
||||
int m_index;
|
||||
};
|
||||
|
||||
#endif // MIXERCURVEPOINT_H
|
||||
|
@ -36,7 +36,8 @@
|
||||
/*
|
||||
* Initialize the widget
|
||||
*/
|
||||
MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
|
||||
MixerCurveWidget::MixerCurveWidget(QWidget *parent) :
|
||||
QGraphicsView(parent), m_xAxisTextItem(0), m_yAxisTextItem(0)
|
||||
{
|
||||
// Create a layout, add a QGraphicsView and put the SVG inside.
|
||||
// The Mixer Curve widget looks like this:
|
||||
@ -54,50 +55,60 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
curveMin = 0.0;
|
||||
curveMax = 1.0;
|
||||
m_curveMin = 0.0;
|
||||
m_curveMax = 1.0;
|
||||
|
||||
setFrameStyle(QFrame::NoFrame);
|
||||
setStyleSheet("background:transparent");
|
||||
|
||||
QGraphicsScene *scene = new QGraphicsScene(this);
|
||||
QSvgRenderer *renderer = new QSvgRenderer();
|
||||
plot = new QGraphicsSvgItem();
|
||||
m_plot = new QGraphicsSvgItem();
|
||||
renderer->load(QString(":/uavobjectwidgetutils/images/curve-bg.svg"));
|
||||
plot->setSharedRenderer(renderer);
|
||||
m_plot->setSharedRenderer(renderer);
|
||||
|
||||
scene->addItem(plot);
|
||||
plot->setZValue(-1);
|
||||
scene->addItem(m_plot);
|
||||
m_plot->setZValue(-1);
|
||||
|
||||
scene->setSceneRect(plot->boundingRect());
|
||||
scene->setSceneRect(m_plot->boundingRect());
|
||||
setScene(scene);
|
||||
|
||||
setupXAxisLabel();
|
||||
setupYAxisLabel();
|
||||
initNodes(MixerCurveWidget::NODE_NUMELEM);
|
||||
}
|
||||
|
||||
MixerCurveWidget::~MixerCurveWidget()
|
||||
{
|
||||
while (!nodeList.isEmpty()) {
|
||||
delete nodeList.takeFirst();
|
||||
while (!m_nodeList.isEmpty()) {
|
||||
delete m_nodeList.takeFirst();
|
||||
}
|
||||
|
||||
while (!edgeList.isEmpty()) {
|
||||
delete edgeList.takeFirst();
|
||||
while (!m_edgeList.isEmpty()) {
|
||||
delete m_edgeList.takeFirst();
|
||||
}
|
||||
if (m_xAxisTextItem) {
|
||||
delete m_xAxisTextItem;
|
||||
m_xAxisTextItem = NULL;
|
||||
}
|
||||
if (m_yAxisTextItem) {
|
||||
delete m_yAxisTextItem;
|
||||
m_yAxisTextItem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setPositiveColor(QString color)
|
||||
{
|
||||
for (int i = 0; i < nodeList.count(); i++) {
|
||||
MixerNode *node = nodeList.at(i);
|
||||
for (int i = 0; i < m_nodeList.count(); i++) {
|
||||
MixerNode *node = m_nodeList.at(i);
|
||||
node->setPositiveColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setNegativeColor(QString color)
|
||||
{
|
||||
for (int i = 0; i < nodeList.count(); i++) {
|
||||
MixerNode *node = nodeList.at(i);
|
||||
for (int i = 0; i < m_nodeList.count(); i++) {
|
||||
MixerNode *node = m_nodeList.at(i);
|
||||
node->setNegativeColor(color);
|
||||
}
|
||||
}
|
||||
@ -120,8 +131,8 @@ void MixerCurveWidget::initCurve(const QList<double> *points)
|
||||
void MixerCurveWidget::initNodes(int numPoints)
|
||||
{
|
||||
// First of all, clear any existing list
|
||||
if (nodeList.count()) {
|
||||
foreach(MixerNode * node, nodeList) {
|
||||
if (m_nodeList.count()) {
|
||||
foreach(MixerNode * node, m_nodeList) {
|
||||
foreach(Edge * edge, node->edges()) {
|
||||
if (edge->sourceNode() == node) {
|
||||
scene()->removeItem(edge);
|
||||
@ -132,7 +143,7 @@ void MixerCurveWidget::initNodes(int numPoints)
|
||||
delete node;
|
||||
}
|
||||
|
||||
nodeList.clear();
|
||||
m_nodeList.clear();
|
||||
}
|
||||
|
||||
// Create the nodes and edges
|
||||
@ -140,7 +151,7 @@ void MixerCurveWidget::initNodes(int numPoints)
|
||||
for (int i = 0; i < numPoints; i++) {
|
||||
MixerNode *node = new MixerNode(this);
|
||||
|
||||
nodeList.append(node);
|
||||
m_nodeList.append(node);
|
||||
scene()->addItem(node);
|
||||
|
||||
node->setPos(0, 0);
|
||||
@ -153,6 +164,32 @@ void MixerCurveWidget::initNodes(int numPoints)
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setupXAxisLabel()
|
||||
{
|
||||
if (!m_xAxisString.isEmpty()) {
|
||||
if (m_xAxisTextItem) {
|
||||
m_xAxisTextItem->setPlainText(m_xAxisString);
|
||||
} else {
|
||||
m_xAxisTextItem = new QGraphicsTextItem(m_xAxisString, m_plot);
|
||||
scene()->addItem(m_xAxisTextItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setupYAxisLabel()
|
||||
{
|
||||
if (!m_yAxisString.isEmpty()) {
|
||||
if (m_yAxisTextItem) {
|
||||
m_yAxisTextItem->setPlainText(m_yAxisString);
|
||||
} else {
|
||||
m_yAxisTextItem = new QGraphicsTextItem(m_yAxisString, m_plot);
|
||||
// m_yAxisTextItem->setTransformOriginPoint(m_yAxisTextItem->boundingRect().height(), m_yAxisTextItem->boundingRect().left());
|
||||
m_yAxisTextItem->setRotation(270);
|
||||
scene()->addItem(m_yAxisTextItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the current curve settings
|
||||
*/
|
||||
@ -160,7 +197,7 @@ QList<double> MixerCurveWidget::getCurve()
|
||||
{
|
||||
QList<double> list;
|
||||
|
||||
foreach(MixerNode * node, nodeList) {
|
||||
foreach(MixerNode * node, m_nodeList) {
|
||||
list.append(node->value());
|
||||
}
|
||||
|
||||
@ -185,55 +222,51 @@ void MixerCurveWidget::initLinearCurve(int numPoints, double maxValue, double mi
|
||||
*/
|
||||
void MixerCurveWidget::setCurve(const QList<double> *points)
|
||||
{
|
||||
curveUpdating = true;
|
||||
m_curveUpdating = true;
|
||||
|
||||
int ptCnt = points->count();
|
||||
if (nodeList.count() != ptCnt) {
|
||||
if (m_nodeList.count() != ptCnt) {
|
||||
initNodes(ptCnt);
|
||||
}
|
||||
|
||||
double range = curveMax - curveMin;
|
||||
double range = m_curveMax - m_curveMin;
|
||||
|
||||
qreal w = plot->boundingRect().width() / (ptCnt - 1);
|
||||
qreal h = plot->boundingRect().height();
|
||||
qreal w = m_plot->boundingRect().width() / (ptCnt - 1);
|
||||
qreal h = m_plot->boundingRect().height();
|
||||
for (int i = 0; i < ptCnt; i++) {
|
||||
double val = (points->at(i) < curveMin) ? curveMin : (points->at(i) > curveMax) ? curveMax : points->at(i);
|
||||
double val = (points->at(i) < m_curveMin) ? m_curveMin : (points->at(i) > m_curveMax) ? m_curveMax : points->at(i);
|
||||
|
||||
val += range;
|
||||
val -= (curveMin + range);
|
||||
val -= (m_curveMin + range);
|
||||
val /= range;
|
||||
|
||||
MixerNode *node = nodeList.at(i);
|
||||
MixerNode *node = m_nodeList.at(i);
|
||||
node->setPos(w * i, h - (val * h));
|
||||
node->verticalMove(true);
|
||||
|
||||
node->update();
|
||||
}
|
||||
curveUpdating = false;
|
||||
m_curveUpdating = false;
|
||||
|
||||
update();
|
||||
|
||||
emit curveUpdated();
|
||||
}
|
||||
|
||||
|
||||
void MixerCurveWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
// Thit fitInView method should only be called now, once the
|
||||
// widget is shown, otherwise it cannot compute its values and
|
||||
// the result is usually a ahrsbargraph that is way too small.
|
||||
|
||||
QRectF rect = plot->boundingRect();
|
||||
fitInView(rect.adjusted(-12, -12, 12, 12), Qt::KeepAspectRatio);
|
||||
positionAxisLabels();
|
||||
setSceneRect(scene()->itemsBoundingRect());
|
||||
fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void MixerCurveWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
QRectF rect = plot->boundingRect();
|
||||
fitInView(rect.adjusted(-12, -12, 12, 12), Qt::KeepAspectRatio);
|
||||
positionAxisLabels();
|
||||
setSceneRect(scene()->itemsBoundingRect());
|
||||
fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void MixerCurveWidget::changeEvent(QEvent *event)
|
||||
@ -241,50 +274,77 @@ void MixerCurveWidget::changeEvent(QEvent *event)
|
||||
QGraphicsView::changeEvent(event);
|
||||
|
||||
if (event->type() == QEvent::EnabledChange) {
|
||||
foreach(MixerNode * node, nodeList) {
|
||||
foreach(MixerNode * node, m_nodeList) {
|
||||
node->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::positionAxisLabels()
|
||||
{
|
||||
QRectF rect = m_plot->boundingRect();
|
||||
|
||||
if (m_xAxisTextItem) {
|
||||
m_xAxisTextItem->setPos(rect.right() -
|
||||
m_xAxisTextItem->boundingRect().width(), rect.bottom() - 4);
|
||||
}
|
||||
|
||||
if (m_yAxisTextItem) {
|
||||
m_yAxisTextItem->setPos(rect.left() -
|
||||
m_yAxisTextItem->boundingRect().height(), m_yAxisTextItem->boundingRect().width());
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::itemMoved(double itemValue)
|
||||
{
|
||||
Q_UNUSED(itemValue);
|
||||
|
||||
if (!curveUpdating) {
|
||||
if (!m_curveUpdating) {
|
||||
emit curveUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setMin(double value)
|
||||
{
|
||||
if (curveMin != value) {
|
||||
if (m_curveMin != value) {
|
||||
emit curveMinChanged(value);
|
||||
}
|
||||
|
||||
curveMin = value;
|
||||
m_curveMin = value;
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setMax(double value)
|
||||
{
|
||||
if (curveMax != value) {
|
||||
if (m_curveMax != value) {
|
||||
emit curveMaxChanged(value);
|
||||
}
|
||||
|
||||
curveMax = value;
|
||||
m_curveMax = value;
|
||||
}
|
||||
|
||||
double MixerCurveWidget::getMin()
|
||||
{
|
||||
return curveMin;
|
||||
return m_curveMin;
|
||||
}
|
||||
double MixerCurveWidget::getMax()
|
||||
{
|
||||
return curveMax;
|
||||
return m_curveMax;
|
||||
}
|
||||
double MixerCurveWidget::setRange(double min, double max)
|
||||
{
|
||||
curveMin = min;
|
||||
curveMax = max;
|
||||
return curveMax - curveMin;
|
||||
m_curveMin = min;
|
||||
m_curveMax = max;
|
||||
return m_curveMax - m_curveMin;
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setXAxisLabel(QString label)
|
||||
{
|
||||
m_xAxisString = label;
|
||||
setupXAxisLabel();
|
||||
}
|
||||
|
||||
void MixerCurveWidget::setYAxisLabel(QString label)
|
||||
{
|
||||
m_yAxisString = label;
|
||||
setupYAxisLabel();
|
||||
}
|
||||
|
@ -41,6 +41,8 @@ class UAVOBJECTWIDGETUTILS_EXPORT MixerCurveWidget : public QGraphicsView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static const int NODE_NUMELEM = 5;
|
||||
|
||||
MixerCurveWidget(QWidget *parent = 0);
|
||||
~MixerCurveWidget();
|
||||
|
||||
@ -57,34 +59,44 @@ public:
|
||||
double getMax();
|
||||
double setRange(double min, double max);
|
||||
|
||||
static const int NODE_NUMELEM = 5;
|
||||
public slots:
|
||||
void setXAxisLabel(QString label);
|
||||
void setYAxisLabel(QString label);
|
||||
|
||||
signals:
|
||||
void curveUpdated();
|
||||
void curveMinChanged(double value);
|
||||
void curveMaxChanged(double value);
|
||||
|
||||
private slots:
|
||||
|
||||
private:
|
||||
QGraphicsSvgItem *plot;
|
||||
|
||||
QList<Edge *> edgeList;
|
||||
QList<MixerNode *> nodeList;
|
||||
|
||||
double curveMin;
|
||||
double curveMax;
|
||||
bool curveUpdating;
|
||||
|
||||
void initNodes(int numPoints);
|
||||
void setPositiveColor(QString color);
|
||||
void setNegativeColor(QString color);
|
||||
|
||||
void resizeCommands();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void changeEvent(QEvent *event);
|
||||
|
||||
private slots:
|
||||
void positionAxisLabels();
|
||||
|
||||
private:
|
||||
QGraphicsSvgItem *m_plot;
|
||||
QGraphicsTextItem *m_xAxisTextItem;
|
||||
QGraphicsTextItem *m_yAxisTextItem;
|
||||
|
||||
QList<Edge *> m_edgeList;
|
||||
QList<MixerNode *> m_nodeList;
|
||||
|
||||
QString m_xAxisString;
|
||||
QString m_yAxisString;
|
||||
|
||||
double m_curveMin;
|
||||
double m_curveMax;
|
||||
bool m_curveUpdating;
|
||||
|
||||
void initNodes(int numPoints);
|
||||
void setupXAxisLabel();
|
||||
void setupYAxisLabel();
|
||||
void setPositiveColor(QString color);
|
||||
void setNegativeColor(QString color);
|
||||
|
||||
void resizeCommands();
|
||||
};
|
||||
#endif /* MIXERCURVEWIDGET_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user