File indexing completed on 2024-05-05 05:35:33

0001 //////////////////////////////////////////////////////////////////////////////
0002 // itemmodel.cpp
0003 // -------------------
0004 //
0005 // SPDX-FileCopyrightText: 2009-2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0006 //
0007 // SPDX-License-Identifier: MIT
0008 //////////////////////////////////////////////////////////////////////////////
0009 
0010 #include "oxygenitemmodel.h"
0011 
0012 namespace Oxygen
0013 {
0014 //_______________________________________________________________
0015 ItemModel::ItemModel(QObject *parent)
0016     : QAbstractItemModel(parent)
0017     , _sortColumn(0)
0018     , _sortOrder(Qt::AscendingOrder)
0019 {
0020 }
0021 
0022 //____________________________________________________________
0023 void ItemModel::sort(int column, Qt::SortOrder order)
0024 {
0025     // store column and order
0026     _sortColumn = column;
0027     _sortOrder = order;
0028 
0029     // emit signals and call private methods
0030     emit layoutAboutToBeChanged();
0031     privateSort(column, order);
0032     emit layoutChanged();
0033 }
0034 
0035 //____________________________________________________________
0036 QModelIndexList ItemModel::indexes(int column, const QModelIndex &parent) const
0037 {
0038     QModelIndexList out;
0039     int rows(rowCount(parent));
0040     for (int row = 0; row < rows; row++) {
0041         QModelIndex index(this->index(row, column, parent));
0042         if (!index.isValid())
0043             continue;
0044         out.append(index);
0045         out += indexes(column, index);
0046     }
0047 
0048     return out;
0049 }
0050 }