diff --git a/interface/src/scripting/SelectionScriptingInterface.cpp b/interface/src/scripting/SelectionScriptingInterface.cpp index 841e1738e3..195f1657e8 100644 --- a/interface/src/scripting/SelectionScriptingInterface.cpp +++ b/interface/src/scripting/SelectionScriptingInterface.cpp @@ -80,6 +80,20 @@ bool SelectionScriptingInterface::clearSelectedItemsList(const QString& listName return true; } +QStringList SelectionScriptingInterface::getListNames() const { + QStringList list; + QReadLocker lock(&_selectionListsLock); + list = _selectedItemsListMap.keys(); + return list; +} + +QStringList SelectionScriptingInterface::getHighlightedListNames() const { + QStringList list; + QReadLocker lock(&_highlightStylesLock); + list = _highlightStyleMap.keys(); + return list; +} + bool SelectionScriptingInterface::enableListHighlight(const QString& listName, const QVariantMap& highlightStyleValues) { QWriteLocker lock(&_highlightStylesLock); @@ -146,14 +160,6 @@ QVariantMap SelectionScriptingInterface::getListHighlightStyle(const QString& li } } - -QStringList SelectionScriptingInterface::getHighlightStyles() const { - QStringList list; - QReadLocker lock(&_highlightStylesLock); - list = _highlightStyleMap.keys(); - return list; -} - render::HighlightStyle SelectionScriptingInterface::getHighlightStyle(const QString& listName) const { QReadLocker lock(&_highlightStylesLock); auto highlightStyle = _highlightStyleMap.find(listName); @@ -234,6 +240,43 @@ void SelectionScriptingInterface::printList(const QString& listName) { } } +QVariantMap SelectionScriptingInterface::getSelectedItemsList(const QString& listName) const { + QReadLocker lock(&_selectionListsLock); + QVariantMap list; + auto currentList = _selectedItemsListMap.find(listName); + if (currentList != _selectedItemsListMap.end()) { + if ((*currentList).getContainsData()) { + + if (!(*currentList).getAvatarIDs().empty()) { + QList avatarIDs = QList::fromVector(QVector::fromStdVector((*currentList).getAvatarIDs())); + list["avatars"].fromValue( avatarIDs); + } + if (!(*currentList).getEntityIDs().empty()) { + // QList entityIDs = QList::fromVector(QVector::fromStdVector((*currentList).getEntityIDs())); + QList entityIDs; + for (auto j : (*currentList).getEntityIDs()) { + entityIDs.push_back( j ); + } + list["entities"] = (entityIDs); + } + if (!(*currentList).getOverlayIDs().empty()) { + QList overlayIDs = QList::fromVector(QVector::fromStdVector((*currentList).getOverlayIDs())); + list["overlays"].fromValue(overlayIDs); + } + + return list; + } + else { + //qDebug() << "List named " << listName << " empty"; + return list; + } + } + else { + // qDebug() << "List named " << listName << " doesn't exist."; + return list; + } +} + bool SelectionScriptingInterface::removeListFromMap(const QString& listName) { bool removed = false; { diff --git a/interface/src/scripting/SelectionScriptingInterface.h b/interface/src/scripting/SelectionScriptingInterface.h index d0dcf8caec..a05ddaa62c 100644 --- a/interface/src/scripting/SelectionScriptingInterface.h +++ b/interface/src/scripting/SelectionScriptingInterface.h @@ -27,17 +27,17 @@ class GameplayObjects { public: GameplayObjects(); - bool getContainsData() { return containsData; } + bool getContainsData() const { return containsData; } - std::vector getAvatarIDs() { return _avatarIDs; } + std::vector getAvatarIDs() const { return _avatarIDs; } bool addToGameplayObjects(const QUuid& avatarID); bool removeFromGameplayObjects(const QUuid& avatarID); - std::vector getEntityIDs() { return _entityIDs; } + std::vector getEntityIDs() const { return _entityIDs; } bool addToGameplayObjects(const EntityItemID& entityID); bool removeFromGameplayObjects(const EntityItemID& entityID); - std::vector getOverlayIDs() { return _overlayIDs; } + std::vector getOverlayIDs() const { return _overlayIDs; } bool addToGameplayObjects(const OverlayID& overlayID); bool removeFromGameplayObjects(const OverlayID& overlayID); @@ -90,14 +90,8 @@ class SelectionScriptingInterface : public QObject, public Dependency { public: SelectionScriptingInterface(); - GameplayObjects getList(const QString& listName); + Q_INVOKABLE QStringList getListNames() const; - /**jsdoc - * Prints out the list of avatars, entities and overlays stored in a particular selection. - * @function Selection.printList - * @param listName {string} name of the selection - */ - Q_INVOKABLE void printList(const QString& listName); /**jsdoc * Removes a named selection from the list of selections. * @function Selection.removeListFromMap @@ -132,6 +126,26 @@ public: */ Q_INVOKABLE bool clearSelectedItemsList(const QString& listName); + + + /**jsdoc + * Prints out the list of avatars, entities and overlays stored in a particular selection. + * @function Selection.printList + * @param listName {string} name of the selection + */ + Q_INVOKABLE void printList(const QString& listName); + + /**jsdoc + * Query the list of avatars, entities and overlays stored in a particular selection. + * @function Selection.getList + * @param listName {string} name of the selection + * @return + */ + Q_INVOKABLE QVariantMap getSelectedItemsList(const QString& listName) const; + + // + Q_INVOKABLE QStringList getHighlightedListNames() const; + /**jsdoc * Enable highlighting for the named selection. * If the Selection doesn't exist, it will be created. @@ -176,7 +190,8 @@ public: */ Q_INVOKABLE QVariantMap getListHighlightStyle(const QString& listName) const; - Q_INVOKABLE QStringList getHighlightStyles() const; + + GameplayObjects getList(const QString& listName); render::HighlightStyle getHighlightStyle(const QString& listName) const; diff --git a/scripts/developer/utilities/render/highlight2.qml b/scripts/developer/utilities/render/highlight2.qml index 583488c37d..b22cfd4033 100644 --- a/scripts/developer/utilities/render/highlight2.qml +++ b/scripts/developer/utilities/render/highlight2.qml @@ -24,7 +24,7 @@ Item { anchors.margins: 0 property var listName: "contextOverlayHighlightList" - property var styleList: Selection.getHighlightStyles() + property var styleList: Selection.getHighlightedListNames() signal sendToScript(var message); @@ -50,10 +50,9 @@ Item { id: debug text: "Refresh" height: 24 - width: 128 onClicked: { print("list of highlight styles") - root.styleList = Selection.getHighlightStyles() + root.styleList = Selection.getHighlightedListNames() print(root.styleList) styleSelectorLoader.sourceComponent = undefined; @@ -71,7 +70,6 @@ Item { id: selectorWidget HifiControls.ComboBox { id: box - width: 350 z: 999 editable: true colorScheme: hifi.colorSchemes.dark