CustomDelegate.cpp
Go to the documentation of this file.
00001 /*
00002         Aseba - an event-based framework for distributed robot control
00003         Copyright (C) 2007--2012:
00004                 Stephane Magnenat <stephane at magnenat dot net>
00005                 (http://stephane.magnenat.net)
00006                 and other contributors, see authors.txt for details
00007         
00008         This program is free software: you can redistribute it and/or modify
00009         it under the terms of the GNU Lesser General Public License as published
00010         by the Free Software Foundation, version 3 of the License.
00011         
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU Lesser General Public License for more details.
00016         
00017         You should have received a copy of the GNU Lesser General Public License
00018         along with this program. If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "CustomDelegate.h"
00022 #include <QtGui>
00023 
00024 #include <CustomDelegate.moc>
00025 
00026 namespace Aseba
00027 {
00030         
00031         SpinBoxDelegate::SpinBoxDelegate(int minValue, int maxValue, QObject *parent) :
00032                 QItemDelegate(parent),
00033                 minValue(minValue),
00034                 maxValue(maxValue)
00035         {
00036         }
00037  
00038         QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
00039                 const QStyleOptionViewItem &/* option */,
00040                 const QModelIndex &/* index */) const
00041         {
00042                 QSpinBox *editor = new QSpinBox(parent);
00043                 editor->setMinimum(minValue);
00044                 editor->setMaximum(maxValue);
00045                 editor->installEventFilter(const_cast<SpinBoxDelegate*>(this));
00046         
00047                 return editor;
00048         }
00049                 
00050         void SpinBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
00051         {
00052                 int value = index.model()->data(index, Qt::DisplayRole).toInt();
00053                 
00054                 QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
00055                 spinBox->setValue(value);
00056         }
00057         
00058         void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
00059                 const QModelIndex &index) const
00060         {
00061                 QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
00062                 spinBox->interpretText();
00063                 int value = spinBox->value();
00064                 
00065                 model->setData(index, value);
00066         }
00067         
00068         void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
00069                 const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
00070         {
00071                 editor->setGeometry(option.rect);
00072         }
00073         
00075 }; // Aseba


aseba
Author(s): Stéphane Magnenat
autogenerated on Thu Jan 2 2014 11:17:16