OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / projectexplorer / nodesvisitor.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "nodesvisitor.h"
35 #include "projectnodes.h"
36
37 using namespace ProjectExplorer;
38
39 /*!
40   \class NodesVisitor
41
42   \short Base class for visitors that can be used to traverse a node hierarchy.
43
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().
49 */
50
51 /*!
52   \method NodesVisitor::visitSessionNode(SessionNode *)
53
54   Called for the root session node.
55
56   The default implementation does nothing.
57   */
58
59 /*!
60   \method NodesVisitor::visitProjectNode(SessionNode *)
61
62   Called for a project node.
63
64   The default implementation does nothing.
65   */
66
67 /*!
68   \method NodesVisitor::visitFolderNode(SessionNode *)
69
70   Called for a folder node that is _not_ a SessionNode or a ProjectNode.
71
72   The default implementation does nothing.
73   */
74
75
76 /*!
77   \class FindNodeForFileVisitor
78
79   Searches the first node that has the given file as its path.
80  */
81
82 FindNodesForFileVisitor::FindNodesForFileVisitor(const QString &fileToSearch)
83     : m_path(fileToSearch)
84 {
85 }
86
87 QList<Node*> FindNodesForFileVisitor::nodes() const
88 {
89     return m_nodes;
90 }
91
92 void FindNodesForFileVisitor::visitProjectNode(ProjectNode *node)
93 {
94     visitFolderNode(node);
95 }
96
97 void FindNodesForFileVisitor::visitFolderNode(FolderNode *node)
98 {
99     if (node->path() == m_path) {
100         m_nodes << node;
101     }
102     foreach (FileNode *fileNode, node->fileNodes()) {
103         if (fileNode->path() == m_path) {
104             m_nodes << fileNode;
105         }
106     }
107 }
108
109 /*!
110   \class FindAllFilesVisitor
111
112   Collects file information from all sub file nodes.
113  */
114
115 QStringList FindAllFilesVisitor::filePaths() const
116 {
117     return m_filePaths;
118 }
119
120 void FindAllFilesVisitor::visitProjectNode(ProjectNode *projectNode)
121 {
122     visitFolderNode(projectNode);
123 }
124
125 void FindAllFilesVisitor::visitFolderNode(FolderNode *folderNode)
126 {
127     m_filePaths.append(folderNode->path());
128     foreach (const FileNode *fileNode, folderNode->fileNodes())
129         m_filePaths.append(fileNode->path());
130 }