WModelIndex WIdentityProxyModel::mapFromSource(const WModelIndex &sourceIndex) const { if (!sourceIndex.isValid()) return WModelIndex(); return createIndex(sourceIndex.row(), sourceIndex.column(), sourceIndex.internalPointer()); }
void WSuggestionPopup::setModelColumn(int modelColumn) { modelColumn_ = modelColumn; impl_->clear(); modelRowsInserted(WModelIndex(), 0, model_->rowCount() - 1); }
WModelIndex WSortFilterProxyModel::mapFromSource(const WModelIndex& sourceIndex) const { if (sourceIndex.isValid()) { WModelIndex sourceParent = sourceIndex.parent(); Item *item = itemFromSourceIndex(sourceParent); int row = item->sourceRowMap_[sourceIndex.row()]; if (row != -1) return createIndex(row, sourceIndex.column(), static_cast<void *>(item)); else return WModelIndex(); } else return WModelIndex(); }
WModelIndex WIdentityProxyModel::index(int row, int column, const WModelIndex &parent) const { if (!hasIndex(row, column, parent)) return WModelIndex(); const WModelIndex sourceParent = mapToSource(parent); const WModelIndex sourceIndex = sourceModel()->index(row, column, sourceParent); return mapFromSource(sourceIndex); }
WModelIndex WStandardItemModel::indexFromItem(const WStandardItem *item) const { if (item == invisibleRootItem_) return WModelIndex(); else return createIndex(item->row(), item->column(), static_cast<void *>(item->parent())); }
virtual WModelIndex parent(const WModelIndex& index) const { if (!index.isValid() || index.internalId() == 0) { return WModelIndex(); // treeData_[0] is the tree root } else { const Tree& item = treeData_[index.internalId()]; return createIndex(item.index(), 0, item.parentId()); } }
WModelIndex WSortFilterProxyModel::parent(const WModelIndex& index) const { if (index.isValid()) { Item *parentItem = parentItemFromIndex(index); return mapFromSource(parentItem->sourceIndex_); } else return WModelIndex(); }
WModelIndex WSortFilterProxyModel::mapToSource(const WModelIndex& proxyIndex) const { if (proxyIndex.isValid()) { Item *parentItem = parentItemFromIndex(proxyIndex); return sourceModel()->index(parentItem->proxyRowMap_[proxyIndex.row()], proxyIndex.column(), parentItem->sourceIndex_); } else return WModelIndex(); }
WModelIndex WModelIndex::decodeFromRawIndex() const { if (model_) { if (!isRawIndex()) { LOG_ERROR("decodeFromRawIndex(): can only decode an encoded raw index"); return WModelIndex(); } return model_->fromRawIndex(internalPointer()); } else return *this; }
WSortFilterProxyModel::Item * WSortFilterProxyModel::itemFromIndex(const WModelIndex& index) const { if (index.isValid()) { Item *parentItem = parentItemFromIndex(index); WModelIndex sourceIndex = sourceModel()->index(parentItem->proxyRowMap_[index.row()], index.column(), parentItem->sourceIndex_); return itemFromSourceIndex(sourceIndex); } else return itemFromSourceIndex(WModelIndex()); }
void WSortFilterProxyModel::sourceHeaderDataChanged(Orientation orientation, int start, int end) { if (orientation == Vertical) { Item *item = itemFromIndex(WModelIndex()); for (int row = start; row <= end; ++row) { int mappedRow = item->sourceRowMap_[row]; if (mappedRow != -1) headerDataChanged().emit(orientation, mappedRow, mappedRow); } } else headerDataChanged().emit(orientation, start, end); }
virtual WModelIndex index(int row, int column, const WModelIndex& parent = WModelIndex()) const { int parentId; if (!parent.isValid()) parentId = 0; else { int grandParentId = parent.internalId(); parentId = getTreeId(grandParentId, parent.row()); } return createIndex(row, column, parentId); }
WModelIndex WStandardItemModel::index(int row, int column, const WModelIndex& parent) const { WStandardItem *parentItem = itemFromIndex(parent, false); if (parentItem && row >= 0 && column >= 0 && row < parentItem->rowCount() && column < parentItem->columnCount()) return createIndex(row, column, static_cast<void *>(parentItem)); return WModelIndex(); }
WModelIndex GitModel::parent(const WModelIndex& index) const { // treeData_[0] indicates the top-level parent. if (!index.isValid() || index.internalId() == 0) return WModelIndex(); else { // get the item that corresponds to the parent ... const Tree& item = treeData_[index.internalId()]; // ... and construct that identifies the parent: // row = child index in the grand parent // internalId = id of the grand parent return createIndex(item.index(), 0, item.parentId()); } }
virtual int rowCount(const WModelIndex& parent = WModelIndex()) const { int treeId; if (parent.isValid()) { if (parent.column() != 0) return 0; Git::Object o = getObject(parent); if (o.type == Git::Tree) { // is a folder treeId = getTreeId(parent.internalId(), parent.row()); } else // is a file return 0; } else { treeId = 0; } return treeData_[treeId].rowCount(); }
virtual int columnCount(const WModelIndex& parent = WModelIndex()) const { return 2; }
WModelIndex WModelIndex::child(int row, int column) const { return model_ ? model_->index(row, column, *this) : WModelIndex(); }
boost::any WModelIndex::data(int role) const { return model_ ? model_->data(*this, role) : WModelIndex(); }
WModelIndex WAbstractItemModel::createIndex(int row, int column, ::uint64_t id) const { return WModelIndex(row, column, this, id); }
WModelIndex WAbstractItemModel::fromRawIndex(void *rawIndex) const { return WModelIndex(); }
WModelIndex WAbstractItemModel::createIndex(int row, int column, void *ptr) const { return WModelIndex(row, column, this, ptr); }
void WSuggestionPopup::modelLayoutChanged() { impl_->clear(); modelRowsInserted(WModelIndex(), 0, model_->rowCount() - 1); }
WModelIndex WModelIndex::parent() const { return model_ ? model_->parent(*this) : WModelIndex(); }
WModelIndex WIdentityProxyModel::mapToSource(const WModelIndex &proxyIndex) const { if (!sourceModel() || !proxyIndex.isValid()) return WModelIndex(); return createSourceIndex(proxyIndex.row(), proxyIndex.column(), proxyIndex.internalPointer()); }
WModelIndex WAbstractTableModel::parent(const WModelIndex& index) const { return WModelIndex(); }