File indexing completed on 2024-05-12 13:38:22

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 //_______________________________________________________________
0016 ItemModel::ItemModel(QObject *parent)
0017     : QAbstractItemModel(parent)
0018     , _sortColumn(0)
0019     , _sortOrder(Qt::AscendingOrder)
0020 {
0021 }
0022 
0023 //____________________________________________________________
0024 void ItemModel::sort(int column, Qt::SortOrder order)
0025 {
0026     // store column and order
0027     _sortColumn = column;
0028     _sortOrder = order;
0029 
0030     // emit signals and call private methods
0031     emit layoutAboutToBeChanged();
0032     privateSort(column, order);
0033     emit layoutChanged();
0034 }
0035 
0036 //____________________________________________________________
0037 QModelIndexList ItemModel::indexes(int column, const QModelIndex &parent) const
0038 {
0039     QModelIndexList out;
0040     int rows(rowCount(parent));
0041     for (int row = 0; row < rows; row++) {
0042         QModelIndex index(this->index(row, column, parent));
0043         if (!index.isValid())
0044             continue;
0045         out.append(index);
0046         out += indexes(column, index);
0047     }
0048 
0049     return out;
0050 }
0051 }