Esempio n. 1
0
//------------------------------------------------------------------------------
u32 Entity::removeChild(Entity * child)
{
    u32 i = indexOfChild(child);
    if (i != m_children.size())
        removeChildAtIndex(i);
    return i;
}
int  QAccessibleWidgetEx_QtDShell::__override_indexOfChild(const QAccessibleInterface*  child0, bool static_call) const
{
    if (static_call) {
        return QAccessibleWidgetEx::indexOfChild((const QAccessibleInterface* )child0);
    } else {
        return indexOfChild((const QAccessibleInterface* )child0);
    }
}
void AbstractAspect::removeChild(AbstractAspect* child, bool detach)
{
	Q_ASSERT(indexOfChild(child) != -1);
	beginMacro(tr("%1: remove %2.").arg(name()).arg(child->name()));
	prepareAspectRemoval(child);
	exec(new AspectChildRemoveCmd(d_aspect_private, child, detach));
	endMacro();
}
int  QAccessibleInterfaceEx_QtDShell::__override_indexOfChild(const QAccessibleInterface*  arg__1, bool static_call) const
{
    if (static_call) {
        return 0;
    } else {
        return indexOfChild((const QAccessibleInterface* )arg__1);
    }
}
Esempio n. 5
0
KDPoint HorizontalLayout::positionOfChild(ExpressionLayout * child) {
  KDCoordinate x = 0;
  KDCoordinate y = 0;
  int index = indexOfChild(child);
  if (index > 0) {
    ExpressionLayout * previousChild = editableChild(index-1);
    assert(previousChild != nullptr);
    x = previousChild->origin().x() + previousChild->size().width();
  }
  y = baseline() - child->baseline();
  return KDPoint(x, y);
}
void AbstractAspect::reparentChild(AbstractAspect *new_parent, AbstractAspect *child, int new_index)
{
	Q_ASSERT(indexOfChild(child) != -1);
	Q_ASSERT(new_index > 0 && new_index <= new_parent->childCount());
	Q_ASSERT(new_parent != NULL);
	QString new_name = new_parent->d_aspect_private->uniqueNameFor(child->name());
	beginMacro(tr("%1: move %2 to %3.").arg(name()).arg(child->name()).arg(new_parent->name()));
	if (new_name != child->name()) {
		info(tr("Renaming \"%1\" to \"%2\" in order to avoid name collision.").arg(child->name()).arg(new_name));
		child->setName(new_name);
	}
	prepareAspectRemoval(child);
	exec(new AspectChildReparentCmd(d_aspect_private, new_parent->d_aspect_private, child, new_index));
	new_parent->completeAspectInsertion(child, new_index);
	endMacro();
}
Esempio n. 7
0
void DeleteFieldCommand::init()
{
    for(auto field : m_fields)
    {
        if(nullptr != field->getCanvasField())
        {
            auto parent = field->getParent();
            m_parent.append(field->getParent());
            m_points.append(field->getCanvasField()->pos());
            if(nullptr != parent)
                m_posInModel.append(parent->indexOfChild(field));
        }
    }

    setText(QObject::tr("Delete %n Field(s)","",m_fields.size()));
}
Esempio n. 8
0
ExpressionLayoutCursor HorizontalLayout::cursorRightOf(ExpressionLayoutCursor cursor, bool * shouldRecomputeLayout) {
  // Case: Right. Ask the parent.
  if (cursor.pointedExpressionLayout() == this) {
    if (cursor.position() == ExpressionLayoutCursor::Position::Right) {
      if (m_parent) {
        return m_parent->cursorRightOf(cursor, shouldRecomputeLayout);
      }
      return ExpressionLayoutCursor();
    }
    assert(cursor.position() == ExpressionLayoutCursor::Position::Left);
    /* Case: Left.
     * Go to the first child if there is one, and move Right.
     * Else go Right and ask the parent. */
    if (numberOfChildren() < 1) {
      cursor.setPosition(ExpressionLayoutCursor::Position::Right);
      if (m_parent) {
        return m_parent->cursorRightOf(cursor, shouldRecomputeLayout);
      }
      return ExpressionLayoutCursor();
    }
    ExpressionLayout * firstChild = editableChild(0);
    assert(firstChild != nullptr);
    cursor.setPointedExpressionLayout(firstChild);
    return firstChild->cursorRightOf(cursor, shouldRecomputeLayout);
  }

  // Case: The cursor is Right of a child.
  assert(cursor.position() == ExpressionLayoutCursor::Position::Right);
  int childIndex = indexOfChild(cursor.pointedExpressionLayout());
  assert(childIndex >= 0);
  if (childIndex == numberOfChildren() - 1) {
    // Case: the child is the rightmost. Ask the parent.
    if (m_parent) {
      cursor.setPointedExpressionLayout(this);
      return m_parent->cursorRightOf(cursor, shouldRecomputeLayout);
    }
    return ExpressionLayoutCursor();
  }
  /* Case: the child is not the rightmost. Go to its right sibling and move
   * Right. */
  cursor.setPointedExpressionLayout(editableChild(childIndex+1));
  cursor.setPosition(ExpressionLayoutCursor::Position::Left);
  return editableChild(childIndex+1)->cursorRightOf(cursor, shouldRecomputeLayout);
}
Esempio n. 9
0
void HorizontalLayout::deleteBeforeCursor(ExpressionLayoutCursor * cursor) {
  if (cursor->pointedExpressionLayout() == this
      && cursor->position() == ExpressionLayoutCursor::Position::Left
      && m_parent == nullptr)
  {
    // Case: Left and this is the main layout. Return.
    return;
  }
  if (cursor->pointedExpressionLayout() == this
      && cursor->position() == ExpressionLayoutCursor::Position::Right
      && m_parent == nullptr
      && numberOfChildren() == 0)
  {
    // Case: Right and this is the main layout with no children. Return.
    return;
  }
  if (cursor->position() == ExpressionLayoutCursor::Position::Left) {
    int indexOfPointedExpression = indexOfChild(cursor->pointedExpressionLayout());
    if (indexOfPointedExpression >= 0) {
      /* Case: Left of a child.
       * Point Right of the previous child. If there is no previous child, point
       * Left of this. Perform another backspace. */
      if (indexOfPointedExpression == 0) {
        cursor->setPointedExpressionLayout(this);
      } else if (indexOfPointedExpression > 0) {
        cursor->setPointedExpressionLayout(editableChild(indexOfPointedExpression - 1));
        cursor->setPosition(ExpressionLayoutCursor::Position::Right);
      }
      cursor->performBackspace();
      return;
    }
  }
  assert(cursor->pointedExpressionLayout() == this);
  if (cursor->position() == ExpressionLayoutCursor::Position::Right) {
    // Case: Right. Point to the last child and perform backspace.
    cursor->setPointedExpressionLayout(editableChild(numberOfChildren() - 1));
    cursor->performBackspace();
    return;
  }
  ExpressionLayout::deleteBeforeCursor(cursor);
}
Esempio n. 10
0
ExpressionLayoutCursor HorizontalLayout::equivalentCursor(ExpressionLayoutCursor cursor) {
  ExpressionLayoutCursor result;
  ExpressionLayout * newPointedLayout = nullptr;
  ExpressionLayoutCursor::Position newPosition = ExpressionLayoutCursor::Position::Left;
  if (cursor.pointedExpressionLayout() == this) {
    // First or last child, if any
    if(numberOfChildren() == 0) {
      return result;
    } else {
      newPointedLayout = editableChild(cursor.position() == ExpressionLayoutCursor::Position::Left ? 0 : numberOfChildren() - 1);
      newPosition = cursor.position();
    }
  } else {
    // Left or right child
    int indexOfPointedLayout = indexOfChild(cursor.pointedExpressionLayout());
    if (indexOfPointedLayout < 0) {
      return result;
    } else if (cursor.position() == ExpressionLayoutCursor::Position::Left) {
      if (indexOfPointedLayout == 0) {
        newPointedLayout = this;
        newPosition = ExpressionLayoutCursor::Position::Left;
      } else {
        newPointedLayout = editableChild(indexOfPointedLayout - 1);
        newPosition = ExpressionLayoutCursor::Position::Right;
      }
    } else {
      assert(cursor.position() == ExpressionLayoutCursor::Position::Right);
      if (indexOfPointedLayout == numberOfChildren() - 1) {
        newPointedLayout = this;
        newPosition = ExpressionLayoutCursor::Position::Right;
      } else {
        newPointedLayout = editableChild(indexOfPointedLayout + 1);
        newPosition = ExpressionLayoutCursor::Position::Left;
      }
    }
  }
  result.setPointedExpressionLayout(newPointedLayout);
  result.setPosition(newPosition);
  return result;
}
Esempio n. 11
0
void QAccessibleTable::modelChange(QAccessibleTableModelChangeEvent *event)
{
    // if there is no cache yet, we don't update anything
    if (childToId.isEmpty())
        return;

    switch (event->modelChangeType()) {
    case QAccessibleTableModelChangeEvent::ModelReset:
        Q_FOREACH (QAccessible::Id id, childToId)
            QAccessible::deleteAccessibleInterface(id);
        childToId.clear();
        break;

    // rows are inserted: move every row after that
    case QAccessibleTableModelChangeEvent::RowsInserted:
    case QAccessibleTableModelChangeEvent::ColumnsInserted: {
        int newRows = event->lastRow() - event->firstRow() + 1;
        int newColumns = event->lastColumn() - event->firstColumn() + 1;

        ChildCache newCache;
        ChildCache::ConstIterator iter = childToId.constBegin();

        while (iter != childToId.constEnd()) {
            QAccessible::Id id = iter.value();
            QAccessibleInterface *iface = QAccessible::accessibleInterface(id);
            Q_ASSERT(iface);
            if (iface->role() == QAccessible::Cell || iface->role() == QAccessible::ListItem) {
                Q_ASSERT(iface->tableCellInterface());
                QAccessibleTableCell *cell = static_cast<QAccessibleTableCell*>(iface->tableCellInterface());
                if (event->modelChangeType() == QAccessibleTableModelChangeEvent::RowsInserted
                        && cell->m_index.row() >= event->firstRow()) {
                    int newRow = cell->m_index.row() + newRows;
                    cell->m_index = cell->m_index.sibling(newRow, cell->m_index.column());
                } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::ColumnsInserted
                        && cell->m_index.column() >= event->firstColumn()) {
                    int newColumn = cell->m_index.column() + newColumns;
                    cell->m_index = cell->m_index.sibling(cell->m_index.row(), newColumn);
                }
            } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::RowsInserted
                       && iface->role() == QAccessible::RowHeader) {
                QAccessibleTableHeaderCell *cell = static_cast<QAccessibleTableHeaderCell*>(iface);
                if (cell->index >= event->firstRow()) {
                    cell->index += newRows;
                }
            } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::ColumnsInserted
                   && iface->role() == QAccessible::ColumnHeader) {
                QAccessibleTableHeaderCell *cell = static_cast<QAccessibleTableHeaderCell*>(iface);
                if (cell->index >= event->firstColumn()) {
                    cell->index += newColumns;
                }
            }
            if (indexOfChild(iface) >= 0) {
                newCache.insert(indexOfChild(iface), id);
            } else {
                // ### This should really not happen,
                // but it might if the view has a root index set.
                // This needs to be fixed.
                QAccessible::deleteAccessibleInterface(id);
            }
            ++iter;
        }
        childToId = newCache;
        break;
    }

    case QAccessibleTableModelChangeEvent::ColumnsRemoved:
    case QAccessibleTableModelChangeEvent::RowsRemoved: {
        int deletedColumns = event->lastColumn() - event->firstColumn() + 1;
        int deletedRows = event->lastRow() - event->firstRow() + 1;
        ChildCache newCache;
        ChildCache::ConstIterator iter = childToId.constBegin();
        while (iter != childToId.constEnd()) {
            QAccessible::Id id = iter.value();
            QAccessibleInterface *iface = QAccessible::accessibleInterface(id);
            Q_ASSERT(iface);
            if (iface->role() == QAccessible::Cell || iface->role() == QAccessible::ListItem) {
                Q_ASSERT(iface->tableCellInterface());
                QAccessibleTableCell *cell = static_cast<QAccessibleTableCell*>(iface->tableCellInterface());
                if (event->modelChangeType() == QAccessibleTableModelChangeEvent::RowsRemoved) {
                    if (cell->m_index.row() < event->firstRow()) {
                        newCache.insert(indexOfChild(cell), id);
                    } else if (cell->m_index.row() > event->lastRow()) {
                        int newRow = cell->m_index.row() - deletedRows;
                        cell->m_index = cell->m_index.sibling(newRow, cell->m_index.column());
                        newCache.insert(indexOfChild(cell), id);
                    } else {
                        QAccessible::deleteAccessibleInterface(id);
                    }
                } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::ColumnsRemoved) {
                    if (cell->m_index.column() < event->firstColumn()) {
                        newCache.insert(indexOfChild(cell), id);
                    } else if (cell->m_index.column() > event->lastColumn()) {
                        int newColumn = cell->m_index.column() - deletedColumns;
                        cell->m_index = cell->m_index.sibling(cell->m_index.row(), newColumn);
                        newCache.insert(indexOfChild(cell), id);
                    } else {
                        QAccessible::deleteAccessibleInterface(id);
                    }
                }
            } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::RowsRemoved
                       && iface->role() == QAccessible::RowHeader) {
                QAccessibleTableHeaderCell *cell = static_cast<QAccessibleTableHeaderCell*>(iface);
                if (cell->index < event->firstRow()) {
                    newCache.insert(indexOfChild(cell), id);
                } else if (cell->index > event->lastRow()) {
                    cell->index -= deletedRows;
                    newCache.insert(indexOfChild(cell), id);
                } else {
                    QAccessible::deleteAccessibleInterface(id);
                }
            } else if (event->modelChangeType() == QAccessibleTableModelChangeEvent::ColumnsRemoved
                   && iface->role() == QAccessible::ColumnHeader) {
                QAccessibleTableHeaderCell *cell = static_cast<QAccessibleTableHeaderCell*>(iface);
                if (cell->index < event->firstColumn()) {
                    newCache.insert(indexOfChild(cell), id);
                } else if (cell->index > event->lastColumn()) {
                    cell->index -= deletedColumns;
                    newCache.insert(indexOfChild(cell), id);
                } else {
                    QAccessible::deleteAccessibleInterface(id);
                }
            }
            ++iter;
        }
        childToId = newCache;
        break;
    }

    case QAccessibleTableModelChangeEvent::DataChanged:
        // nothing to do in this case
        break;
    }
}
Esempio n. 12
0
void HorizontalLayout::privateReplaceChild(const ExpressionLayout * oldChild, ExpressionLayout * newChild, bool deleteOldChild, ExpressionLayoutCursor * cursor) {
  bool oldWasAncestorOfNewLayout = false;
  if (newChild->hasAncestor(this)) {
    newChild->editableParent()->detachChild(newChild);
    oldWasAncestorOfNewLayout = true;
  }
  int oldChildIndex = indexOfChild(oldChild);
  if (newChild->isEmpty()) {
    if (numberOfChildren() > 1) {
      /* If the new layout is empty and the horizontal layout has other
       * children, just delete the old child. */
      if (!newChild->hasAncestor(oldChild)) {
        delete newChild;
      }
      removeChildAtIndex(oldChildIndex, deleteOldChild);
      if (cursor == nullptr) {
        return;
      }
      if (oldChildIndex == 0) {
        cursor->setPointedExpressionLayout(this);
        cursor->setPosition(ExpressionLayoutCursor::Position::Left);
        return;
      }
      cursor->setPointedExpressionLayout(editableChild(oldChildIndex -1));
      cursor->setPosition(ExpressionLayoutCursor::Position::Right);
      return;
    }
    /* If the new layout is empty and it was the only horizontal layout child,
     * replace the horizontal layout with this empty layout (only if this is not
     * the main layout, so only if the layout has a parent). */
    if (m_parent) {
      if (!deleteOldChild) {
        removeChildAtIndex(indexOfChild(oldChild), false);
      }
      if (cursor) {
        replaceWithAndMoveCursor(newChild, true, cursor);
        return;
      }
      replaceWith(newChild, deleteOldChild);
      return;
    }
    /* If this is the main horizontal layout, the old child its only child and
     * the new child is Empty, remove the old child and delete the new child. */
    assert(m_parent == nullptr);
    removeChildAtIndex(0, deleteOldChild);
    delete newChild;
    if (cursor == nullptr) {
      return;
    }
    cursor->setPointedExpressionLayout(this);
    cursor->setPosition(ExpressionLayoutCursor::Position::Left);
    return;
  }
  /* If the new child is also an horizontal layout, steal the children of the
   * new layout then destroy it. */
  if (newChild->isHorizontal()) {
    int indexForInsertion = indexOfChild(oldChild);
    if (cursor != nullptr) {
      /* If the old layout is not an ancestor of the new layout, or if the
       * cursor was on the right of the new layout, place the cursor on the
       * right of the new layout, which is left of the next sibling or right of
       * the parent. */
      if (!oldWasAncestorOfNewLayout || cursor->position() == ExpressionLayoutCursor::Position::Right) {
        if (oldChildIndex == numberOfChildren() - 1) {
          cursor->setPointedExpressionLayout(this);
          cursor->setPosition(ExpressionLayoutCursor::Position::Right);
        } else {
          cursor->setPointedExpressionLayout(editableChild(oldChildIndex + 1));
          cursor->setPosition(ExpressionLayoutCursor::Position::Left);
        }
      } else {
        /* Else place the cursor on the left of the new layout, which is right
         * of the previous sibling or left of the parent. */
        if (oldChildIndex == 0) {
          cursor->setPointedExpressionLayout(this);
          cursor->setPosition(ExpressionLayoutCursor::Position::Left);
        } else {
          cursor->setPointedExpressionLayout(editableChild(oldChildIndex - 1));
          cursor->setPosition(ExpressionLayoutCursor::Position::Right);
        }
      }
    }
    bool oldChildRemovedAtMerge = oldChild->isEmpty();
    mergeChildrenAtIndex(static_cast<HorizontalLayout *>(newChild), indexForInsertion + 1, true);
    if (!oldChildRemovedAtMerge) {
      removeChildAtIndex(indexForInsertion, deleteOldChild);
    }
    return;
  }
  // Else, just replace the child.
  if (cursor != nullptr && !oldWasAncestorOfNewLayout) {
    cursor->setPosition(ExpressionLayoutCursor::Position::Right);
  }
  ExpressionLayout::replaceChild(oldChild, newChild, deleteOldChild);
  if (cursor == nullptr) {
    return;
  }
  cursor->setPointedExpressionLayout(newChild);
}