xmlRpcItemDelegate.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2015, C. Dornhege, University of Freiburg
00003  * All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *  * Redistributions of source code must retain the above copyright notice, this
00009  *    list of conditions and the following disclaimer.
00010  *  * Redistributions in binary form must reproduce the above copyright notice, 
00011  *    this list of conditions and the following disclaimer in the documentation 
00012  *    and/or other materials provided with the distribution.
00013  *  * Neither the name of the University of Freiburg nor the names
00014  *    of its contributors may be used to endorse or promote products derived from
00015  *    this software without specific prior written permission.
00016  * 
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00023  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00024  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00025  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00026  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include "qt_paramedit/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    // based on the index figure out which data type we are editing:
00050    QVariant data = index.model()->data(index, Qt::EditRole);
00051    switch(data.type()) {
00052       case QVariant::Double:  // bring up double spinbox with higher decimals
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:     // bring up spinbox (done by default)
00062       case QVariant::String:  // use std line edit, but fill it (done by default)
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 


qt_paramedit
Author(s): Christian Dornhege
autogenerated on Thu Jun 6 2019 20:47:39