FieldListModel::FieldListModel(IndexedFieldContainer * fieldContainer)
{
_fieldContainer = fieldContainer;
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[ValueRole] = "value";
roles[DescriptionRole] = "description";
setRoleNames(roles);
IndexedFieldContainer::Iterator it = _fieldContainer->begin();
for ( ; it != _fieldContainer->end(); ++it )
{
QObject::connect((*it
),
SIGNAL(fieldValueChanged
(int)),
this, SLOT(fieldCurrentValueChanged(int)));
}
}
{
if ( !index.isValid() )
if (index.row() < 0 || index.row() > _fieldContainer->count())
{
}
DataModelBasicField * field = _fieldContainer->at(index.row());
switch ( role )
{
case NameRole:
return field->getName();
break;
case ValueRole:
return field->toString();
break;
case DescriptionRole:
return field->getDescription();
break;
default:
}
}
int FieldListModel
::rowCount(const QModelIndex & /* parent*/ ) const {
return _fieldContainer->count();
}
void FieldListModel::fieldCurrentValueChanged(int listIndex)
{
dataChanged(index,index);
}
FieldListModel::FieldListModel(IndexedFieldContainer * fieldContainer)
{
_fieldContainer = fieldContainer;
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[ValueRole] = "value";
roles[DescriptionRole] = "description";
setRoleNames(roles);
IndexedFieldContainer::Iterator it = _fieldContainer->begin();
for ( ; it != _fieldContainer->end(); ++it )
{
QObject::connect((*it), SIGNAL(fieldValueChanged(int)),
this, SLOT(fieldCurrentValueChanged(int)));
}
}
QVariant FieldListModel::data(const QModelIndex & index, int role) const
{
if ( !index.isValid() )
return QVariant();
if (index.row() < 0 || index.row() > _fieldContainer->count())
{
return QVariant();
}
DataModelBasicField * field = _fieldContainer->at(index.row());
switch ( role )
{
case NameRole:
return field->getName();
break;
case ValueRole:
return field->toString();
break;
case DescriptionRole:
return field->getDescription();
break;
default:
return QVariant();
}
return QVariant();
}
int FieldListModel::rowCount(const QModelIndex & /* parent*/ ) const
{
return _fieldContainer->count();
}
void FieldListModel::fieldCurrentValueChanged(int listIndex)
{
QModelIndex index = createIndex(listIndex, listIndex);
dataChanged(index,index);
}
To copy to clipboard, switch view to plain text mode
Do you need other things?
edit:
typedef QHash<QString, DataModelBasicField*> FieldContainer;
typedef QVector<DataModelBasicField*> IndexedFieldContainer;
typedef QHash<QString, DataModelBasicField*> FieldContainer;
typedef QVector<DataModelBasicField*> IndexedFieldContainer;
To copy to clipboard, switch view to plain text mode
Bookmarks