It appears that QDirModel uses rows to store directory entries, which means that columns are not useful at all. So I have a simple hierarchy:
ls -R
A C
./A:
B
./A/B:
./C:
ls -R
A C
./A:
B
./A/B:
./C:
To copy to clipboard, switch view to plain text mode
If I run the following code to browse the hierarchy:
void
{
for (int i=indent ; i>0 ; i--)
this->Print(" \r");
this->Print("%d %d %s", idx.row(), idx.column(), info.fileName().toAscii().constData());
for (int i=0 ; idx.child(i, 0).isValid() ; i++)
this->ComputeSizes(idx.child(i, 0), indent+2);
}
void
MyClass::Browse(QModelIndex idx, int indent)
{
QFileInfo info = this->fileInfo(idx);
for (int i=indent ; i>0 ; i--)
this->Print(" \r");
this->Print("%d %d %s", idx.row(), idx.column(), info.fileName().toAscii().constData());
for (int i=0 ; idx.child(i, 0).isValid() ; i++)
this->ComputeSizes(idx.child(i, 0), indent+2);
}
To copy to clipboard, switch view to plain text mode
I get the expected output:
MyClass: 38 0 test
MyClass: 0 0 A
MyClass: 0 0 B
MyClass: 1 0 C
MyClass: 38 0 test
MyClass: 0 0 A
MyClass: 0 0 B
MyClass: 1 0 C
To copy to clipboard, switch view to plain text mode
But if I change the code so as to browse columns rather that rows as follow:
void
{
for (int i=indent ; i>0 ; i--)
this->Print(" \r");
this->Print("%d %d %s", idx.row(), idx.column(), info.fileName().toAscii().constData());
for (int i=0 ; idx.child(0, i).isValid() ; i++)
this->ComputeSizes(idx.child(0, i), indent+2);
}
void
MyClass::Browse(QModelIndex idx, int indent)
{
QFileInfo info = this->fileInfo(idx);
for (int i=indent ; i>0 ; i--)
this->Print(" \r");
this->Print("%d %d %s", idx.row(), idx.column(), info.fileName().toAscii().constData());
for (int i=0 ; idx.child(0, i).isValid() ; i++)
this->ComputeSizes(idx.child(0, i), indent+2);
}
To copy to clipboard, switch view to plain text mode
I get an unexpected output:
MyClass: 38 0 test
MyClass: 0 0 A
MyClass: 0 0 B
MyClass: 0 1 B
MyClass: 0 2 B
MyClass: 0 3 B
MyClass: 0 1 A
MyClass: 0 2 A
MyClass: 0 3 A
MyClass: 38 0 test
MyClass: 0 0 A
MyClass: 0 0 B
MyClass: 0 1 B
MyClass: 0 2 B
MyClass: 0 3 B
MyClass: 0 1 A
MyClass: 0 2 A
MyClass: 0 3 A
To copy to clipboard, switch view to plain text mode
I would have expected that idx.child(0, i>0) be unvalid!
I have one more question: what is the difference between QDirModel::sibling() and QDirModel::child()?
Bookmarks