qml 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,12 +7,11 @@
7
7
  #include <QtCore/QObject>
8
8
 
9
9
  namespace RubyQml {
10
- namespace Ext {
11
10
 
12
- class MetaObject
11
+ class Ext_MetaObject
13
12
  {
14
13
  public:
15
- MetaObject(RubyValue self);
14
+ Ext_MetaObject(RubyValue self);
16
15
 
17
16
  RubyValue className() const;
18
17
 
@@ -58,5 +57,4 @@ private:
58
57
  QHash<ID, int> mPropertyHash;
59
58
  };
60
59
 
61
- } // namespace Ext
62
60
  } // namespace RubyQml
@@ -5,25 +5,24 @@
5
5
  #include <QtCore/QSet>
6
6
 
7
7
  namespace RubyQml {
8
- namespace Ext {
9
8
 
10
- PluginLoader::PluginLoader(RubyValue self) :
9
+ Ext_PluginLoader::Ext_PluginLoader(RubyValue self) :
11
10
  self(self),
12
11
  mPluginLoader(new QPluginLoader())
13
12
  {
14
13
  }
15
14
 
16
- PluginLoader::~PluginLoader()
15
+ Ext_PluginLoader::~Ext_PluginLoader()
17
16
  {
18
17
  }
19
18
 
20
- RubyValue PluginLoader::initialize(RubyValue path)
19
+ RubyValue Ext_PluginLoader::initialize(RubyValue path)
21
20
  {
22
21
  mPluginLoader->setFileName(path.to<QString>());
23
22
  return self;
24
23
  }
25
24
 
26
- RubyValue PluginLoader::load()
25
+ RubyValue Ext_PluginLoader::load()
27
26
  {
28
27
  auto ok = mPluginLoader->load();
29
28
  if (!ok) {
@@ -32,7 +31,7 @@ RubyValue PluginLoader::load()
32
31
  return self;
33
32
  }
34
33
 
35
- RubyValue PluginLoader::instance()
34
+ RubyValue Ext_PluginLoader::instance()
36
35
  {
37
36
  self.send("load");
38
37
  auto instance = mPluginLoader->instance();
@@ -43,13 +42,12 @@ RubyValue PluginLoader::instance()
43
42
  }
44
43
  }
45
44
 
46
- void PluginLoader::defineClass()
45
+ void Ext_PluginLoader::defineClass()
47
46
  {
48
- WrapperRubyClass<PluginLoader> klass(RubyModule::fromPath("QML"), "PluginLoader");
49
- klass.defineMethod(MethodAccess::Private, "initialize", RUBYQML_MEMBER_FUNCTION_INFO(&PluginLoader::initialize));
50
- klass.defineMethod(MethodAccess::Public, "load", RUBYQML_MEMBER_FUNCTION_INFO(&PluginLoader::load));
51
- klass.defineMethod(MethodAccess::Public, "instance", RUBYQML_MEMBER_FUNCTION_INFO(&PluginLoader::instance));
47
+ WrapperRubyClass<Ext_PluginLoader> klass(RubyModule::fromPath("QML"), "PluginLoader");
48
+ klass.defineMethod(MethodAccess::Private, "initialize", RUBYQML_MEMBER_FUNCTION_INFO(&Ext_PluginLoader::initialize));
49
+ klass.defineMethod(MethodAccess::Public, "load", RUBYQML_MEMBER_FUNCTION_INFO(&Ext_PluginLoader::load));
50
+ klass.defineMethod(MethodAccess::Public, "instance", RUBYQML_MEMBER_FUNCTION_INFO(&Ext_PluginLoader::instance));
52
51
  }
53
52
 
54
- } // namespace Ext
55
53
  } // namespace RubyQml
@@ -6,13 +6,12 @@
6
6
  class QPluginLoader;
7
7
 
8
8
  namespace RubyQml {
9
- namespace Ext {
10
9
 
11
- class PluginLoader
10
+ class Ext_PluginLoader
12
11
  {
13
12
  public:
14
- PluginLoader(RubyValue self);
15
- ~PluginLoader();
13
+ Ext_PluginLoader(RubyValue self);
14
+ ~Ext_PluginLoader();
16
15
 
17
16
  RubyValue initialize(RubyValue path);
18
17
  RubyValue load();
@@ -27,6 +26,5 @@ private:
27
26
  std::unique_ptr<QPluginLoader> mPluginLoader;
28
27
  };
29
28
 
30
- } // namespace Ext
31
29
  } // namespace RubyQml
32
30
 
@@ -2,7 +2,7 @@
2
2
  #include "markable.h"
3
3
  #include "objectdata.h"
4
4
  #include "objectgc.h"
5
- #include "application.h"
5
+ #include "kernel.h"
6
6
  #include <QObject>
7
7
  #include <QHash>
8
8
  #include <QQmlEngine>
@@ -11,27 +11,26 @@
11
11
  #include <QCoreApplication>
12
12
 
13
13
  namespace RubyQml {
14
- namespace Ext {
15
14
 
16
- Pointer::Pointer(RubyValue self) :
15
+ Ext_Pointer::Ext_Pointer(RubyValue self) :
17
16
  self(self)
18
17
  {
19
18
  }
20
19
 
21
- Pointer::~Pointer()
20
+ Ext_Pointer::~Ext_Pointer()
22
21
  {
23
22
  ObjectGC::instance()->debug() << "\u267B\uFE0F releasing object:" << mObject << "managed:" << mIsManaged;
24
23
  }
25
24
 
26
- RubyValue Pointer::fromQObject(QObject *obj, bool owned)
25
+ RubyValue Ext_Pointer::fromQObject(QObject *obj, bool owned)
27
26
  {
28
- auto klass = wrapperRubyClass<Pointer>();
27
+ auto klass = wrapperRubyClass<Ext_Pointer>();
29
28
  auto ptr = klass.newInstance();
30
29
  klass.unwrap(ptr)->setQObject(obj, owned);
31
30
  return ptr;
32
31
  }
33
32
 
34
- QObject *Pointer::fetchQObject()
33
+ QObject *Ext_Pointer::fetchQObject()
35
34
  {
36
35
  if (!mObject) {
37
36
  fail("QML::QtObjectError", "referencing already deleted Qt Object");
@@ -39,7 +38,7 @@ QObject *Pointer::fetchQObject()
39
38
  return mObject;
40
39
  }
41
40
 
42
- void Pointer::setQObject(QObject *obj, bool managed)
41
+ void Ext_Pointer::setQObject(QObject *obj, bool managed)
43
42
  {
44
43
  if (!obj) {
45
44
  throw std::logic_error("null object");
@@ -51,12 +50,12 @@ void Pointer::setQObject(QObject *obj, bool managed)
51
50
  ObjectGC::instance()->debug() << "\u2728 acquiring object:" << mObject;
52
51
  }
53
52
 
54
- void Pointer::setManaged(bool managed)
53
+ void Ext_Pointer::setManaged(bool managed)
55
54
  {
56
55
  if (mObject) {
57
56
  if (managed) {
58
57
  QQmlEngine::setObjectOwnership(mObject, QQmlEngine::JavaScriptOwnership);
59
- mJSValue = Application::engine()->newQObject(mObject);
58
+ mJSValue = Kernel::instance()->engine()->newQObject(mObject);
60
59
  } else {
61
60
  QQmlEngine::setObjectOwnership(mObject, QQmlEngine::CppOwnership);
62
61
  mJSValue = QJSValue();
@@ -67,7 +66,7 @@ void Pointer::setManaged(bool managed)
67
66
  }
68
67
  }
69
68
 
70
- void Pointer::preferManaged(bool managed)
69
+ void Ext_Pointer::preferManaged(bool managed)
71
70
  {
72
71
  auto ownership = QQmlEngine::objectOwnership(mObject);
73
72
 
@@ -83,52 +82,51 @@ void Pointer::preferManaged(bool managed)
83
82
  setManaged(managed);
84
83
  }
85
84
 
86
- RubyValue Pointer::ext_isManaged() const
85
+ RubyValue Ext_Pointer::ext_isManaged() const
87
86
  {
88
87
  return RubyValue::from(mIsManaged);
89
88
  }
90
89
 
91
- RubyValue Pointer::ext_setManaged(RubyValue managed)
90
+ RubyValue Ext_Pointer::ext_setManaged(RubyValue managed)
92
91
  {
93
92
  setManaged(managed.to<bool>());
94
93
  return ext_isManaged();
95
94
  }
96
95
 
97
- RubyValue Pointer::ext_preferManaged(RubyValue managed)
96
+ RubyValue Ext_Pointer::ext_preferManaged(RubyValue managed)
98
97
  {
99
98
  preferManaged(managed.to<bool>());
100
99
  return ext_isManaged();
101
100
  }
102
101
 
103
- RubyValue Pointer::ext_isNull() const
102
+ RubyValue Ext_Pointer::ext_isNull() const
104
103
  {
105
104
  return RubyValue::from(!mObject);
106
105
  }
107
106
 
108
- RubyValue Pointer::ext_toString() const
107
+ RubyValue Ext_Pointer::ext_toString() const
109
108
  {
110
109
  QString name;
111
110
  QDebug(&name) << mObject.data();
112
111
  return RubyValue::from(name);
113
112
  }
114
113
 
115
- void Pointer::gc_mark()
114
+ void Ext_Pointer::gc_mark()
116
115
  {
117
116
  if (mIsManaged) {
118
117
  ObjectGC::instance()->markOwnedObject(mObject);
119
118
  }
120
119
  }
121
120
 
122
- void Pointer::defineClass()
121
+ void Ext_Pointer::defineClass()
123
122
  {
124
- WrapperRubyClass<Pointer> klass(RubyModule::fromPath("QML"), "Pointer");
125
- klass.defineMethod("managed?", RUBYQML_MEMBER_FUNCTION_INFO(&Pointer::ext_isManaged));
126
- klass.defineMethod("managed=", RUBYQML_MEMBER_FUNCTION_INFO(&Pointer::ext_setManaged));
127
- klass.defineMethod("prefer_managed", RUBYQML_MEMBER_FUNCTION_INFO(&Pointer::ext_preferManaged));
128
- klass.defineMethod("null?", RUBYQML_MEMBER_FUNCTION_INFO(&Pointer::ext_isNull));
129
- klass.defineMethod("to_s", RUBYQML_MEMBER_FUNCTION_INFO(&Pointer::ext_toString));
123
+ WrapperRubyClass<Ext_Pointer> klass(RubyModule::fromPath("QML"), "Pointer");
124
+ klass.defineMethod("managed?", RUBYQML_MEMBER_FUNCTION_INFO(&Ext_Pointer::ext_isManaged));
125
+ klass.defineMethod("managed=", RUBYQML_MEMBER_FUNCTION_INFO(&Ext_Pointer::ext_setManaged));
126
+ klass.defineMethod("prefer_managed", RUBYQML_MEMBER_FUNCTION_INFO(&Ext_Pointer::ext_preferManaged));
127
+ klass.defineMethod("null?", RUBYQML_MEMBER_FUNCTION_INFO(&Ext_Pointer::ext_isNull));
128
+ klass.defineMethod("to_s", RUBYQML_MEMBER_FUNCTION_INFO(&Ext_Pointer::ext_toString));
130
129
  klass.aliasMethod("inspect", "to_s");
131
130
  }
132
131
 
133
- } // namespace Ext
134
132
  } // namespace RubyQml
@@ -4,13 +4,12 @@
4
4
  #include <QJSValue>
5
5
 
6
6
  namespace RubyQml {
7
- namespace Ext {
8
7
 
9
- class Pointer
8
+ class Ext_Pointer
10
9
  {
11
10
  public:
12
- Pointer(RubyValue self);
13
- ~Pointer();
11
+ Ext_Pointer(RubyValue self);
12
+ ~Ext_Pointer();
14
13
 
15
14
  static RubyValue fromQObject(QObject *obj, bool owned);
16
15
 
@@ -39,5 +38,4 @@ private:
39
38
  QJSValue mJSValue;
40
39
  };
41
40
 
42
- } // namespace Ext
43
41
  } // namespace RubyQml
@@ -3,8 +3,7 @@
3
3
  #include "objectgc.h"
4
4
 
5
5
  namespace RubyQml {
6
- namespace Ext {
7
- namespace TestUtil {
6
+ namespace Ext_TestUtil {
8
7
 
9
8
  namespace {
10
9
 
@@ -38,5 +37,4 @@ void defineModule()
38
37
  }
39
38
 
40
39
  } // namespace TestUtil
41
- } // namespace Ext
42
40
  } // namespace RubyQml
@@ -1,11 +1,9 @@
1
1
  #pragma once
2
2
 
3
3
  namespace RubyQml {
4
- namespace Ext {
5
- namespace TestUtil {
4
+ namespace Ext_TestUtil {
6
5
 
7
6
  void defineModule();
8
7
 
9
8
  } // namespace TestUtil
10
- } // namespace Ext
11
9
  } // namespace RubyQml
@@ -2,10 +2,10 @@
2
2
  #include "ext_pointer.h"
3
3
  #include "ext_pluginloader.h"
4
4
  #include "ext_anywrapper.h"
5
- #include "ext_accesssupport.h"
5
+ #include "ext_accesswrapperfactory.h"
6
6
  #include "ext_testutil.h"
7
7
  #include "ext_kernel.h"
8
- #include "application.h"
8
+ #include "kernel.h"
9
9
  #include "signalforwarder.h"
10
10
  #include "valuereference.h"
11
11
  #include "objectgc.h"
@@ -23,19 +23,19 @@ void defineMetaTypes()
23
23
 
24
24
  void defineClasses()
25
25
  {
26
- Ext::MetaObject::defineClass();
27
- Ext::Pointer::defineClass();
28
- Ext::PluginLoader::defineClass();
29
- Ext::AnyWrapper::defineClass();
30
- Ext::AccessWrapperFactory::defineClass();
31
- Ext::TestUtil::defineModule();
32
- Ext::Kernel::defineModule();
26
+ Ext_MetaObject::defineClass();
27
+ Ext_Pointer::defineClass();
28
+ Ext_PluginLoader::defineClass();
29
+ Ext_AnyWrapper::defineClass();
30
+ Ext_AccessWrapperFactory::defineClass();
31
+ Ext_TestUtil::defineModule();
32
+ Ext_Kernel::defineModule();
33
33
  ListModel::defineUtilMethods();
34
34
  }
35
35
 
36
36
  void setupGlobalGCMarking()
37
37
  {
38
- auto marker = Ext::AnyWrapper::create(QVariant(), [](const QVariant &) {
38
+ auto marker = Ext_AnyWrapper::create(QVariant(), [](const QVariant &) {
39
39
  ValueReference::markAllReferences();
40
40
  ObjectGC::instance()->markNonOwnedObjects();
41
41
  });
@@ -0,0 +1,39 @@
1
+ #include "kernel.h"
2
+ #include "util.h"
3
+ #include <QTimer>
4
+
5
+ namespace RubyQml {
6
+
7
+ Kernel *Kernel::instance()
8
+ {
9
+ if (!mInstance) {
10
+ fail("QML::UninitializedError", "ruby-qml not yet initialized");
11
+ }
12
+ return mInstance;
13
+ }
14
+
15
+ void Kernel::init(const QList<QByteArray> &args)
16
+ {
17
+ if (mInstance) {
18
+ fail("QML::AlreadyInitializedErryr", "ruby-qml already initialized");
19
+ }
20
+ mInstance = new Kernel(args);
21
+ }
22
+
23
+ Kernel::Kernel(const QList<QByteArray> &args)
24
+ {
25
+ mArgc = args.size();
26
+ mArgData = args;
27
+ mArgv = new char*[mArgc];
28
+ std::transform(mArgData.begin(), mArgData.end(), mArgv, [](QByteArray &ba) { return ba.data(); });
29
+
30
+ mApplication = new QApplication(mArgc, mArgv);
31
+ mEngine = new QQmlEngine();
32
+ mEventLoopHookTimer = new QTimer();
33
+ mEventLoopHookTimer->setInterval(0);
34
+ mEventLoopHookTimer->setSingleShot(false);
35
+ }
36
+
37
+ Kernel *Kernel::mInstance = nullptr;
38
+
39
+ } // namespace RubyQml
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include <QList>
4
+ #include <QApplication>
5
+ #include <QQmlEngine>
6
+
7
+ namespace RubyQml {
8
+
9
+ class Kernel
10
+ {
11
+ public:
12
+ QApplication *application() { return mApplication; }
13
+ QQmlEngine *engine() { return mEngine; }
14
+ QTimer *eventLoopHookTimer() { return mEventLoopHookTimer; }
15
+
16
+ static bool initialized() { return mInstance; }
17
+ static void init(const QList<QByteArray> &args);
18
+ static Kernel *instance();
19
+
20
+ private:
21
+ Kernel(const QList<QByteArray> &args);
22
+ static Kernel *mInstance;
23
+
24
+ QList<QByteArray> mArgData;
25
+ int mArgc;
26
+ char **mArgv;
27
+ QApplication *mApplication = nullptr;
28
+ QQmlEngine *mEngine = nullptr;
29
+ QTimer *mEventLoopHookTimer = nullptr;
30
+ };
31
+
32
+ } // namespace RubyQml
@@ -8,11 +8,6 @@ namespace RubyQml {
8
8
  ApplicationExtension::ApplicationExtension(QApplication *app) :
9
9
  mApp(app)
10
10
  {
11
- auto timer = new QTimer(this);
12
- timer->setInterval(0);
13
- timer->setSingleShot(false);
14
- timer->start();
15
- connect(timer, &QTimer::timeout, this, &ApplicationExtension::eventsProcessed);
16
11
  }
17
12
 
18
13
  void ApplicationExtension::exec()
@@ -13,9 +13,6 @@ class ApplicationExtension : public QObject
13
13
  public:
14
14
  explicit ApplicationExtension(QApplication *app);
15
15
 
16
- signals:
17
- void eventsProcessed();
18
-
19
16
  public slots:
20
17
  void exec();
21
18
  void processEvents();
@@ -5,7 +5,7 @@
5
5
  #include "objectdata.h"
6
6
  #include "accessobject.h"
7
7
  #include "listmodel.h"
8
- #include "ext_accesssupport.h"
8
+ #include "ext_accesswrapperfactory.h"
9
9
  #include <ruby/intern.h>
10
10
  #define ONIG_ESCAPE_UCHAR_COLLISION
11
11
  #include <ruby/encoding.h>
@@ -328,7 +328,7 @@ template <> const QMetaObject *Conversion<const QMetaObject *>::from(RubyValue x
328
328
  if (x == RubyValue()) {
329
329
  return nullptr;
330
330
  }
331
- return wrapperRubyClass<Ext::MetaObject>().unwrap(x)->metaObject();
331
+ return wrapperRubyClass<Ext_MetaObject>().unwrap(x)->metaObject();
332
332
  }
333
333
 
334
334
  template <> RubyValue Conversion<const QMetaObject *>::to(const QMetaObject *metaobj)
@@ -336,7 +336,7 @@ template <> RubyValue Conversion<const QMetaObject *>::to(const QMetaObject *met
336
336
  if (!metaobj) {
337
337
  return Qnil;
338
338
  }
339
- return Ext::MetaObject::fromMetaObject(metaobj);
339
+ return Ext_MetaObject::fromMetaObject(metaobj);
340
340
  }
341
341
 
342
342
  } // namespace detail
@@ -449,7 +449,7 @@ bool RubyValue::isConvertibleTo(int metaType) const
449
449
  }
450
450
  return false;
451
451
  }
452
- if (rb_obj_is_kind_of(x, wrapperRubyClass<Ext::MetaObject>())) {
452
+ if (rb_obj_is_kind_of(x, wrapperRubyClass<Ext_MetaObject>())) {
453
453
  return metaType == QMetaType::type("const QMetaObject*");
454
454
  }
455
455
  auto accessModule = RubyModule::fromPath("QML::Access");
@@ -524,7 +524,7 @@ int RubyValue::defaultMetaType() const
524
524
  if (rb_obj_is_kind_of(x, objectBaseClass)) {
525
525
  return QMetaType::QObjectStar;
526
526
  }
527
- if (rb_obj_is_kind_of(x, wrapperRubyClass<Ext::MetaObject>())) {
527
+ if (rb_obj_is_kind_of(x, wrapperRubyClass<Ext_MetaObject>())) {
528
528
  return QMetaType::type("const QMetaObject*");
529
529
  }
530
530
  auto accessModule = RubyModule::fromPath("QML::Access");
@@ -630,8 +630,8 @@ RubyValue RubyValue::fromQObject(QObject *obj, bool implicit)
630
630
  return data->rubyObject;
631
631
  }
632
632
 
633
- auto metaobj = Ext::MetaObject::fromMetaObject(obj->metaObject());
634
- auto pointer = Ext::Pointer::fromQObject(obj, false);
633
+ auto metaobj = Ext_MetaObject::fromMetaObject(obj->metaObject());
634
+ auto pointer = Ext_Pointer::fromQObject(obj, false);
635
635
 
636
636
  RubyValue wrapper;
637
637
  protect([&] {
@@ -656,7 +656,7 @@ QObject *RubyValue::toQObject() const
656
656
  auto wrapperFactory = protect([&] {
657
657
  return rb_funcall(rb_obj_class(x), RUBYQML_INTERN("access_wrapper_factory"), 0);
658
658
  });
659
- return wrapperRubyClass<Ext::AccessWrapperFactory>().unwrap(wrapperFactory)->create(x);
659
+ return wrapperRubyClass<Ext_AccessWrapperFactory>().unwrap(wrapperFactory)->create(x);
660
660
  }
661
661
  static auto listModelClass = RubyModule::fromPath("QML::Data::ListModel");
662
662
  if (x.isKindOf(listModelClass)) {
@@ -670,8 +670,8 @@ QObject *RubyValue::toQObject() const
670
670
  .arg(x.send("class").send("name").to<QString>()));
671
671
  }
672
672
  auto objptr = x.send(RUBYQML_INTERN("pointer"));
673
- auto obj = wrapperRubyClass<Ext::Pointer>().unwrap(objptr)->fetchQObject();
674
- Ext::MetaObject::fromMetaObject(obj->metaObject()).send(RUBYQML_INTERN("build_class"));
673
+ auto obj = wrapperRubyClass<Ext_Pointer>().unwrap(objptr)->fetchQObject();
674
+ Ext_MetaObject::fromMetaObject(obj->metaObject()).send(RUBYQML_INTERN("build_class"));
675
675
  return obj;
676
676
  }
677
677