What is the correct way to subclass or use the QIdentityProxyModel?
the next are the minimal example who represent my problem. MyIdentityModel can modify the DisplayRole value (change de capitalitation for upper) but the value in ListView are from the listModel not IdentModel
#include <QtGui>
#include <QDebug>
class MyIdentityModel : public QIdentityProxyModel
{
public:
MyIdentityModel
(QObject* parent
= 0): QIdentityProxyModel
(parent
) { qDebug() << "constructor"; }
QVariant var
= QIdentityProxyModel
::data(index,role
);
if (role == Qt::DisplayRole)
return var.toString().toUpper();
return var;
}
};
int main(int argc, char *argv[])
{
list << "uno" << "dos" << "tres" << "cuatro"
<< "cinco" << "seis" << "siete";
listModel->setStringList(list);
MyIdentityModel * identModel = new MyIdentityModel;
identModel->setSourceModel(listModel); //setSource model works?
//The ident proxy works fine. convert Display role to Upper
//but value display in QListView are from listModel
qDebug() << "data" << identModel->data(
identModel->index(3,0),
Qt::DisplayRole);
w->setModel(identModel);
w->show();
return a.exec();
}
#include <QtGui>
#include <QDebug>
class MyIdentityModel : public QIdentityProxyModel
{
public:
MyIdentityModel(QObject* parent = 0): QIdentityProxyModel(parent)
{ qDebug() << "constructor"; }
QVariant data(const QModelIndex &index, int role) {
QVariant var = QIdentityProxyModel::data(index,role);
if (role == Qt::DisplayRole)
return var.toString().toUpper();
return var;
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QStringList list;
list << "uno" << "dos" << "tres" << "cuatro"
<< "cinco" << "seis" << "siete";
QStringListModel *listModel = new QStringListModel;
listModel->setStringList(list);
MyIdentityModel * identModel = new MyIdentityModel;
identModel->setSourceModel(listModel); //setSource model works?
//The ident proxy works fine. convert Display role to Upper
//but value display in QListView are from listModel
qDebug() << "data" << identModel->data(
identModel->index(3,0),
Qt::DisplayRole);
QListView *w = new QListView;
w->setModel(identModel);
w->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks