-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRAFT: add the ability to invoke QML functions
- Loading branch information
1 parent
368793a
commit 786b620
Showing
28 changed files
with
756 additions
and
177 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*** | ||
* 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, int64_t, uint64_t, double, std::string, | ||
std::chrono::time_point<std::chrono::system_clock>, std::vector<Variant>, std::map<std::string, Variant>>; | ||
} | ||
|
||
// TODO: make this a block comment | ||
// 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. | ||
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, | ||
Int64, | ||
Uint64, | ||
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 |
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
Oops, something went wrong.