-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add the ability to invoke QML functions #56
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*** | ||
* Copyright (C) Noah Koontz. All rights reserved. | ||
* Licensed under the MIT license. | ||
* See LICENSE.txt file in the project root for full license information. | ||
****/ | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <map> | ||
#include <string> | ||
#include <variant> | ||
#include <vector> | ||
|
||
#include <Spix/spix_export.h> | ||
|
||
namespace spix { | ||
|
||
struct Variant; | ||
|
||
namespace { | ||
using VariantBaseType = std::variant<std::nullptr_t, bool, long long, unsigned long long, double, std::string, | ||
std::chrono::time_point<std::chrono::system_clock>, std::vector<Variant>, std::map<std::string, Variant>>; | ||
} | ||
|
||
/** | ||
* Utility union type that contains a number of RPC-able types, including a list of itself and a map of {std::string: | ||
* itself}. Inherits from std::variant. This variant is used to abstract between RPC union types (ex anyrpc::Value) the | ||
* scene union types (ex. QVariant). | ||
* | ||
* NOTE: std::visit is broken for this variant for GCC <= 11.2 and clang <= 14.0, see | ||
* http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2162r0.html for more info. Instead, type switches must be | ||
* created manually using the index() method and the TypeIndex enum. | ||
*/ | ||
struct SPIX_EXPORT Variant : VariantBaseType { | ||
using ListType = std::vector<Variant>; | ||
using MapType = std::map<std::string, Variant>; | ||
using VariantType = VariantBaseType; | ||
using VariantBaseType::variant; | ||
VariantBaseType const& base() const { return *this; } | ||
VariantBaseType& base() { return *this; } | ||
|
||
enum TypeIndex | ||
{ | ||
Nullptr = 0, | ||
Bool, | ||
Int, | ||
Uint, | ||
Double, | ||
String, | ||
Time, | ||
List, | ||
Map, | ||
TypeIndexCount | ||
}; | ||
}; | ||
|
||
static_assert( | ||
Variant::TypeIndexCount == std::variant_size_v<VariantBaseType>, "Variant enum does not cover all Variant types"); | ||
|
||
} // namespace spix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*** | ||
* Copyright (C) Falko Axmann. All rights reserved. | ||
* Licensed under the MIT license. | ||
* See LICENSE.txt file in the project root for full license information. | ||
****/ | ||
|
||
#include "InvokeMethod.h" | ||
|
||
#include <Scene/Scene.h> | ||
|
||
namespace spix { | ||
namespace cmd { | ||
|
||
InvokeMethod::InvokeMethod(ItemPath path, std::string method, std::vector<Variant> args, std::promise<Variant> promise) | ||
: m_path(std::move(path)) | ||
, m_method(std::move(method)) | ||
, m_args(std::move(args)) | ||
, m_promise(std::move(promise)) | ||
{ | ||
} | ||
|
||
void InvokeMethod::execute(CommandEnvironment& env) | ||
{ | ||
auto item = env.scene().itemAtPath(m_path); | ||
|
||
if (item) { | ||
Variant ret; | ||
bool success = item->invokeMethod(m_method, m_args, ret); | ||
if (!success) | ||
env.state().reportError("InvokeMethod: Failed to invoke method: " + m_method); | ||
m_promise.set_value(ret); | ||
} else { | ||
env.state().reportError("InvokeMethod: Item not found: " + m_path.string()); | ||
m_promise.set_value(Variant(nullptr)); | ||
} | ||
} | ||
|
||
} // namespace cmd | ||
} // namespace spix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*** | ||
* Copyright (C) Falko Axmann. All rights reserved. | ||
* Licensed under the MIT license. | ||
* See LICENSE.txt file in the project root for full license information. | ||
****/ | ||
|
||
#pragma once | ||
|
||
#include <Spix/spix_export.h> | ||
|
||
#include "Command.h" | ||
#include <Spix/Data/ItemPath.h> | ||
#include <Spix/Data/Variant.h> | ||
|
||
#include <future> | ||
|
||
namespace spix { | ||
namespace cmd { | ||
|
||
class SPIX_EXPORT InvokeMethod : public Command { | ||
public: | ||
InvokeMethod(ItemPath path, std::string method, std::vector<Variant> args, std::promise<Variant> promise); | ||
|
||
void execute(CommandEnvironment& env) override; | ||
|
||
private: | ||
ItemPath m_path; | ||
std::string m_method; | ||
std::vector<Variant> m_args; | ||
std::promise<Variant> m_promise; | ||
}; | ||
|
||
} // namespace cmd | ||
} // namespace spix |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally makes sense to put your name here. Now that more and more people are contributing, I was thinking about changing all the copyright lines to a "(C) Spix Authors" and adding the names of contributors into a AUTHORS.txt or something like that.
Would you also be fine with that? Would be a separate PR once this is all merged that would be just about changing the copyright text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that sounds great!