File indexing completed on 2024-05-12 16:44:05

0001 /*
0002     SPDX-FileCopyrightText: 2009-2010 Alvaro Soliverez <asoliverez@gmail.com>
0003     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kpricetreeitem.h"
0008 
0009 // ----------------------------------------------------------------------------
0010 // QT Includes
0011 
0012 #include <QDate>
0013 
0014 // ----------------------------------------------------------------------------
0015 // KDE Includes
0016 
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 #include "mymoneymoney.h"
0022 
0023 KPriceTreeItem::KPriceTreeItem(QTreeWidget* parent) : QTreeWidgetItem(parent)
0024 {
0025 }
0026 
0027 bool KPriceTreeItem::operator<(const QTreeWidgetItem &otherItem) const
0028 {
0029     bool result = false;
0030     int column = 0;
0031     column = this->treeWidget()->sortColumn();
0032 
0033     switch (column) {
0034     case ePricePrice: //price
0035         result = data(column, OrderRole).value<MyMoneyMoney>() < otherItem.data(column, OrderRole).value<MyMoneyMoney>();
0036         break;
0037     case ePriceDate: //price date
0038         result = data(column, OrderRole).toDate() < otherItem.data(column, OrderRole).toDate();
0039         break;
0040     default:
0041         result = text(column).toLower() < otherItem.text(column).toLower();
0042     }
0043 
0044     return result;
0045 }
0046