On Viernes 19 Noviembre 2010 13:02:53 usted escribió:
> > I think that the override is not possible because the
> > QAbstractTableModel is tied to the QSQL module. If you need to override
> > these setting you should use QAbstractItemModel.
This is my error, the class tied to QSQL is QSqlTableModel.
>
> What do you mean by tied to the QSQL module? I can't just inherit
> from QAbstractItemModel as its methods are also final and I would have
> the same problem.
>
> http://doc.qt.nokia.com/qtjambi-4.5.0_01/com/trolltech/qt/core/QAbstractIte
> mModel.html#rowCount()
>
> Even setData on QAbstractItemModel is final! How does one implement
> anything in these models with all these final methods?
mmm, I think that the documentation is wrong. Look this example with Qtjambi
4.5.2_1:
package com.nettrace.sifactura.gui.models;
import static com.nettrace.sifactura.gui.models.enums.ColClave.CLAVE;
import static com.nettrace.sifactura.gui.models.enums.ColClave.ID;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import com.nettrace.sifactura.gui.models.enums.ColClave;
import com.nettrace.sifactura.gui.models.enums.ColRazonSocial;
import com.nettrace.sifactura.jpa.models.Cliente;
import com.trolltech.qt.core.QModelIndex;
import com.trolltech.qt.core.Qt.ItemDataRole;
import com.trolltech.qt.core.Qt.Orientation;
import com.trolltech.qt.gui.QAbstractTableModel;
/**
* Clase modelo permite visualizar en un QTableView o QCompleter los Ids y las
* claves de los Cliente(s) mediante un List.
*
* @author José Arcángel Salazar Delgado
*
*/
public class ClaveListModel extends QAbstractTableModel {
private final List<Cliente> clientes = new ArrayList<Cliente>();
private final Map<ColClave, String> headers = new EnumMap<ColClave,
String>(
ColClave.class);
/**
* Construye el modelo con el List de Cliente que se le proporciona.
*
* @param detalles
* El List de Cliente.
*/
public ClaveListModel(final List<Cliente> clientes) {
super();
beginInsertRows(null, 0, clientes.size() - 1);
this.clientes.addAll(clientes);
endInsertRows();
createHeaderMap();
}
@Override
public final int columnCount(final QModelIndex arg0) {
return ColRazonSocial.values().length;
}
/**
* Crea las cabeceras de la tabla
*/
private void createHeaderMap() {
headers.put(CLAVE, "Razón Social");
headers.put(ID, "Id");
}
/**
* @param index
* Es el número de fila en el que se encuentra la tabla.
* @param role
* @return data El objeto a regresar Completa las celdas de la tabla
*/
@Override
public final Object data(final QModelIndex index, final int role) {
Object data = null;
final ColClave column = ColClave.values()[index.column()];
if (role == ItemDataRole.DisplayRole) {
switch (column) {
case CLAVE:
data = clientes.get(index.row()).getClave();
break;
case ID:
data = clientes.get(index.row()).getId();
break;
default:
break;
}
}
return data;
}
/**
* @param section
* Es la cabecera de cada columna.
* @param orientation
* Indica la cabecera de las columnas.
* @param role
* @return data el objeto a regresar. Coloca las cabeceras de la tabla.
*
*/
@Override
public final Object headerData(final int section,
final Orientation orientation, final int role) {
Object data = null;
final ColClave column = ColClave.values()[section];
if ((role == ItemDataRole.DisplayRole)
&& (orientation == Orientation.Horizontal)) {
data = headers.get(column);
} else if ((role == ItemDataRole.DisplayRole)
&& (orientation == Orientation.Vertical)) {
data = super.headerData(section, orientation, role);
}
return data;
}
/**
* @return int Ingresa el número de filas que va a contener la tabla
*/
@Override
public final int rowCount(final QModelIndex arg0) {
return clientes.size();
}
}
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest