-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTreeModelStandardItem.cpp
48 lines (40 loc) · 1.22 KB
/
TreeModelStandardItem.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
45
46
47
48
#include "TreeModelStandardItem.h"
TreeModelStandardItem::TreeModelStandardItem(int columns):
TreeModelItem(columns) {}
TreeModelStandardItem::TreeModelStandardItem(const QString &text, const QPixmap &pixmap):
TreeModelItem(1)
{
setData(0, text, Qt::DisplayRole);
setPixmap(pixmap);
}
void TreeModelStandardItem::setPixmap(const QPixmap &pixmap, int column)
{
if(!pixmap.isNull())
setData(column, QVariant::fromValue(pixmap), Qt::DecorationRole);
else
setData(column, QVariant(), Qt::DecorationRole);
}
void TreeModelStandardItem::setToolTip(const QString &toolTip, int column)
{
if(!toolTip.isEmpty())
setData(column, toolTip, Qt::ToolTipRole);
else
setData(column, QVariant(), Qt::ToolTipRole);
}
bool TreeModelStandardItem::setData(int column, const QVariant &value, int role)
{
if(column >= columnCount())
return false;
if(!value.isNull())
m_data[column].insert(role, value);
else
m_data[column].remove(role);
return true;
}
QVariant TreeModelStandardItem::data(int column, int role) const
{
if(m_data.contains(column) &&
m_data[column].contains(role))
return m_data[column].value(role);
return QVariant();
}