MCPcopy Create free account
hub / github.com/KDAB/KDChart / buildPlaneLayoutGraph

Method buildPlaneLayoutGraph

src/KDChart/KDChartChart.cpp:464–547  ·  view source on GitHub ↗

* this method determines the needed layout of the graph * taking care of the sharing problematic * its NOT allowed to have a diagram that shares * more than one axis in the same direction */

Source from the content-addressed store, hash-verified

462 * more than one axis in the same direction
463 */
464QVector<LayoutGraphNode *> Chart::Private::buildPlaneLayoutGraph()
465{
466 QHash<AbstractCoordinatePlane *, LayoutGraphNode *> planeNodeMapping;
467 QVector<LayoutGraphNode *> allNodes;
468 // create all nodes and a mapping between plane and nodes
469 Q_FOREACH (AbstractCoordinatePlane *curPlane, coordinatePlanes) {
470 if (curPlane->diagram()) {
471 allNodes.append(new LayoutGraphNode);
472 allNodes[allNodes.size() - 1]->diagramPlane = curPlane;
473 allNodes[allNodes.size() - 1]->priority = allNodes.size();
474 checkExistingAxes(allNodes[allNodes.size() - 1]);
475 planeNodeMapping[curPlane] = allNodes[allNodes.size() - 1];
476 }
477 }
478 // build the graph connections
479 Q_FOREACH (LayoutGraphNode *curNode, allNodes) {
480 QVector<CartesianAxis *> sharedAxes;
481 CoordinatePlaneList xSharedPlanes = findSharingAxisDiagrams(curNode->diagramPlane, coordinatePlanes, Abscissa, &sharedAxes);
482 Q_ASSERT(sharedAxes.size() < 2);
483 // TODO duplicated code make a method out of it
484 if (sharedAxes.size() == 1 && xSharedPlanes.size() > 1) {
485 // xSharedPlanes.removeAll( sharedAxes.first()->diagram()->coordinatePlane() );
486 // std::sort( xSharedPlanes.begin(), xSharedPlanes.end(), PriorityComparator( planeNodeMapping ) );
487 for (int i = 0; i < xSharedPlanes.size() - 1; ++i) {
488 LayoutGraphNode *tmpNode = planeNodeMapping[xSharedPlanes[i]];
489 Q_ASSERT(tmpNode);
490 LayoutGraphNode *tmpNode2 = planeNodeMapping[xSharedPlanes[i + 1]];
491 Q_ASSERT(tmpNode2);
492 tmpNode->bottomSuccesor = tmpNode2;
493 }
494 // if ( sharedAxes.first()->diagram() && sharedAxes.first()->diagram()->coordinatePlane() )
495 // {
496 // LayoutGraphNode *lastNode = planeNodeMapping[ xSharedPlanes.last() ];
497 // Q_ASSERT( lastNode );
498 // Q_ASSERT( sharedAxes.first()->diagram()->coordinatePlane() );
499 // LayoutGraphNode *ownerNode = planeNodeMapping[ sharedAxes.first()->diagram()->coordinatePlane() ];
500 // Q_ASSERT( ownerNode );
501 // lastNode->bottomSuccesor = ownerNode;
502 // }
503 // merge AxisInformation, needs a two pass run
504 LayoutGraphNode axisInfoNode;
505 for (int count = 0; count < 2; ++count) {
506 for (int i = 0; i < xSharedPlanes.size(); ++i) {
507 mergeNodeAxisInformation(&axisInfoNode, planeNodeMapping[xSharedPlanes[i]]);
508 }
509 }
510 }
511 sharedAxes.clear();
512 CoordinatePlaneList ySharedPlanes = findSharingAxisDiagrams(curNode->diagramPlane, coordinatePlanes, Ordinate, &sharedAxes);
513 Q_ASSERT(sharedAxes.size() < 2);
514 if (sharedAxes.size() == 1 && ySharedPlanes.size() > 1) {
515 // ySharedPlanes.removeAll( sharedAxes.first()->diagram()->coordinatePlane() );
516 // std::sort( ySharedPlanes.begin(), ySharedPlanes.end(), PriorityComparator( planeNodeMapping ) );
517 for (int i = 0; i < ySharedPlanes.size() - 1; ++i) {
518 LayoutGraphNode *tmpNode = planeNodeMapping[ySharedPlanes[i]];
519 Q_ASSERT(tmpNode);
520 LayoutGraphNode *tmpNode2 = planeNodeMapping[ySharedPlanes[i + 1]];
521 Q_ASSERT(tmpNode2);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected