ui/qt/model.cpp

changeset 582
6c86efe60b37
parent 581
7486347f73cf
child 583
30083c6cb198
equal deleted inserted replaced
581:7486347f73cf 582:6c86efe60b37
97 free(sel.rows); 97 free(sel.rows);
98 } 98 }
99 99
100 100
101 101
102 TableModel::TableModel(UiObject *obj, QTreeView *view, UiVar *var, ui_getvaluefunc getvalue){ 102 TableModel::TableModel(UiObject *obj, QTreeView *view, UiVar *var, UiModel *model){
103 this->obj = obj; 103 this->obj = obj;
104 this->view = view; 104 this->view = view;
105 this->var = var; 105 this->var = var;
106 this->getvalue = getvalue; 106 this->model = model;
107 this->onactivate = nullptr; 107 this->onactivate = nullptr;
108 this->onactivatedata = nullptr; 108 this->onactivatedata = nullptr;
109 this->onselection = nullptr; 109 this->onselection = nullptr;
110 this->onselectiondata = nullptr; 110 this->onselectiondata = nullptr;
111 } 111 }
132 int TableModel::rowCount(const QModelIndex& parent) const { 132 int TableModel::rowCount(const QModelIndex& parent) const {
133 UiList *list = (UiList*)var->value; 133 UiList *list = (UiList*)var->value;
134 return ui_list_count(list); 134 return ui_list_count(list);
135 } 135 }
136 136
137 int TableModel::columnCount(const QModelIndex &parent) const {
138 return model->columns;
139 }
140
137 QVariant TableModel::data(const QModelIndex &index, int role) const { 141 QVariant TableModel::data(const QModelIndex &index, int role) const {
138 if(role == Qt::DisplayRole) { 142 if(role == Qt::DisplayRole) {
139 UiList *ls = (UiList*)var->value; 143 UiList *ls = (UiList*)var->value;
140 void *rowData = ls->get(ls, index.row()); 144 void *rowData = ls->get(ls, index.row());
141 if(rowData && getvalue) { 145 if(rowData && model->getvalue) {
142 void *value = getvalue(rowData, 0); 146 void *value = model->getvalue(rowData, index.column());
143 return QString::fromUtf8((char*)value); 147 return QString::fromUtf8((char*)value);
144 } 148 }
149 }
150 return QVariant();
151 }
152
153 QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const {
154 if(role == Qt::DisplayRole) {
155 char *label = model->titles[section];
156 return QString::fromUtf8(label);
145 } 157 }
146 return QVariant(); 158 return QVariant();
147 } 159 }
148 160
149 void TableModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { 161 void TableModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) {

mercurial