Exemplo n.º 1
0
QModelIndex model::DbContainerModel::parent(const QModelIndex& index) const
{
	TreeNode* node = Index2Node(index);
	if (node == nullptr || node->GetParent() == nullptr)
	{
		return QModelIndex();
	}
	TreeNode* parentNode = const_cast<TreeNode*>(node->GetParent());
	// It is one of the root nodes, set its row as the index of the roots vector
	int rootIndex = m_rootNodes.indexOf(parentNode);
	return createIndex(rootIndex >= 0 ? rootIndex : node->GetRow(), 0, parentNode);
}
Exemplo n.º 2
0
Qt::ItemFlags model::DbContainerModel::flags(const QModelIndex& index) const
{
	int flags = QAbstractItemModel::flags(index);
	TreeNode* node = Index2Node(index);
	if (node != nullptr && node->GetParent() != nullptr)
	{
		flags |= Qt::ItemIsEditable;
	}
	return flags;
}
Exemplo n.º 3
0
/*----------------------------------------------------------------------------------------------------------------------
|	
*/
inline effective_postorder_edge_iterator::effective_postorder_edge_iterator(
  TreeNode * effRoot, 		/**< "focal" node of the iteration (order of nodes will be postorder if this node were the root) */
  NodeValidityChecker f)	/**< functor that takes two Node pointers and returns true if the iteration in this subtree should be stopped) */
  : isValidChecker(f), effectiveRoot(effRoot)
	{
	PHYCAS_ASSERT(!isValidChecker.empty());
	PHYCAS_ASSERT(effectiveRoot != NULL);

	// Build that part of edge_stack based on nodes above effectiveRoot
	BuildStackFromNodeAndSiblings(effectiveRoot->GetLeftChild(), NULL);

	// Now finish the job by considering nodes below effectiveRoot
	TreeNode * currAvoidNode = effectiveRoot;
	for (TreeNode * currAnc = effectiveRoot->GetParent(); currAnc != NULL; currAnc = currAnc->GetParent())
		{
#if 0
		if (!isValidChecker.empty() && isValidChecker(currAnc, currAvoidNode))
			break;
#else
		if (!isValidChecker.empty())
            {
            bool ok = isValidChecker(currAnc, currAvoidNode);
            if (ok)
			    break;
            }
#endif

		// 
		edgeStack.push(EdgeEndpoints(currAnc, currAvoidNode));
		BuildStackFromNodeAndSiblings(currAnc->GetLeftChild(), currAvoidNode);
		currAvoidNode = currAnc;
		}

	// Make sure we look like a default-constructed object if there are no edges in edgeStack
	// This allows the iterator to determine when it has reached the end
	if (edgeStack.empty())
		effectiveRoot = NULL;
	}
Exemplo n.º 4
0
/*----------------------------------------------------------------------------------------------------------------------
|   Selects an internal node at random from a discrete uniform distribution with the constraint that the returned node
|   is not equal to the subroot (the sole child of the tip node serving as the root).
*/
TreeNode * LargetSimonMove::randomInternalAboveSubroot()
    {
	// Avoiding the "subroot" node (only child of the tip serving as the root), so the number of
	// acceptable nodes is one fewer than the number of internal nodes
	unsigned numAcceptableNodes = tree->GetNInternals() - 1;

	unsigned ypos = rng->SampleUInt(numAcceptableNodes);
	unsigned i = 0;
    TreeNode * nd = tree->GetFirstPreorder();
	for (; nd != NULL; nd = nd->GetNextPreorder())
		{
		if (nd->IsInternal() && !nd->GetParentConst()->IsTipRoot())
			{
			if (i == ypos)
				break;
			++i;
			}
		}
	PHYCAS_ASSERT(nd->GetLeftChild() != NULL);
	PHYCAS_ASSERT(nd->GetParentConst() != NULL);
	PHYCAS_ASSERT(!nd->GetParent()->IsTipRoot());
    return nd;
    }
Exemplo n.º 5
0
void VirtualDirectorySelectorDlg::DoBuildTree()
{
    wxWindowUpdateLocker locker(m_treeCtrl);
    m_treeCtrl->DeleteAllItems();

    if ( m_images == NULL ) {
        m_images = new wxImageList(16, 16);
        BitmapLoader bmpLoader;
        m_images->Add( bmpLoader.LoadBitmap( wxT( "workspace/16/workspace" ) ) );//0
        m_images->Add( bmpLoader.LoadBitmap( wxT( "workspace/16/virtual_folder" ) ) );    //1
        m_images->Add( bmpLoader.LoadBitmap( wxT( "workspace/16/project" ) ) );  //2
        m_treeCtrl->AssignImageList(m_images);
    }

    if (m_workspace) {
        wxArrayString projects;
        m_workspace->GetProjectList(projects);

        VisualWorkspaceNode nodeData;
        nodeData.name = m_workspace->GetName();
        nodeData.type = ProjectItem::TypeWorkspace;

        TreeNode<wxString, VisualWorkspaceNode> *tree = new TreeNode<wxString, VisualWorkspaceNode>(m_workspace->GetName(), nodeData);

        for (size_t i=0; i<projects.GetCount(); i++) {
            if (!m_projectName.empty() && projects.Item(i) != m_projectName) {
                // If we were passed a specific project, display only that one
                continue;
            }

            wxString err;
            ProjectPtr p = m_workspace->FindProjectByName(projects.Item(i), err);
            if (p) {
                p->GetVirtualDirectories(tree);
            }
        }

        //create the tree
        wxTreeItemId root = m_treeCtrl->AddRoot(nodeData.name, 0, 0);
        tree->GetData().itemId = root;
        TreeWalker<wxString, VisualWorkspaceNode> walker(tree);

        for (; !walker.End(); walker++) {
            // Add the item to the tree
            TreeNode<wxString, VisualWorkspaceNode>* node = walker.GetNode();

            // Skip root node
            if (node->IsRoot())
                continue;

            wxTreeItemId parentHti = node->GetParent()->GetData().itemId;
            if (parentHti.IsOk() == false) {
                parentHti = root;
            }

            int imgId(2); // Virtual folder
            switch (node->GetData().type) {
            case ProjectItem::TypeWorkspace:
                imgId = 0;
                break;
            case ProjectItem::TypeProject:
                imgId = 2;
                break;
            case ProjectItem::TypeVirtualDirectory:
            default:
                imgId = 1;
                break;

            }

            //add the item to the tree
            node->GetData().itemId = m_treeCtrl->AppendItem(
                                         parentHti,				// parent
                                         node->GetData().name,	// display name
                                         imgId,					// item image index
                                         imgId					// selected item image
                                     );
            m_treeCtrl->SortChildren(parentHti);
        }


#if !defined(__WXMSW__)
        // For a single project, hide the workspace node. This doesn't work on wxMSW
        if (!m_projectName.empty()) {
            m_treeCtrl->SetWindowStyle(m_treeCtrl->GetWindowStyle() | wxTR_HIDE_ROOT);
            wxTreeItemIdValue cookie;
            wxTreeItemId projitem = m_treeCtrl->GetFirstChild(root, cookie);
            if (projitem.IsOk() && m_treeCtrl->HasChildren(projitem)) {
                m_treeCtrl->Expand(projitem);
            }
        }
        else
#endif
            if (root.IsOk() && m_treeCtrl->HasChildren(root)) {
                m_treeCtrl->Expand(root);
            }
        delete tree;
    }

    // if a initialPath was provided, try to find and select it
    if (SelectPath(m_initialPath)) {
        m_treeCtrl->Expand(m_treeCtrl->GetSelection());
    }
}