Go to the documentation of this file.00001 #include <QtGui>
00002
00003 #include "delegate.h"
00004
00005 SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
00006 : QItemDelegate(parent)
00007 {
00008 }
00009
00010 QWidget *SpinBoxDelegate::createEditor(QWidget *parent,
00011 const QStyleOptionViewItem &,
00012 const QModelIndex &) const
00013 {
00014 QSpinBox *editor = new QSpinBox(parent);
00015 editor->setMinimum(0);
00016 editor->setMaximum(100);
00017
00018 return editor;
00019 }
00020
00021 void SpinBoxDelegate::setEditorData(QWidget *editor,
00022 const QModelIndex &index) const
00023 {
00024 int value = index.model()->data(index, Qt::EditRole).toInt();
00025
00026 QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
00027 spinBox->setValue(value);
00028 }
00029
00030 void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
00031 const QModelIndex &index) const
00032 {
00033 QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
00034 spinBox->interpretText();
00035 int value = spinBox->value();
00036
00037 model->setData(index, value, Qt::EditRole);
00038 }
00039
00040 void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,
00041 const QStyleOptionViewItem &option, const QModelIndex &) const
00042 {
00043 editor->setGeometry(option.rect);
00044 }
00045
00046 ComboBoxDelegate::ComboBoxDelegate(QObject *parent) : QItemDelegate(parent) {
00047
00048 }
00049
00050 QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
00051 QComboBox *editor = new QComboBox(parent);
00052 editor->insertItem(0,"INT");
00053 editor->insertItem(1, "VARCHAR");
00054 editor->insertItem(2, "BOOL");
00055 editor->insertItem(3, "DATE");
00056 editor->insertItem(4, "TIME");
00057 return editor;
00058 }
00059
00060 void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
00061 QString value = index.model()->data(index, Qt::EditRole).toString();
00062 QComboBox *combo = static_cast<QComboBox*>(editor);
00063 combo->setEditable(true);
00064 combo->setEditText(value);
00065 }
00066
00067 void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
00068 QComboBox *combo = static_cast<QComboBox*>(editor);
00069 model->setData(index, combo->currentText());
00070 }
00071
00072 void ComboBoxDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
00073 editor->setGeometry(option.rect);
00074 }
00075