本文整理汇总了C++中WModelIndex::parent方法的典型用法代码示例。如果您正苦于以下问题:C++ WModelIndex::parent方法的具体用法?C++ WModelIndex::parent怎么用?C++ WModelIndex::parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WModelIndex
的用法示例。
在下文中一共展示了WModelIndex::parent方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: match
WModelIndexList WAbstractItemModel::match(const WModelIndex& start,
int role,
const boost::any& value,
int hits,
WFlags<MatchFlag> flags)
const
{
WModelIndexList result;
const int rc = rowCount(start.parent());
for (int i = 0; i < rc; ++i) {
int row = start.row() + i;
if (row >= rc) {
if (!(flags & MatchWrap))
break;
else
row -= rc;
}
WModelIndex idx = index(row, start.column(), start.parent());
boost::any v = data(idx, role);
if (Impl::matchValue(v, value, flags))
result.push_back(idx);
}
return result;
}
示例2: dropEvent
void WAbstractItemModel::dropEvent(const WDropEvent& e, DropAction action,
int row, int column,
const WModelIndex& parent)
{
// TODO: For now, we assumes selectionBehavior() == RowSelection !
WItemSelectionModel *selectionModel
= dynamic_cast<WItemSelectionModel *>(e.source());
if (selectionModel) {
WAbstractItemModel *sourceModel = selectionModel->model();
/*
* (1) Insert new rows (or later: cells ?)
*/
if (action == MoveAction || row == -1) {
if (row == -1)
row = rowCount(parent);
insertRows(row, selectionModel->selectedIndexes().size(), parent);
}
/*
* (2) Copy data
*/
WModelIndexSet selection = selectionModel->selectedIndexes();
int r = row;
for (WModelIndexSet::const_iterator i = selection.begin();
i != selection.end(); ++i) {
WModelIndex sourceIndex = *i;
if (selectionModel->selectionBehavior() == SelectRows) {
WModelIndex sourceParent = sourceIndex.parent();
for (int col = 0; col < sourceModel->columnCount(sourceParent); ++col) {
WModelIndex s = sourceModel->index(sourceIndex.row(), col,
sourceParent);
WModelIndex d = index(r, col, parent);
copyData(sourceModel, s, this, d);
}
++r;
} else {
}
}
/*
* (3) Remove original data
*/
if (action == MoveAction) {
while (!selectionModel->selectedIndexes().empty()) {
WModelIndex i = Utils::last(selectionModel->selectedIndexes());
sourceModel->removeRow(i.row(), i.parent());
}
}
}
}
示例3: sourceDataChanged
void WSortFilterProxyModel::sourceDataChanged(const WModelIndex& topLeft,
const WModelIndex& bottomRight)
{
bool refilter
= dynamic_ && (filterKeyColumn_ >= topLeft.column()
&& filterKeyColumn_ <= bottomRight.column());
bool resort
= dynamic_ && (sortKeyColumn_ >= topLeft.column()
&& sortKeyColumn_ <= bottomRight.column());
WModelIndex parent = mapFromSource(topLeft.parent());
Item *item = itemFromIndex(parent);
for (int row = topLeft.row(); row <= bottomRight.row(); ++row) {
int oldMappedRow = item->sourceRowMap_[row];
bool propagateDataChange = oldMappedRow != -1;
if (refilter || resort) {
// Determine new insertion point: erase it temporarily for this
if (oldMappedRow != -1)
item->proxyRowMap_.erase(item->proxyRowMap_.begin() + oldMappedRow);
int newMappedRow = mappedInsertionPoint(row, item);
if (oldMappedRow != -1)
item->proxyRowMap_.insert(item->proxyRowMap_.begin() + oldMappedRow, row);
if (newMappedRow != oldMappedRow) {
if (oldMappedRow != -1) {
beginRemoveRows(parent, oldMappedRow, oldMappedRow);
item->proxyRowMap_.erase
(item->proxyRowMap_.begin() + oldMappedRow);
rebuildSourceRowMap(item);
endRemoveRows();
}
if (newMappedRow != -1) {
beginInsertRows(parent, newMappedRow, newMappedRow);
item->proxyRowMap_.insert
(item->proxyRowMap_.begin() + newMappedRow, row);
rebuildSourceRowMap(item);
endInsertRows();
}
propagateDataChange = false;
}
}
if (propagateDataChange) {
WModelIndex l = sourceModel()->index(row, topLeft.column(),
topLeft.parent());
WModelIndex r = sourceModel()->index(row, bottomRight.column(),
topLeft.parent());
dataChanged().emit(mapFromSource(l), mapFromSource(r));
}
}
}
示例4: modelDataChanged
void WSuggestionPopup::modelDataChanged(const WModelIndex& topLeft,
const WModelIndex& bottomRight)
{
if (topLeft.parent().isValid())
return;
if (modelColumn_ < topLeft.column() || modelColumn_ > bottomRight.column())
return;
for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
WContainerWidget *w = dynamic_cast<WContainerWidget *>(impl_->widget(i));
WAnchor *anchor = dynamic_cast<WAnchor *>(w->widget(0));
WText *value = dynamic_cast<WText *>(anchor->widget(0));
WModelIndex index = model_->index(i, modelColumn_);
boost::any d = index.data();
value->setText(asString(d));
TextFormat format = index.flags() & ItemIsXHTMLText ? XHTMLText : PlainText;
value->setTextFormat(format);
boost::any d2 = model_->data(i, modelColumn_, UserRole);
if (d2.empty())
d2 = d;
value->setAttributeValue("sug", asString(d2));
}
}
示例5: mapFromSource
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();
}
示例6: modelDataChanged
void WSuggestionPopup::modelDataChanged(const WModelIndex& topLeft,
const WModelIndex& bottomRight)
{
if (topLeft.parent().isValid())
return;
if (modelColumn_ < topLeft.column() || modelColumn_ > bottomRight.column())
return;
for (int i = topLeft.row(); i <= bottomRight.row(); ++i) {
WContainerWidget *w = dynamic_cast<WContainerWidget *>(content_->widget(i));
WText *value = dynamic_cast<WText *>(w->widget(0));
boost::any d = model_->data(i, modelColumn_);
value->setText(asString(d));
boost::any d2 = model_->data(i, modelColumn_, UserRole);
if (d2.empty())
d2 = d;
value->setAttributeValue("sug", asString(d2));
}
}
示例7: shiftModelIndexes
void WAbstractProxyModel::shiftModelIndexes(const WModelIndex& sourceParent,
int start, int count,
ItemMap& items)
{
/*
* We must shift all indexes within sourceParent >= start with count
* and delete items when count < 0.
*/
std::vector<BaseItem *> shifted;
std::vector<BaseItem *> erased;
for (ItemMap::iterator it
= items.lower_bound(sourceModel()->index(start, 0, sourceParent));
it != items.end();) {
#ifndef WT_TARGET_JAVA
ItemMap::iterator n = it;
++n;
#endif
WModelIndex i = it->first;
if (i.isValid()) {
WModelIndex p = i.parent();
if (p != sourceParent && !WModelIndex::isAncestor(p, sourceParent))
break;
if (p == sourceParent) {
shifted.push_back(it->second);
} else if (count < 0) {
// delete indexes that are about to be deleted, if they are within
// the range of deleted indexes
do {
if (p.parent() == sourceParent
&& p.row() >= start
&& p.row() < start - count) {
erased.push_back(it->second);
break;
} else
p = p.parent();
} while (p != sourceParent);
}
}
#ifndef WT_TARGET_JAVA
it = n;
#endif
}
for (unsigned i = 0; i < erased.size(); ++i) {
items.erase(erased[i]->sourceIndex_);
delete erased[i];
}
for (unsigned i = 0; i < shifted.size(); ++i) {
BaseItem *item = shifted[i];
items.erase(item->sourceIndex_);
if (item->sourceIndex_.row() + count >= start) {
item->sourceIndex_ = sourceModel()->index
(item->sourceIndex_.row() + count,
item->sourceIndex_.column(),
sourceParent);
} else {
delete item;
shifted[i] = 0;
}
}
for (unsigned i = 0; i < shifted.size(); ++i) {
if (shifted[i])
items[shifted[i]->sourceIndex_] = shifted[i];
}
}
示例8: parent
WModelIndex WIdentityProxyModel::parent(const WModelIndex &child) const
{
const WModelIndex sourceIndex = mapToSource(child);
const WModelIndex sourceParent = sourceIndex.parent();
return mapFromSource(sourceParent);
}