• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::

            This will depend a little on the size of your dataset. Since we use a stable sort you can relatively easily achieve this by keeping a list of sort columns and sort them from last to first. See the example below for a demonstration.

            If you have a lot of records you might want to implement your own model that will more efficiently sort based on multiple columns.

            #include <QtGui>
            
            #define SETPERSON(index, first, second, salary)     setItem(index, 0, new QTableWidgetItem(first));     setItem(index, 1, new QTableWidgetItem(second));     setItem(index, 2, new QTableWidgetItem);     item(index, 2)->setData(Qt::DisplayRole, salary);
            
            class Table : public QTableWidget
            {
                Q_OBJECT
            public:
                Table(QWidget *parent = 0)
                    : QTableWidget(6, 3, parent)
                {
                    SETPERSON(0, "Jerry", "Springer", 1000000);
                    SETPERSON(1, "Foo", "Springer", 12341);
                    SETPERSON(2, "John", "Wayne", 12341);
                    SETPERSON(3, "Bob", "Carver", 80000);
                    SETPERSON(4, "Bob", "Carver", 81000);
                    SETPERSON(5, "Bob", "Ulong", 60000);
                    updateSortOrder();
                    connect(horizontalHeader(), SIGNAL(sectionClicked(int)),
                            this, SLOT(onHeaderClicked(int)));
                    disconnect(horizontalHeader(), SIGNAL(sectionPressed(int)), this, SLOT(selectColumn(int)));
            
                }
            
                void updateSortOrder()
                {
                    QStringList list;
                    list << "First name" << "Last name" << "Salary";
                    for (int i=0; i<sortOrder.size(); ++i)
                        list[sortOrder.at(i).column].append("(" + QString::number(i + 1) + ")");
                    setHorizontalHeaderLabels(list);
                    for (int i=sortOrder.size() - 1; i>=0; --i) {
                        sortItems(sortOrder.at(i).column, sortOrder.at(i).ascending ? Qt::AscendingOrder : Qt::DescendingOrder);
                    }
                }
            public slots:
                void onHeaderClicked(int section)
                {
                    bool ascending = true;
                    if (!(QApplication::keyboardModifiers() & Qt::ControlModifier) || sortOrder.isEmpty()) {
                        if (!sortOrder.isEmpty() && sortOrder.first().column == section) {
                            ascending = !sortOrder.first().ascending;
                        }
                        sortOrder.clear();
                    } else {
                        const int index = findSection(section);
                        if (index != -1) {
                            if (index == sortOrder.size() - 1) {
                                ascending = !sortOrder.last().ascending;
                            }
                            sortOrder.removeAt(index);
                        }
            		}
                    sortOrder.append(SortData(section, ascending));
                    updateSortOrder();
                }
            private:
                int findSection(int section) const
                {
                    for (int i=0; i<sortOrder.size(); ++i) {
                        if (sortOrder.at(i).column == section)
                            return i;
                    }
                    return -1;
                }
                struct SortData {
                    SortData(int sec = -1, bool asc = true) : column(sec), ascending(asc) {}
            
                    int column;
                    bool ascending;
                };
                QList<SortData> sortOrder;
            };
            
            
            #include "main.moc"
            
            
            int main(int argc, char **argv)
            {
                QApplication a(argc, argv);
                Table w;
                w.show();
                return a.exec();
            }
            posted on 2009-05-18 17:28 逛奔的蝸牛 閱讀(1405) 評論(0)  編輯 收藏 引用 所屬分類: Qt
            久久激情五月丁香伊人| 久久丫精品国产亚洲av| 国产精品无码久久综合网| 国产精品热久久毛片| 久久精品中文字幕一区| 国产精品久久久久久五月尺| 狠狠综合久久AV一区二区三区| 日韩精品无码久久久久久| 夜夜亚洲天天久久| 亚洲日韩欧美一区久久久久我| 日产精品99久久久久久| 国产福利电影一区二区三区久久老子无码午夜伦不 | 国产成人精品久久亚洲| 久久综合久久综合亚洲| 久久久青草久久久青草| 伊人久久综合无码成人网| 国产亚洲成人久久| 99精品久久精品| 亚洲AV日韩精品久久久久久| 精品久久久久久无码免费| 欧美丰满熟妇BBB久久久| 久久99精品九九九久久婷婷| 99久久久精品| 久久久久久精品无码人妻| 国产成人香蕉久久久久| 91精品国产91久久久久久青草| 久久天天躁狠狠躁夜夜网站| 中文字幕精品久久| 久久免费大片| 欧美久久一区二区三区| 丰满少妇人妻久久久久久4| 国产精品久久久久天天影视| 久久久久久午夜成人影院| 精品久久亚洲中文无码| 久久人人青草97香蕉| 伊人久久大香线蕉成人| 亚洲国产精品一区二区三区久久 | 久久亚洲精品无码播放| 色天使久久综合网天天| 日日狠狠久久偷偷色综合0| 久久99精品久久久久久水蜜桃|