コード例 #1
0
ファイル: mergemodel.cpp プロジェクト: ForNeVeR/leechcraft
	void MergeModel::handleRowsAboutToBeInserted (const QModelIndex& parent,
			int first, int last)
	{
		const auto model = static_cast<QAbstractItemModel*> (sender ());

		const auto startingRow = parent.isValid () ?
				0 :
				GetStartingRow (FindModel (model));
		beginInsertRows (mapFromSource (parent),
				first + startingRow, last + startingRow);
	}
コード例 #2
0
QModelIndex KConcatenateRowsProxyModel::index(int row, int column, const QModelIndex &parent) const
{
    Q_ASSERT(row >= 0);
    Q_ASSERT(column >= 0);
    int sourceRow;
    QAbstractItemModel *sourceModel = d->sourceModelForRow(row, &sourceRow);
    if (!sourceModel) {
        return QModelIndex();
    }
    return mapFromSource(sourceModel->index(sourceRow, column, parent));
}
コード例 #3
0
ファイル: MsgListModel.cpp プロジェクト: adamkudrna/trojita
void MsgListModel::handleRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
{
    checkPersistentIndex();
    if (! parent.isValid())
        return;

    TreeItemMsgList *newList = dynamic_cast<TreeItemMsgList *>(Model::realTreeItem(parent));
    if (msgListPtr && msgListPtr == newList) {
        beginInsertRows(mapFromSource(parent), start, end);
    }
}
コード例 #4
0
QModelIndex GroupProxyModel::parent(const QModelIndex &child) const {
    if (! child.isValid())
        return QModelIndex();

    int* srcParent = (int*) child.internalPointer();

    if (srcParent == NULL || *srcParent == -1)
        return QModelIndex();
    else
        return mapFromSource(sourceModel()->index(*srcParent, 0));
}
コード例 #5
0
ファイル: qidentityproxymodel.cpp プロジェクト: Afreeca/qt
/*!
    \reimp
 */
QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex& parent) const
{
    Q_ASSERT(parent.isValid() ? parent.model() == this : true);
    Q_D(const QIdentityProxyModel);
    if (!hasIndex(row, column, parent))
        return QModelIndex();
    const QModelIndex sourceParent = mapToSource(parent);
    const QModelIndex sourceIndex = d->model->index(row, column, sourceParent);
    Q_ASSERT(sourceIndex.isValid());
    return mapFromSource(sourceIndex);
}
コード例 #6
0
QModelIndex WorkPackageProxyModel::mapFromBaseModel( const QModelIndex &idx ) const
{
    if ( ! idx.isValid() ) {
        return QModelIndex();
    }
    QModelIndex in = idx;
    for ( int i = m_proxies.count() -1; i >= 0; --i ) {
        in = m_proxies.at( i )->mapFromSource( in );
    }
    return mapFromSource( in );
}
コード例 #7
0
void SelectionModelSynchronizer::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
  Q_UNUSED(previous);

  _changeCurrentEnabled = false;
  QSet<QItemSelectionModel *>::iterator iter = _selectionModels.begin();
  while(iter != _selectionModels.end()) {
    (*iter)->setCurrentIndex(mapFromSource(current, (*iter)), QItemSelectionModel::Current);
    iter++;
  }
  _changeCurrentEnabled = true;
}
コード例 #8
0
ファイル: qabstractproxymodel.cpp プロジェクト: Afreeca/qt
/*!
  Returns a proxy selection mapped from the specified \a sourceSelection.

  Reimplement this method to map source selections to proxy selections.
*/
QItemSelection QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const
{
    QModelIndexList sourceIndexes = sourceSelection.indexes();
    QItemSelection proxySelection;
    for (int i = 0; i < sourceIndexes.size(); ++i) {
        const QModelIndex srcIdx = mapFromSource(sourceIndexes.at(i));
        if (!srcIdx.isValid())
            continue;
        proxySelection << QItemSelectionRange(srcIdx);
    }
    return proxySelection;
}
コード例 #9
0
QModelIndex ProxyModel::index(int row, int column, const QModelIndex &parent) const
{
	const QModelIndex sourceParent = mapToSource(parent);
	const QModelIndex sourceIndex = m_model->index(row, 0, sourceParent);

	if (column > 0)
	{
		return createIndex(row, column, sourceIndex.internalId());
	}

	return mapFromSource(sourceIndex);
}
コード例 #10
0
ファイル: MailboxModel.cpp プロジェクト: adamkudrna/trojita
void MailboxModel::handleRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
{
    TreeItemMailbox *parentMbox = dynamic_cast<TreeItemMailbox *>(static_cast<TreeItem *>(parent.internalPointer()));
    if (parent.internalPointer() && ! parentMbox)
        return;
    if (! parentMbox)
        parentMbox = static_cast<Imap::Mailbox::Model *>(sourceModel())->m_mailboxes;
    Q_ASSERT(first >= 1);
    Q_ASSERT(last <= parentMbox->m_children.size() - 1);
    Q_ASSERT(first <= last);
    beginRemoveRows(mapFromSource(parent), first - 1, last - 1);
}
コード例 #11
0
ファイル: MsgListModel.cpp プロジェクト: adamkudrna/trojita
void MsgListModel::handleRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
{
    if (! parent.isValid()) {
        // Top-level items are tricky :(. As a quick hack, let's just die.
        resetMe();
        return;
    }

    checkPersistentIndex();
    if (! msgListPtr)
        return;

    TreeItem *item = Model::realTreeItem(parent);
    TreeItemMailbox *mailbox = dynamic_cast<TreeItemMailbox *>(item);
    TreeItemMsgList *newList = dynamic_cast<TreeItemMsgList *>(item);

    if (parent.isValid()) {
        Q_ASSERT(parent.model() == sourceModel());
    } else {
        // a top-level mailbox might have been deleted, so we gotta setup proper pointer
        mailbox = static_cast<Model *>(sourceModel())->m_mailboxes;
        Q_ASSERT(mailbox);
    }

    if (newList) {
        if (newList == msgListPtr) {
            beginRemoveRows(mapFromSource(parent), start, end);
            for (int i = start; i <= end; ++i)
                emit messageRemoved(msgListPtr->m_children[i]);
        }
    } else if (mailbox) {
        Q_ASSERT(start > 0);
        // if we're below it, we're gonna die
        for (int i = start; i <= end; ++i) {
            const Model *model = 0;
            QModelIndex translatedParent;
            Model::realTreeItem(parent, &model, &translatedParent);
            // FIXME: this assumes that no rows were removed by the proxy model
            TreeItemMailbox *m = dynamic_cast<TreeItemMailbox *>(static_cast<TreeItem *>(model->index(i, 0, translatedParent).internalPointer()));
            Q_ASSERT(m);
            TreeItem *up = msgListPtr->parent();
            while (up) {
                if (m == up) {
                    resetMe();
                    return;
                }
                up = up->parent();
            }
        }
    }
}
コード例 #12
0
QModelIndex Utils::ModelListModel::parent(const QModelIndex& index) const
{
	Utils::ModelListModel::SubModelIndex smi = mapToSource(index);
	QModelIndex parent = smi.first->parent(smi.second);
	if (smi.first == m_metaModel || parent.isValid())
		return parent;
	else
	{
		//This item from a submodel has a parent in the metamodel.
		Utils::ModelListModel::SubModelIndex smiParent;
		smiParent.first = m_metaModel;
		smiParent.second = m_metaModel->index(m_subModels.indexOf(smi.first), 0);
		return mapFromSource(smiParent);
	}
}
コード例 #13
0
ファイル: qidentityproxymodel.cpp プロジェクト: fluxer/katie
/*!
    \reimp
 */
QModelIndexList QIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const
{
    Q_D(const QIdentityProxyModel);
    Q_ASSERT(start.isValid() ? start.model() == this : true);
    if (!d->model)
        return QModelIndexList();

    const QModelIndexList sourceList = d->model->match(mapToSource(start), role, value, hits, flags);
    QModelIndexList::const_iterator it = sourceList.constBegin();
    const QModelIndexList::const_iterator end = sourceList.constEnd();
    QModelIndexList proxyList;
    for ( ; it != end; ++it)
        proxyList.append(mapFromSource(*it));
    return proxyList;
}
コード例 #14
0
QModelIndex MergedProxyModel::index(int row, int column, const QModelIndex &parent) const {
  QModelIndex source_index;

  if (!parent.isValid()) {
    source_index = sourceModel()->index(row, column, QModelIndex());
  } else {
    QModelIndex source_parent = mapToSource(parent);
    const QAbstractItemModel* child_model = merge_points_.key(source_parent);

    if (child_model)
      source_index = child_model->index(row, column, QModelIndex());
    else
      source_index = source_parent.model()->index(row, column, source_parent);
  }

  return mapFromSource(source_index);
}
コード例 #15
0
ファイル: WSortFilterProxyModel.C プロジェクト: Spencerx/wt
void WSortFilterProxyModel::sourceRowsAboutToBeRemoved
(const WModelIndex& parent, int start, int end)
{
  WModelIndex pparent = mapFromSource(parent);
  Item *item = itemFromIndex(pparent);

  for (int row = start; row <= end; ++row) {
    int mappedRow = item->sourceRowMap_[row];

    if (mappedRow != -1) {
      beginRemoveRows(pparent, mappedRow, mappedRow);
      item->proxyRowMap_.erase(item->proxyRowMap_.begin() + mappedRow);
      rebuildSourceRowMap(item); // erase may have shifted some
      endRemoveRows();
    }
  }
}
コード例 #16
0
void SelectionModelSynchronizer::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
    Q_UNUSED(previous);

    _changeCurrentEnabled = false;
    QSet<QItemSelectionModel*>::iterator iter = _selectionModels.begin();
    while (iter != _selectionModels.end()) {
        (*iter)->setCurrentIndex(mapFromSource(current, (*iter)), QItemSelectionModel::Current);
        ++iter;
    }
    _changeCurrentEnabled = true;

    // Trigger a dataChanged() signal from the base model to update all proxy models (e.g. filters).
    // Since signals are protected, we have to use invokeMethod for faking signal emission.
    if (previous.isValid()) {
        QMetaObject::invokeMethod(model(), "dataChanged", Qt::DirectConnection, Q_ARG(QModelIndex, previous), Q_ARG(QModelIndex, previous));
    }
}
コード例 #17
0
ファイル: WSortFilterProxyModel.C プロジェクト: Spencerx/wt
void WSortFilterProxyModel::sourceRowsAboutToBeInserted
  (const WModelIndex& parent, int start, int end)
{
  if (inserting_)
    return;

  /*
   * Make sure the item starts in a known state, otherwise if the item
   * does not yet have a sourceRowMap, it will be created taking into
   * account the already updated number of source rows, in
   * sourceRowsInserted().
   *
   * BTW. one might wonder if a user of the proxy model is interested
   * at all in changes to a node which he has not yet 'opened' ..., but
   * strictly spoken we are obliged to propagate these changes !
   */
  itemFromIndex(mapFromSource(parent));
}
コード例 #18
0
ファイル: WSortFilterProxyModel.C プロジェクト: Spencerx/wt
void WSortFilterProxyModel::sourceRowsRemoved(const WModelIndex& parent,
					      int start, int end)
{
  int count = end - start + 1;

  shiftModelIndexes(parent, start, -count, mappedIndexes_);

  WModelIndex pparent = mapFromSource(parent);
  Item *item = itemFromIndex(pparent);

  // Shift existing entries in proxyRowMap, and remove entries in sourceRowMap
  for (unsigned i = 0; i < item->proxyRowMap_.size(); ++i) {
    if (item->proxyRowMap_[i] >= start)
      item->proxyRowMap_[i] -= count;
  }

  item->sourceRowMap_.erase(item->sourceRowMap_.begin() + start,
			    item->sourceRowMap_.begin() + start + count);
}
コード例 #19
0
ファイル: WSortFilterProxyModel.C プロジェクト: LifeGo/wt
void WSortFilterProxyModel::sourceRowsAboutToBeRemoved
(const WModelIndex& parent, int start, int end)
{
  WModelIndex pparent = mapFromSource(parent);
  // distinguish between invalid parent being root item or being filtered out
  if (parent.isValid() && !pparent.isValid())
    return;
  Item *item = itemFromIndex(pparent);

  for (int row = start; row <= end; ++row) {
    int mappedRow = item->sourceRowMap_[row];

    if (mappedRow != -1) {
      beginRemoveRows(pparent, mappedRow, mappedRow);
      item->proxyRowMap_.erase(item->proxyRowMap_.begin() + mappedRow);
      rebuildSourceRowMap(item); // erase may have shifted some
      endRemoveRows();
    }
  }
}
コード例 #20
0
void SelectionModelSynchronizer::synchronizeSelectionModel(QItemSelectionModel* selectionModel)
{
    if (!checkBaseModel(selectionModel)) {
        qWarning() << "cannot Synchronize SelectionModel" << selectionModel << "which has a different baseModel()";
        return;
    }

    if (_selectionModels.contains(selectionModel)) {
        selectionModel->setCurrentIndex(mapFromSource(currentIndex(), selectionModel), QItemSelectionModel::Current);
        selectionModel->select(mapSelectionFromSource(currentSelection(), selectionModel), QItemSelectionModel::ClearAndSelect);
        return;
    }

    connect(selectionModel, &QItemSelectionModel::currentChanged, this, &SelectionModelSynchronizer::syncedCurrentChanged);
    connect(selectionModel, &QItemSelectionModel::selectionChanged, this, &SelectionModelSynchronizer::syncedSelectionChanged);

    connect(selectionModel, &QObject::destroyed, this, &SelectionModelSynchronizer::selectionModelDestroyed);

    _selectionModels << selectionModel;
}
コード例 #21
0
void ContactListProxyModel::setName(const QModelIndex &source, const QString &value)
{
    if(!source.isValid())
        return;
    TreeItem *source_item = static_cast<TreeItem*>(source.internalPointer());
    //qWarning() << source_item;
    int source_type = source_item->data(Qt::UserRole).toInt();
    if(source_type==0)
    {
        removeItem(source);
        insertItem(source);
    }
    else
    {
        QModelIndex proxy_index = mapFromSource(source);
        if(!proxy_index.isValid())
            return;
        ProxyModelItem *item = getItem(proxy_index);
        item->setName(value);
    }
}
コード例 #22
0
ファイル: WSortFilterProxyModel.C プロジェクト: chr-thien/wt
void WSortFilterProxyModel::sourceRowsRemoved(const WModelIndex& parent,
					      int start, int end)
{
  int count = end - start + 1;
  endShiftModelIndexes(parent, start, -count, mappedIndexes_);

  WModelIndex pparent = mapFromSource(parent);
  // distinguish between invalid parent being root item or being filtered out
  if (parent.isValid() && !pparent.isValid())
    return;
  Item *item = itemFromIndex(pparent);

  // Shift existing entries in proxyRowMap, and remove entries in sourceRowMap
  for (unsigned i = 0; i < item->proxyRowMap_.size(); ++i) {
    if (item->proxyRowMap_[i] >= start)
      item->proxyRowMap_[i] -= count;
  }

  item->sourceRowMap_.erase(item->sourceRowMap_.begin() + start,
			    item->sourceRowMap_.begin() + start + count);
}
コード例 #23
0
ファイル: history.cpp プロジェクト: Metrological/qtwebengine
void HistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start, int end)
{
    Q_ASSERT(start == end && start == 0);
    Q_UNUSED(end);
    if (!m_loaded)
        return;
    QModelIndex idx = sourceModel()->index(start, 0, parent);
    QString url = idx.data(HistoryModel::UrlStringRole).toString();
    if (m_historyHash.contains(url)) {
        int sourceRow = sourceModel()->rowCount() - m_historyHash[url];
        int realRow = mapFromSource(sourceModel()->index(sourceRow, 0)).row();
        beginRemoveRows(QModelIndex(), realRow, realRow);
        m_sourceRow.removeAt(realRow);
        m_historyHash.remove(url);
        endRemoveRows();
    }
    beginInsertRows(QModelIndex(), 0, 0);
    m_historyHash.insert(url, sourceModel()->rowCount() - start);
    m_sourceRow.insert(0, sourceModel()->rowCount());
    endInsertRows();
}
コード例 #24
0
void HistoryTreeModel::sourceRowsInserted(const QModelIndex &parent, int start, int end)
{
    Q_UNUSED(parent); // Avoid warnings when compiling release
    Q_ASSERT(!parent.isValid());
    if (start != 0 || start != end) {
        m_sourceRowCache.clear();
        reset();
        return;
    }

    m_sourceRowCache.clear();
    QModelIndex treeIndex = mapFromSource(sourceModel()->index(start, 0));
    QModelIndex treeParent = treeIndex.parent();
    if (rowCount(treeParent) == 1) {
        beginInsertRows(QModelIndex(), 0, 0);
        endInsertRows();
    } else {
        beginInsertRows(treeParent, treeIndex.row(), treeIndex.row());
        endInsertRows();
    }
}
コード例 #25
0
ファイル: WSortFilterProxyModel.C プロジェクト: chr-thien/wt
void WSortFilterProxyModel::sourceRowsInserted(const WModelIndex& parent,
					       int start, int end)
{
  startShiftModelIndexes(parent, end + 1, (end - start + 1), mappedIndexes_);

  if (inserting_)
    return;

  int count = end - start + 1;

  WModelIndex pparent = mapFromSource(parent);
  // distinguish between invalid parent being root item or being filtered out
  if (parent.isValid() && !pparent.isValid())
    return;
  Item *item = itemFromIndex(pparent);

  // Shift existing entries in proxyRowMap, and reserve place in sourceRowMap
  // After this step, existing rows are okay again.
  for (unsigned i = 0; i < item->proxyRowMap_.size(); ++i) {
    if (item->proxyRowMap_[i] >= start)
      item->proxyRowMap_[i] += count;
  }

  item->sourceRowMap_.insert(item->sourceRowMap_.begin() + start, count, -1);

  if (!dynamic_)
    return;

  for (int row = start; row <= end; ++row) {
    int newMappedRow = mappedInsertionPoint(row, item);
    if (newMappedRow != -1) {
      beginInsertRows(pparent, newMappedRow, newMappedRow);
      item->proxyRowMap_.insert
	(item->proxyRowMap_.begin() + newMappedRow, row);
      rebuildSourceRowMap(item); // insertion may have shifted some
      endInsertRows();
    } else
      item->sourceRowMap_[row] = -1;
  }
}
コード例 #26
0
void MergedProxyModel::SubModelReset() {
  QAbstractItemModel* submodel = static_cast<QAbstractItemModel*>(sender());

  // TODO: When we require Qt 4.6, use beginResetModel() and endResetModel()
  // in LibraryModel and catch those here - that will let us do away with this
  // std::numeric_limits<int>::max() hack.

  // Remove all the children of the item that got deleted
  QModelIndex source_parent = merge_points_.value(submodel);
  QModelIndex proxy_parent = mapFromSource(source_parent);

  // We can't know how many children it had, since it's already disappeared...
  resetting_model_ = submodel;
  beginRemoveRows(proxy_parent, 0, std::numeric_limits<int>::max() - 1);
  endRemoveRows();
  resetting_model_ = NULL;

  // Delete all the mappings that reference the submodel
  MappingContainer::index<tag_by_pointer>::type::iterator it =
      mappings_.get<tag_by_pointer>().begin();
  MappingContainer::index<tag_by_pointer>::type::iterator end =
      mappings_.get<tag_by_pointer>().end();
  while (it != end) {
    if ((*it)->source_index.model() == submodel) {
      delete *it;
      it = mappings_.get<tag_by_pointer>().erase(it);
    } else {
      ++it;
    }
  }

  // "Insert" items from the newly reset submodel
  int count = submodel->rowCount();
  if (count) {
    beginInsertRows(proxy_parent, 0, count-1);
    endInsertRows();
  }

  emit SubModelReset(proxy_parent, submodel);
}
コード例 #27
0
void SideBarModel::trigger(int row)
{
    const QModelIndex &idx = index(row, 0);
    const QModelIndex &sourceIndex = mapToSource(idx);

    if (sourceIndex.row() != m_activeSourceRow) {
        const QModelIndex &oldActiveIndex = mapFromSource(m_sourceModel->index(m_activeSourceRow, 0));

        m_activeSourceRow = sourceIndex.row();

        InstalledAppsFilterModel* model = 0;

        for(int i = 0; i < m_sourceModel->rowCount(); ++i) {
            model = static_cast<InstalledAppsFilterModel *>(m_sourceModel->modelForRow(i));
            model->setHidden(i != m_activeSourceRow);
        }

        emit dataChanged(oldActiveIndex, oldActiveIndex);
        emit dataChanged(idx, idx);
        invalidateFilter();
    }
}
コード例 #28
0
void MergedProxyModel::AddSubModel(const QModelIndex& source_parent,
                                   QAbstractItemModel* submodel) {
  connect(submodel, SIGNAL(modelReset()), this, SLOT(SubModelReset()));
  connect(submodel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
          this, SLOT(RowsAboutToBeInserted(QModelIndex,int,int)));
  connect(submodel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
          this, SLOT(RowsAboutToBeRemoved(QModelIndex,int,int)));
  connect(submodel, SIGNAL(rowsInserted(QModelIndex,int,int)),
          this, SLOT(RowsInserted(QModelIndex,int,int)));
  connect(submodel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
          this, SLOT(RowsRemoved(QModelIndex,int,int)));

  QModelIndex proxy_parent = mapFromSource(source_parent);
  const int rows = submodel->rowCount();

  if (rows)
    beginInsertRows(proxy_parent, 0, rows-1);

  merge_points_.insert(submodel, source_parent);

  if (rows)
    endInsertRows();
}
コード例 #29
0
void QmlProfilerStatisticsMainView::displayTypeIndex(int typeIndex)
{
    if (typeIndex < 0) {
        setCurrentIndex(QModelIndex());
    } else {
        auto sortModel = qobject_cast<const QSortFilterProxyModel *>(model());
        QTC_ASSERT(sortModel, return);

        QAbstractItemModel *sourceModel = sortModel->sourceModel();
        QTC_ASSERT(sourceModel, return);

        QModelIndex sourceIndex = sourceModel->index(qMin(typeIndex, sourceModel->rowCount() - 1),
                                                     MainCallCount);
        QTC_ASSERT(sourceIndex.data(TypeIdRole).toInt() == typeIndex, return);

        setCurrentIndex(sourceIndex.data(SortRole).toInt() > 0
                        ? sortModel->mapFromSource(sourceIndex)
                        : QModelIndex());
    }

    // show in callers/callees subwindow
    emit propagateTypeIndex(typeIndex);
}
bool LibraryFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
{
	if (filterAcceptsRowItself(sourceRow, sourceParent)) {
		if (!filterRegExp().isEmpty()) {
			emit aboutToExpand(mapFromSource(sourceParent));
		}
		return true;
	}

	//accept if any of the parents is accepted on it's own merits
	QModelIndex parent = sourceParent;
	while (parent.isValid()) {
		if (filterAcceptsRowItself(parent.row(), parent.parent())) {
			return true;
		}
		parent = parent.parent();
	}

	//accept if any of the children is accepted on it's own merits
	if (hasAcceptedChildren(sourceRow, sourceParent)) {
		return true;
	}
	return false;
}