File indexing completed on 2024-04-14 03:40:12
0001 /************************************************************************************* 0002 * Copyright (C) 2009 by Aleix Pol <aleixpol@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 #include "variablesdelegate.h" 0020 0021 #include <QDoubleSpinBox> 0022 0023 QWidget *VariablesDelegate::createEditor(QWidget *p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const 0024 { 0025 QVariant val = idx.model()->data(idx); 0026 if (val.metaType().id() == QMetaType::Double) { 0027 QDoubleSpinBox *spin = new QDoubleSpinBox(p); 0028 spin->setDecimals(10); 0029 return spin; 0030 } else 0031 return QItemDelegate::createEditor(p, opt, idx); 0032 } 0033 0034 void VariablesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const 0035 { 0036 QDoubleSpinBox *spin = qobject_cast<QDoubleSpinBox *>(editor); 0037 if (spin) 0038 spin->setValue(index.model()->data(index).value<double>()); 0039 else 0040 QItemDelegate::setEditorData(editor, index); 0041 }