File indexing completed on 2024-05-12 05:07:35
0001 /* 0002 SPDX-FileCopyrightText: 2015-2019 Thomas Baumgart <tbaumgart@kde.org> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 0007 #include "accountdelegate.h" 0008 0009 // ---------------------------------------------------------------------------- 0010 // QT Includes 0011 0012 #include <QApplication> 0013 #include <QDebug> 0014 #include <QPainter> 0015 #include <QTreeView> 0016 0017 // ---------------------------------------------------------------------------- 0018 // KDE Includes 0019 0020 // ---------------------------------------------------------------------------- 0021 // Project Includes 0022 0023 #include "mymoneyfile.h" 0024 #include "accountsmodel.h" 0025 #include "securitiesmodel.h" 0026 #include "mymoneymoney.h" 0027 #include "mymoneyenums.h" 0028 0029 0030 0031 class AccountDelegate::Private 0032 { 0033 public: 0034 Private() 0035 {} 0036 0037 ~Private() 0038 { 0039 } 0040 }; 0041 0042 0043 AccountDelegate::AccountDelegate(QObject* parent) 0044 : QStyledItemDelegate(parent) 0045 , d(new Private) 0046 { 0047 } 0048 0049 AccountDelegate::~AccountDelegate() 0050 { 0051 delete d; 0052 } 0053 0054 void AccountDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const 0055 { 0056 QStyleOptionViewItem opt = option; 0057 QModelIndex baseIdx; 0058 initStyleOption(&opt, index); 0059 0060 QTreeView* view = qobject_cast< QTreeView*>(parent()); 0061 0062 if (view) { 0063 switch(index.column()) { 0064 case AccountsModel::Column::Balance: 0065 baseIdx = index.model()->index(index.row(), 0, index.parent()); 0066 if (!view->isExpanded(baseIdx) && index.model()->rowCount(index) != 0 0067 && baseIdx.data(eMyMoney::Model::AccountCurrencyIdRole).toString() != MyMoneyFile::instance()->baseCurrency().id()) { 0068 opt.text.clear(); 0069 } 0070 break; 0071 0072 case AccountsModel::Column::TotalPostedValue: 0073 baseIdx = index.model()->index(index.row(), 0, index.parent()); 0074 if (index.parent().isValid() && (view->isExpanded(baseIdx) || index.model()->rowCount(index) == 0)) { 0075 paint(painter, option, index.model()->index(index.row(), AccountsModel::Column::PostedValue, index.parent())); 0076 return; 0077 } 0078 break; 0079 } 0080 } 0081 0082 QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter); 0083 }