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
     return self;
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
 template<> QByteArray getself(QScriptContext *context)
698
 template<> QByteArray getself(QScriptContext *context)
693
 {
699
 {
694
     QByteArray self = context->thisObject().toVariant().toByteArray();
700
     QByteArray self = context->thisObject().toVariant().toByteArray();
16363
 Q_DECLARE_METATYPE(QModelIndex)
16369
 Q_DECLARE_METATYPE(QModelIndex)
16364
 
16370
 
16365
 @ Next we need a pair of functions to convert |QModelIndex| to and from script
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
 @<Function prototypes for scripting@>=
16374
 @<Function prototypes for scripting@>=
16369
 QScriptValue QModelIndex_toScriptValue(QScriptEngine *engine, const QModelIndex &index);
16375
 QScriptValue QModelIndex_toScriptValue(QScriptEngine *engine, const QModelIndex &index);
16370
 void QModelIndex_fromScriptValue(const QScriptValue &value, QModelIndex &index);
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
 @ These are implemented thusly.
16380
 @ These are implemented thusly.
16373
 
16381
 
16377
     QVariant var;
16385
     QVariant var;
16378
     var.setValue(index);
16386
     var.setValue(index);
16379
     QScriptValue object = engine->newVariant(var);
16387
     QScriptValue object = engine->newVariant(var);
16388
+    setQModelIndexProperties(object, engine);
16380
     return object;
16389
     return object;
16381
 }
16390
 }
16382
 
16391
 
16385
     index = value.toVariant().value<QModelIndex>();
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
 @ Finally we register this with the engine.
16408
 @ Finally we register this with the engine.
16389
 
16409
 
16390
 @<Set up the scripting engine@>=
16410
 @<Set up the scripting engine@>=

Loading…
Cancel
Save