Qt Custom model implements file system filename ordering (redefine the sort function.) Suddenly enlightened: In fact, capture click Header event, internal reordering, all refresh display can be)

Source: Internet
Author: User

Some time ago, a function that needed to be done was to do the sorting of the file system. Because it is the model that you write, you define the data structure. The original idea was to implement a sorting algorithm for folders and filenames, but it was more time-consuming. Later thought is that Qfilesystemmodel is the QT standard file system model, you can put the algorithm in order to put forward, there is no need to repeatedly build wheels. Look at the source of Qfilesystemmodel, find the sorting algorithm as follows (main unit in qfilesystemmodel.cpp):

1) file system filename Sorting is mainly related to the order of folders and files (folder to be ranked in front of the file), file size sorting, file type, modify the time of the sort

2) Qfilesystemmodel rewrite the sort

[CPP]View PlainCopy 
    1. void sort (int column, qt::sortorder order = Qt::ascendingorder);

Inside the first through a qlist<qpair<qfilesystemmodelprivate::qfilesystemnode*, int> > Take all the nodes out, and then call

[CPP]View PlainCopy 
    1. D->sortchildren (column, Index (RootPath ()));


The data is sorted, and the SortChildren is filtered for the sub that belongs to the current path. Then call Qfilesystemmodelsorter to sort the nodes inside. Called by the STL Std:sort, the sorting algorithm is called by the Qfilesystemmodelsorter. The algorithm here can be presented throughout. The details of the algorithm are not going to go on.

3) The model of its own can also refer to such a process: Rewrite the sort file, the current path of the sub-proposed, and then call Qfilesystemmodelsorter sorting algorithm to sort, will be sorted out of the node, re-construct a new node to model on it.
QT Source also has a lot of things to learn from, is a big treasure.

http://blog.csdn.net/hpjx1987/article/details/39753863

Qt Custom model implements file system filename ordering (redefine the sort function.) Suddenly enlightened: In fact, capture click Header event, internal reordering, all refresh display can be)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.