-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableItemDelegate.cpp
44 lines (40 loc) · 1.21 KB
/
TableItemDelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "TableItemDelegate.h"
#include <QPainter>
#include "TableModel.h"
#include "TradeItem.h"
TableItemDelegate::TableItemDelegate(QMap<int,ColumnObject>& m_ColumnMap,QObject* parent):QItemDelegate(parent)
{
m_UpPixmap = QPixmap("images/Up.png");
m_DownPixmap = QPixmap("images/Down.png");
for(int i=0;i<m_ColumnMap.count();i++)
{
if(m_ColumnMap[i].IsPicture())
{
m_PictureLogicalIndex = i;
break;
}
}
}
void TableItemDelegate::paint(QPainter* painter,const QStyleOptionViewItem& option,const QModelIndex& index) const
{
if(index.column()==m_PictureLogicalIndex)
{
const QAbstractItemModel* model = index.model();
QVariant var = model->data(index,Qt::CheckStateRole);
if(var.isNull())
var = false;
TableModel* tableModel = ((TableModel*)model);
TradeItem item = tableModel->GetItemList().at(index.row());
double perPrice = tableModel->GetPerPriceMap()[item.m_TradingCode].toDouble();
double currentPrice = item.m_CurrentBidPrice.toDouble();
QPixmap pixmap;
if(currentPrice<perPrice)
pixmap = m_DownPixmap;
else if(currentPrice>perPrice)
pixmap = m_UpPixmap;
else
pixmap = QPixmap("");
painter->drawPixmap(option.rect,pixmap);
}
QItemDelegate::paint(painter,option,index);
}