PDA

View Full Version : Peculiar Problems



slash_blog
22nd November 2010, 09:05
I am creating a Family Tree Software, and am facing two "peculiar" problems. The Family tree is saved and loaded, to and from an XML file.

First Problem:
I am using a custom model (TreeModel) derived from QAbstractItemModel, that displays Families in QTreeView. That is working fine.

Further I have TableModel that is inherited from QSortFilterProxyModel and uses TreeModel as source model to display data in QTableView. TableModel doesn't display certain rows from TreeModel and is intended to show the rest of entries with sorting (The sorting isn't working - but that is side issue, I haven't really looked into it).

Apart from this I have IconModel which inherits TableModel and displays data in QListView.

Now the only code present in IconModel is:


QVariant IconModel::data(const QModelIndex &index, int role) const
{
int column = index.column();
if (column == Familier::e_col_name && role == Qt::DecorationRole)
{
int row = index.row();
/* TreeItem is internal data structure used by TreeModel. And,
TreeItem::individualTreeItemList is a list of all the TreeItems
that I display using TreeModel.
*/
TreeItem *item = TreeItem::individualTreeItemList.at(row);
Individual *individual = dynamic_cast<Individual*>(item->fam());
if (individual)
return *(individual->getIcon ());
}
return TableModel::data(index, role);
}

Hence, in no way is it influencing any mapToSource or mapFromSource. Now the issue is, first time I open a Family Tree, everything shows exactly as I expect it should. But now I close the file (all internal data gets cleared, or at least I hope so), and open the file again, and what I observe is that QTreeView and QListView display the data correctly as they should, while QTableView which uses TableModel, displays only limited number of entries. This is peculiar since IconModel does not do any mapping, and apart from the code as given above doesn't do anything at all. So if there was any issue with the mapping, ideally QListView should also be affected. But it is working as expected. What is going wrong here?

Another thing that I notice is that, the number of entries shown in QTableView during second load is same as the number of entries I am blocking using TreeModel. Also the entries shown are otherwise correct as far as data goes, i.e. to say they are entries that I intend to show. Only thing is that not all the entries that I want to show are shown. For. e.g. in this case there are 655 entries to be shown and 37 entries not to be shown. So on second load only 37 entries will be shown from amongst the 655 entries to be shown. I hope I am sounding clear.

Second Problem

I have EventModel derived from QAbstractItemModel which I display using QTableView. Now the data is showing correctly, only that I have 119 rows, while the row number of final row in QTableView is 120. On closer scrutiny I find that display jumps from row number 4 to row number 6 abruptly. This is baffling as there is nothing special in the code anywhere. All data is represented in the same way and EventModel behaves the same for all data items. Anybody has any inkling as to what is happening?

I am willing to share more code if somebody needs it. Please let me know if I have missed something obvious or if you need more information.

TIA.