/usr/share/qt5/doc/qtxmlpatterns/qtxmlpatterns-xmlpatterns-filetree-filetree-cpp.html is in qtxmlpatterns5-doc-html 5.3.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>filetree.cpp Example File | QtXmlPatterns </title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li>Qt 5.3</li>
<li><a href="qtxmlpatterns-index.html">Qt XML Patterns</a></li>
<li><a href="qtxmlpatterns-xmlpatterns-filetree-example.html">File System Example</a></li>
<li>filetree.cpp Example File</li>
<li id="buildversion">
Qt 5.3.2 Reference Documentation</li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<h1 class="title">filetree.cpp Example File</h1>
<span class="subtitle">xmlpatterns/filetree/filetree.cpp</span>
<!-- $$$xmlpatterns/filetree/filetree.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp"><span class="comment">/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/</span>
<span class="preprocessor">#include <QtCore/QUrl></span>
<span class="preprocessor">#include <QtCore/QVariant></span>
<span class="preprocessor">#include <QtXmlPatterns/QXmlNamePool></span>
<span class="preprocessor">#include "filetree.h"</span>
<span class="comment">/*
The model has two types of nodes: elements & attributes.
<directory name="">
<file name="">
</file>
</directory>
In QXmlNodeModelIndex we store two values. QXmlNodeIndex::data()
is treated as a signed int, and it is an index into m_fileInfos
unless it is -1, in which case it has no meaning and the value
of QXmlNodeModelIndex::additionalData() is a Type name instead.
*/</span>
<span class="comment">/*!
The constructor passes \a pool to the base class, then loads an
internal vector with an instance of QXmlName for each of the
strings "file", "directory", "fileName", "filePath", "size",
"mimeType", and "suffix".
*/</span>
FileTree<span class="operator">::</span>FileTree(<span class="keyword">const</span> <span class="type"><a href="qxmlnamepool.html">QXmlNamePool</a></span><span class="operator">&</span> pool)
: <span class="type"><a href="qsimplexmlnodemodel.html">QSimpleXmlNodeModel</a></span>(pool)<span class="operator">,</span>
m_filterAllowAll(<span class="type">QDir</span><span class="operator">::</span>AllEntries <span class="operator">|</span>
<span class="type">QDir</span><span class="operator">::</span>AllDirs <span class="operator">|</span>
<span class="type">QDir</span><span class="operator">::</span>NoDotAndDotDot <span class="operator">|</span>
<span class="type">QDir</span><span class="operator">::</span>Hidden)<span class="operator">,</span>
m_sortFlags(<span class="type">QDir</span><span class="operator">::</span>Name)
{
<span class="type"><a href="qxmlnamepool.html">QXmlNamePool</a></span> np <span class="operator">=</span> namePool();
m_names<span class="operator">.</span>resize(<span class="number">7</span>);
m_names<span class="operator">[</span>File<span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qxmlname.html">QXmlName</a></span>(np<span class="operator">,</span> QLatin1String(<span class="string">"file"</span>));
m_names<span class="operator">[</span>Directory<span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qxmlname.html">QXmlName</a></span>(np<span class="operator">,</span> QLatin1String(<span class="string">"directory"</span>));
m_names<span class="operator">[</span>AttributeFileName<span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qxmlname.html">QXmlName</a></span>(np<span class="operator">,</span> QLatin1String(<span class="string">"fileName"</span>));
m_names<span class="operator">[</span>AttributeFilePath<span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qxmlname.html">QXmlName</a></span>(np<span class="operator">,</span> QLatin1String(<span class="string">"filePath"</span>));
m_names<span class="operator">[</span>AttributeSize<span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qxmlname.html">QXmlName</a></span>(np<span class="operator">,</span> QLatin1String(<span class="string">"size"</span>));
m_names<span class="operator">[</span>AttributeMIMEType<span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qxmlname.html">QXmlName</a></span>(np<span class="operator">,</span> QLatin1String(<span class="string">"mimeType"</span>));
m_names<span class="operator">[</span>AttributeSuffix<span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="qxmlname.html">QXmlName</a></span>(np<span class="operator">,</span> QLatin1String(<span class="string">"suffix"</span>));
}
<span class="comment">/*!
Returns the QXmlNodeModelIndex for the model node representing
the directory \a dirName.
It calls QDir::cleanPath(), because an instance of QFileInfo
constructed for a path ending in '/' will return the empty string in
fileName(), instead of the directory name.
*/</span>
<span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> FileTree<span class="operator">::</span>nodeFor(<span class="keyword">const</span> <span class="type">QString</span><span class="operator">&</span> dirName) <span class="keyword">const</span>
{
<span class="type">QFileInfo</span> dirInfo(<span class="type">QDir</span><span class="operator">::</span>cleanPath(dirName));
Q_ASSERT(dirInfo<span class="operator">.</span>exists());
<span class="keyword">return</span> toNodeIndex(dirInfo);
}
<span class="comment">/*!
Since the value will always be in m_fileInfos, it is safe for
us to return a const reference to it.
*/</span>
<span class="keyword">const</span> <span class="type">QFileInfo</span><span class="operator">&</span>
FileTree<span class="operator">::</span>toFileInfo(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>nodeIndex) <span class="keyword">const</span>
{
<span class="keyword">return</span> m_fileInfos<span class="operator">.</span>at(nodeIndex<span class="operator">.</span>data());
}
<span class="comment">/*!
Returns the model node index for the node specified by the
QFileInfo and node Type.
*/</span>
<span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span>
FileTree<span class="operator">::</span>toNodeIndex(<span class="keyword">const</span> <span class="type">QFileInfo</span> <span class="operator">&</span>fileInfo<span class="operator">,</span> Type attributeName) <span class="keyword">const</span>
{
<span class="keyword">const</span> <span class="type">int</span> indexOf <span class="operator">=</span> m_fileInfos<span class="operator">.</span>indexOf(fileInfo);
<span class="keyword">if</span> (indexOf <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>) {
m_fileInfos<span class="operator">.</span>append(fileInfo);
<span class="keyword">return</span> createIndex(m_fileInfos<span class="operator">.</span>count()<span class="operator">-</span><span class="number">1</span><span class="operator">,</span> attributeName);
}
<span class="keyword">else</span>
<span class="keyword">return</span> createIndex(indexOf<span class="operator">,</span> attributeName);
}
<span class="comment">/*!
Returns the model node index for the node specified by the
QFileInfo, which must be a Type::File or Type::Directory.
*/</span>
<span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> FileTree<span class="operator">::</span>toNodeIndex(<span class="keyword">const</span> <span class="type">QFileInfo</span> <span class="operator">&</span>fileInfo) <span class="keyword">const</span>
{
<span class="keyword">return</span> toNodeIndex(fileInfo<span class="operator">,</span> fileInfo<span class="operator">.</span>isDir() <span class="operator">?</span> Directory : File);
}
<span class="comment">/*!
This private helper function is only called by nextFromSimpleAxis().
It is called whenever nextFromSimpleAxis() is called with an axis
parameter of either \c{PreviousSibling} or \c{NextSibling}.
*/</span>
<span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> FileTree<span class="operator">::</span>nextSibling(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>nodeIndex<span class="operator">,</span>
<span class="keyword">const</span> <span class="type">QFileInfo</span> <span class="operator">&</span>fileInfo<span class="operator">,</span>
<span class="type">qint8</span> offset) <span class="keyword">const</span>
{
Q_ASSERT(offset <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span> <span class="operator">|</span><span class="operator">|</span> offset <span class="operator">=</span><span class="operator">=</span> <span class="number">1</span>);
<span class="comment">// Get the context node's parent.</span>
<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> parent(nextFromSimpleAxis(Parent<span class="operator">,</span> nodeIndex));
<span class="keyword">if</span> (parent<span class="operator">.</span>isNull())
<span class="keyword">return</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span>();
<span class="comment">// Get the parent's child list.</span>
<span class="keyword">const</span> <span class="type">QFileInfo</span> parentFI(toFileInfo(parent));
Q_ASSERT(Type(parent<span class="operator">.</span>additionalData()) <span class="operator">=</span><span class="operator">=</span> Directory);
<span class="keyword">const</span> <span class="type">QFileInfoList</span> siblings(<span class="type">QDir</span>(parentFI<span class="operator">.</span>absoluteFilePath())<span class="operator">.</span>entryInfoList(<span class="type">QStringList</span>()<span class="operator">,</span>
m_filterAllowAll<span class="operator">,</span>
m_sortFlags));
Q_ASSERT_X(<span class="operator">!</span>siblings<span class="operator">.</span>isEmpty()<span class="operator">,</span> Q_FUNC_INFO<span class="operator">,</span> <span class="string">"Can't happen! We started at a child."</span>);
<span class="comment">// Find the index of the child where we started.</span>
<span class="keyword">const</span> <span class="type">int</span> indexOfMe <span class="operator">=</span> siblings<span class="operator">.</span>indexOf(fileInfo);
<span class="comment">// Apply the offset.</span>
<span class="keyword">const</span> <span class="type">int</span> siblingIndex <span class="operator">=</span> indexOfMe <span class="operator">+</span> offset;
<span class="keyword">if</span> (siblingIndex <span class="operator"><</span> <span class="number">0</span> <span class="operator">|</span><span class="operator">|</span> siblingIndex <span class="operator">></span> siblings<span class="operator">.</span>count() <span class="operator">-</span> <span class="number">1</span>)
<span class="keyword">return</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span>();
<span class="keyword">else</span>
<span class="keyword">return</span> toNodeIndex(siblings<span class="operator">.</span>at(siblingIndex));
}
<span class="comment">/*!
This function is called by the Qt XML Patterns query engine when it
wants to move to the next node in the model. It moves along an \a
axis, \e from the node specified by \a nodeIndex.
This function is usually the one that requires the most design and
implementation work, because the implementation depends on the
perhaps unique structure of your non-XML data.
There are \l {QAbstractXmlNodeModel::SimpleAxis} {four values} for
\a axis that the implementation must handle, but there are really
only two axes, i.e., vertical and horizontal. Two of the four values
specify direction on the vertical axis (\c{Parent} and
\c{FirstChild}), and the other two values specify direction on the
horizontal axis (\c{PreviousSibling} and \c{NextSibling}).
The typical implementation will be a \c switch statement with
a case for each of the four \a axis values.
*/</span>
<span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span>
FileTree<span class="operator">::</span>nextFromSimpleAxis(SimpleAxis axis<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>nodeIndex) <span class="keyword">const</span>
{
<span class="keyword">const</span> <span class="type">QFileInfo</span> fi(toFileInfo(nodeIndex));
<span class="keyword">const</span> Type type <span class="operator">=</span> Type(nodeIndex<span class="operator">.</span>additionalData());
<span class="keyword">if</span> (type <span class="operator">!</span><span class="operator">=</span> File <span class="operator">&</span><span class="operator">&</span> type <span class="operator">!</span><span class="operator">=</span> Directory) {
Q_ASSERT_X(axis <span class="operator">=</span><span class="operator">=</span> Parent<span class="operator">,</span> Q_FUNC_INFO<span class="operator">,</span> <span class="string">"An attribute only has a parent!"</span>);
<span class="keyword">return</span> toNodeIndex(fi<span class="operator">,</span> Directory);
}
<span class="keyword">switch</span> (axis) {
<span class="keyword">case</span> Parent:
<span class="keyword">return</span> toNodeIndex(<span class="type">QFileInfo</span>(fi<span class="operator">.</span>path())<span class="operator">,</span> Directory);
<span class="keyword">case</span> FirstChild:
{
<span class="keyword">if</span> (type <span class="operator">=</span><span class="operator">=</span> File) <span class="comment">// A file has no children.</span>
<span class="keyword">return</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span>();
<span class="keyword">else</span> {
Q_ASSERT(type <span class="operator">=</span><span class="operator">=</span> Directory);
Q_ASSERT_X(fi<span class="operator">.</span>isDir()<span class="operator">,</span> Q_FUNC_INFO<span class="operator">,</span> <span class="string">"It isn't really a directory!"</span>);
<span class="keyword">const</span> <span class="type">QDir</span> dir(fi<span class="operator">.</span>absoluteFilePath());
Q_ASSERT(dir<span class="operator">.</span>exists());
<span class="keyword">const</span> <span class="type">QFileInfoList</span> children(dir<span class="operator">.</span>entryInfoList(<span class="type">QStringList</span>()<span class="operator">,</span>
m_filterAllowAll<span class="operator">,</span>
m_sortFlags));
<span class="keyword">if</span> (children<span class="operator">.</span>isEmpty())
<span class="keyword">return</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span>();
<span class="keyword">const</span> <span class="type">QFileInfo</span> firstChild(children<span class="operator">.</span>first());
<span class="keyword">return</span> toNodeIndex(firstChild);
}
}
<span class="keyword">case</span> PreviousSibling:
<span class="keyword">return</span> nextSibling(nodeIndex<span class="operator">,</span> fi<span class="operator">,</span> <span class="operator">-</span><span class="number">1</span>);
<span class="keyword">case</span> NextSibling:
<span class="keyword">return</span> nextSibling(nodeIndex<span class="operator">,</span> fi<span class="operator">,</span> <span class="number">1</span>);
}
Q_ASSERT_X(<span class="keyword">false</span><span class="operator">,</span> Q_FUNC_INFO<span class="operator">,</span> <span class="string">"Don't ever get here!"</span>);
<span class="keyword">return</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span>();
}
<span class="comment">/*!
No matter what part of the file system we model (the whole file
tree or a subtree), \a node will always have \c{file:///} as
the document URI.
*/</span>
<span class="type">QUrl</span> FileTree<span class="operator">::</span>documentUri(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>node) <span class="keyword">const</span>
{
Q_UNUSED(node);
<span class="keyword">return</span> <span class="type">QUrl</span>(<span class="string">"file:///"</span>);
}
<span class="comment">/*!
This function returns QXmlNodeModelIndex::Element if \a node
is a directory or a file, and QXmlNodeModelIndex::Attribute
otherwise.
*/</span>
<span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">::</span>NodeKind
FileTree<span class="operator">::</span>kind(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>node) <span class="keyword">const</span>
{
<span class="keyword">switch</span> (Type(node<span class="operator">.</span>additionalData())) {
<span class="keyword">case</span> Directory:
<span class="keyword">case</span> File:
<span class="keyword">return</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">::</span>Element;
<span class="keyword">default</span>:
<span class="keyword">return</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">::</span>Attribute;
}
}
<span class="comment">/*!
No order is defined for this example, so we always return
QXmlNodeModelIndex::Is, just to keep everyone happy.
*/</span>
<span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">::</span>DocumentOrder
FileTree<span class="operator">::</span>compareOrder(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">&</span><span class="operator">,</span>
<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">&</span>) <span class="keyword">const</span>
{
<span class="keyword">return</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">::</span>Is;
}
<span class="comment">/*!
Returns the name of \a node. The caller guarantees that \a node is
not null and that it is contained in this node model.
*/</span>
<span class="type"><a href="qxmlname.html">QXmlName</a></span> FileTree<span class="operator">::</span>name(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>node) <span class="keyword">const</span>
{
<span class="keyword">return</span> m_names<span class="operator">.</span>at(node<span class="operator">.</span>additionalData());
}
<span class="comment">/*!
Always returns the QXmlNodeModelIndex for the root of the
file system, i.e. "/".
*/</span>
<span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> FileTree<span class="operator">::</span>root(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>node) <span class="keyword">const</span>
{
Q_UNUSED(node);
<span class="keyword">return</span> toNodeIndex(<span class="type">QFileInfo</span>(QLatin1String(<span class="string">"/"</span>)));
}
<span class="comment">/*!
Returns the typed value for \a node, which must be either an
attribute or an element. The QVariant returned represents the atomic
value of an attribute or the atomic value contained in an element.
If the QVariant is returned as a default constructed variant,
it means that \a node has no typed value.
*/</span>
<span class="type">QVariant</span> FileTree<span class="operator">::</span>typedValue(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>node) <span class="keyword">const</span>
{
<span class="keyword">const</span> <span class="type">QFileInfo</span> <span class="operator">&</span>fi <span class="operator">=</span> toFileInfo(node);
<span class="keyword">switch</span> (Type(node<span class="operator">.</span>additionalData())) {
<span class="keyword">case</span> Directory:
<span class="comment">// deliberate fall through.</span>
<span class="keyword">case</span> File:
<span class="keyword">return</span> <span class="type">QString</span>();
<span class="keyword">case</span> AttributeFileName:
<span class="keyword">return</span> fi<span class="operator">.</span>fileName();
<span class="keyword">case</span> AttributeFilePath:
<span class="keyword">return</span> fi<span class="operator">.</span>filePath();
<span class="keyword">case</span> AttributeSize:
<span class="keyword">return</span> fi<span class="operator">.</span>size();
<span class="keyword">case</span> AttributeMIMEType:
{
<span class="comment">/* We don't have any MIME detection code currently, so return
* the most generic one. */</span>
<span class="keyword">return</span> QLatin1String(<span class="string">"application/octet-stream"</span>);
}
<span class="keyword">case</span> AttributeSuffix:
<span class="keyword">return</span> fi<span class="operator">.</span>suffix();
}
Q_ASSERT_X(<span class="keyword">false</span><span class="operator">,</span> Q_FUNC_INFO<span class="operator">,</span> <span class="string">"This line should never be reached."</span>);
<span class="keyword">return</span> <span class="type">QString</span>();
}
<span class="comment">/*!
Returns the attributes of \a element. The caller guarantees
that \a element is an element in this node model.
*/</span>
<span class="type">QVector</span><span class="operator"><</span><span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">></span>
FileTree<span class="operator">::</span>attributes(<span class="keyword">const</span> <span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span> <span class="operator">&</span>element) <span class="keyword">const</span>
{
<span class="type">QVector</span><span class="operator"><</span><span class="type"><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></span><span class="operator">></span> result;
<span class="comment">/* Both elements has this attribute. */</span>
<span class="keyword">const</span> <span class="type">QFileInfo</span> <span class="operator">&</span>forElement <span class="operator">=</span> toFileInfo(element);
result<span class="operator">.</span>append(toNodeIndex(forElement<span class="operator">,</span> AttributeFilePath));
result<span class="operator">.</span>append(toNodeIndex(forElement<span class="operator">,</span> AttributeFileName));
<span class="keyword">if</span> (Type(element<span class="operator">.</span>additionalData() <span class="operator">=</span><span class="operator">=</span> File)) {
result<span class="operator">.</span>append(toNodeIndex(forElement<span class="operator">,</span> AttributeSize));
result<span class="operator">.</span>append(toNodeIndex(forElement<span class="operator">,</span> AttributeSuffix));
<span class="comment">//result.append(toNodeIndex(forElement, AttributeMIMEType));</span>
}
<span class="keyword">else</span> {
Q_ASSERT(element<span class="operator">.</span>additionalData() <span class="operator">=</span><span class="operator">=</span> Directory);
}
<span class="keyword">return</span> result;
}</pre>
</div>
<!-- @@@xmlpatterns/filetree/filetree.cpp -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2014 Digia Plc and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|