| 26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
| 27 */ |
27 */ |
| 28 |
28 |
| 29 #include "model.h" |
29 #include "model.h" |
| 30 |
30 |
| 31 static void* model_getvalue(UiModel *model, UiList *list, void *elm, int row, int col) { |
31 static void* model_getvalue(UiModel *model, UiList *list, void *elm, int row, int col, UiBool *freeResult) { |
| 32 if(model->getvalue2) { |
32 if(model->getvalue2) { |
| 33 return model->getvalue2(list, elm, row, col, model->getvalue2data); |
33 return model->getvalue2(list, elm, row, col, model->getvalue2data, freeResult); |
| 34 } else if(model->getvalue) { |
34 } else if(model->getvalue) { |
| 35 return model->getvalue(elm, col); |
35 return model->getvalue(elm, col); |
| 36 } |
36 } |
| 37 return NULL; |
37 return NULL; |
| 38 } |
38 } |
| 76 QVariant ListModel::data(const QModelIndex &index, int role) const { |
76 QVariant ListModel::data(const QModelIndex &index, int role) const { |
| 77 if(role == Qt::DisplayRole) { |
77 if(role == Qt::DisplayRole) { |
| 78 UiList *ls = (UiList*)var->value; |
78 UiList *ls = (UiList*)var->value; |
| 79 void *rowData = ls->get(ls, index.row()); |
79 void *rowData = ls->get(ls, index.row()); |
| 80 if(rowData && getvalue) { |
80 if(rowData && getvalue) { |
| 81 void *value = getvalue(ls, rowData, index.row(), 0, getvaluedata); |
81 UiBool freeResult = false; |
| |
82 void *value = getvalue(ls, rowData, index.row(), 0, getvaluedata, &freeResult); |
| 82 if(value) { |
83 if(value) { |
| 83 return QString::fromUtf8((char*)value); |
84 auto qs = QString::fromUtf8((char*)value); |
| |
85 if(freeResult) { |
| |
86 free(value); |
| |
87 } |
| |
88 return qs; |
| 84 } |
89 } |
| 85 } |
90 } |
| 86 } |
91 } |
| 87 return QVariant(); |
92 return QVariant(); |
| 88 } |
93 } |
| 153 if(role == Qt::DisplayRole) { |
158 if(role == Qt::DisplayRole) { |
| 154 UiList *ls = (UiList*)var->value; |
159 UiList *ls = (UiList*)var->value; |
| 155 void *rowData = ls->get(ls, index.row()); |
160 void *rowData = ls->get(ls, index.row()); |
| 156 if(rowData) { |
161 if(rowData) { |
| 157 int col = index.column(); |
162 int col = index.column(); |
| 158 void *value = model_getvalue(model, ls, rowData, index.row(), col); |
163 UiBool freeResult = false; |
| |
164 void *value = model_getvalue(model, ls, rowData, index.row(), col, &freeResult); |
| 159 if(value) { |
165 if(value) { |
| 160 UiModelType type = model->types[col]; |
166 UiModelType type = model->types[col]; |
| 161 switch(type) { |
167 switch(type) { |
| 162 case UI_STRING: { |
168 case UI_STRING: { |
| 163 return QString::fromUtf8((char*)value); |
169 auto qs = QString::fromUtf8((char*)value); |
| |
170 if(freeResult) { |
| |
171 free(value); |
| |
172 } |
| |
173 return qs; |
| 164 } |
174 } |
| 165 case UI_STRING_FREE: { |
175 case UI_STRING_FREE: { |
| 166 QString s = QString::fromUtf8((char*)value); |
176 QString s = QString::fromUtf8((char*)value); |
| 167 free(value); |
177 free(value); |
| 168 return s; |
178 return s; |