1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

OP-359 Added setting in UAVO browser widget to enable/disable editors

using scientific notation.
This commit is contained in:
Fredrik Arvidsson 2012-07-07 12:57:11 +02:00
parent bdfefa25f2
commit 115f9ba473
7 changed files with 67 additions and 32 deletions

View File

@ -48,8 +48,6 @@
#define QINT32MAX std::numeric_limits<qint32>::max() #define QINT32MAX std::numeric_limits<qint32>::max()
#define QUINT32MAX std::numeric_limits<qint32>::max() #define QUINT32MAX std::numeric_limits<qint32>::max()
//#define USE_SCIENTIFIC_NOTATION
class FieldTreeItem : public TreeItem class FieldTreeItem : public TreeItem
{ {
Q_OBJECT Q_OBJECT
@ -214,10 +212,10 @@ class FloatFieldTreeItem : public FieldTreeItem
{ {
Q_OBJECT Q_OBJECT
public: public:
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) : FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, bool scientific = false, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) { } FieldTreeItem(index, data, parent), m_field(field), m_useScientificNotation(scientific){}
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) : FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, bool scientific = false, TreeItem *parent = 0) :
FieldTreeItem(index, data, parent), m_field(field) { } FieldTreeItem(index, data, parent), m_field(field), m_useScientificNotation(scientific) { }
void setData(QVariant value, int column) { void setData(QVariant value, int column) {
setChanged(m_field->getValue(m_index) != value); setChanged(m_field->getValue(m_index) != value);
TreeItem::setData(value, column); TreeItem::setData(value, column);
@ -233,39 +231,49 @@ public:
setHighlight(true); setHighlight(true);
} }
} }
QWidget *createEditor(QWidget *parent) { QWidget *createEditor(QWidget *parent) {
#ifdef USE_SCIENTIFIC_NOTATION if(m_useScientificNotation) {
QScienceSpinBox *editor = new QScienceSpinBox(parent); QScienceSpinBox *editor = new QScienceSpinBox(parent);
editor->setDecimals(6); editor->setDecimals(6);
#else editor->setMinimum(-std::numeric_limits<float>::max());
editor->setMaximum(std::numeric_limits<float>::max());
return editor;
} else {
QDoubleSpinBox *editor = new QDoubleSpinBox(parent); QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
editor->setDecimals(8); editor->setDecimals(8);
#endif editor->setMinimum(-std::numeric_limits<float>::max());
editor->setMinimum(-std::numeric_limits<float>::max()); editor->setMaximum(std::numeric_limits<float>::max());
editor->setMaximum(std::numeric_limits<float>::max()); return editor;
return editor; }
} }
QVariant getEditorValue(QWidget *editor) { QVariant getEditorValue(QWidget *editor) {
#ifdef USE_SCIENTIFIC_NOTATION if(m_useScientificNotation) {
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor); QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
#else spinBox->interpretText();
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); return spinBox->value();
#endif } else {
spinBox->interpretText(); QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
return spinBox->value(); spinBox->interpretText();
return spinBox->value();
}
} }
void setEditorValue(QWidget *editor, QVariant value) { void setEditorValue(QWidget *editor, QVariant value) {
#ifdef USE_SCIENTIFIC_NOTATION
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor); if(m_useScientificNotation) {
#else QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor); spinBox->setValue(value.toDouble());
#endif } else {
spinBox->setValue(value.toDouble()); QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
spinBox->setValue(value.toDouble());
}
} }
private: private:
UAVObjectField *m_field; UAVObjectField *m_field;
bool m_useScientificNotation;
}; };
#endif // FIELDTREEITEM_H #endif // FIELDTREEITEM_H

View File

@ -146,10 +146,9 @@ private:
bool m_changed; bool m_changed;
QTime m_highlightExpires; QTime m_highlightExpires;
HighLightManager* m_highlightManager; HighLightManager* m_highlightManager;
static int m_highlightTimeMs;
public: public:
static const int dataColumn = 1; static const int dataColumn = 1;
private:
static int m_highlightTimeMs;
}; };
class TopTreeItem : public TreeItem class TopTreeItem : public TreeItem

View File

@ -202,6 +202,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="scientificNotationCheckbox">
<property name="toolTip">
<string>Use scientific editors</string>
</property>
<property name="text">
<string>Scientific</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">

View File

@ -59,6 +59,7 @@ UAVObjectBrowserWidget::UAVObjectBrowserWidget(QWidget *parent) : QWidget(parent
connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject())); connect(m_browser->eraseSDButton, SIGNAL(clicked()), this, SLOT(eraseObject()));
connect(m_browser->sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate())); connect(m_browser->sendButton, SIGNAL(clicked()), this, SLOT(sendUpdate()));
connect(m_browser->requestButton, SIGNAL(clicked()), this, SLOT(requestUpdate())); connect(m_browser->requestButton, SIGNAL(clicked()), this, SLOT(requestUpdate()));
connect(m_browser->scientificNotationCheckbox, SIGNAL(toggled(bool)), this, SLOT(useScientificNotation(bool)));
enableSendRequest(false); 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<UAVObjectManager>();
Q_ASSERT(objManager);
UAVObjectTreeModel* tmpModel = m_model;
m_model = new UAVObjectTreeModel(0, scientific);
m_browser->treeView->setModel(m_model);
delete tmpModel;
}
void UAVObjectBrowserWidget::sendUpdate() void UAVObjectBrowserWidget::sendUpdate()
{ {
ObjectTreeItem *objItem = findCurrentObjectTreeItem(); ObjectTreeItem *objItem = findCurrentObjectTreeItem();

View File

@ -51,6 +51,7 @@ public:
public slots: public slots:
void showMetaData(bool show); void showMetaData(bool show);
void useScientificNotation(bool scientific);
private slots: private slots:
void sendUpdate(); void sendUpdate();

View File

@ -38,8 +38,9 @@
#include <QtCore/QSignalMapper> #include <QtCore/QSignalMapper>
#include <QtCore/QDebug> #include <QtCore/QDebug>
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) : UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent, bool useScientificNotation) :
QAbstractItemModel(parent), QAbstractItemModel(parent),
m_useScientificFloatNotation(useScientificNotation),
m_recentlyUpdatedTimeout(500), // ms m_recentlyUpdatedTimeout(500), // ms
m_recentlyUpdatedColor(QColor(255, 230, 230)), m_recentlyUpdatedColor(QColor(255, 230, 230)),
m_manuallyChangedColor(QColor(230, 230, 255)) m_manuallyChangedColor(QColor(230, 230, 255))
@ -198,7 +199,7 @@ void UAVObjectTreeModel::addSingleField(int index, UAVObjectField *field, TreeIt
case UAVObjectField::FLOAT32: case UAVObjectField::FLOAT32:
data.append(field->getValue(index)); data.append(field->getValue(index));
data.append(field->getUnits()); data.append(field->getUnits());
item = new FloatFieldTreeItem(field, index, data); item = new FloatFieldTreeItem(field, index, data, m_useScientificFloatNotation);
break; break;
default: default:
Q_ASSERT(false); Q_ASSERT(false);

View File

@ -48,7 +48,7 @@ class UAVObjectTreeModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UAVObjectTreeModel(QObject *parent = 0); explicit UAVObjectTreeModel(QObject *parent = 0, bool useScientificNotation = false);
~UAVObjectTreeModel(); ~UAVObjectTreeModel();
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
@ -97,6 +97,7 @@ private:
int m_recentlyUpdatedTimeout; int m_recentlyUpdatedTimeout;
QColor m_recentlyUpdatedColor; QColor m_recentlyUpdatedColor;
QColor m_manuallyChangedColor; QColor m_manuallyChangedColor;
bool m_useScientificFloatNotation;
// Highlight manager to handle highlighting of tree items. // Highlight manager to handle highlighting of tree items.
HighLightManager *m_highlightManager; HighLightManager *m_highlightManager;