PDA

View Full Version : QDirModel lowlevel acces to model items for add it



Jarikus
25th October 2010, 21:59
I use QTreeView + QDirModel, for view my catalog. My catalog have one file 'File1.txt'. But I need display second file ‘File2.txt’ in QTreeView but don’t create this file in my catalog!.
File2.txt have been to QDirModel and display in QTreeView but not create physically on my drive when be located my catalog i.e. I`am not use Filters.


MyCatalog
-- File1.txt - Realy file in my catalog
-- File2.txt - Only display file in QTreeView!


I create class with reimplemented method “insertRow()”:



class DirModelMod : public QDirModel
{

public:
DirModelMod();
~DirModelMod();

private:
bool insertRow ( int row, const QModelIndex & parent = QModelIndex() );

};



But how I`am can add item (files) in insertRow()?
Please litle sample how add item in QDirModel in reimplement insertRow() or what I need using. And then for setData() I`am understand myself. Tnks.


PS I`am not insert ‘File2.txt’ in QTreeView because it created in QT Designer and file must view in other widgets.
PS Sr for my English ;)

wysota
25th October 2010, 22:02
Try describing your problem again in some simpler words and proper sentences. It is hard to understand what you have, what you need and what doesn't work.

Jarikus
25th October 2010, 22:34
Try describing your problem again in some simpler words and proper sentences. It is hard to understand what you have, what you need and what doesn't work.

I have catalog where only one file:
http://spiribit.com/support/temp/explorer.jpg

My program display it via QTreeView + QDirModel:
http://spiribit.com/support/temp/myprogram.jpg

But I need display second file in QTreeView without creation this file:
http://spiribit.com/support/temp/need.jpg


I think modification method insertRow () and then manually add it:



insertRow( 1, rootIndex );
setData( this->index( 1, 0, rootIndex), QVariant("N:/File2.txt"), FilePathRole);
setData( this->index( 1, 0, rootIndex), QVariant("File2.txt"), FileNameRole);


But I`am don’t know how modification method:



bool insertRow ()
{
……
}

wysota
25th October 2010, 22:42
Either subclass the model and reimplement rowCount() and data() to return the additional item or use a proxy model wrapping the base model and add the artificial item there. Touching insertRow (or rather insertRows) from the dir model is not a good idea.

squidge
25th October 2010, 23:56
Depending on how much of QDirModel you are using, you may even find that it's worthwhile creating your own model based on QAbstractItemModel and using QDirIterator, but that is a little like using a sledgehammer to crack a nut :) It depends on what your design shows for future versions of your class.