--- a/ui/qt/model.cpp Fri Jan 09 14:33:40 2015 +0100 +++ b/ui/qt/model.cpp Sat Jan 10 10:14:28 2015 +0100 @@ -28,9 +28,11 @@ #include "model.h" -TableModel::TableModel(UiListPtr *list, UiModelInfo *info) { +TableModel::TableModel(UiObject *obj, QTreeView *view, UiListPtr *list, UiModelInfo *info) { + this->obj = obj; this->list = list; this->info = info; + this->view = view; } int TableModel::rowCount(const QModelIndex &parent) const { @@ -61,4 +63,62 @@ return QVariant(); } +QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const { + if(role == Qt::DisplayRole) { + char *label = info->titles[section]; + return QString::fromUtf8(label); + } + return QVariant(); +} +UiListSelection* TableModel::listSelection() { + UiListSelection *selection = new UiListSelection(); + + QModelIndexList list = view->selectionModel()->selectedRows(); + selection->count = list.count(); + if(selection->count > 0) { + selection->rows = new int[selection->count]; + } + + QModelIndex index; + int i=0; + foreach(index, list) { + selection->rows[i] = index.row(); + i++; + } + return selection; +} + +void TableModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { + UiListSelection *selection = listSelection(); + + UiEvent e; + e.obj = obj; + e.window = obj->window; + e.document = obj->ctx->document; + e.eventdata = selection; + e.intval = selection->count > 0 ? selection->rows[0] : -1; + info->selection(&e, info->userdata); + + if(selection->count > 0) { + delete selection->rows; + } + delete selection; +} + +void TableModel::activate(const QModelIndex &) { + UiListSelection *selection = listSelection(); + + UiEvent e; + e.obj = obj; + e.window = obj->window; + e.document = obj->ctx->document; + e.eventdata = selection; + e.intval = selection->count > 0 ? selection->rows[0] : -1; + info->activate(&e, info->userdata); + + if(selection->count > 0) { + delete selection->rows; + } + delete selection; +}