Originally Posted by
jpn
Is it possible that the hierarchy changes when you reload the model or does it remain the same?
no remain the same ....
I solved on this way ... colums 0 from Category having a nummer and 1 the name
and level 3 pages not...
Now i must only write QMap to Qsetting .
void PageList::savestate()
{
/* enum COLLAPSENR { COLLAPSEID = Qt::UserRole + 20 }; */
CollState.clear(); /* QMap<int,int> CollState; */
for (int r = 0; r < model->rowCount(); ++r) {
for (int c = 0; c < model->columnCount(); ++c) {
savestate(node);
}
}
qDebug() << "### SAVE SIZEeeeeeeeeee " << CollState.size();
}
void PageList
::savestate( const QModelIndex node ,
bool fromchild
) {
if (!node.isValid()) {
return;
}
if (node.data().toString().toInt() < 1 || node.column() !=0 ) {
return;
}
const int cid = node.data().toString().toInt();
if (CollState[cid]) { /* is register on qmap ? after clear */
return;
}
CollState.insert(cid,isExpanded(node) ? 1 : 0 );
if ( item->hasChildren() ) {
for (int i = 0; i < limit_page; ++i) {
savestate(node.child(i,0),true);
}
}
}
void PageList::RestoreCollapseState()
{
if (CollState.size() < 1) {
return;
}
for (int r = 0; r < model->rowCount(); ++r) {
for (int c = 0; c < model->columnCount(); ++c) {
staterestore(node);
}
}
}
{
if (!node.isValid()) {
return;
}
if (node.data().toString().toInt() < 1 || node.column() !=0 ) {
return;
}
const int cid = node.data().toString().toInt();
if (!CollState[cid]) {
return;
}
if (CollState[cid] == 1) {
////////qDebug() << "### expand on name " << node.data().toString();
///////////qDebug() << "### expand on " << node.row() << node.column();
setExpanded(node,true);
}
if ( item->hasChildren() ) {
for (int i = 0; i < limit_page; ++i) {
staterestore(node.child(i,0));
}
}
}
void PageList::savestate()
{
/* enum COLLAPSENR { COLLAPSEID = Qt::UserRole + 20 }; */
CollState.clear(); /* QMap<int,int> CollState; */
for (int r = 0; r < model->rowCount(); ++r) {
for (int c = 0; c < model->columnCount(); ++c) {
QModelIndex node = model->index(r,c);
savestate(node);
}
}
qDebug() << "### SAVE SIZEeeeeeeeeee " << CollState.size();
}
void PageList::savestate( const QModelIndex node , bool fromchild )
{
if (!node.isValid()) {
return;
}
if (node.data().toString().toInt() < 1 || node.column() !=0 ) {
return;
}
const int cid = node.data().toString().toInt();
if (CollState[cid]) { /* is register on qmap ? after clear */
return;
}
CollState.insert(cid,isExpanded(node) ? 1 : 0 );
QStandardItem *item = model->itemFromIndex(node);
if ( item->hasChildren() ) {
for (int i = 0; i < limit_page; ++i) {
savestate(node.child(i,0),true);
}
}
}
void PageList::RestoreCollapseState()
{
if (CollState.size() < 1) {
return;
}
for (int r = 0; r < model->rowCount(); ++r) {
for (int c = 0; c < model->columnCount(); ++c) {
QModelIndex node = model->index(r,c);
staterestore(node);
}
}
}
void PageList::staterestore( const QModelIndex node )
{
if (!node.isValid()) {
return;
}
if (node.data().toString().toInt() < 1 || node.column() !=0 ) {
return;
}
const int cid = node.data().toString().toInt();
if (!CollState[cid]) {
return;
}
if (CollState[cid] == 1) {
////////qDebug() << "### expand on name " << node.data().toString();
///////////qDebug() << "### expand on " << node.row() << node.column();
setExpanded(node,true);
}
QStandardItem *item = model->itemFromIndex(node);
if ( item->hasChildren() ) {
for (int i = 0; i < limit_page; ++i) {
staterestore(node.child(i,0));
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks