diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/fieldtreeitem.h b/ground/openpilotgcs/src/plugins/uavobjectbrowser/fieldtreeitem.h index 366121d00..bd980749f 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/fieldtreeitem.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/fieldtreeitem.h @@ -48,8 +48,6 @@ #define QINT32MAX std::numeric_limits::max() #define QUINT32MAX std::numeric_limits::max() -//#define USE_SCIENTIFIC_NOTATION - class FieldTreeItem : public TreeItem { Q_OBJECT @@ -214,10 +212,10 @@ class FloatFieldTreeItem : public FieldTreeItem { Q_OBJECT public: - FloatFieldTreeItem(UAVObjectField *field, int index, const QList &data, TreeItem *parent = 0) : - FieldTreeItem(index, data, parent), m_field(field) { } - FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) : - FieldTreeItem(index, data, parent), m_field(field) { } + FloatFieldTreeItem(UAVObjectField *field, int index, const QList &data, bool scientific = false, TreeItem *parent = 0) : + FieldTreeItem(index, data, parent), m_field(field), m_useScientificNotation(scientific){} + FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, bool scientific = false, TreeItem *parent = 0) : + FieldTreeItem(index, data, parent), m_field(field), m_useScientificNotation(scientific) { } void setData(QVariant value, int column) { setChanged(m_field->getValue(m_index) != value); TreeItem::setData(value, column); @@ -233,39 +231,49 @@ public: setHighlight(true); } } + QWidget *createEditor(QWidget *parent) { - #ifdef USE_SCIENTIFIC_NOTATION - QScienceSpinBox *editor = new QScienceSpinBox(parent); - editor->setDecimals(6); - #else + if(m_useScientificNotation) { + QScienceSpinBox *editor = new QScienceSpinBox(parent); + editor->setDecimals(6); + editor->setMinimum(-std::numeric_limits::max()); + editor->setMaximum(std::numeric_limits::max()); + return editor; + } else { QDoubleSpinBox *editor = new QDoubleSpinBox(parent); editor->setDecimals(8); - #endif - editor->setMinimum(-std::numeric_limits::max()); - editor->setMaximum(std::numeric_limits::max()); - return editor; + editor->setMinimum(-std::numeric_limits::max()); + editor->setMaximum(std::numeric_limits::max()); + return editor; + } } QVariant getEditorValue(QWidget *editor) { - #ifdef USE_SCIENTIFIC_NOTATION - QScienceSpinBox *spinBox = static_cast(editor); - #else - QDoubleSpinBox *spinBox = static_cast(editor); - #endif - spinBox->interpretText(); - return spinBox->value(); + if(m_useScientificNotation) { + QScienceSpinBox *spinBox = static_cast(editor); + spinBox->interpretText(); + return spinBox->value(); + } else { + QDoubleSpinBox *spinBox = static_cast(editor); + spinBox->interpretText(); + return spinBox->value(); + } } void setEditorValue(QWidget *editor, QVariant value) { - #ifdef USE_SCIENTIFIC_NOTATION - QScienceSpinBox *spinBox = static_cast(editor); - #else - QDoubleSpinBox *spinBox = static_cast(editor); - #endif - spinBox->setValue(value.toDouble()); + + if(m_useScientificNotation) { + QScienceSpinBox *spinBox = static_cast(editor); + spinBox->setValue(value.toDouble()); + } else { + QDoubleSpinBox *spinBox = static_cast(editor); + spinBox->setValue(value.toDouble()); + } } private: UAVObjectField *m_field; + bool m_useScientificNotation; + }; #endif // FIELDTREEITEM_H diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h b/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h index f30368e25..f18250188 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h @@ -165,10 +165,9 @@ private: bool m_changed; QTime m_highlightExpires; HighLightManager* m_highlightManager; + static int m_highlightTimeMs; public: static const int dataColumn = 1; -private: - static int m_highlightTimeMs; }; class DataObjectTreeItem; diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowser.ui b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowser.ui index 0d36859fd..4669e7624 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowser.ui +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowser.ui @@ -215,6 +215,16 @@ + + + + Use scientific editors + + + Scientific + + + diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp index 2ce386799..a2ca44131 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp @@ -60,6 +60,7 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject())); connect(m_browser->sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate())); connect(m_browser->requestButton, SIGNAL(clicked()), this, SLOT(requestUpdate())); + connect(m_browser->scientificNotationCheckbox, SIGNAL(toggled(bool)), this, SLOT(useScientificNotation(bool))); enableSendRequest(false); } @@ -85,7 +86,7 @@ void UAVObjectBrowserWidget::categorize(bool categorize) Q_ASSERT(objManager); UAVObjectTreeModel* tmpModel = m_model; - m_model = new UAVObjectTreeModel(0, categorize); + m_model = new UAVObjectTreeModel(0, categorize,m_browser->scientificNotationCheckbox->isChecked()); m_model->setRecentlyUpdatedColor(m_recentlyUpdatedColor); m_model->setManuallyChangedColor(m_manuallyChangedColor); m_model->setRecentlyUpdatedTimeout(m_recentlyUpdatedTimeout); @@ -96,6 +97,24 @@ void UAVObjectBrowserWidget::categorize(bool categorize) delete tmpModel; } +void UAVObjectBrowserWidget::useScientificNotation(bool scientific) +{ + ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); + Q_ASSERT(pm); + UAVObjectManager *objManager = pm->getObject(); + Q_ASSERT(objManager); + + UAVObjectTreeModel* tmpModel = m_model; + m_model = new UAVObjectTreeModel(0, m_browser->categorizeCheckbox->isChecked(),scientific); + m_model->setRecentlyUpdatedColor(m_recentlyUpdatedColor); + m_model->setManuallyChangedColor(m_manuallyChangedColor); + m_model->setRecentlyUpdatedTimeout(m_recentlyUpdatedTimeout); + m_browser->treeView->setModel(m_model); + showMetaData(m_browser->metaCheckBox->isChecked()); + + delete tmpModel; +} + void UAVObjectBrowserWidget::sendUpdate() { ObjectTreeItem *objItem = findCurrentObjectTreeItem(); diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h index d0c3b7700..764ca2225 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h @@ -54,6 +54,7 @@ public: public slots: void showMetaData(bool show); void categorize(bool categorize); + void useScientificNotation(bool scientific); private slots: void sendUpdate(); diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp index 3025e8dc4..0688dbd08 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.cpp @@ -38,8 +38,9 @@ #include #include -UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool categorize) : +UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool categorize, bool useScientificNotation) : QAbstractItemModel(parent), + m_useScientificFloatNotation(useScientificNotation), m_recentlyUpdatedTimeout(500), // ms m_recentlyUpdatedColor(QColor(255, 230, 230)), m_manuallyChangedColor(QColor(230, 230, 255)) @@ -227,7 +228,7 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt case UAVObjectField::FLOAT32: data.append(field->getValue(index)); data.append(field->getUnits()); - item = new FloatFieldTreeItem(field, index, data); + item = new FloatFieldTreeItem(field, index, data, m_useScientificFloatNotation); break; default: Q_ASSERT(false); diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h index 8d1d5a7d7..8bed21aaf 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h @@ -49,7 +49,7 @@ class UAVObjectTreeModel : public QAbstractItemModel { Q_OBJECT public: - explicit UAVObjectTreeModel(QObject *parent = 0, bool categorize=true); + explicit UAVObjectTreeModel(QObject *parent = 0, bool categorize=true, bool useScientificNotation=false); ~UAVObjectTreeModel(); QVariant data(const QModelIndex &index, int role) const; @@ -105,6 +105,7 @@ private: QColor m_recentlyUpdatedColor; QColor m_manuallyChangedColor; bool m_onlyHilightChangedValues; + bool m_useScientificFloatNotation; // Highlight manager to handle highlighting of tree items. HighLightManager *m_highlightManager;