Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "rxparamedit/xmlRpcItemDelegate.h"
00030 #include <stdio.h>
00031 #include <limits.h>
00032 #include <math.h>
00033 #include <QSpinBox>
00034 #include <QDoubleSpinBox>
00035 #include <QLineEdit>
00036
00037 XmlRpcItemDelegate::XmlRpcItemDelegate(QObject* parent) : QStyledItemDelegate(parent)
00038 {
00039 doubleDecimals = 10;
00040 }
00041
00042 XmlRpcItemDelegate::~XmlRpcItemDelegate()
00043 {
00044 }
00045
00046 QWidget* XmlRpcItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem & option,
00047 const QModelIndex & index) const
00048 {
00049
00050 QVariant data = index.model()->data(index, Qt::EditRole);
00051 switch(data.type()) {
00052 case QVariant::Double:
00053 {
00054 QDoubleSpinBox* editor = new QDoubleSpinBox(parent);
00055 editor->setDecimals(doubleDecimals);
00056 editor->setMinimum(-INFINITY);
00057 editor->setMaximum(INFINITY);
00058 return editor;
00059 break;
00060 }
00061 case QVariant::Int:
00062 case QVariant::String:
00063 default:
00064 return QStyledItemDelegate::createEditor(parent, option, index);
00065 }
00066
00067 return QStyledItemDelegate::createEditor(parent, option, index);
00068 }
00069
00070 void XmlRpcItemDelegate::setEditorData(QWidget* editor, const QModelIndex & index) const
00071 {
00072 QStyledItemDelegate::setEditorData(editor, index);
00073 }
00074
00075 void XmlRpcItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex & index) const
00076 {
00077 QStyledItemDelegate::setModelData(editor, model, index);
00078 }
00079
00080 void XmlRpcItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem & option,
00081 const QModelIndex & index) const
00082 {
00083 QStyledItemDelegate::updateEditorGeometry(editor, option, index);
00084 }
00085
00086 QString XmlRpcItemDelegate::displayText(const QVariant & value, const QLocale & locale) const
00087 {
00088 if(value.type() == QVariant::Double) {
00089 return locale.toString(value.toDouble(), 'g', doubleDecimals);
00090 } else {
00091 return QStyledItemDelegate::displayText(value, locale);
00092 }
00093 }
00094