ui/qt/model.cpp

changeset 637
6a2c744fe042
parent 634
14016ce0a434
child 659
d6baaa93f7be
equal deleted inserted replaced
636:4630ddf7a20c 637:6a2c744fe042
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;
170 case UI_INTEGER: { 180 case UI_INTEGER: {
171 intptr_t i = (intptr_t)value; 181 intptr_t i = (intptr_t)value;
172 return QString::number(i); 182 return QString::number(i);
173 } 183 }
174 case UI_ICON: { 184 case UI_ICON: {
175 break; 185 break; // TODO
176 } 186 }
177 case UI_ICON_TEXT: { 187 case UI_ICON_TEXT: {
178 break; 188 break; // TODO
179 } 189 }
180 case UI_ICON_TEXT_FREE: { 190 case UI_ICON_TEXT_FREE: {
181 break; 191 break; // TODO
182 } 192 }
183 } 193 }
184 } 194 }
185 } 195 }
186 } 196 }

mercurial