PDA

View Full Version : Custom Dir View - Folders first, with improved Sort Functions



Threepwood
24th June 2010, 10:51
Hi,

I´m trying to create a Widget that displays the content of a "virtual Folder".
"Virtual Folder", since the Elements, that need to be displayed later, were delivered by a Server in XML Format.
The XML File contains all informations, that QDir and QFileInfo would offer.

If possible, I would like to realise the whole Widget in a single extended subclass of QTreeWidget.


2 Points need to be considered:

1.) The Folders should always be displayed on top. While Files can be sorted by Name, Type, Size, ... (Asc & Dsc), the Folders should always be sorted by Name (Asc / Dsc) and stay on top of the list.

2.) The Columns should contain Human readable data (QStrings), but need to be sorted by sortable values (QStrings, qint64, QDateTime, ...)

i.e. the Size Columns:

Text in Item Column : 1,00 Mb (QString) - should be sorted by -
Data in Item Column : 1048576 (qint64 )


Basically, you can reduce my post to one single question:

Is there a way to differ between the displayed Text and the (hidden) sortable value of an Item?

I would use this as an advantage, to hold the Folders always on Top, by prepending data to the sortable values.


Thanks in advance for any kind of clue.

Vit Stepanek
24th June 2010, 14:50
All you need is to create your own model. Are you acquainted with Model/View architecture? The documentation is exhaustive. Here's online doc.: http://doc.qt.nokia.com/4.6/model-view-introduction.html#the-model-view-architecture

The Qt class QAbstractItemModel is where to start.

Keep your data in a separate structure. Derive your own model that will provide the translation of data from the data storage to the view. Then join the view and the data storage through that model. Qt is very friendly in these tasks!