From c5e540b1ff1981a00e58ed35e9359ea8ed8070e8 Mon Sep 17 00:00:00 2001 From: edouard Date: Sun, 4 Jul 2010 22:00:50 +0000 Subject: [PATCH] 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 --- .../plugins/lineardial/lineardialgadget.cpp | 4 ++- .../lineardialgadgetconfiguration.cpp | 8 ++++- .../lineardialgadgetconfiguration.h | 8 +++++ .../lineardialgadgetoptionspage.cpp | 6 +++- .../lineardial/lineardialgadgetoptionspage.ui | 31 +++++++++++++++++++ .../lineardial/lineardialgadgetwidget.cpp | 22 ++++++++----- .../lineardial/lineardialgadgetwidget.h | 6 ++-- 7 files changed, 73 insertions(+), 12 deletions(-) diff --git a/ground/src/plugins/lineardial/lineardialgadget.cpp b/ground/src/plugins/lineardial/lineardialgadget.cpp index 67575efef..af968985a 100644 --- a/ground/src/plugins/lineardial/lineardialgadget.cpp +++ b/ground/src/plugins/lineardial/lineardialgadget.cpp @@ -48,11 +48,13 @@ LineardialGadget::~LineardialGadget() void LineardialGadget::loadConfiguration(IUAVGadgetConfiguration* config) { LineardialGadgetConfiguration *m = qobject_cast(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->setGreenRange(m->getGreenMin(), m->getGreenMax()); m_widget->setYellowRange(m->getYellowMin(), m->getYellowMax()); m_widget->setRedRange(m->getRedMin(), m->getRedMax()); m_widget->setDialFile(m->getDialFile()); // Triggers widget repaint m_widget->connectInput(m->getSourceDataObject(), m->getSourceObjectField()); - m_widget->setDialFont(m->getFont()); } diff --git a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp index d8f2b6fc6..71704296c 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp +++ b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.cpp @@ -44,7 +44,9 @@ LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, co yellowMin(33), yellowMax(66), greenMin(66), - greenMax(100) + greenMax(100), + factor(1.00), + decimalPlaces(0) { //if a saved configuration exists load it if (state.count() > 0) { @@ -61,6 +63,8 @@ LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, co stream >> greenMin; stream >> greenMax; stream >> font; + stream >> decimalPlaces; + stream >> factor; } } /** @@ -93,6 +97,8 @@ QByteArray LineardialGadgetConfiguration::saveState() const stream << greenMin; stream << greenMax; stream << font; + stream << decimalPlaces; + stream << factor; return bytes; } diff --git a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h index 43fd1dca2..e317d9a2a 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h +++ b/ground/src/plugins/lineardial/lineardialgadgetconfiguration.h @@ -50,6 +50,9 @@ public: 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 setSourceObjField(QString text) { sourceObjectField = text; } @@ -66,6 +69,8 @@ public: QString getSourceDataObject() { return sourceDataObject;} QString getSourceObjectField() { return sourceObjectField;} QString getFont() { return font;} + int getDecimalPlaces() { return decimalPlaces; } + double getFactor() { return factor; } QByteArray saveState() const; IUAVGadgetConfiguration *clone(); @@ -91,6 +96,9 @@ private: double yellowMax; double greenMin; double greenMax; + double factor; + + int decimalPlaces; }; #endif // LINEARDIALGADGETCONFIGURATION_H diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp index 54a13dcee..5897b71eb 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.cpp @@ -64,6 +64,8 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent) options_page->yellowMax->setValue(m_config->getYellowMax()); options_page->redMin->setValue(m_config->getRedMin()); 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()); // Fills the combo boxes for the UAVObjects @@ -113,6 +115,8 @@ void LineardialGadgetOptionsPage::apply() m_config->setSourceDataObject(options_page->objectName->currentText()); m_config->setSourceObjField(options_page->objectField->currentText()); 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() { bool ok; - font = QFontDialog::getFont(&ok, QFont("Arial", 12), qobject_cast(this)); + font = QFontDialog::getFont(&ok, font , qobject_cast(this)); } diff --git a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui index 6dda8fd97..a59e758a3 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui +++ b/ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui @@ -447,6 +447,37 @@ + + + + Decimal places: + + + + + + + 99 + + + + + + + Factor: + + + + + + + -10000.000000000000000 + + + 100000.000000000000000 + + + diff --git a/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp b/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp index 6ad4b282e..fc595d0af 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp +++ b/ground/src/plugins/lineardial/lineardialgadgetwidget.cpp @@ -47,6 +47,8 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView( fieldValue = NULL; indexTarget = 0; indexValue = 0; + places = 0; + factor = 1; // This timer mechanism makes the index rotate smoothly connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex())); @@ -98,9 +100,9 @@ void LineardialGadgetWidget::updateIndex(UAVObject *object1) { if (field) { QString s; if (field->isNumeric()) { - double v = field->getDouble(); + double v = field->getDouble()*factor; setIndex(v); - s.sprintf("%.0f",v); + s.sprintf("%.*f",places,v); } if (field->isText()) { s = field->getValue().toString(); @@ -233,8 +235,11 @@ void LineardialGadgetWidget::setDialFile(QString dfn) // Check whether the dial wants to display a moving index: if (m_renderer->elementExists("needle")) { QMatrix textMatrix = m_renderer->matrixForElement("needle"); - startX = textMatrix.mapRect(m_renderer->boundsOnElement("needle")).x(); - startY = textMatrix.mapRect(m_renderer->boundsOnElement("needle")).y(); + QRectF nRect = textMatrix.mapRect(m_renderer->boundsOnElement("needle")); + startX = nRect.x(); + startY = nRect.y(); + //indexWidth = nRect.width(); + //indexHeight = nRect.height(); QTransform matrix; matrix.translate(startX,startY); index = new QGraphicsSvgItem(); @@ -378,12 +383,15 @@ void LineardialGadgetWidget::moveIndex() } QTransform matrix; index->resetTransform(); - qreal factor = indexValue*bargraphSize/100; + qreal trans = indexValue*bargraphSize/100; 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 { - 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); + update(); } diff --git a/ground/src/plugins/lineardial/lineardialgadgetwidget.h b/ground/src/plugins/lineardial/lineardialgadgetwidget.h index efbd13662..3cd525174 100644 --- a/ground/src/plugins/lineardial/lineardialgadgetwidget.h +++ b/ground/src/plugins/lineardial/lineardialgadgetwidget.h @@ -55,6 +55,8 @@ public: void connectInput(QString obj, QString field); void setIndex(double val); void setDialFont(QString fontProps); + void setFactor (double val) { factor = val;} + void setDecimalPlaces(int val) { places = val;} public slots: void updateIndex(UAVObject *object1); @@ -92,8 +94,6 @@ private: qreal indexHeight; qreal indexWidth; - double testVal; - double minValue; double maxValue; double greenMin; @@ -102,6 +102,8 @@ private: double yellowMax; double redMin; double redMax; + double factor; + int places; // The Value and target variables // are expressed in degrees