From 115f9ba47392fcfac6110406688cc92ab8b89e3b Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Sat, 7 Jul 2012 12:57:11 +0200 Subject: [PATCH 1/2] OP-359 Added setting in UAVO browser widget to enable/disable editors using scientific notation. --- .../plugins/uavobjectbrowser/fieldtreeitem.h | 62 +++++++++++-------- .../src/plugins/uavobjectbrowser/treeitem.h | 3 +- .../uavobjectbrowser/uavobjectbrowser.ui | 10 +++ .../uavobjectbrowserwidget.cpp | 15 +++++ .../uavobjectbrowser/uavobjectbrowserwidget.h | 1 + .../uavobjectbrowser/uavobjecttreemodel.cpp | 5 +- .../uavobjectbrowser/uavobjecttreemodel.h | 3 +- 7 files changed, 67 insertions(+), 32 deletions(-) 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 708513d91..90e6bfdf8 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/treeitem.h @@ -146,10 +146,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 TopTreeItem : public TreeItem diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowser.ui b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowser.ui index 091c0c5eb..ba4807c34 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowser.ui +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowser.ui @@ -202,6 +202,16 @@ + + + + Use scientific editors + + + Scientific + + + diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp index 31c395ccc..b7d0644dc 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp @@ -59,6 +59,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); } @@ -79,6 +80,20 @@ void UAVObjectBrowserWidget::showMetaData(bool show) } } +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, scientific); + m_browser->treeView->setModel(m_model); + + 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 b047d37f0..cd058dadc 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h @@ -51,6 +51,7 @@ public: public slots: void showMetaData(bool show); + 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 120d9d0d8..6bc5a7925 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) : +UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool useScientificNotation) : QAbstractItemModel(parent), + m_useScientificFloatNotation(useScientificNotation), m_recentlyUpdatedTimeout(500), // ms m_recentlyUpdatedColor(QColor(255, 230, 230)), m_manuallyChangedColor(QColor(230, 230, 255)) @@ -198,7 +199,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 d9787e3a7..fbb08dc28 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjecttreemodel.h @@ -48,7 +48,7 @@ class UAVObjectTreeModel : public QAbstractItemModel { Q_OBJECT public: - explicit UAVObjectTreeModel(QObject *parent = 0); + explicit UAVObjectTreeModel(QObject *parent = 0, bool useScientificNotation = false); ~UAVObjectTreeModel(); QVariant data(const QModelIndex &index, int role) const; @@ -97,6 +97,7 @@ private: int m_recentlyUpdatedTimeout; QColor m_recentlyUpdatedColor; QColor m_manuallyChangedColor; + bool m_useScientificFloatNotation; // Highlight manager to handle highlighting of tree items. HighLightManager *m_highlightManager; From 9f9d294f6c673618b782192fa4c12410fd5e3822 Mon Sep 17 00:00:00 2001 From: Fredrik Arvidsson Date: Sun, 8 Jul 2012 16:43:47 +0200 Subject: [PATCH 2/2] OP-359 Fixed colors, hilight time and meta data state bug when switching using scientific editors and not. --- .../uavobjectbrowser/uavobjectbrowserwidget.cpp | 4 ++++ .../plugins/uavobjectbrowser/uavobjectbrowserwidget.h | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp index b7d0644dc..91111fd76 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp @@ -89,7 +89,11 @@ void UAVObjectBrowserWidget::useScientificNotation(bool scientific) UAVObjectTreeModel* tmpModel = m_model; m_model = new UAVObjectTreeModel(0, 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; } diff --git a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h index cd058dadc..5b0d3a7f6 100644 --- a/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h +++ b/ground/openpilotgcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h @@ -45,9 +45,9 @@ class UAVObjectBrowserWidget : public QWidget public: UAVObjectBrowserWidget(QWidget *parent = 0); ~UAVObjectBrowserWidget(); - void setRecentlyUpdatedColor(QColor color) { m_model->setRecentlyUpdatedColor(color); } - void setManuallyChangedColor(QColor color) { m_model->setManuallyChangedColor(color); } - void setRecentlyUpdatedTimeout(int timeout) { m_model->setRecentlyUpdatedTimeout(timeout); } + void setRecentlyUpdatedColor(QColor color) { m_recentlyUpdatedColor = color; m_model->setRecentlyUpdatedColor(color); } + void setManuallyChangedColor(QColor color) { m_manuallyChangedColor = color; m_model->setManuallyChangedColor(color); } + void setRecentlyUpdatedTimeout(int timeout) { m_recentlyUpdatedTimeout = timeout; m_model->setRecentlyUpdatedTimeout(timeout); } public slots: void showMetaData(bool show); @@ -67,6 +67,10 @@ private: Ui_UAVObjectBrowser *m_browser; UAVObjectTreeModel *m_model; + int m_recentlyUpdatedTimeout; + QColor m_recentlyUpdatedColor; + QColor m_manuallyChangedColor; + void updateObjectPersistance(ObjectPersistence::OperationOptions op, UAVObject *obj); void enableSendRequest(bool enable); ObjectTreeItem *findCurrentObjectTreeItem();