ui/qt/model.cpp

changeset 115
e57ca2747782
parent 109
c3dfcb8f0be7
equal deleted inserted replaced
114:3da24640513a 115:e57ca2747782
27 */ 27 */
28 28
29 #include "model.h" 29 #include "model.h"
30 30
31 31
32 ListModel::ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc2 getvalue, void *getvaluedata){ 32 ListModel::ListModel(UiObject *obj, QListView *view, UiVar *var, ui_getvaluefunc2 getvalue, void *getvaluedata) {
33 this->obj = obj; 33 this->obj = obj;
34 this->view = view; 34 this->listview = view;
35 this->combobox = nullptr;
36 this->var = var;
37 this->getvalue = getvalue;
38 this->getvaluedata = getvaluedata;
39 this->onactivate = nullptr;
40 this->onactivatedata = nullptr;
41 this->onselection = nullptr;
42 this->onselectiondata = nullptr;
43 }
44
45 ListModel::ListModel(UiObject *obj, QComboBox *view, UiVar *var, ui_getvaluefunc2 getvalue, void *getvaluedata) {
46 this->obj = obj;
47 this->combobox = view;
48 this->listview = nullptr;
35 this->var = var; 49 this->var = var;
36 this->getvalue = getvalue; 50 this->getvalue = getvalue;
37 this->getvaluedata = getvaluedata; 51 this->getvaluedata = getvaluedata;
38 this->onactivate = nullptr; 52 this->onactivate = nullptr;
39 this->onactivatedata = nullptr; 53 this->onactivatedata = nullptr;
83 } 97 }
84 return QVariant(); 98 return QVariant();
85 } 99 }
86 100
87 void ListModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { 101 void ListModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) {
88 UiListSelection sel = ui_selection_model_to_selection(view->selectionModel()); 102 UiListSelection sel;
103 if(listview) {
104 sel = ui_selection_model_to_selection(listview->selectionModel());
105 } else {
106 // TODO
107 }
89 108
90 UiEvent event; 109 UiEvent event;
91 event.obj = obj; 110 event.obj = obj;
92 event.window = obj->window; 111 event.window = obj->window;
93 event.document = obj->ctx->document; 112 event.document = obj->ctx->document;
255 QItemSelection selection; 274 QItemSelection selection;
256 for (int i=0;i<sel.count;i++) { 275 for (int i=0;i<sel.count;i++) {
257 QModelIndex index = model->index(sel.rows[i]); 276 QModelIndex index = model->index(sel.rows[i]);
258 selection.select(index, index); 277 selection.select(index, index);
259 } 278 }
260 model->view->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect); 279 if(model->listview) {
280 model->listview->selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect);
281 } else if(model->combobox) {
282 // TODO
283 }
261 } 284 }
262 285
263 UiListSelection ui_listmodel_getselection(UiList *list) { 286 UiListSelection ui_listmodel_getselection(UiList *list) {
264 ListModel *model = (ListModel*)list->obj; 287 ListModel *model = (ListModel*)list->obj;
265 return ui_selection_model_to_selection(model->view->selectionModel()); 288 if(model->listview) {
266 } 289 return ui_selection_model_to_selection(model->listview->selectionModel());
290 } else {
291 UiListSelection sel = { 0, NULL };
292 return sel;
293 }
294 }

mercurial