mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-01 18:29:16 +01:00
Added option (#define USE_SCIENTIFIC_NOTATION) to use scientific notation (or not as the case maybe)
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2872 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
223b3089ed
commit
3883a561e4
@ -1,255 +1,271 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file fieldtreeitem.h
|
* @file fieldtreeitem.h
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @addtogroup GCSPlugins GCS Plugins
|
* @addtogroup GCSPlugins GCS Plugins
|
||||||
* @{
|
* @{
|
||||||
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
|
* @addtogroup UAVObjectBrowserPlugin UAVObject Browser Plugin
|
||||||
* @{
|
* @{
|
||||||
* @brief The UAVObject Browser gadget plugin
|
* @brief The UAVObject Browser gadget plugin
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef FIELDTREEITEM_H
|
#ifndef FIELDTREEITEM_H
|
||||||
#define FIELDTREEITEM_H
|
#define FIELDTREEITEM_H
|
||||||
|
|
||||||
#include "treeitem.h"
|
#include "treeitem.h"
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtGui/QSpinBox>
|
#include <QtGui/QSpinBox>
|
||||||
#include <qscispinbox/QScienceSpinBox.h>
|
#include <QtGui/QDoubleSpinBox>
|
||||||
#include <QtGui/QComboBox>
|
#include <qscispinbox/QScienceSpinBox.h>
|
||||||
#include <limits>
|
#include <QtGui/QComboBox>
|
||||||
|
#include <limits>
|
||||||
#define QINT8MIN std::numeric_limits<qint8>::min()
|
|
||||||
#define QINT8MAX std::numeric_limits<qint8>::max()
|
#define QINT8MIN std::numeric_limits<qint8>::min()
|
||||||
#define QUINTMIN std::numeric_limits<quint8>::min()
|
#define QINT8MAX std::numeric_limits<qint8>::max()
|
||||||
#define QUINT8MAX std::numeric_limits<quint8>::max()
|
#define QUINTMIN std::numeric_limits<quint8>::min()
|
||||||
#define QINT16MIN std::numeric_limits<qint16>::min()
|
#define QUINT8MAX std::numeric_limits<quint8>::max()
|
||||||
#define QINT16MAX std::numeric_limits<qint16>::max()
|
#define QINT16MIN std::numeric_limits<qint16>::min()
|
||||||
#define QUINT16MAX std::numeric_limits<quint16>::max()
|
#define QINT16MAX std::numeric_limits<qint16>::max()
|
||||||
#define QINT32MIN std::numeric_limits<qint32>::min()
|
#define QUINT16MAX std::numeric_limits<quint16>::max()
|
||||||
#define QINT32MAX std::numeric_limits<qint32>::max()
|
#define QINT32MIN std::numeric_limits<qint32>::min()
|
||||||
#define QUINT32MAX std::numeric_limits<qint32>::max()
|
#define QINT32MAX std::numeric_limits<qint32>::max()
|
||||||
|
#define QUINT32MAX std::numeric_limits<qint32>::max()
|
||||||
class FieldTreeItem : public TreeItem
|
|
||||||
{
|
#define USE_SCIENTIFIC_NOTATION
|
||||||
Q_OBJECT
|
|
||||||
public:
|
class FieldTreeItem : public TreeItem
|
||||||
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
{
|
||||||
TreeItem(data, parent), m_index(index) { }
|
Q_OBJECT
|
||||||
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
public:
|
||||||
TreeItem(data, parent), m_index(index) { }
|
FieldTreeItem(int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||||
bool isEditable() { return true; }
|
TreeItem(data, parent), m_index(index) { }
|
||||||
virtual QWidget *createEditor(QWidget *parent) = 0;
|
FieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
||||||
virtual QVariant getEditorValue(QWidget *editor) = 0;
|
TreeItem(data, parent), m_index(index) { }
|
||||||
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
|
bool isEditable() { return true; }
|
||||||
virtual void apply() { }
|
virtual QWidget *createEditor(QWidget *parent) = 0;
|
||||||
protected:
|
virtual QVariant getEditorValue(QWidget *editor) = 0;
|
||||||
int m_index;
|
virtual void setEditorValue(QWidget *editor, QVariant value) = 0;
|
||||||
};
|
virtual void apply() { }
|
||||||
|
protected:
|
||||||
class EnumFieldTreeItem : public FieldTreeItem
|
int m_index;
|
||||||
{
|
};
|
||||||
Q_OBJECT
|
|
||||||
public:
|
class EnumFieldTreeItem : public FieldTreeItem
|
||||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data,
|
{
|
||||||
TreeItem *parent = 0) :
|
Q_OBJECT
|
||||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
public:
|
||||||
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data,
|
EnumFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data,
|
||||||
TreeItem *parent = 0) :
|
TreeItem *parent = 0) :
|
||||||
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
||||||
void setData(QVariant value, int column) {
|
EnumFieldTreeItem(UAVObjectField *field, int index, const QVariant &data,
|
||||||
QStringList options = m_field->getOptions();
|
TreeItem *parent = 0) :
|
||||||
QVariant tmpValue = m_field->getValue(m_index);
|
FieldTreeItem(index, data, parent), m_enumOptions(field->getOptions()), m_field(field) { }
|
||||||
int tmpValIndex = options.indexOf(tmpValue.toString());
|
void setData(QVariant value, int column) {
|
||||||
setChanged(tmpValIndex != value);
|
QStringList options = m_field->getOptions();
|
||||||
TreeItem::setData(value, column);
|
QVariant tmpValue = m_field->getValue(m_index);
|
||||||
}
|
int tmpValIndex = options.indexOf(tmpValue.toString());
|
||||||
QString enumOptions(int index) {
|
setChanged(tmpValIndex != value);
|
||||||
if((index < 0) || (index >= m_enumOptions.length())) {
|
TreeItem::setData(value, column);
|
||||||
return QString("Invalid Value (") + QString().setNum(index) + QString(")");
|
}
|
||||||
}
|
QString enumOptions(int index) {
|
||||||
return m_enumOptions.at(index);
|
if((index < 0) || (index >= m_enumOptions.length())) {
|
||||||
}
|
return QString("Invalid Value (") + QString().setNum(index) + QString(")");
|
||||||
void apply() {
|
}
|
||||||
int value = data(dataColumn).toInt();
|
return m_enumOptions.at(index);
|
||||||
QStringList options = m_field->getOptions();
|
}
|
||||||
m_field->setValue(options[value], m_index);
|
void apply() {
|
||||||
setChanged(false);
|
int value = data(dataColumn).toInt();
|
||||||
}
|
QStringList options = m_field->getOptions();
|
||||||
void update() {
|
m_field->setValue(options[value], m_index);
|
||||||
QStringList options = m_field->getOptions();
|
setChanged(false);
|
||||||
QVariant value = m_field->getValue(m_index);
|
}
|
||||||
int valIndex = options.indexOf(value.toString());
|
void update() {
|
||||||
if (data() != valIndex || changed()) {
|
QStringList options = m_field->getOptions();
|
||||||
TreeItem::setData(valIndex);
|
QVariant value = m_field->getValue(m_index);
|
||||||
setHighlight(true);
|
int valIndex = options.indexOf(value.toString());
|
||||||
}
|
if (data() != valIndex || changed()) {
|
||||||
}
|
TreeItem::setData(valIndex);
|
||||||
QWidget *createEditor(QWidget *parent) {
|
setHighlight(true);
|
||||||
QComboBox *editor = new QComboBox(parent);
|
}
|
||||||
foreach (QString option, m_enumOptions)
|
}
|
||||||
editor->addItem(option);
|
QWidget *createEditor(QWidget *parent) {
|
||||||
return editor;
|
QComboBox *editor = new QComboBox(parent);
|
||||||
}
|
foreach (QString option, m_enumOptions)
|
||||||
|
editor->addItem(option);
|
||||||
QVariant getEditorValue(QWidget *editor) {
|
return editor;
|
||||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
}
|
||||||
return comboBox->currentIndex();
|
|
||||||
}
|
QVariant getEditorValue(QWidget *editor) {
|
||||||
|
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||||
void setEditorValue(QWidget *editor, QVariant value) {
|
return comboBox->currentIndex();
|
||||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
}
|
||||||
comboBox->setCurrentIndex(value.toInt());
|
|
||||||
}
|
void setEditorValue(QWidget *editor, QVariant value) {
|
||||||
private:
|
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||||
QStringList m_enumOptions;
|
comboBox->setCurrentIndex(value.toInt());
|
||||||
UAVObjectField *m_field;
|
}
|
||||||
};
|
private:
|
||||||
|
QStringList m_enumOptions;
|
||||||
class IntFieldTreeItem : public FieldTreeItem
|
UAVObjectField *m_field;
|
||||||
{
|
};
|
||||||
Q_OBJECT
|
|
||||||
public:
|
class IntFieldTreeItem : public FieldTreeItem
|
||||||
IntFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
{
|
||||||
FieldTreeItem(index, data, parent), m_field(field) {
|
Q_OBJECT
|
||||||
setMinMaxValues();
|
public:
|
||||||
}
|
IntFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||||
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
FieldTreeItem(index, data, parent), m_field(field) {
|
||||||
FieldTreeItem(index, data, parent), m_field(field) {
|
setMinMaxValues();
|
||||||
setMinMaxValues();
|
}
|
||||||
}
|
IntFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||||
|
FieldTreeItem(index, data, parent), m_field(field) {
|
||||||
void setMinMaxValues() {
|
setMinMaxValues();
|
||||||
switch (m_field->getType()) {
|
}
|
||||||
case UAVObjectField::INT8:
|
|
||||||
m_minValue = QINT8MIN;
|
void setMinMaxValues() {
|
||||||
m_maxValue = QINT8MAX;
|
switch (m_field->getType()) {
|
||||||
break;
|
case UAVObjectField::INT8:
|
||||||
case UAVObjectField::INT16:
|
m_minValue = QINT8MIN;
|
||||||
m_minValue = QINT16MIN;
|
m_maxValue = QINT8MAX;
|
||||||
m_maxValue = QINT16MAX;
|
break;
|
||||||
break;
|
case UAVObjectField::INT16:
|
||||||
case UAVObjectField::INT32:
|
m_minValue = QINT16MIN;
|
||||||
m_minValue = QINT32MIN;
|
m_maxValue = QINT16MAX;
|
||||||
m_maxValue = QINT32MAX;
|
break;
|
||||||
break;
|
case UAVObjectField::INT32:
|
||||||
case UAVObjectField::UINT8:
|
m_minValue = QINT32MIN;
|
||||||
m_minValue = QUINTMIN;
|
m_maxValue = QINT32MAX;
|
||||||
m_maxValue = QUINT8MAX;
|
break;
|
||||||
break;
|
case UAVObjectField::UINT8:
|
||||||
case UAVObjectField::UINT16:
|
m_minValue = QUINTMIN;
|
||||||
m_minValue = QUINTMIN;
|
m_maxValue = QUINT8MAX;
|
||||||
m_maxValue = QUINT16MAX;
|
break;
|
||||||
break;
|
case UAVObjectField::UINT16:
|
||||||
case UAVObjectField::UINT32:
|
m_minValue = QUINTMIN;
|
||||||
m_minValue = QUINTMIN;
|
m_maxValue = QUINT16MAX;
|
||||||
m_maxValue = QUINT32MAX;
|
break;
|
||||||
break;
|
case UAVObjectField::UINT32:
|
||||||
default:
|
m_minValue = QUINTMIN;
|
||||||
Q_ASSERT(false);
|
m_maxValue = QUINT32MAX;
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
}
|
Q_ASSERT(false);
|
||||||
|
break;
|
||||||
QWidget *createEditor(QWidget *parent) {
|
}
|
||||||
QSpinBox *editor = new QSpinBox(parent);
|
}
|
||||||
editor->setMinimum(m_minValue);
|
|
||||||
editor->setMaximum(m_maxValue);
|
QWidget *createEditor(QWidget *parent) {
|
||||||
return editor;
|
QSpinBox *editor = new QSpinBox(parent);
|
||||||
}
|
editor->setMinimum(m_minValue);
|
||||||
|
editor->setMaximum(m_maxValue);
|
||||||
QVariant getEditorValue(QWidget *editor) {
|
return editor;
|
||||||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
}
|
||||||
spinBox->interpretText();
|
|
||||||
return spinBox->value();
|
QVariant getEditorValue(QWidget *editor) {
|
||||||
}
|
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||||
|
spinBox->interpretText();
|
||||||
void setEditorValue(QWidget *editor, QVariant value) {
|
return spinBox->value();
|
||||||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
}
|
||||||
spinBox->setValue(value.toInt());
|
|
||||||
}
|
void setEditorValue(QWidget *editor, QVariant value) {
|
||||||
void setData(QVariant value, int column) {
|
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||||
setChanged(m_field->getValue(m_index) != value);
|
spinBox->setValue(value.toInt());
|
||||||
TreeItem::setData(value, column);
|
}
|
||||||
}
|
void setData(QVariant value, int column) {
|
||||||
void apply() {
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
m_field->setValue(data(dataColumn).toInt(), m_index);
|
TreeItem::setData(value, column);
|
||||||
setChanged(false);
|
}
|
||||||
}
|
void apply() {
|
||||||
void update() {
|
m_field->setValue(data(dataColumn).toInt(), m_index);
|
||||||
int value = m_field->getValue(m_index).toInt();
|
setChanged(false);
|
||||||
if (data() != value || changed()) {
|
}
|
||||||
TreeItem::setData(value);
|
void update() {
|
||||||
setHighlight(true);
|
int value = m_field->getValue(m_index).toInt();
|
||||||
}
|
if (data() != value || changed()) {
|
||||||
}
|
TreeItem::setData(value);
|
||||||
|
setHighlight(true);
|
||||||
private:
|
}
|
||||||
UAVObjectField *m_field;
|
}
|
||||||
int m_minValue;
|
|
||||||
int m_maxValue;
|
private:
|
||||||
};
|
UAVObjectField *m_field;
|
||||||
|
int m_minValue;
|
||||||
class FloatFieldTreeItem : public FieldTreeItem
|
int m_maxValue;
|
||||||
{
|
};
|
||||||
Q_OBJECT
|
|
||||||
public:
|
class FloatFieldTreeItem : public FieldTreeItem
|
||||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
{
|
||||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
Q_OBJECT
|
||||||
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
public:
|
||||||
FieldTreeItem(index, data, parent), m_field(field) { }
|
FloatFieldTreeItem(UAVObjectField *field, int index, const QList<QVariant> &data, TreeItem *parent = 0) :
|
||||||
void setData(QVariant value, int column) {
|
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||||
setChanged(m_field->getValue(m_index) != value);
|
FloatFieldTreeItem(UAVObjectField *field, int index, const QVariant &data, TreeItem *parent = 0) :
|
||||||
TreeItem::setData(value, column);
|
FieldTreeItem(index, data, parent), m_field(field) { }
|
||||||
}
|
void setData(QVariant value, int column) {
|
||||||
void apply() {
|
setChanged(m_field->getValue(m_index) != value);
|
||||||
m_field->setValue(data(dataColumn).toDouble(), m_index);
|
TreeItem::setData(value, column);
|
||||||
setChanged(false);
|
}
|
||||||
}
|
void apply() {
|
||||||
void update() {
|
m_field->setValue(data(dataColumn).toDouble(), m_index);
|
||||||
double value = m_field->getValue(m_index).toDouble();
|
setChanged(false);
|
||||||
if (data() != value || changed()) {
|
}
|
||||||
TreeItem::setData(value);
|
void update() {
|
||||||
setHighlight(true);
|
double value = m_field->getValue(m_index).toDouble();
|
||||||
}
|
if (data() != value || changed()) {
|
||||||
}
|
TreeItem::setData(value);
|
||||||
QWidget *createEditor(QWidget *parent) {
|
setHighlight(true);
|
||||||
QScienceSpinBox *editor = new QScienceSpinBox(parent);
|
}
|
||||||
editor->setDecimals(6);
|
}
|
||||||
editor->setMinimum(-std::numeric_limits<float>::max());
|
QWidget *createEditor(QWidget *parent) {
|
||||||
editor->setMaximum(std::numeric_limits<float>::max());
|
#idef USE_SCIENTIFIC_NOTATION
|
||||||
return editor;
|
QScienceSpinBox *editor = new QScienceSpinBox(parent);
|
||||||
}
|
editor->setDecimals(6);
|
||||||
|
#else
|
||||||
QVariant getEditorValue(QWidget *editor) {
|
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
||||||
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
|
editor->setDecimals(8);
|
||||||
spinBox->interpretText();
|
#endif
|
||||||
return spinBox->value();
|
editor->setMinimum(-std::numeric_limits<float>::max());
|
||||||
}
|
editor->setMaximum(std::numeric_limits<float>::max());
|
||||||
|
return editor;
|
||||||
void setEditorValue(QWidget *editor, QVariant value) {
|
}
|
||||||
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
|
|
||||||
spinBox->setValue(value.toDouble());
|
QVariant getEditorValue(QWidget *editor) {
|
||||||
}
|
#idef USE_SCIENTIFIC_NOTATION
|
||||||
private:
|
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
|
||||||
UAVObjectField *m_field;
|
#else
|
||||||
};
|
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||||
|
#endif
|
||||||
#endif // FIELDTREEITEM_H
|
spinBox->interpretText();
|
||||||
|
return spinBox->value();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEditorValue(QWidget *editor, QVariant value) {
|
||||||
|
#idef USE_SCIENTIFIC_NOTATION
|
||||||
|
QScienceSpinBox *spinBox = static_cast<QScienceSpinBox*>(editor);
|
||||||
|
#else
|
||||||
|
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||||
|
#endif
|
||||||
|
spinBox->setValue(value.toDouble());
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
UAVObjectField *m_field;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FIELDTREEITEM_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user