-
Notifications
You must be signed in to change notification settings - Fork 18
/
CListProperty.cpp
145 lines (109 loc) · 2.77 KB
/
CListProperty.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <QDebug>
#include "CListProperty.h"
CListProperty::CListProperty(const QByteArray &id, const QString &name, const CListData &list, int index, int defaultIndex):
CBaseProperty(id, name),
m_index(index),
m_listData(list),
m_defaultIndex(defaultIndex)
{
setIndex(m_index);
}
CListProperty::CListProperty(CBaseProperty *top, const QByteArray &id, const QString &name, const CListData &list, int index, int defaultIndex):
CBaseProperty(top, id, name),
m_index(index),
m_listData(list),
m_defaultIndex(defaultIndex)
{
setIndex(m_index);
}
void CListProperty::setIndex(int index)
{
m_index = index;
CBaseProperty::setValue();
}
int CListProperty::getIndex() const
{
return m_index;
}
void CListProperty::setList(const CListData &list)
{
// handle editor...
m_listData = list;
CBaseProperty::setValue();
}
void CListProperty::onShowEditor(QWidget *editWidget)
{
QComboBox* comboEditor = dynamic_cast<QComboBox*>(editWidget);
if (comboEditor != NULL)
{
if (comboEditor->count() == 0)
{
for (int i = 0; i < m_listData.size(); i++)
{
const CListDataItem& data = m_listData.at(i);
comboEditor->addItem(data.m_icon, data.m_text, data.m_userData);
}
}
}
}
void CListProperty::validateValue()
{
if (m_index < 0)
m_index = 0;
if (m_index >= m_listData.size())
m_index = m_listData.size() - 1;
}
void CListProperty::displayValue()
{
if (treeWidget())
treeWidget()->blockSignals(true);
if (m_listData.isEmpty())
{
setText(1, QObject::tr("<empty>"));
setIcon(1, QIcon());
}
else
if (m_index < 0)
{
setText(1, QObject::tr("<unknown>"));
setIcon(1, QIcon());
}
else
{
const CListDataItem& data = m_listData.at(m_index);
setText(1, data.m_text);
setIcon(1, data.m_icon);
}
if (treeWidget())
treeWidget()->blockSignals(false);
}
QVariant CListProperty::getVariantValue() const
{
return m_index;
}
QWidget *CListProperty::createEditor() const
{
return new QComboBox();
}
void CListProperty::valueToEditor()
{
QComboBox* comboEditor = dynamic_cast<QComboBox*>(getActiveEditor());
if (comboEditor != NULL)
{
//qDebug() << "CListProperty::valueToEditor()" << m_index << m_listData.size();
comboEditor->setCurrentIndex(m_index);
}
}
void CListProperty::valueFromEditor()
{
QComboBox* comboEditor = dynamic_cast<QComboBox*>(getActiveEditor());
if (comboEditor != NULL)
{
int newIndex = comboEditor->currentIndex();
if (newIndex != m_index)
{
setIndex(newIndex);
emitValueChanged();
}
}
}