graffy
27th December 2013, 15:56
Hello,
I'm trying to access data in a QAbstractItemModel implementation that is fitlered through two successive QSortFitlerProxyModel instances.
The data is stored with two identifiers "section" and "name". I instance a "section" filter to filter the model items first by their section, then a "name" filter to choose an item by it's particular name.
The problem is, I can't seem to access the original data through the name filter.
The data filters fine, and the correct columns are being mapped to the source model, but trying to access the data from the second-level filter results in an invalid index at the source level (row() and column() == -1).
void buldAndTestModel (QAbstractItemModel *source, const QString §ionName, const QString &name)
{
QSortFilterProxyModel *sectionModel = new QSortFilterProxyModel();
sectionModel->setSourceModel(source);
sectionModel->setFilterRegExp(sectionName);
sectionModel->setFilterKeyColumn(1);
QSortFilterProxyModel *nameModel = new QSortFilterProxyModel();
nameModel->setSourceModel(sectionModel);
nameModel->setFilterRegExp(name);
nameModel->setFilterKeyColumn(0);
QStringList valueList = nameModel->data(nameModel->index(0, 2, QModelIndeX())).toStringList();
//valueList is empty and the call to the source->data method reveals index.row() and index.column() == -1
}
I'm trying to access data in a QAbstractItemModel implementation that is fitlered through two successive QSortFitlerProxyModel instances.
The data is stored with two identifiers "section" and "name". I instance a "section" filter to filter the model items first by their section, then a "name" filter to choose an item by it's particular name.
The problem is, I can't seem to access the original data through the name filter.
The data filters fine, and the correct columns are being mapped to the source model, but trying to access the data from the second-level filter results in an invalid index at the source level (row() and column() == -1).
void buldAndTestModel (QAbstractItemModel *source, const QString §ionName, const QString &name)
{
QSortFilterProxyModel *sectionModel = new QSortFilterProxyModel();
sectionModel->setSourceModel(source);
sectionModel->setFilterRegExp(sectionName);
sectionModel->setFilterKeyColumn(1);
QSortFilterProxyModel *nameModel = new QSortFilterProxyModel();
nameModel->setSourceModel(sectionModel);
nameModel->setFilterRegExp(name);
nameModel->setFilterKeyColumn(0);
QStringList valueList = nameModel->data(nameModel->index(0, 2, QModelIndeX())).toStringList();
//valueList is empty and the call to the source->data method reveals index.row() and index.column() == -1
}