mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
OP-359 Added setting in UAVO browser widget to enable/disable editors
using scientific notation.
This commit is contained in:
parent
bdfefa25f2
commit
115f9ba473
@ -48,8 +48,6 @@
|
||||
#define QINT32MAX std::numeric_limits<qint32>::max()
|
||||
#define QUINT32MAX std::numeric_limits<qint32>::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<QVariant> &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<QVariant> &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<float>::max());
|
||||
editor->setMaximum(std::numeric_limits<float>::max());
|
||||
return editor;
|
||||
} else {
|
||||
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
||||
editor->setDecimals(8);
|
||||
#endif
|
||||
editor->setMinimum(-std::numeric_limits<float>::max());
|
||||
editor->setMaximum(std::numeric_limits<float>::max());
|
||||
return editor;
|
||||
editor->setMinimum(-std::numeric_limits<float>::max());
|
||||
editor->setMaximum(std::numeric_limits<float>::max());
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
|
||||
QVariant getEditorValue(QWidget *editor) {
|
||||
#ifdef USE_SCIENTIFIC_NOTATION
|
||||
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
|
||||
#else
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
#endif
|
||||
spinBox->interpretText();
|
||||
return spinBox->value();
|
||||
if(m_useScientificNotation) {
|
||||
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
return spinBox->value();
|
||||
} else {
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
return spinBox->value();
|
||||
}
|
||||
}
|
||||
|
||||
void setEditorValue(QWidget *editor, QVariant value) {
|
||||
#ifdef USE_SCIENTIFIC_NOTATION
|
||||
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
|
||||
#else
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
#endif
|
||||
spinBox->setValue(value.toDouble());
|
||||
|
||||
if(m_useScientificNotation) {
|
||||
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
|
||||
spinBox->setValue(value.toDouble());
|
||||
} else {
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->setValue(value.toDouble());
|
||||
}
|
||||
}
|
||||
private:
|
||||
UAVObjectField *m_field;
|
||||
bool m_useScientificNotation;
|
||||
|
||||
};
|
||||
|
||||
#endif // FIELDTREEITEM_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
|
||||
|
@ -202,6 +202,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
|
@ -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<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()
|
||||
{
|
||||
ObjectTreeItem *objItem = findCurrentObjectTreeItem();
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void showMetaData(bool show);
|
||||
void useScientificNotation(bool scientific);
|
||||
|
||||
private slots:
|
||||
void sendUpdate();
|
||||
|
@ -38,8 +38,9 @@
|
||||
#include <QtCore/QSignalMapper>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user