-
Notifications
You must be signed in to change notification settings - Fork 77
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 QJSValue, QJSEngine, and related types to cxx-qt-lib-extras with QJSValue serde support #1147
Open
akiselev
wants to merge
1
commit into
KDAB:main
Choose a base branch
from
akiselev:qjs-extras
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include <QtQml/QJSEngine> | ||
|
||
#include "rust/cxx.h" | ||
|
||
namespace rust | ||
{ | ||
namespace cxxqtlib2 | ||
{ | ||
::std::unique_ptr<QJSEngine> | ||
qjsengineNew(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to replace this with our make_unique template from cxx-qt-lib. Take a look at the |
||
|
||
template <typename T> | ||
::std::unique_ptr<QJSValue> | ||
jsengineNewArray(T &engine, quint32 length) | ||
{ | ||
auto ptr = ::std::make_unique<QJSValue>(engine.newArray(length)); | ||
Q_ASSERT(ptr != nullptr); | ||
|
||
return ptr; | ||
} | ||
|
||
template <typename T> | ||
::std::unique_ptr<QJSValue> | ||
jsengineNewObject(T &engine) | ||
{ | ||
auto ptr = ::std::make_unique<QJSValue>(engine.newObject()); | ||
Q_ASSERT(ptr != nullptr); | ||
|
||
return ptr; | ||
} | ||
|
||
template <typename T> | ||
::std::unique_ptr<QJSValue> | ||
jsengineNewQObject(T &engine, QObject &object) | ||
{ | ||
auto ptr = ::std::make_unique<QJSValue>(engine.newQObject(&object)); | ||
Q_ASSERT(ptr != nullptr); | ||
|
||
return ptr; | ||
} | ||
|
||
template <typename T> | ||
::std::unique_ptr<QJSValue> | ||
jsengineEvaluate( | ||
T &engine, | ||
const QString &program, | ||
const QString &fileName, | ||
int lineNumber) | ||
{ | ||
auto ptr = ::std::make_unique<QJSValue>( | ||
engine.evaluate(program, fileName, lineNumber, nullptr)); | ||
Q_ASSERT(ptr != nullptr); | ||
|
||
return ptr; | ||
} | ||
|
||
template <typename T> | ||
::std::unique_ptr<QJSValue> | ||
jsengineImportModule(T &engine, const QString &fileName) | ||
{ | ||
auto ptr = ::std::make_unique<QJSValue>(engine.importModule(fileName)); | ||
Q_ASSERT(ptr != nullptr); | ||
|
||
return ptr; | ||
} | ||
|
||
template <typename T> | ||
::std::unique_ptr<QJSValue> | ||
jsengineGlobalObject(T &engine) | ||
{ | ||
auto ptr = ::std::make_unique<QJSValue>(engine.globalObject()); | ||
Q_ASSERT(ptr != nullptr); | ||
|
||
return ptr; | ||
} | ||
} | ||
} |
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,36 @@ | ||
#pragma once | ||
|
||
#include <QtQml/QJSValue> | ||
#include <QtCore/QVariant> | ||
|
||
namespace rust | ||
{ | ||
namespace cxxqtlib2 | ||
{ | ||
|
||
::std::unique_ptr<QJSValue> qjsvalue_new(); | ||
::std::unique_ptr<QJSValue> qjsvalue_new_null(); | ||
::std::unique_ptr<QJSValue> qjsvalue_new_bool(bool value); | ||
::std::unique_ptr<QJSValue> qjsvalue_new_int(int value); | ||
::std::unique_ptr<QJSValue> qjsvalue_new_uint(uint value); | ||
::std::unique_ptr<QJSValue> qjsvalue_new_double(double value); | ||
::std::unique_ptr<QJSValue> qjsvalue_new_qstring(const QString &value); | ||
|
||
::std::unique_ptr<QJSValue> qjsvalue_from_jsvalue(const QJSValue &value); | ||
|
||
QString qjsvalue_to_string(const QJSValue &value); | ||
|
||
::std::unique_ptr<QJSValue> qjsvalue_property( | ||
const QJSValue &value, | ||
const QString &name); | ||
::std::unique_ptr<QJSValue> qjsvalue_element( | ||
const QJSValue &value, | ||
quint32 index); | ||
|
||
QVariant qjsvalue_to_qvariant(const QJSValue &value); | ||
QObject *qjsvalue_to_qobject(QJSValue &value); | ||
|
||
bool qvariantCanConvertQJSValue(const QVariant &variant); | ||
::std::unique_ptr<QJSValue> qjsvalueFromQVariant(const QVariant &variant) noexcept; | ||
} | ||
} |
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,15 @@ | ||
#pragma once | ||
|
||
#include <QtQml/QJSValue> | ||
#include <QtQml/QJSValueIterator> | ||
|
||
namespace rust | ||
{ | ||
namespace cxxqtlib2 | ||
{ | ||
|
||
::std::unique_ptr<QJSValueIterator> qjsvalueiterator_new(const QJSValue &value); | ||
|
||
::std::unique_ptr<QJSValue> qjsvalueiterator_value(const QJSValueIterator &value); | ||
} | ||
} |
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,32 @@ | ||
#pragma once | ||
|
||
#include <QtCore/QList> | ||
#include <QtQml/QJSValue> | ||
|
||
// Define a proper operator== for QJSValue | ||
#ifndef QJSVALUE_OPERATOR_EQ_DEFINED | ||
#define QJSVALUE_OPERATOR_EQ_DEFINED | ||
|
||
inline bool operator==(const QJSValue& lhs, const QJSValue& rhs) | ||
{ | ||
return lhs.strictlyEquals(rhs); // Example using strictlyEquals method | ||
} | ||
|
||
#endif // QJSVALUE_OPERATOR_EQ_DEFINED | ||
|
||
namespace rust | ||
{ | ||
namespace cxxqtlib2 | ||
{ | ||
|
||
class QJSValueList : public QList<QJSValue> | ||
{ | ||
public: | ||
QJSValueList() : QList<QJSValue>() {} | ||
~QJSValueList() {} | ||
}; | ||
|
||
::std::unique_ptr<QJSValueList> qjsvaluelistNew(); | ||
::std::unique_ptr<QJSValueList> qjsvaluelistClone(const QJSValueList &list); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -11,3 +11,6 @@ pub use crate::core::*; | |
|
||
mod gui; | ||
pub use crate::gui::*; | ||
|
||
mod qml; | ||
pub use crate::qml::*; |
Oops, something went wrong.
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.
nitpick: I'm unsure if serde should be a default here