Rev 335 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*============================================================================**** Project/Product :** Filename : spinboxdelegate.h** Author(s) : DDP**** Description : A delgated widget to assist in the editing of time items** within a table*******==========================================================================*/#include <QtGui>#include "spinboxdelegate.h"/*----------------------------------------------------------------------------** FUNCTION : SpinBoxDelegate**** DESCRIPTION : Construct a new object**** A delegate that allows the user to change integer** values from the model using a date time widget.**** INPUTS : minvalue** maxvalue** parent - Parent object**** RETURNS :**----------------------------------------------------------------------------*/SpinBoxDelegate::SpinBoxDelegate(int minvalue, int maxvalue, QObject *parent): QItemDelegate(parent){min_value = minvalue;max_value = maxvalue;}/*----------------------------------------------------------------------------** FUNCTION : createEditor**** DESCRIPTION : Create an editor widget****** INPUTS : parent** option** index**** RETURNS : A QSpinBox widget**----------------------------------------------------------------------------*/QWidget *SpinBoxDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &/* option */,const QModelIndex &/* index */) const{QSpinBox *editor = new QSpinBox(parent);editor->setMinimum(min_value);editor->setMaximum(max_value);return editor;}/*----------------------------------------------------------------------------** FUNCTION : setEditorData**** DESCRIPTION : Inserts model data into the editor widget****** INPUTS : editor - Ref to editor widget** index -**** RETURNS :**----------------------------------------------------------------------------*/void SpinBoxDelegate::setEditorData(QWidget *editor,const QModelIndex &index) const{int value = index.model()->data(index, Qt::EditRole).toInt();QSpinBox *spinBox = static_cast<QSpinBox*>(editor);spinBox->setValue(value);}/*----------------------------------------------------------------------------** FUNCTION : setModelData**** DESCRIPTION : Extract data from the editor widget and update the model****** INPUTS : editor - Target widget** model - Current model** index - Index into model**** RETURNS :**----------------------------------------------------------------------------*/void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex &index) const{QSpinBox *spinBox = static_cast<QSpinBox*>(editor);spinBox->interpretText();int value = spinBox->value();model->setData(index, value, Qt::EditRole);}/*----------------------------------------------------------------------------** FUNCTION : updateEditorGeometry**** DESCRIPTION : Updates the geometry of the editor widget****** INPUTS : editor - Target widget** option -* index**** RETURNS :**----------------------------------------------------------------------------*/void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option, const QModelIndex &/* index */) const{editor->setGeometry(option.rect);}