// // ScriptsModelFilter.h // interface/src // // Created by Thijs Wenker on 01/11/15. // Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // /// @addtogroup ScriptEngine /// @{ #ifndef hifi_ScriptsModelFilter_h #define hifi_ScriptsModelFilter_h #include "ScriptsModel.h" #include /*@jsdoc * Sorted and filtered information on the scripts that are in the default scripts directory of the Interface installation. This * is provided as a property of {@link ScriptDiscoveryService}. * *

The information provided reflects the subdirectory structure. Properties, methods, and signals are per QT's * QSortFilterProxyModel class, with the following details:

* * * @class ScriptsModelFilter * @hideconstructor * * @hifi-interface * @hifi-client-entity * @hifi-avatar * * @example List all scripts that include "edit" in their name. * var DISPLAY_ROLE = 0; * var PATH_ROLE = 256; * * function printDirectory(parentIndex, directoryLevel, indent) { * var numRows = ScriptDiscoveryService.scriptsModelFilter.rowCount(parentIndex); * for (var i = 0; i < numRows; i++) { * var rowIndex = ScriptDiscoveryService.scriptsModelFilter.index(i, 0, parentIndex); * * var name = ScriptDiscoveryService.scriptsModelFilter.data(rowIndex, DISPLAY_ROLE); * var hasChildren = ScriptDiscoveryService.scriptsModelFilter.hasChildren(rowIndex); * var path = hasChildren ? "" : ScriptDiscoveryService.scriptsModelFilter.data(rowIndex, PATH_ROLE); * * print(indent + "- " + name + (hasChildren ? "" : " - " + path)); * * if (hasChildren) { * printDirectory(rowIndex, directoryLevel + 1, indent + " "); * } * } * } * * ScriptDiscoveryService.scriptsModelFilter.filterRegExp = new RegExp("^.*edit.*$", "i"); // Set the filter. * print("Edit scripts:"); * printDirectory(null, 0, ""); // null index for the root directory. */ /// Provides script file information available from the ScriptDiscoveryService scripting interface class ScriptsModelFilter : public QSortFilterProxyModel { Q_OBJECT public: ScriptsModelFilter(QObject *parent = NULL); protected: bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; bool lessThan(const QModelIndex& left, const QModelIndex& right) const override; }; #endif // hifi_ScriptsModelFilter_h /// @}