I insert on a QMap each first level node if is Expanded or not
CollState.insert(cid,isExpanded(node) ? 1 : 0 );
after user chance the page order criteria from a node i must reload the model and restore
all expanded item state..
this is run only on first level ..
How i can register the state from child ?
node.child show not valid ... but exist!
i can not use expandAll the are to many childs..
void PageList::savestate()
{
/* enum COLLAPSENR { COLLAPSEID = Qt::UserRole + 20 }; */
CollState.clear(); /* QMap<int,int> CollState; clear old state */
for (int r = 0; r < model->rowCount(); ++r) {
for (int c = 0; c < model->columnCount(); ++c) {
savestate(node);
}
}
}
{
if (!node.isValid()) {
return;
}
const int cid = node.data(COLLAPSEID).toInt();
if (CollState[cid]) { /* is register on qmap ? after clear */
return;
}
CollState.insert(cid,isExpanded(node) ? 1 : 0 );
savestate(node.child(node.row(),node.column()));
}
/* restore if expanded or not */
{
if (!node.isValid()) {
return;
}
const int cid = node.data(COLLAPSEID).toInt();
if (!CollState[cid]) {
return;
}
if (CollState[cid] == 1) {
setExpanded(node,true);
}
staterestore(node.child(node.row(),node.column()));
}
void PageList::savestate()
{
/* enum COLLAPSENR { COLLAPSEID = Qt::UserRole + 20 }; */
CollState.clear(); /* QMap<int,int> CollState; clear old state */
for (int r = 0; r < model->rowCount(); ++r) {
for (int c = 0; c < model->columnCount(); ++c) {
QModelIndex node = model->index(r,c);
savestate(node);
}
}
}
void PageList::savestate( const QModelIndex node )
{
if (!node.isValid()) {
return;
}
const int cid = node.data(COLLAPSEID).toInt();
if (CollState[cid]) { /* is register on qmap ? after clear */
return;
}
CollState.insert(cid,isExpanded(node) ? 1 : 0 );
savestate(node.child(node.row(),node.column()));
}
/* restore if expanded or not */
void PageList::staterestore( const QModelIndex node )
{
if (!node.isValid()) {
return;
}
const int cid = node.data(COLLAPSEID).toInt();
if (!CollState[cid]) {
return;
}
if (CollState[cid] == 1) {
setExpanded(node,true);
}
staterestore(node.child(node.row(),node.column()));
}
To copy to clipboard, switch view to plain text mode
Bookmarks