В
20 void Cell::setDirty
21 {
22 cacheIsDirty = true;
23 }
Функция
24 QVariant Cell::data(int role) const
25 {
26 if (role == Qt::DisplayRole) {
27 if (value.isValid) {
28 return value.toString;
29 } else {
30 return "####";
31 }
32 } else if (role == Qt::TextAlignmentRole) {
33 if (value.type == QVariant::String) {
34 return int(Qt::AlignLeft | Qt::AlignVCenter);
35 } else {
36 return int(Qt::AlignRight | Qt::AlignVCenter);
37 }
38 } else {
39 return QTableWidgetltem::data(role);
40 }
41 }
Функция
Функция
42 const QVariant Invalid;
43 QVariant Cell::value const
44 {
45 if (cacheIsDirty) {
46 cacheIsDirty = false;
47 QString formulaStr = formula;
48 if (formulaStr.startsWith('\'')) {
49 cachedValue = formulaStr.mid(1);
50 } else if (formulaStr.startsWith('=')) {
51 cachedValue = Invalid;
52 QString expr = formulaStr.mid(1);
53 expr.replace(" ", "");
54 expr.append(QChar::Null);
55 int pos = 0;
56 cachedValue = evalExpression(expr, pos);
57 if (expr[pos] != QChar::Null)
58 cachedValue = Invalid;
59 } else {
60 bool ok;
61 double d = formulaStr.toDouble(&ok);
62 if (ok) {
63 cachedValue = d;
64 } else {
65 cachedValue = formulaStr;
66 }
67 }
68 }
69 return cachedValue;
70 }
Закрытая функция