mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
OP-60 : new options for linear dial: number of decimal places and factor (+ bug fixes)
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1025 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
b13f8296dc
commit
c5e540b1ff
@ -48,11 +48,13 @@ LineardialGadget::~LineardialGadget()
|
|||||||
void LineardialGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
void LineardialGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||||
{
|
{
|
||||||
LineardialGadgetConfiguration *m = qobject_cast<LineardialGadgetConfiguration*>(config);
|
LineardialGadgetConfiguration *m = qobject_cast<LineardialGadgetConfiguration*>(config);
|
||||||
|
m_widget->setDialFont(m->getFont());
|
||||||
|
m_widget->setFactor(m->getFactor());
|
||||||
|
m_widget->setDecimalPlaces(m->getDecimalPlaces());
|
||||||
m_widget->setRange(m->getMin(),m->getMax());
|
m_widget->setRange(m->getMin(),m->getMax());
|
||||||
m_widget->setGreenRange(m->getGreenMin(), m->getGreenMax());
|
m_widget->setGreenRange(m->getGreenMin(), m->getGreenMax());
|
||||||
m_widget->setYellowRange(m->getYellowMin(), m->getYellowMax());
|
m_widget->setYellowRange(m->getYellowMin(), m->getYellowMax());
|
||||||
m_widget->setRedRange(m->getRedMin(), m->getRedMax());
|
m_widget->setRedRange(m->getRedMin(), m->getRedMax());
|
||||||
m_widget->setDialFile(m->getDialFile()); // Triggers widget repaint
|
m_widget->setDialFile(m->getDialFile()); // Triggers widget repaint
|
||||||
m_widget->connectInput(m->getSourceDataObject(), m->getSourceObjectField());
|
m_widget->connectInput(m->getSourceDataObject(), m->getSourceObjectField());
|
||||||
m_widget->setDialFont(m->getFont());
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,9 @@ LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, co
|
|||||||
yellowMin(33),
|
yellowMin(33),
|
||||||
yellowMax(66),
|
yellowMax(66),
|
||||||
greenMin(66),
|
greenMin(66),
|
||||||
greenMax(100)
|
greenMax(100),
|
||||||
|
factor(1.00),
|
||||||
|
decimalPlaces(0)
|
||||||
{
|
{
|
||||||
//if a saved configuration exists load it
|
//if a saved configuration exists load it
|
||||||
if (state.count() > 0) {
|
if (state.count() > 0) {
|
||||||
@ -61,6 +63,8 @@ LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, co
|
|||||||
stream >> greenMin;
|
stream >> greenMin;
|
||||||
stream >> greenMax;
|
stream >> greenMax;
|
||||||
stream >> font;
|
stream >> font;
|
||||||
|
stream >> decimalPlaces;
|
||||||
|
stream >> factor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -93,6 +97,8 @@ QByteArray LineardialGadgetConfiguration::saveState() const
|
|||||||
stream << greenMin;
|
stream << greenMin;
|
||||||
stream << greenMax;
|
stream << greenMax;
|
||||||
stream << font;
|
stream << font;
|
||||||
|
stream << decimalPlaces;
|
||||||
|
stream << factor;
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,9 @@ public:
|
|||||||
|
|
||||||
void setFont(QString text) { font = text; }
|
void setFont(QString text) { font = text; }
|
||||||
|
|
||||||
|
void setFactor(double val) { factor = val; }
|
||||||
|
void setDecimalPlaces (int val) { decimalPlaces = val; }
|
||||||
|
|
||||||
void setSourceDataObject(QString text) {sourceDataObject = text; }
|
void setSourceDataObject(QString text) {sourceDataObject = text; }
|
||||||
void setSourceObjField(QString text) { sourceObjectField = text; }
|
void setSourceObjField(QString text) { sourceObjectField = text; }
|
||||||
|
|
||||||
@ -66,6 +69,8 @@ public:
|
|||||||
QString getSourceDataObject() { return sourceDataObject;}
|
QString getSourceDataObject() { return sourceDataObject;}
|
||||||
QString getSourceObjectField() { return sourceObjectField;}
|
QString getSourceObjectField() { return sourceObjectField;}
|
||||||
QString getFont() { return font;}
|
QString getFont() { return font;}
|
||||||
|
int getDecimalPlaces() { return decimalPlaces; }
|
||||||
|
double getFactor() { return factor; }
|
||||||
|
|
||||||
QByteArray saveState() const;
|
QByteArray saveState() const;
|
||||||
IUAVGadgetConfiguration *clone();
|
IUAVGadgetConfiguration *clone();
|
||||||
@ -91,6 +96,9 @@ private:
|
|||||||
double yellowMax;
|
double yellowMax;
|
||||||
double greenMin;
|
double greenMin;
|
||||||
double greenMax;
|
double greenMax;
|
||||||
|
double factor;
|
||||||
|
|
||||||
|
int decimalPlaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LINEARDIALGADGETCONFIGURATION_H
|
#endif // LINEARDIALGADGETCONFIGURATION_H
|
||||||
|
@ -64,6 +64,8 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
options_page->yellowMax->setValue(m_config->getYellowMax());
|
options_page->yellowMax->setValue(m_config->getYellowMax());
|
||||||
options_page->redMin->setValue(m_config->getRedMin());
|
options_page->redMin->setValue(m_config->getRedMin());
|
||||||
options_page->redMax->setValue(m_config->getRedMax());
|
options_page->redMax->setValue(m_config->getRedMax());
|
||||||
|
options_page->factor->setValue(m_config->getFactor());
|
||||||
|
options_page->decPlaces->setValue(m_config->getDecimalPlaces());
|
||||||
font.fromString(m_config->getFont());
|
font.fromString(m_config->getFont());
|
||||||
|
|
||||||
// Fills the combo boxes for the UAVObjects
|
// Fills the combo boxes for the UAVObjects
|
||||||
@ -113,6 +115,8 @@ void LineardialGadgetOptionsPage::apply()
|
|||||||
m_config->setSourceDataObject(options_page->objectName->currentText());
|
m_config->setSourceDataObject(options_page->objectName->currentText());
|
||||||
m_config->setSourceObjField(options_page->objectField->currentText());
|
m_config->setSourceObjField(options_page->objectField->currentText());
|
||||||
m_config->setFont(font.toString());
|
m_config->setFont(font.toString());
|
||||||
|
m_config->setDecimalPlaces(options_page->decPlaces->value());
|
||||||
|
m_config->setFactor(options_page->factor->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +126,7 @@ void LineardialGadgetOptionsPage::apply()
|
|||||||
void LineardialGadgetOptionsPage::on_fontPicker_clicked()
|
void LineardialGadgetOptionsPage::on_fontPicker_clicked()
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
font = QFontDialog::getFont(&ok, QFont("Arial", 12), qobject_cast<QWidget*>(this));
|
font = QFontDialog::getFont(&ok, font , qobject_cast<QWidget*>(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -447,6 +447,37 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_15">
|
||||||
|
<property name="text">
|
||||||
|
<string>Decimal places:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="decPlaces">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>99</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_16">
|
||||||
|
<property name="text">
|
||||||
|
<string>Factor:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDoubleSpinBox" name="factor">
|
||||||
|
<property name="minimum">
|
||||||
|
<double>-10000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<double>100000.000000000000000</double>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -47,6 +47,8 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(
|
|||||||
fieldValue = NULL;
|
fieldValue = NULL;
|
||||||
indexTarget = 0;
|
indexTarget = 0;
|
||||||
indexValue = 0;
|
indexValue = 0;
|
||||||
|
places = 0;
|
||||||
|
factor = 1;
|
||||||
|
|
||||||
// This timer mechanism makes the index rotate smoothly
|
// This timer mechanism makes the index rotate smoothly
|
||||||
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
|
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
|
||||||
@ -98,9 +100,9 @@ void LineardialGadgetWidget::updateIndex(UAVObject *object1) {
|
|||||||
if (field) {
|
if (field) {
|
||||||
QString s;
|
QString s;
|
||||||
if (field->isNumeric()) {
|
if (field->isNumeric()) {
|
||||||
double v = field->getDouble();
|
double v = field->getDouble()*factor;
|
||||||
setIndex(v);
|
setIndex(v);
|
||||||
s.sprintf("%.0f",v);
|
s.sprintf("%.*f",places,v);
|
||||||
}
|
}
|
||||||
if (field->isText()) {
|
if (field->isText()) {
|
||||||
s = field->getValue().toString();
|
s = field->getValue().toString();
|
||||||
@ -233,8 +235,11 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
|
|||||||
// Check whether the dial wants to display a moving index:
|
// Check whether the dial wants to display a moving index:
|
||||||
if (m_renderer->elementExists("needle")) {
|
if (m_renderer->elementExists("needle")) {
|
||||||
QMatrix textMatrix = m_renderer->matrixForElement("needle");
|
QMatrix textMatrix = m_renderer->matrixForElement("needle");
|
||||||
startX = textMatrix.mapRect(m_renderer->boundsOnElement("needle")).x();
|
QRectF nRect = textMatrix.mapRect(m_renderer->boundsOnElement("needle"));
|
||||||
startY = textMatrix.mapRect(m_renderer->boundsOnElement("needle")).y();
|
startX = nRect.x();
|
||||||
|
startY = nRect.y();
|
||||||
|
//indexWidth = nRect.width();
|
||||||
|
//indexHeight = nRect.height();
|
||||||
QTransform matrix;
|
QTransform matrix;
|
||||||
matrix.translate(startX,startY);
|
matrix.translate(startX,startY);
|
||||||
index = new QGraphicsSvgItem();
|
index = new QGraphicsSvgItem();
|
||||||
@ -378,12 +383,15 @@ void LineardialGadgetWidget::moveIndex()
|
|||||||
}
|
}
|
||||||
QTransform matrix;
|
QTransform matrix;
|
||||||
index->resetTransform();
|
index->resetTransform();
|
||||||
qreal factor = indexValue*bargraphSize/100;
|
qreal trans = indexValue*bargraphSize/100;
|
||||||
if (verticalDial) {
|
if (verticalDial) {
|
||||||
matrix.translate(startX-indexWidth/2,factor+startY-indexHeight/2);
|
//matrix.translate(startX-indexWidth/2,trans+startY-indexHeight/2);
|
||||||
|
matrix.translate(startX,trans+startY);
|
||||||
} else {
|
} else {
|
||||||
matrix.translate(factor+startX-indexWidth/2,startY-indexHeight/2);
|
//matrix.translate(trans+startX-indexWidth/2,startY-indexHeight/2);
|
||||||
|
matrix.translate(trans+startX,startY);
|
||||||
}
|
}
|
||||||
index->setTransform(matrix,false);
|
index->setTransform(matrix,false);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,8 @@ public:
|
|||||||
void connectInput(QString obj, QString field);
|
void connectInput(QString obj, QString field);
|
||||||
void setIndex(double val);
|
void setIndex(double val);
|
||||||
void setDialFont(QString fontProps);
|
void setDialFont(QString fontProps);
|
||||||
|
void setFactor (double val) { factor = val;}
|
||||||
|
void setDecimalPlaces(int val) { places = val;}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateIndex(UAVObject *object1);
|
void updateIndex(UAVObject *object1);
|
||||||
@ -92,8 +94,6 @@ private:
|
|||||||
qreal indexHeight;
|
qreal indexHeight;
|
||||||
qreal indexWidth;
|
qreal indexWidth;
|
||||||
|
|
||||||
double testVal;
|
|
||||||
|
|
||||||
double minValue;
|
double minValue;
|
||||||
double maxValue;
|
double maxValue;
|
||||||
double greenMin;
|
double greenMin;
|
||||||
@ -102,6 +102,8 @@ private:
|
|||||||
double yellowMax;
|
double yellowMax;
|
||||||
double redMin;
|
double redMin;
|
||||||
double redMax;
|
double redMax;
|
||||||
|
double factor;
|
||||||
|
int places;
|
||||||
|
|
||||||
// The Value and target variables
|
// The Value and target variables
|
||||||
// are expressed in degrees
|
// are expressed in degrees
|
||||||
|
Loading…
x
Reference in New Issue
Block a user