Esempio n. 1
0
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."));
	}   
    }
}
Esempio n. 2
0
void RenderWindow::sEdit()
{
    if(_table->currentSelection() == -1)
        return;

    bool do_update = false;

    int r = _table->currentRow();
    Q3CheckTableItem * ctItem = (Q3CheckTableItem*)_table->item(r, 0);
    if(ctItem == 0)
        return;
    bool active = ctItem->isChecked();
    QString name = _table->text(r, 1);
    QVariant var = _params[name];

    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->_name->setText(name);
        be->_active->setChecked(active);
        be->setValue(var.toBool());
        if(be->exec() == QDialog::Accepted) {
            var = QVariant(be->value(), 0);
            active = be->_active->isChecked();
            do_update = TRUE;
        }
        delete be;
        be = 0;
        break;
    case QVariant::Int:
        ie = new IntEdit(this);
        ie->_name->setText(name);
        ie->_active->setChecked(active);
        ie->_value->setText(QString::number(var.toInt()));
        if(ie->exec() == QDialog::Accepted) {
            var = QVariant(ie->_value->text().toInt());
            active = ie->_active->isChecked();
            do_update = TRUE;
        }
        delete ie;
        ie = 0;
        break;
    case QVariant::Double:
        de = new DoubleEdit(this);
        de->_name->setText(name);
        de->_active->setChecked(active);
        de->_value->setText(QString::number(var.toDouble()));
        if(de->exec() == QDialog::Accepted) {
            var = QVariant(de->_value->text().toDouble());
            active = de->_active->isChecked();
            do_update = TRUE;
        }
        delete de;
        de = 0;
        break;
    case QVariant::String:
        se = new StringEdit(this);
        se->_name->setText(name);
        se->_active->setChecked(active);
        se->_value->setText(var.toString());
        if(se->exec() == QDialog::Accepted) {
            var = QVariant(se->_value->text());
            active = se->_active->isChecked();
            do_update = TRUE;
        }
        delete se;
        se = 0;
        break;
    case QVariant::List:
        le = new ListEdit(this);
        le->_name->setText(name);
        le->_active->setChecked(active);
        le->setList(var.toList());
        if(le->exec() == QDialog::Accepted) {
            var = QVariant(le->list());
            active = le->_active->isChecked();
            do_update = TRUE;
        }
        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()));
    };

    if(do_update) {
        _params[name] = var;
        ctItem->setChecked(active);
        _table->setText(r, 1, name);
        _table->setText(r, 2, var.typeName());
        _table->setText(r, 3, var.toString());
    }
}
Esempio n. 3
0
void ParameterEdit::editItem(int row)
{
    bool do_update = false;
    bool active = _table->item(row, 0)->checkState() == Qt::Checked;
    QString name = _table->item(row, 1)->text();
    QVariant var = _params[name];
    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->_name->setText(name);
        be->_active->setChecked(active);
        be->setValue(var.toBool());
        if(be->exec() == QDialog::Accepted) {
        var = QVariant((bool)be->value());
        active = be->_active->isChecked();
        do_update = TRUE;
        }
        delete be;
        be = 0;
        break;
      case QVariant::Int:
        ie = new IntEdit(this);
        ie->_name->setText(name);
        ie->_active->setChecked(active);
        ie->_value->setText(QString::number(var.toInt()));
        if(ie->exec() == QDialog::Accepted) {
        var = QVariant(ie->_value->text().toInt());
        active = ie->_active->isChecked();
        do_update = TRUE;
        }
        delete ie;
        ie = 0;
        break;
      case QVariant::Double:
        de = new DoubleEdit(this);
        de->_name->setText(name);
        de->_active->setChecked(active);
        de->_value->setText(QString::number(var.toDouble()));
        if(de->exec() == QDialog::Accepted) {
        var = QVariant(de->_value->text().toDouble());
        active = de->_active->isChecked();
        do_update = TRUE;
        }
        delete de;
        de = 0;
        break;
      case QVariant::String:
        se = new StringEdit(this);
        se->_name->setText(name);
        se->_active->setChecked(active);
        se->_value->setText(var.toString());
        if(se->exec() == QDialog::Accepted) {
        var = QVariant(se->_value->text());
        active = se->_active->isChecked();
        do_update = TRUE;
        }
        delete se;
        se = 0;
        break;
      case QVariant::List:
        le = new ListEdit(this);
        le->_name->setText(name);
        le->_active->setChecked(active);
        le->setList(var.toList());
        if(le->exec() == QDialog::Accepted) {
        var = QVariant(le->list());
        active = le->_active->isChecked();
        do_update = TRUE;
        }
        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()));
    };
        
    if(do_update) {
        _params[name] = var;
        _table->item(row, 0)->setCheckState((active ? Qt::Checked : Qt::Unchecked));
        _table->item(row, 1)->setText(name);
        _table->item(row, 2)->setText(var.typeName());
        _table->item(row, 3)->setText(var.toString());
    }
}