Browse Source

Expose QModelIndex::row() to host environment

Neal Wilson 5 years ago
parent
commit
2b0d7c7e37
Signed by: Neal Wilson <neal@typica.us> GPG Key ID: 2A0BDDE701E66EB9
1 changed files with 21 additions and 1 deletions
  1. 21
    1
      src/typica.w

+ 21
- 1
src/typica.w View File

@@ -689,6 +689,12 @@ template<> QTime getself(QScriptContext *context)
689 689
     return self;
690 690
 }
691 691
 
692
+template<> QModelIndex getself(QScriptContext *context)
693
+{
694
+    QModelIndex self = context->thisObject().toVariant().value<QModelIndex>();
695
+    return self;
696
+}
697
+
692 698
 template<> QByteArray getself(QScriptContext *context)
693 699
 {
694 700
     QByteArray self = context->thisObject().toVariant().toByteArray();
@@ -16363,11 +16369,13 @@ we declare that as a metatype.
16363 16369
 Q_DECLARE_METATYPE(QModelIndex)
16364 16370
 
16365 16371
 @ Next we need a pair of functions to convert |QModelIndex| to and from script
16366
-values.
16372
+values. Some |QModelIndex| methods are also exposed to the host environment.
16367 16373
 
16368 16374
 @<Function prototypes for scripting@>=
16369 16375
 QScriptValue QModelIndex_toScriptValue(QScriptEngine *engine, const QModelIndex &index);
16370 16376
 void QModelIndex_fromScriptValue(const QScriptValue &value, QModelIndex &index);
16377
+void setQModelIndexProperties(QScriptValue value, QScriptEngine *engine);
16378
+QScriptValue QModelIndex_row(QScriptContext *context, QScriptEngine *engine);
16371 16379
 
16372 16380
 @ These are implemented thusly.
16373 16381
 
@@ -16377,6 +16385,7 @@ QScriptValue QModelIndex_toScriptValue(QScriptEngine *engine, const QModelIndex
16377 16385
     QVariant var;
16378 16386
     var.setValue(index);
16379 16387
     QScriptValue object = engine->newVariant(var);
16388
+    setQModelIndexProperties(object, engine);
16380 16389
     return object;
16381 16390
 }
16382 16391
 
@@ -16385,6 +16394,17 @@ void QModelIndex_fromScriptValue(const QScriptValue &value, QModelIndex &index)
16385 16394
     index = value.toVariant().value<QModelIndex>();
16386 16395
 }
16387 16396
 
16397
+void setQModelIndexProperties(QScriptValue value, QScriptEngine *engine)
16398
+{
16399
+    value.setProperty("row", engine->newFunction(QModelIndex_row));
16400
+}
16401
+
16402
+QScriptValue QModelIndex_row(QScriptContext *context, QScriptEngine *engine)
16403
+{
16404
+    QModelIndex self = getself<QModelIndex>(context);
16405
+    return QScriptValue(engine, self.row());
16406
+}
16407
+
16388 16408
 @ Finally we register this with the engine.
16389 16409
 
16390 16410
 @<Set up the scripting engine@>=

Loading…
Cancel
Save