QWidget *spinDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { QSpinBox *editor = new QSpinBox(parent); editor->setRange(0, 10000); editor->installEventFilter(const_cast<spinDelegate *>(this)); return editor; }
QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex & index ) const { QSpinBox *editor = new QSpinBox(parent); editor->setMinimum(0); editor->setMaximum(100); editor->installEventFilter(const_cast<SpinBoxDelegate*>(this)); const_cast<SpinBoxDelegate*>(this)->setCurrentEditor( editor, index ); return editor; }
QWidget *HopDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &index) const { QComboBox *combo; QSpinBox *spin; QDoubleSpinBox *dspin; QString suffix; // can only edit name on blank row bool blank = index.row() >= index.model()->rowCount(); // different kind of editor for each column switch (index.column()) { case HopModel::NAME: combo = new QComboBox(parent); combo->setEditable(true); combo->addItem(QString()); combo->addItems(Data::instance()->hopsList()); combo->installEventFilter(const_cast<HopDelegate*>(this)); return combo; case HopModel::WEIGHT: if (blank) return 0; dspin = new QDoubleSpinBox(parent); dspin->setDecimals(3); dspin->setRange(0.00, 1000.00); dspin->setSingleStep(0.25); suffix = " " + Data::instance()->defaultHopUnit().symbol(); dspin->setSuffix(suffix); dspin->setAccelerated(true); dspin->installEventFilter(const_cast<HopDelegate*>(this)); return dspin; case HopModel::ALPHA: if (blank) return 0; dspin = new QDoubleSpinBox(parent); dspin->setDecimals(1); dspin->setRange(0.0, 50.0); dspin->setSingleStep(0.1); dspin->setSuffix("%"); dspin->setAccelerated(true); dspin->installEventFilter(const_cast<HopDelegate*>(this)); return dspin; case HopModel::TIME: if (blank) return 0; spin = new QSpinBox(parent); spin->setRange(0, 120); spin->setSingleStep(5); spin->setSuffix(tr(" min", "minutes")); spin->setAccelerated(true); spin->installEventFilter(const_cast<HopDelegate*>(this)); return spin; case HopModel::TYPE: if (blank) return 0; combo = new QComboBox(parent); combo->setEditable(true); combo->addItems(Hop::typeStringList()); combo->installEventFilter(const_cast<HopDelegate*>(this)); return combo; default: return 0; } }
QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const { QSpinBox *editor = new QSpinBox(parent); editor->installEventFilter(const_cast<SpinBoxDelegate*>(this)); return editor; }