mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
GCS/uavobjectbrowser: Fix qdoublespinbox issue.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@438 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
25e9e31584
commit
d3afdf5d54
@ -30,6 +30,7 @@
|
||||
#include <QtGui/QSpinBox>
|
||||
#include <QtGui/QDoubleSpinBox>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <limits>
|
||||
|
||||
BrowserItemDelegate::BrowserItemDelegate(QObject *parent) :
|
||||
QStyledItemDelegate(parent)
|
||||
@ -53,8 +54,15 @@ QWidget *BrowserItemDelegate::createEditor(QWidget *parent,
|
||||
foreach (QString option, enumItem->enumOptions)
|
||||
editor->addItem(option);
|
||||
return editor;
|
||||
} else if (item->isFloatType()) {
|
||||
FloatFieldTreeItem *floatItem = static_cast<FloatFieldTreeItem*>(item);
|
||||
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
||||
editor->setDecimals(6);
|
||||
editor->setMinimum(-std::numeric_limits<float>::max());
|
||||
return editor;
|
||||
} else {
|
||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||
}
|
||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||
}
|
||||
|
||||
|
||||
@ -70,6 +78,10 @@ void BrowserItemDelegate::setEditorData(QWidget *editor,
|
||||
int value = index.model()->data(index, Qt::EditRole).toInt();
|
||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||
comboBox->setCurrentIndex(value);
|
||||
} else if (item->isFloatType()) {
|
||||
float value = index.model()->data(index, Qt::EditRole).toDouble();
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->setValue(value);
|
||||
} else {
|
||||
QStyledItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
@ -88,6 +100,11 @@ void BrowserItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *mode
|
||||
QComboBox *comboBox = static_cast<QComboBox*>(editor);
|
||||
int value = comboBox->currentIndex();
|
||||
model->setData(index, value, Qt::EditRole);
|
||||
} else if (item->isFloatType()) {
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
float value = spinBox->value();
|
||||
model->setData(index, value, Qt::EditRole);
|
||||
} else {
|
||||
QStyledItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
@ -101,5 +118,5 @@ void BrowserItemDelegate::updateEditorGeometry(QWidget *editor,
|
||||
|
||||
QSize BrowserItemDelegate::sizeHint(const QStyleOptionViewItem & option, const QModelIndex &index) const
|
||||
{
|
||||
return QSpinBox().sizeHint();
|
||||
return QSpinBox().sizeHint();
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ public:
|
||||
bool isEditable() { return true; }
|
||||
virtual bool isIntType() { return false; }
|
||||
virtual bool isEnum() { return false; }
|
||||
virtual bool isFloatType() { return false; }
|
||||
private:
|
||||
int m_index;
|
||||
};
|
||||
@ -152,7 +153,7 @@ public:
|
||||
FieldTreeItem(index, data, parent) { }
|
||||
FloatFieldTreeItem(int index, const QVariant &data, TreeItem *parent = 0) :
|
||||
FieldTreeItem(index, data, parent) { }
|
||||
virtual bool isIntType() { return false; }
|
||||
bool isFloatType() { return true; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -41,18 +41,18 @@
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include <QtGui/QColor>
|
||||
#include <QtCore/QDebug>
|
||||
#include <limits>
|
||||
|
||||
#define QINT8MIN -128
|
||||
#define QINT8MAX 127
|
||||
#define QUINTMIN 0
|
||||
#define QUINT8MAX 255
|
||||
#define QINT16MIN -32768
|
||||
#define QINT16MAX 32767
|
||||
#define QUINT16MAX 65535
|
||||
#define QINT32MIN -2147483648
|
||||
#define QINT32MAX 2147483647
|
||||
#define QUINT32MAX 2147483647
|
||||
|
||||
#define QINT8MIN std::numeric_limits<qint8>::min()
|
||||
#define QINT8MAX std::numeric_limits<qint8>::max()
|
||||
#define QUINTMIN std::numeric_limits<quint8>::min()
|
||||
#define QUINT8MAX std::numeric_limits<quint8>::max()
|
||||
#define QINT16MIN std::numeric_limits<qint16>::min()
|
||||
#define QINT16MAX std::numeric_limits<qint16>::max()
|
||||
#define QUINT16MAX std::numeric_limits<quint16>::max()
|
||||
#define QINT32MIN std::numeric_limits<qint32>::min()
|
||||
#define QINT32MAX std::numeric_limits<qint32>::max()
|
||||
#define QUINT32MAX std::numeric_limits<qint32>::max()
|
||||
|
||||
|
||||
UAVObjectTreeModel::UAVObjectTreeModel(QObject *parent) :
|
||||
|
Loading…
x
Reference in New Issue
Block a user