| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
It seems as thought a simple QAbstractProxyModel will not work on a
QDirModel using a QListView. the attached example shows this. Is there
somthing I'm doing wrong?
#include <QApplication>
#include <QAbstractProxyModel>
#include <QDirModel>
#include <QListView>
class ToggleProxyModel : public QAbstractProxyModel
{
bool m_cleared;
public:
ToggleProxyModel(QAbstractItemModel *parent)
: QAbstractProxyModel(parent)
{
setSourceModel(parent);
}
QModelIndex index(int row, int column, const QModelIndex
&parent=QModelIndex()) const
{
return mapFromSource(sourceModel()->index(row, column, parent));
}
QModelIndex parent(const QModelIndex &index) const
{
return sourceModel()->parent(index);
}
QModelIndex mapToSource(const QModelIndex &proxyIndex) const
{
return sourceModel()->index(proxyIndex.row(), proxyIndex.column(),
proxyIndex.parent());
}
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
{
return createIndex(sourceIndex.row(), sourceIndex.column(),
sourceIndex.internalPointer());
}
int rowCount(const QModelIndex &index=QModelIndex()) const
{
return sourceModel()->rowCount(index);
}
int columnCount(const QModelIndex &index=QModelIndex()) const
{
return sourceModel()->columnCount(index);
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QListView lw;
QDirModel *source = new QDirModel(&lw);
ToggleProxyModel *proxy = new ToggleProxyModel(source);
lw.setModel(proxy);
QModelIndex index = proxy->mapFromSource(source->index("/"));
lw.setRootIndex(index);
lw.show();
app.exec();
}
--
[ signature omitted ]
Attachment:
test_dirproxy.zip
Description: Zip archive