void QCtkXipSGWidget::setMField(const char * fieldContainerName, const char * fieldName, const char * value, int index)
{
  if(!value || !fieldContainerName || !fieldName)
    return;

  SoMField *field = getMField(fieldContainerName, fieldName);

  if (field)
  {
    if (strlen(value) > 0)
    {
      // If this is really a MF then use the index
      if (field->isOfType(SoMField::getClassTypeId()))
      {        
        // If this is really a MF then use the index
        SoMField *mfield = (SoMField*)field;
        mfield->set1(index, value);
      }
    }
    else
    {
      field->touch();
    }
  }

}
示例#2
0
void MFieldEditor::on_buttonBox_clicked(QAbstractButton * button)
{
	if (Ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole)
	{
		QString S;
		SbString oldValue;

		//Buscamos el SoMField que estamos editando
		SoMField *field = current_mfield;

		//Leemos el tipo de este campo
		SoType tipo=field->getTypeId();
		const char*nombre_tipo = tipo.getName();  

		//Actualizamos el contenido del SoMField

		//Si es necesario, ampliamos el tamaño del SoMField
		field->setNum(Ui.table->rowCount()-1);

		//Miramos cuantas columnas tiene la tabla
		int numComp = Ui.table->columnCount();

		//Tratamiento de los campos SoMFString
		if (!strcmp(nombre_tipo, "MFString") )
		{
			//Convertimos el campo a SoMFString
			SoMFString *soMFString = (SoMFString *)field;

			//Recorremos las filas de la tabla
			for(int i=0;i<Ui.table->rowCount()-1;i++)
			{
				//Extraemos el contenido de las celdas
				S = Ui.table->item(i,0)->text();

				//Aplicamos el valor al campo
				soMFString->set1Value(i, SbString(qPrintable(S)));

			} // for(int i=0;i<Ui.table->rowCount()-1;i++)
		}
		else

			//Recorremos las filas de la tabla
			for(int i=0;i<Ui.table->rowCount()-1;i++)
			{
				//Sacamos una copia del field actual, por si hay errores
				field->get1(i, oldValue);
				//qDebug("old: %s\n", oldValue.getString());

				//Extraemos el contenido de la primera celda
				S = Ui.table->item(i,0)->text();

				//Concatenamos el resto de celdas de la fila
				for (int j=1; j < numComp; j++)
				{
					S.append(' ');
					S.append(Ui.table->item(i,j)->text());
				}

				//Leemos la cadena mediante el parser de openInventor
				//fprintf(stderr, "Introduciendo: %s\n", txt);
				if (!field->set1(i, qPrintable(S)))
				{
					//Si hubo un error en la lectura, restablecemos el valor anterior
					field->set1(i, oldValue.getString() );
					QMessageBox::warning( this, tr("Warning"), tr("Error on row:")+S.setNum(i));
					qDebug("Error leyendo campo en fila %d\n", i);
				}

			}//for

	}//if (Ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole)
}