Overte C++ Documentation
ScriptsModelFilter.h
1 //
2 // ScriptsModelFilter.h
3 // interface/src
4 //
5 // Created by Thijs Wenker on 01/11/15.
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
14 
15 #ifndef hifi_ScriptsModelFilter_h
16 #define hifi_ScriptsModelFilter_h
17 
18 #include "ScriptsModel.h"
19 #include <QSortFilterProxyModel>
20 
21 /*@jsdoc
22  * Sorted and filtered information on the scripts that are in the default scripts directory of the Interface installation. This
23  * is provided as a property of {@link ScriptDiscoveryService}.
24  *
25  * <p>The information provided reflects the subdirectory structure. Properties, methods, and signals are per QT's
26  * <a href="https://doc.qt.io/qt-5/qsortfilterproxymodel.html">QSortFilterProxyModel</a> class, with the following details:</p>
27  * <ul>
28  * <li>The rows are sorted per directory and file names.</li>
29  * <li>A single column of data: <code>columnCount(index)</code> returns <code>1</code>. </li>
30  * <li>Data is provided for the following roles:
31  * <table>
32  * <thead>
33  * <tr><th>Role</th><th>Value</th><th>Description</th></tr>
34  * </thead>
35  * <tbody>
36  * <tr><td>Display</td><td><code>0</code></td><td>The directory or script file name.</td></tr>
37  * <tr><td>Path</td><td><code>256</code></td><td>The path and filename of the data item if it is a script,
38  * <code>undefined</code> if it is a directory.</td></tr>
39  * </tbody>
40  * </table>
41  * </li>
42  * <li>Use <code>null</code> for the root directory's index.</li>
43  * </ul>
44  *
45  * @class ScriptsModelFilter
46  * @hideconstructor
47  *
48  * @hifi-interface
49  * @hifi-client-entity
50  * @hifi-avatar
51  *
52  * @example <caption>List all scripts that include "edit" in their name.</caption>
53  * var DISPLAY_ROLE = 0;
54  * var PATH_ROLE = 256;
55  *
56  * function printDirectory(parentIndex, directoryLevel, indent) {
57  * var numRows = ScriptDiscoveryService.scriptsModelFilter.rowCount(parentIndex);
58  * for (var i = 0; i < numRows; i++) {
59  * var rowIndex = ScriptDiscoveryService.scriptsModelFilter.index(i, 0, parentIndex);
60  *
61  * var name = ScriptDiscoveryService.scriptsModelFilter.data(rowIndex, DISPLAY_ROLE);
62  * var hasChildren = ScriptDiscoveryService.scriptsModelFilter.hasChildren(rowIndex);
63  * var path = hasChildren ? "" : ScriptDiscoveryService.scriptsModelFilter.data(rowIndex, PATH_ROLE);
64  *
65  * print(indent + "- " + name + (hasChildren ? "" : " - " + path));
66  *
67  * if (hasChildren) {
68  * printDirectory(rowIndex, directoryLevel + 1, indent + " ");
69  * }
70  * }
71  * }
72  *
73  * ScriptDiscoveryService.scriptsModelFilter.filterRegExp = new RegExp("^.*edit.*$", "i"); // Set the filter.
74  * print("Edit scripts:");
75  * printDirectory(null, 0, ""); // null index for the root directory.
76  */
78 class ScriptsModelFilter : public QSortFilterProxyModel {
79  Q_OBJECT
80 public:
81  ScriptsModelFilter(QObject *parent = NULL);
82 protected:
83  bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
84  bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
85 };
86 
87 #endif // hifi_ScriptsModelFilter_h
88 
Provides script file information available from the ScriptDiscoveryService scripting interface.
Definition: ScriptsModelFilter.h:78