ui/qt/model.cpp

changeset 634
14016ce0a434
parent 585
e71867b33bfd
child 637
6a2c744fe042
equal deleted inserted replaced
633:4c6ba81d319e 634:14016ce0a434
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 31 static void* model_getvalue(UiModel *model, UiList *list, void *elm, int row, int col) {
32 ListModel::ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc getvalue){ 32 if(model->getvalue2) {
33 return model->getvalue2(list, elm, row, col, model->getvalue2data);
34 } else if(model->getvalue) {
35 return model->getvalue(elm, col);
36 }
37 return NULL;
38 }
39
40 ListModel::ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc2 getvalue, void *getvaluedata){
33 this->obj = obj; 41 this->obj = obj;
34 this->view = view; 42 this->view = view;
35 this->var = var; 43 this->var = var;
36 this->getvalue = getvalue; 44 this->getvalue = getvalue;
45 this->getvaluedata = getvaluedata;
37 this->onactivate = nullptr; 46 this->onactivate = nullptr;
38 this->onactivatedata = nullptr; 47 this->onactivatedata = nullptr;
39 this->onselection = nullptr; 48 this->onselection = nullptr;
40 this->onselectiondata = nullptr; 49 this->onselectiondata = nullptr;
41 } 50 }
67 QVariant ListModel::data(const QModelIndex &index, int role) const { 76 QVariant ListModel::data(const QModelIndex &index, int role) const {
68 if(role == Qt::DisplayRole) { 77 if(role == Qt::DisplayRole) {
69 UiList *ls = (UiList*)var->value; 78 UiList *ls = (UiList*)var->value;
70 void *rowData = ls->get(ls, index.row()); 79 void *rowData = ls->get(ls, index.row());
71 if(rowData && getvalue) { 80 if(rowData && getvalue) {
72 void *value = getvalue(rowData, 0); 81 void *value = getvalue(ls, rowData, index.row(), 0, getvaluedata);
73 if(value) { 82 if(value) {
74 return QString::fromUtf8((char*)value); 83 return QString::fromUtf8((char*)value);
75 } 84 }
76 } 85 }
77 } 86 }
142 151
143 QVariant TableModel::data(const QModelIndex &index, int role) const { 152 QVariant TableModel::data(const QModelIndex &index, int role) const {
144 if(role == Qt::DisplayRole) { 153 if(role == Qt::DisplayRole) {
145 UiList *ls = (UiList*)var->value; 154 UiList *ls = (UiList*)var->value;
146 void *rowData = ls->get(ls, index.row()); 155 void *rowData = ls->get(ls, index.row());
147 if(rowData && model->getvalue) { 156 if(rowData) {
148 int col = index.column(); 157 int col = index.column();
149 void *value = model->getvalue(rowData, col); 158 void *value = model_getvalue(model, ls, rowData, index.row(), col);
150 if(value) { 159 if(value) {
151 UiModelType type = model->types[col]; 160 UiModelType type = model->types[col];
152 switch(type) { 161 switch(type) {
153 case UI_STRING: { 162 case UI_STRING: {
154 return QString::fromUtf8((char*)value); 163 return QString::fromUtf8((char*)value);

mercurial