xmlRpcItemDelegate.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, C. Dornhege, University of Freiburg
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the University of Freiburg nor the names
14  * of its contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
30 #include <stdio.h>
31 #include <limits.h>
32 #include <math.h>
33 #include <QSpinBox>
34 #include <QDoubleSpinBox>
35 #include <QLineEdit>
36 
37 XmlRpcItemDelegate::XmlRpcItemDelegate(QObject* parent) : QStyledItemDelegate(parent)
38 {
39  doubleDecimals = 10;
40 }
41 
43 {
44 }
45 
46 QWidget* XmlRpcItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem & option,
47  const QModelIndex & index) const
48 {
49  // based on the index figure out which data type we are editing:
50  QVariant data = index.model()->data(index, Qt::EditRole);
51  switch(data.type()) {
52  case QVariant::Double: // bring up double spinbox with higher decimals
53  {
54  QDoubleSpinBox* editor = new QDoubleSpinBox(parent);
55  editor->setDecimals(doubleDecimals);
56  editor->setMinimum(-INFINITY);
57  editor->setMaximum(INFINITY);
58  return editor;
59  break;
60  }
61  case QVariant::Int: // bring up spinbox (done by default)
62  case QVariant::String: // use std line edit, but fill it (done by default)
63  default:
64  return QStyledItemDelegate::createEditor(parent, option, index);
65  }
66 
67  return QStyledItemDelegate::createEditor(parent, option, index);
68 }
69 
70 void XmlRpcItemDelegate::setEditorData(QWidget* editor, const QModelIndex & index) const
71 {
72  QStyledItemDelegate::setEditorData(editor, index);
73 }
74 
75 void XmlRpcItemDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex & index) const
76 {
77  QStyledItemDelegate::setModelData(editor, model, index);
78 }
79 
80 void XmlRpcItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem & option,
81  const QModelIndex & index) const
82 {
83  QStyledItemDelegate::updateEditorGeometry(editor, option, index);
84 }
85 
86 QString XmlRpcItemDelegate::displayText(const QVariant & value, const QLocale & locale) const
87 {
88  if(value.type() == QVariant::Double) {
89  return locale.toString(value.toDouble(), 'g', doubleDecimals);
90  } else {
91  return QStyledItemDelegate::displayText(value, locale);
92  }
93 }
94 
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void setEditorData(QWidget *editor, const QModelIndex &index) const
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
unsigned int doubleDecimals
QString displayText(const QVariant &value, const QLocale &locale) const
XmlRpcItemDelegate(QObject *parent=NULL)


qt_paramedit
Author(s): Christian Dornhege
autogenerated on Mon Feb 28 2022 23:37:51