1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "nodesvisitor.h"
35 #include "projectnodes.h"
37 using namespace ProjectExplorer;
42 \short Base class for visitors that can be used to traverse a node hierarchy.
44 The class follows the visitor pattern as described in Gamma et al. Pass
45 an instance of NodesVisitor to FolderNode::accept(): The visit methods
46 will be called for each node in the subtree, except for file nodes:
47 Access these through FolderNode::fileNodes() in visitProjectNode()
48 and visitoFolderNode().
52 \method NodesVisitor::visitSessionNode(SessionNode *)
54 Called for the root session node.
56 The default implementation does nothing.
60 \method NodesVisitor::visitProjectNode(SessionNode *)
62 Called for a project node.
64 The default implementation does nothing.
68 \method NodesVisitor::visitFolderNode(SessionNode *)
70 Called for a folder node that is _not_ a SessionNode or a ProjectNode.
72 The default implementation does nothing.
77 \class FindNodeForFileVisitor
79 Searches the first node that has the given file as its path.
82 FindNodesForFileVisitor::FindNodesForFileVisitor(const QString &fileToSearch)
83 : m_path(fileToSearch)
87 QList<Node*> FindNodesForFileVisitor::nodes() const
92 void FindNodesForFileVisitor::visitProjectNode(ProjectNode *node)
94 visitFolderNode(node);
97 void FindNodesForFileVisitor::visitFolderNode(FolderNode *node)
99 if (node->path() == m_path) {
102 foreach (FileNode *fileNode, node->fileNodes()) {
103 if (fileNode->path() == m_path) {
110 \class FindAllFilesVisitor
112 Collects file information from all sub file nodes.
115 QStringList FindAllFilesVisitor::filePaths() const
120 void FindAllFilesVisitor::visitProjectNode(ProjectNode *projectNode)
122 visitFolderNode(projectNode);
125 void FindAllFilesVisitor::visitFolderNode(FolderNode *folderNode)
127 m_filePaths.append(folderNode->path());
128 foreach (const FileNode *fileNode, folderNode->fileNodes())
129 m_filePaths.append(fileNode->path());