QList<QVariant> ListEdit::list() { QList<QVariant> varlist; Q3ListBoxItem * item = 0; QListBoxVariant * var = 0; item = _list->item(0); while(item) { if(item->rtti() == QListBoxVariant::RTTI) { var = (QListBoxVariant*)item; varlist.append(var->variant()); } item = item->next(); } return varlist; }
void ListEdit::editItem() { Q3ListBoxItem * item = _list->selectedItem(); if(item) { if(item->rtti() == QListBoxVariant::RTTI) { QListBoxVariant * lbvar = (QListBoxVariant*)item; QVariant var = lbvar->variant(); BoolEdit * be = 0; IntEdit * ie = 0; DoubleEdit * de = 0; StringEdit * se = 0; ListEdit * le = 0; switch(var.type()) { case QVariant::Bool: be = new BoolEdit(this); be->_lblName->hide(); be->_name->hide(); be->_active->hide(); be->setValue(var.toBool()); if(be->exec() == QDialog::Accepted) { lbvar->setVariant(QVariant(be->value(), 0)); } delete be; be = 0; break; case QVariant::Int: ie = new IntEdit(this); ie->_lblName->hide(); ie->_name->hide(); ie->_active->hide(); ie->_value->setText(QString::number(var.toInt())); if(ie->exec() == QDialog::Accepted) { lbvar->setVariant(QVariant(ie->_value->text().toInt())); } delete ie; ie = 0; break; case QVariant::Double: de = new DoubleEdit(this); de->_lblName->hide(); de->_name->hide(); de->_active->hide(); de->_value->setText(QString::number(var.toDouble())); if(de->exec() == QDialog::Accepted) { lbvar->setVariant(QVariant(de->_value->text().toDouble())); } delete de; de = 0; break; case QVariant::String: se = new StringEdit(this); se->_lblName->hide(); se->_name->hide(); se->_active->hide(); se->_value->setText(var.toString()); if(se->exec() == QDialog::Accepted) { lbvar->setVariant(QVariant(se->_value->text())); } delete se; se = 0; break; case QVariant::List: le = new ListEdit(this); le->_lblName->hide(); le->_name->hide(); le->_active->hide(); le->setList(var.toList()); if(le->exec() == QDialog::Accepted) { lbvar->setVariant(QVariant(le->list())); } delete le; le = 0; break; default: QMessageBox::warning(this, tr("Warning"), QString(tr("I do not know how to edit QVariant type %1.")).arg(var.typeName())); }; } else { QMessageBox::warning(this, tr("Warning"), tr("The item you selected is not a QListBoxVariant item. I do not know what to do.")); } } }