/
pmrworkspacefilenode.cpp
176 lines (121 loc) · 4.66 KB
/
pmrworkspacefilenode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://gnu.org/licenses>.
*******************************************************************************/
//==============================================================================
// PMR workspace file node
//==============================================================================
#include "pmrworkspacefilenode.h"
//==============================================================================
namespace OpenCOR {
namespace PMRSupport {
//==============================================================================
PmrWorkspaceFileNode::PmrWorkspaceFileNode(const QString &pName,
const QString &pPath,
const CharPair &pStatus,
PmrWorkspaceFileNode *pParent) :
QObject(pParent),
mParent(pParent),
mName(pName),
mPath(pPath),
mStatus(pStatus)
{
}
//==============================================================================
PmrWorkspaceFileNode::PmrWorkspaceFileNode(PmrWorkspaceFileNode *pParent) :
PmrWorkspaceFileNode({}, {}, {}, pParent)
{
}
//==============================================================================
PmrWorkspaceFileNode * PmrWorkspaceFileNode::parent() const
{
// Return our parent
return mParent;
}
//==============================================================================
QString PmrWorkspaceFileNode::name() const
{
// Return our name
return mName;
}
//==============================================================================
QString PmrWorkspaceFileNode::path() const
{
// Return our path
return mPath;
}
//==============================================================================
void PmrWorkspaceFileNode::setPath(const QString &pPath)
{
// Set our path
mPath = pPath;
}
//==============================================================================
CharPair PmrWorkspaceFileNode::status() const
{
// Return our status
return mStatus;
}
//==============================================================================
void PmrWorkspaceFileNode::setStatus(const CharPair &pStatus)
{
// Set our status
mStatus = pStatus;
}
//==============================================================================
bool PmrWorkspaceFileNode::hasChildren() const
{
// Return whether we have children
return !mChildren.isEmpty();
}
//==============================================================================
PmrWorkspaceFileNodes PmrWorkspaceFileNode::children() const
{
// Return our children
return mChildren;
}
//==============================================================================
PmrWorkspaceFileNode * PmrWorkspaceFileNode::addChild(const QString &pName,
const CharPair &pStatus)
{
// Check whether we already have the given child and, if so, return it
for (auto child : mChildren) {
if (child->name() == pName) {
// This is the child we are trying to add, so update its status and
// return it
child->setStatus(pStatus);
return child;
}
}
// We don't already have the given child, so add it to ourselves and return
// it
auto res = new PmrWorkspaceFileNode(pName, path()+"/"+pName, pStatus, this);
mChildren << res;
return res;
}
//==============================================================================
bool PmrWorkspaceFileNode::removeChild(PmrWorkspaceFileNode *pChild)
{
// Remove the given child, if possible
if (mChildren.contains(pChild)) {
delete pChild;
mChildren.removeOne(pChild);
return true;
}
return false;
}
//==============================================================================
} // namespace PMRSupport
} // namespace OpenCOR
//==============================================================================
// End of file
//==============================================================================