HierarchyTreeControlNode::HierarchyTreeControlNode(HierarchyTreeNode* parent,
												   const HierarchyTreeControlNode* node):
	HierarchyTreeNode(node)
{
	this->parent = parent;
	this->uiObject = node->GetUIObject()->Clone();
	this->needReleaseUIObjects = false;
	
	// Remove real children & subcontrols - each control is responsible for its
	// subcontrols by itself.
	const List<UIControl* > &realChildren = GetUIObject()->GetRealChildrenAndSubcontrols();
	for (List<UIControl* >::const_iterator iter = realChildren.begin();
		 iter != realChildren.end();
		 ++iter)
	{
        GetUIObject()->RemoveControl(*iter);
	}
	
	AddControlToParent();
	
	const HierarchyTreeNode::HIERARCHYTREENODESLIST& child = node->GetChildNodes();
	for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = child.begin();
		 iter != child.end();
		 ++iter)
	{
		const HierarchyTreeControlNode* controlNode = dynamic_cast<const HierarchyTreeControlNode*>((*iter));
		if (!controlNode)
			continue;
				
		AddTreeNode(new HierarchyTreeControlNode(this, controlNode));
	}
}
bool HierarchyTreePlatformNode::Load(YamlNode* platform)
{
	YamlNode* width = platform->Get(WIDTH_NODE);
	YamlNode* height = platform->Get(HEIGHT_NODE);
	if (!width || !height)
		return false;
	
	bool result = true;
	SetSize(width->AsInt(), height->AsInt());
	ActivatePlatform();
	
	YamlNode* screens = platform->Get(SCREENS_NODE);
	if (screens)
	{
		for (int i = 0; i < screens->GetCount(); i++)
		{
			YamlNode* screen = screens->Get(i);
			if (!screen)
				continue;
			String screenName = screen->AsString();
			
			QString screenPath = QString(SCREEN_PATH).arg(GetResourceFolder()).arg(QString::fromStdString(screenName));
			HierarchyTreeScreenNode* screenNode = new HierarchyTreeScreenNode(this, QString::fromStdString(screenName));
			result &= screenNode->Load(screenPath);
			AddTreeNode(screenNode);
		}
	}
	return result;
}
HierarchyTreeScreenNode::HierarchyTreeScreenNode(HierarchyTreePlatformNode* parent, const HierarchyTreeScreenNode* base):
	HierarchyTreeNode(base),
    loaded(false)
{
	this->parent = parent;
	this->screen = new ScreenControl();
	if (parent)
		screen->SetRect(Rect(0, 0, parent->GetWidth(), parent->GetHeight()));
	
	scale = 1.f;
	posX = 0;
	posY = 0;

	unsavedChangesCounter = 0;

	const HierarchyTreeNode::HIERARCHYTREENODESLIST& chilren = base->GetChildNodes();
	for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = chilren.begin();
		 iter != chilren.end();
		 ++iter)
	{
		const HierarchyTreeControlNode* baseControl = dynamic_cast<const HierarchyTreeControlNode* >((*iter));
		if (!baseControl)
			continue;
		
		HierarchyTreeControlNode* control = new HierarchyTreeControlNode(this, baseControl);
		AddTreeNode(control);
	}
}
Exemple #4
0
TreeNode *AddTreeNode(TreeNode *root, const char *word, int line_num) {
  int i = 0;

  if (root == NULL) {
    root = (TreeNode *) malloc(sizeof(TreeNode));
    root->word = strdup(word);
    // Null head of LinkNode
    root->lines = (LinkNode *) malloc(sizeof(LinkNode));
    root->lines->line_num = 0;
    root->lines->next = (LinkNode *) malloc(sizeof(LinkNode));
    root->lines->next->line_num = line_num;
    root->lines->next->next = NULL;
    root->left = root->right = NULL;
  } else if ((i = strcmp(word, root->word)) == 0) {
    AppendLinkList(root->lines, line_num);
  } else if (i < 0) {
    root->left = AddTreeNode(root->left, word, line_num);
  } else {
    root->right = AddTreeNode(root->right, word, line_num);
  }
  return root;
}
// Add the node to the list after the particular node.
void HierarchyTreeNode::AddTreeNode(HierarchyTreeNode* treeNode, HierarchyTreeNode* nodeToAddAfter)
{
    if (treeNode == NULL)
        return;
	
	HIERARCHYTREENODESITER iter = std::find(childNodes.begin(), childNodes.end(), treeNode);
    if (iter != childNodes.end())
		return;

	if (nodeToAddAfter == NULL)
	{
		AddTreeNode(treeNode);
		return;
	}
	
	if (nodeToAddAfter == this)
	{
		childNodes.push_front(treeNode);
		return;
	}

	// Look for the "nodeToAddAfter" to insert the tree node after it.
    HIERARCHYTREENODESITER nodeAfterIter = std::find(childNodes.begin(), childNodes.end(), nodeToAddAfter);
    if (nodeAfterIter == childNodes.end())
    {
		return AddTreeNode(treeNode);
    }

	nodeAfterIter ++;
	if (nodeAfterIter == childNodes.end())
    {
		return AddTreeNode(treeNode);
    }
	
	childNodes.insert(nodeAfterIter, treeNode);
}
HierarchyTreeControlNode::HierarchyTreeControlNode(HierarchyTreeNode* parent,
        const HierarchyTreeControlNode* node):
    HierarchyTreeNode(node),
    listDelegate(NULL)
{
    this->parent = parent;
    this->uiObject = node->GetUIObject()->Clone();
    this->needReleaseUIObjects = false;

    // All UIList controls should always have a delegate
    // We set a delegate here to avoid inappropriate loading of saved list
    UIList *list = dynamic_cast<UIList*>(this->uiObject);
    UIList *srcList = dynamic_cast<UIList*>(node->GetUIObject());
    if (list)
    {
        listDelegate = new EditorListDelegate(list->GetRect(), list->GetOrientation());
        EditorListDelegate *srcListDelegate = dynamic_cast<EditorListDelegate*>(srcList->GetDelegate());
        if (srcListDelegate)
        {
            listDelegate->SetAggregatorID(srcListDelegate->GetAggregatorID());
        }
        list->SetDelegate(listDelegate);
    }

    // Remove real children & subcontrols - each control is responsible for its
    // subcontrols by itself.
    const List<UIControl* > &realChildren = GetUIObject()->GetRealChildren();
    for (List<UIControl* >::const_iterator iter = realChildren.begin();
            iter != realChildren.end();
            ++iter)
    {
        GetUIObject()->RemoveControl(*iter);
    }

    AddControlToParent();

    const HierarchyTreeNode::HIERARCHYTREENODESLIST& child = node->GetChildNodes();
    for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = child.begin();
            iter != child.end();
            ++iter)
    {
        const HierarchyTreeControlNode* controlNode = dynamic_cast<const HierarchyTreeControlNode*>((*iter));
        if (!controlNode)
            continue;

        AddTreeNode(controlNode->CreateControlCopy(parent ? this : NULL));
    }
}
Exemple #7
0
/* Cross referencer, prints all words and its line number */
int main() {
  TreeNode *root;
  char word[kMaxWord];
  int line_num = 1;

  root = NULL;
  while (GetWord(word, kMaxWord) != EOF) {
    if (isalpha(word[0]) && IsNoiseWord(word) == -1) {
      root = AddTreeNode(root, word, line_num);
    } else if (word[0] == '\n') {
      ++line_num;
    }
  }
  PrintTree(root);
  return 0;
}
Exemple #8
0
HierarchyTreePlatformNode::HierarchyTreePlatformNode(HierarchyTreeRootNode* rootNode, const HierarchyTreePlatformNode* base) :
	HierarchyTreeNode(base)
{
	this->rootNode = rootNode;
	this->width = base->GetWidth();
	this->height = base->GetHeight();
	
	const HierarchyTreeNode::HIERARCHYTREENODESLIST& chilren = base->GetChildNodes();
	for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = chilren.begin();
		 iter != chilren.end();
		 ++iter)
	{
		const HierarchyTreeScreenNode* baseControl = dynamic_cast<const HierarchyTreeScreenNode* >((*iter));
		if (!baseControl)
			continue;
		
		HierarchyTreeScreenNode* control = new HierarchyTreeScreenNode(this, baseControl);
		AddTreeNode(control);
	}
}
Exemple #9
0
void main()
{
	CBTType *root=NULL;
	char  menusel;
	void (*TreeNodeData1)(CBTType *p);
	TreeNodeData1=TreeNodeData;

	root = InitTree();
	do{
		printf("请选择菜单添加二叉树的节点\n");
		printf("0.退出\t");
		printf("1.添加二叉树的节点\n");
		menusel = getch();
		switch(menusel)
		{
		case '1':
			AddTreeNode(root);
			break;
		case '0':
			break;
		default:
			;
		}
	}while(menusel != '0');

	do{
		printf("请选择菜单遍历二叉树,输入0表示退出:\n");
		printf("1.先序遍历DLR\t");
		printf("2.中序遍历LDR\n");
		printf("3.后序遍历LRD\t");
		printf("4.按层遍历\n");


		menusel = getch();
		switch(menusel)
		{
		case '0':
			break;
		case '1':
			printf("\n 先序遍历DLR的结果:");
			DLRTree(root,TreeNodeData1);
			printf("\n");
			break;
		case '2':
			printf("\n中序遍历LDR的结果:");
			LDRTree(root,TreeNodeData1);
			printf("\n");
			break;
		case '3':
			printf("\n 后序遍历LRD的结果:");
			LRDTree(root,TreeNodeData1);
			printf("\n");
			break;
		case '4':
			printf("\n 按层遍历的结果:");
			LevelTree(root,TreeNodeData1);
			printf("\n");
			break;
		default:
			;
		}
	
	}while(menusel != '0');

	printf("\n 二叉树深度为:%d \n",TreeDepth(root));

	ClearTree(root);
	root = NULL;


}