示例#1
0
void ContainerNode::parserAppendChild(PassRefPtr<Node> newChild)
{
    ASSERT(newChild);
    ASSERT(!newChild->parentNode()); // Use appendChild if you need to handle reparenting (and want DOM mutation events).
    ASSERT(!newChild->isDocumentFragment());
    ASSERT(!hasTagName(HTMLNames::templateTag));

    if (document() != newChild->document())
        document()->adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);

    Node* last = m_lastChild;
    {
        NoEventDispatchAssertion assertNoEventDispatch;
        // FIXME: This method should take a PassRefPtr.
        appendChildToContainer(newChild.get(), this);
        treeScope()->adoptIfNeeded(newChild.get());
    }

    newChild->updateAncestorConnectedSubframeCountForInsertion();

    ChildListMutationScope(this).childAdded(newChild.get());

    childrenChanged(true, last, 0, 1);
    ChildNodeInsertionNotifier(this).notify(newChild.get());
}
示例#2
0
QGLView::QGLView(QQuickItem *parent)
    : QQuickPaintedItem(parent)
    , m_initialized(false)
    , m_modelProgram(0)
    , m_lineProgram(0)
    , m_textProgram(0)
    , m_projectionAspectRatio(1.0)
    , m_backgroundColor(QColor(Qt::black))
    , m_pathEnabled(false)
    , m_selectionModeActive(false)
    , m_currentGlItem(NULL)
    , m_propertySignalMapper(new QSignalMapper(this))
    , m_camera(new QGLCamera(this))
    , m_light(new QGLLight(this))
{
    //setFlag(QQuickItem::ItemHasContents, true);

    connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
    // queue this connection to prevent trigger on destruction
    connect(this, SIGNAL(childrenChanged()), this, SLOT(updateChildren()), Qt::QueuedConnection);
    connect(m_propertySignalMapper, SIGNAL(mapped(QObject*)), this, SLOT(updateItem(QObject*)));
    //connect(this, SIGNAL(initialized()), this, SLOT(updateItems()), Qt::QueuedConnection);

    setRenderTarget(QQuickPaintedItem::InvertedYFramebufferObject);
    setMipmap(true);
    //setAntialiasing(true);
}
示例#3
0
void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node* nextChild)
{
    ASSERT(newChild);
    ASSERT(nextChild);
    ASSERT(nextChild->parentNode() == this);
    ASSERT(!newChild->isDocumentFragment());
#if ENABLE(TEMPLATE_ELEMENT)
    ASSERT(!hasTagName(HTMLNames::templateTag));
#endif

    if (nextChild->previousSibling() == newChild || nextChild == newChild) // nothing to do
        return;

    if (&document() != &newChild->document())
        document().adoptNode(newChild.get(), ASSERT_NO_EXCEPTION);

    insertBeforeCommon(nextChild, newChild.get());

    newChild->updateAncestorConnectedSubframeCountForInsertion();

    ChildListMutationScope(this).childAdded(newChild.get());

    childrenChanged(true, newChild->previousSibling(), nextChild, 1);
    ChildNodeInsertionNotifier(this).notify(newChild.get());
}
QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
        : QQuickItem(parent),
        m_plugin(0),
        m_serviceProvider(0),
        m_mappingManager(0),
        m_center(51.5073,-0.1277), //London city center
        m_activeMapType(0),
        m_gestureArea(new QQuickGeoMapGestureArea(this)),
        m_map(0),
        m_error(QGeoServiceProvider::NoError),
        m_zoomLevel(8.0),
        m_componentCompleted(false),
        m_mappingManagerInitialized(false),
        m_color(QColor::fromRgbF(0.9, 0.9, 0.9)),
        m_pendingFitViewport(false),
        m_validRegion(false)
{
    setAcceptHoverEvents(false);
    setAcceptedMouseButtons(Qt::LeftButton);
    setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape);
    setFiltersChildMouseEvents(true);

    connect(this, SIGNAL(childrenChanged()), this, SLOT(onMapChildrenChanged()), Qt::QueuedConnection);

    m_activeMapType = new QDeclarativeGeoMapType(QGeoMapType(QGeoMapType::NoMap,
                                                             tr("No Map"),
                                                             tr("No Map"), false, false, 0), this);
}
示例#5
0
void ContainerNode::parserInsertBefore(PassRefPtr<Node> newChild, Node* nextChild)
{
    ASSERT(newChild);
    ASSERT(nextChild);
    ASSERT(nextChild->parentNode() == this);

    NodeVector targets;
    collectTargetNodes(newChild.get(), targets);
    if (targets.isEmpty())
        return;

    if (nextChild->previousSibling() == newChild || nextChild == newChild) // nothing to do
        return;

    RefPtr<Node> next = nextChild;
    RefPtr<Node> nextChildPreviousSibling = nextChild->previousSibling();
    for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
        Node* child = it->get();

        insertBeforeCommon(next.get(), child);

        childrenChanged(true, nextChildPreviousSibling.get(), nextChild, 1);
        ChildNodeInsertionNotifier(this).notify(child);
    }
}
QDeclarativeGeoMapItemBase::QDeclarativeGeoMapItemBase(QQuickItem *parent)
    : QQuickItem(parent),
      map_(0),
      quickMap_(0)
{
    connect(this, SIGNAL(childrenChanged()),
            this, SLOT(afterChildrenChanged()));
}
示例#7
0
bool ContainerNode::removeChild(Node* oldChild, ExceptionCode& ec)
{
    // Check that this node is not "floating".
    // If it is, it can be deleted as a side effect of sending mutation events.
    ASSERT(refCount() || parentOrShadowHostNode());

    RefPtr<Node> protect(this);

    ec = 0;

    // NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
    if (isReadOnlyNode()) {
        ec = NO_MODIFICATION_ALLOWED_ERR;
        return false;
    }

    // NOT_FOUND_ERR: Raised if oldChild is not a child of this node.
    if (!oldChild || oldChild->parentNode() != this) {
        ec = NOT_FOUND_ERR;
        return false;
    }

    RefPtr<Node> child = oldChild;

    document().removeFocusedNodeOfSubtree(child.get());

#if ENABLE(FULLSCREEN_API)
    document().removeFullScreenElementOfSubtree(child.get());
#endif

    // Events fired when blurring currently focused node might have moved this
    // child into a different parent.
    if (child->parentNode() != this) {
        ec = NOT_FOUND_ERR;
        return false;
    }

    willRemoveChild(child.get());

    // Mutation events might have moved this child into a different parent.
    if (child->parentNode() != this) {
        ec = NOT_FOUND_ERR;
        return false;
    }

    {
        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;

        Node* prev = child->previousSibling();
        Node* next = child->nextSibling();
        removeBetween(prev, next, child.get());
        childrenChanged(false, prev, next, -1);
        ChildNodeRemovalNotifier(this).notify(child.get());
    }
    dispatchSubtreeModifiedEvent();

    return child;
}
示例#8
0
void ContainerNode::notifyChildRemoved(Node& child, Node* previousSibling, Node* nextSibling, ChildChangeSource source)
{
    ChildChange change;
    change.type = child.isElementNode() ? ElementRemoved : child.isTextNode() ? TextRemoved : NonContentsChildChanged;
    change.previousSiblingElement = (!previousSibling || previousSibling->isElementNode()) ? toElement(previousSibling) : ElementTraversal::previousSibling(previousSibling);
    change.nextSiblingElement = (!nextSibling || nextSibling->isElementNode()) ? toElement(nextSibling) : ElementTraversal::nextSibling(nextSibling);
    change.source = source;

    childrenChanged(change);
}
void
CQIllustratorShape::
addChild(CQIllustratorShape *child)
{
  child->parent_ = this;

  shapes_.push_back(child);

  childrenChanged();
}
void
CQIllustratorShape::
removeChild(CQIllustratorShape *child)
{
  child->parent_ = 0;

  shapes_.remove(child);

  childrenChanged();
}
示例#11
0
void ContainerNode::notifyChildInserted(Node& child, ChildChangeSource source)
{
    ChildChange change;
    change.type = child.isElementNode() ? ElementInserted : child.isTextNode() ? TextInserted : NonContentsChildChanged;
    change.previousSiblingElement = ElementTraversal::previousSibling(&child);
    change.nextSiblingElement = ElementTraversal::nextSibling(&child);
    change.source = source;

    childrenChanged(change);
}
示例#12
0
void ContainerNode::parserRemoveChild(Node* oldChild)
{
    ASSERT(oldChild);
    ASSERT(oldChild->parentNode() == this);

    Node* prev = oldChild->previousSibling();
    Node* next = oldChild->nextSibling();

    removeBetween(prev, next, oldChild);

    childrenChanged(true, prev, next, -1);
    ChildNodeRemovalNotifier(this).notify(oldChild);
}
示例#13
0
// this differs from other remove functions because it forcibly removes all the children,
// regardless of read-only status or event exceptions, e.g.
void ContainerNode::removeChildren()
{
    if (!m_firstChild)
        return;

    // The container node can be removed from event handlers.
    RefPtr<ContainerNode> protect(this);

    // Exclude this node when looking for the focused or full screen Node since
    // only children will be removed.
    // FIXME: We should call these inside the loop below. Right now you can focus
    // a node with mutation events and it'll never get blured.
    document()->removeFocusedNodeOfSubtree(this, true);
    document()->removeFullScreenElementOfSubtree(this, true);

    ChildListMutationScope mutation(this);
    NodeVector removedChildren;
    {
        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;

        while (RefPtr<Node> child = m_firstChild) {
            // Dispatch synchronous events like mutation and unload events.
            dispatchChildRemovalEvents(child.get());
            ChildFrameDisconnector(child.get()).disconnect();

            // FIXME: In theory this can fire focus events when the selection
            // changes, but there's no obvious way to test it.
            document()->nodeWillBeRemoved(child.get());

            // If an event moved the child start over.
            if (child != m_firstChild)
                continue;

            mutation.willRemoveChild(child.get());
            child->notifyMutationObserversNodeWillDetach();
            removeBetween(0, child->nextSibling(), child.get());
            removedChildren.append(child.release());
        }

        // FIXME: We could avoid walking all the children twice by calling
        // notify inside the loop and childrenChanged after but that would mean
        // calling childrenChanged in a different order than all other methods.
        // Figure out if this is safe.
        childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size()));
        for (size_t i = 0; i < removedChildren.size(); ++i)
            ChildNodeRemovalNotifier(this).notify(removedChildren[i].get());
    }

    dispatchSubtreeModifiedEvent();
}
bool ChildrenChangeEventFilter::eventFilter(QObject * /*object*/, QEvent *event)
{
    switch (event->type()) {
        case QEvent::ChildAdded:
        case QEvent::ChildRemoved:
            {
                QChildEvent *childEvent = static_cast<QChildEvent*>(event);
                emit childrenChanged(childEvent->child()); break;
            }
        default: break;
    }

    return false;
}
示例#15
0
void ContainerNode::parserAppendChild(PassRefPtr<Node> newChild)
{
    ASSERT(newChild);
    ASSERT(!newChild->parentNode()); // Use appendChild if you need to handle reparenting (and want DOM mutation events).

    Node* last = m_lastChild;
    {
        NoEventDispatchAssertion assertNoEventDispatch;
        // FIXME: This method should take a PassRefPtr.
        appendChildToContainer(newChild.get(), this);
        treeScope()->adoptIfNeeded(newChild.get());
    }

    childrenChanged(true, last, 0, 1);
    ChildNodeInsertionNotifier(this).notify(newChild.get());
}
示例#16
0
// this differs from other remove functions because it forcibly removes all the children,
// regardless of read-only status or event exceptions, e.g.
void ContainerNode::removeChildren()
{
    if (!m_firstChild)
        return;

    // The container node can be removed from event handlers.
    Ref<ContainerNode> protect(*this);

    // exclude this node when looking for removed focusedNode since only children will be removed
    document().removeFocusedNodeOfSubtree(this, true);

#if ENABLE(FULLSCREEN_API)
    document().removeFullScreenElementOfSubtree(this, true);
#endif

    // Do any prep work needed before actually starting to detach
    // and remove... e.g. stop loading frames, fire unload events.
    willRemoveChildren(*this);

    NodeVector removedChildren;
    {
        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
        {
            NoEventDispatchAssertion assertNoEventDispatch;
            removedChildren.reserveInitialCapacity(countChildNodes());
            while (RefPtr<Node> n = m_firstChild) {
                removedChildren.append(*m_firstChild);
                removeBetween(0, m_firstChild->nextSibling(), *m_firstChild);
            }
        }

        ChildChange change = { AllChildrenRemoved, nullptr, nullptr, ChildChangeSourceAPI };
        childrenChanged(change);
        
        for (size_t i = 0; i < removedChildren.size(); ++i)
            ChildNodeRemovalNotifier(*this).notify(removedChildren[i].get());
    }

    if (document().svgExtensions()) {
        Element* shadowHost = this->shadowHost();
        if (!shadowHost || !shadowHost->hasTagName(SVGNames::useTag))
            document().accessSVGExtensions()->rebuildElements();
    }

    dispatchSubtreeModifiedEvent();
}
示例#17
0
void ContainerNode::parserRemoveChild(Node* oldChild)
{
    ASSERT(oldChild);
    ASSERT(oldChild->parentNode() == this);
    ASSERT(!oldChild->isDocumentFragment());

    Node* prev = oldChild->previousSibling();
    Node* next = oldChild->nextSibling();

    oldChild->updateAncestorConnectedSubframeCountForRemoval();

    ChildListMutationScope(this).willRemoveChild(oldChild);
    oldChild->notifyMutationObserversNodeWillDetach();

    removeBetween(prev, next, oldChild);

    childrenChanged(true, prev, next, -1);
    ChildNodeRemovalNotifier(this).notify(oldChild);
}
示例#18
0
// this differs from other remove functions because it forcibly removes all the children,
// regardless of read-only status or event exceptions, e.g.
void ContainerNode::removeChildren()
{
    if (!m_firstChild)
        return;

    // The container node can be removed from event handlers.
    RefPtr<ContainerNode> protect(this);

    // exclude this node when looking for removed focusedNode since only children will be removed
    document().removeFocusedNodeOfSubtree(this, true);

#if ENABLE(FULLSCREEN_API)
    document().removeFullScreenElementOfSubtree(this, true);
#endif

    // Do any prep work needed before actually starting to detach
    // and remove... e.g. stop loading frames, fire unload events.
    willRemoveChildren(protect.get());

    NodeVector removedChildren;
    {
        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
        {
            NoEventDispatchAssertion assertNoEventDispatch;
            removedChildren.reserveInitialCapacity(childNodeCount());
            while (RefPtr<Node> n = m_firstChild) {
                removedChildren.append(m_firstChild);
                removeBetween(0, m_firstChild->nextSibling(), m_firstChild);
            }
        }

        childrenChanged(false, 0, 0, -static_cast<int>(removedChildren.size()));
        
        for (size_t i = 0; i < removedChildren.size(); ++i)
            ChildNodeRemovalNotifier(this).notify(removedChildren[i].get());
    }

    dispatchSubtreeModifiedEvent();
}
示例#19
0
QT_BEGIN_NAMESPACE

/*!
    \qmltype Map
    \instantiates QDeclarativeGeoMap
    \inqmlmodule QtLocation
    \ingroup qml-QtLocation5-maps
    \since Qt Location 5.0

    \brief The Map type displays a map.

    The Map type is used to display a map or image of the Earth, with
    the capability to also display interactive objects tied to the map's
    surface.

    There are a variety of different ways to visualize the Earth's surface
    in a 2-dimensional manner, but all of them involve some kind of projection:
    a mathematical relationship between the 3D coordinates (latitude, longitude
    and altitude) and 2D coordinates (X and Y in pixels) on the screen.

    Different sources of map data can use different projections, and from the
    point of view of the Map type, we treat these as one replaceable unit:
    the Map plugin. A Map plugin consists of a data source, as well as all other
    details needed to display its data on-screen.

    The current Map plugin in use is contained in the \l plugin property of
    the Map item. In order to display any image in a Map item, you will need
    to set this property. See the \l Plugin type for a description of how
    to retrieve an appropriate plugin for use.

    The geographic region displayed in the Map item is referred to as its
    viewport, and this is defined by the properties \l center, and
    \l zoomLevel. The \l center property contains a \l {coordinate}
    specifying the center of the viewport, while \l zoomLevel controls the scale of the
    map. See each of these properties for further details about their values.

    When the map is displayed, each possible geographic coordinate that is
    visible will map to some pixel X and Y coordinate on the screen. To perform
    conversions between these two, Map provides the \l toCoordinate and
    \l toScreenPosition functions, which are of general utility.

    \section2 Map Objects

    Map related objects can be declared within the body of a Map object in Qt Quick and will
    automatically appear on the Map. To add objects programmatically, first be
    sure they are created with the Map as their parent (for example in an argument to
    Component::createObject), and then call the \l addMapItem method on the Map.
    A corresponding \l removeMapItem method also exists to do the opposite and
    remove an object from the Map.

    Moving Map objects around, resizing them or changing their shape normally
    does not involve any special interaction with Map itself -- changing these
    details about a map object will automatically update the display.

    \section2 Interaction

    The Map type includes support for pinch and flick gestures to control
    zooming and panning. These are enabled by default, and available at any
    time by using the \l gesture object. The actual GestureArea is constructed
    specially at startup and cannot be replaced or destroyed. Its properties
    can be altered, however, to control its behavior.

    \section2 Performance

    Maps are rendered using OpenGL (ES) and the Qt Scene Graph stack, and as
    a result perform quite well where GL accelerated hardware is available.

    For "online" Map plugins, network bandwidth and latency can be major
    contributors to the user's perception of performance. Extensive caching is
    performed to mitigate this, but such mitigation is not always perfect. For
    "offline" plugins, the time spent retrieving the stored geographic data
    and rendering the basic map features can often play a dominant role. Some
    offline plugins may use hardware acceleration themselves to (partially)
    avert this.

    In general, large and complex Map items such as polygons and polylines with
    large numbers of vertices can have an adverse effect on UI performance.
    Further, more detailed notes on this are in the documentation for each
    map item type.

    \section2 Example Usage

    The following snippet shows a simple Map and the necessary Plugin type
    to use it. The map is centered near Brisbane, Australia, zoomed out to the
    minimum zoom level, with gesture interaction enabled.

    \code
    Plugin {
        id: somePlugin
        // code here to choose the plugin as necessary
    }

    Map {
        id: map

        plugin: somePlugin

        center {
            latitude: -27
            longitude: 153
        }
        zoomLevel: map.minimumZoomLevel

        gesture.enabled: true
    }
    \endcode

    \image api-map.png
*/

QDeclarativeGeoMap::QDeclarativeGeoMap(QQuickItem *parent)
        : QQuickItem(parent),
        plugin_(0),
        serviceProvider_(0),
        mappingManager_(0),
        zoomLevel_(8.0),
        center_(51.5073,-0.1277), //London city center
        activeMapType_(0),
        componentCompleted_(false),
        mappingManagerInitialized_(false),
        touchTimer_(-1),
        map_(0)
{
    QLOC_TRACE0;
    setAcceptHoverEvents(false);
    setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton);
    setFlags(QQuickItem::ItemHasContents | QQuickItem::ItemClipsChildrenToShape);
    setFiltersChildMouseEvents(true);

    connect(this, SIGNAL(childrenChanged()), this, SLOT(onMapChildrenChanged()), Qt::QueuedConnection);

    // Create internal flickable and pinch area.
    gestureArea_ = new QDeclarativeGeoMapGestureArea(this, this);
}
示例#20
0
void Trainer::breed()
{
    std::sort(agents.begin(), agents.end(), fitness_comparison());
    emit agentsChanged(agents);

    children.clear();

    AgentVector selected_agents = selection();

    AgentVector selected_agents_one;
    AgentVector selected_agents_two;

    for (unsigned int i = 0; i < selected_agents.size(); i++)
    {
        if (i % 2)
            selected_agents_one.push_back(selected_agents[i]);
        else
            selected_agents_two.push_back(selected_agents[i]);
    }

    unsigned int min_size = (selected_agents_one.size() < selected_agents_two.size()) ?
                selected_agents_one.size() : selected_agents_two.size();

    if (min_size != 0)
    {
        Agent *braut = selected_agents.at(0);
        for (unsigned int i = 0; i < min_size; i++)
        {
            Agent *child_one = crossover(*braut, *selected_agents_one[i], rand() % 2);
            Agent *child_two = crossover(*selected_agents_two[i], *selected_agents_one[i], rand() % 2);
//            Agent *child_three = crossover(*selected_agents_one[i], *selected_agents_two[i], rand() % 2);

//            if (child_three)
//                children.push_back(child_three);


            if (child_one && braut != selected_agents_one[i])
            {
                if (rand() % 100 < 10)
                {
                    Genome genome_one = child_one->getGenome();
                    mutate(genome_one);
                    child_one->setGenome(genome_one);
                }

                children.push_back(child_one);
            }

            if (child_two)
            {
                if (rand() % 100 > 80)
                {
                    Genome genome_two = child_two->getGenome();
                    mutate(genome_two);
                    child_two->setGenome(genome_two);
                }

                children.push_back(child_two);
            }

        }

        std::sort(children.begin(), children.end(), fitness_comparison());
        Agent *b = children.at(0);
        b->setName("Brautern");

        emit childrenChanged(children);
    }

    agents.clear();
    agents = children;
}
示例#21
0
// this differs from other remove functions because it forcibly removes all the children,
// regardless of read-only status or event exceptions, e.g.
void ContainerNode::removeChildren()
{
    if (!m_firstChild)
        return;

    // The container node can be removed from event handlers.
    RefPtr<ContainerNode> protect(this);

    // exclude this node when looking for removed focusedNode since only children will be removed
    document()->removeFocusedNodeOfSubtree(this, true);

#if ENABLE(FULLSCREEN_API)
    document()->removeFullScreenElementOfSubtree(this, true);
#endif

    // Do any prep work needed before actually starting to detach
    // and remove... e.g. stop loading frames, fire unload events.
    willRemoveChildren(protect.get());

    Vector<RefPtr<Node>, 10> removedChildren;
    {
        WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates;
        NoEventDispatchAssertion assertNoEventDispatch;
        removedChildren.reserveInitialCapacity(childNodeCount());
        while (RefPtr<Node> n = m_firstChild) {
            Node* next = n->nextSibling();

            // Remove the node from the tree before calling detach or removedFromDocument (4427024, 4129744).
            // removeChild() does this after calling detach(). There is no explanation for
            // this discrepancy between removeChild() and its optimized version removeChildren().
            n->setPreviousSibling(0);
            n->setNextSibling(0);
            n->setParentOrHostNode(0);
            document()->adoptIfNeeded(n.get());

            m_firstChild = next;
            if (n == m_lastChild)
                m_lastChild = 0;
            removedChildren.append(n.release());
        }

        size_t removedChildrenCount = removedChildren.size();
        size_t i;

        // Detach the nodes only after properly removed from the tree because
        // a. detaching requires a proper DOM tree (for counters and quotes for
        // example) and during the previous loop the next sibling still points to
        // the node being removed while the node being removed does not point back
        // and does not point to the same parent as its next sibling.
        // b. destroying Renderers of standalone nodes is sometimes faster.
        for (i = 0; i < removedChildrenCount; ++i) {
            Node* removedChild = removedChildren[i].get();
            if (removedChild->attached())
                removedChild->detach();
        }

        childrenChanged(false, 0, 0, -static_cast<int>(removedChildrenCount));

        for (i = 0; i < removedChildrenCount; ++i)
            ChildNodeRemovalNotifier(this).notify(removedChildren[i].get());
    }

    dispatchSubtreeModifiedEvent();
}