Browse Source

Allow passing arguments to windows.

The script functions createWindow() and createReport() now allow an
optional 2nd argument. This can be any script value and it will be
available as the arguments property on the newly created window.
Neal Wilson 4 years ago
parent
commit
7076512317
Signed by: Neal Wilson <neal@typica.us> GPG Key ID: 2A0BDDE701E66EB9
1 changed files with 16 additions and 0 deletions
  1. 16
    0
      src/typica.w

+ 16
- 0
src/typica.w View File

4757
 QScriptValue createWindow(QScriptContext *context, QScriptEngine *engine)@/
4757
 QScriptValue createWindow(QScriptContext *context, QScriptEngine *engine)@/
4758
 {
4758
 {
4759
     QString targetID = argument<QString>(0, context);
4759
     QString targetID = argument<QString>(0, context);
4760
+    @<Get window arguments@>@;
4760
     QDomNode element;
4761
     QDomNode element;
4761
     QScriptValue object;
4762
     QScriptValue object;
4762
     @<Find the window element@>@;
4763
     @<Find the window element@>@;
4777
 QScriptValue createReport(QScriptContext *context, QScriptEngine *engine)
4778
 QScriptValue createReport(QScriptContext *context, QScriptEngine *engine)
4778
 {
4779
 {
4779
     QString targetID = argument<QString>(0, context);
4780
     QString targetID = argument<QString>(0, context);
4781
+    @<Get window arguments@>@;
4780
     QFile file(QString("reports:%1").arg(targetID));
4782
     QFile file(QString("reports:%1").arg(targetID));
4781
     QScriptValue object;
4783
     QScriptValue object;
4782
     if(file.open(QIODevice::ReadOnly))
4784
     if(file.open(QIODevice::ReadOnly))
4793
     return object;
4795
     return object;
4794
 }
4796
 }
4795
 
4797
 
4798
+@ Sometimes it is useful to pass information to a window when it is created.
4799
+A 2nd optional argument to window creation functions can be any script value
4800
+which will be made available under the {\tt arguments} property of the newly
4801
+created window.
4802
+
4803
+@<Get window arguments@>=
4804
+QScriptValue arguments;
4805
+if(context->argumentCount() > 1)
4806
+{
4807
+    arguments = context->argument(1);
4808
+}
4809
+
4796
 @ First we must locate the {\tt <window>} element. The most sensible way to do
4810
 @ First we must locate the {\tt <window>} element. The most sensible way to do
4797
 this would require that each {\tt <window>} element has an ID attribute and
4811
 this would require that each {\tt <window>} element has an ID attribute and
4798
 search the DOM tree for that ID. Unfortunately, as of this writing,
4812
 search the DOM tree for that ID. Unfortunately, as of this writing,
4837
 window->setObjectName(targetID);
4851
 window->setObjectName(targetID);
4838
 object = engine->newQObject(window);
4852
 object = engine->newQObject(window);
4839
 setQMainWindowProperties(object, engine);
4853
 setQMainWindowProperties(object, engine);
4854
+object.setProperty("arguments", arguments);
4840
 QWidget *central = new(QWidget);
4855
 QWidget *central = new(QWidget);
4841
 central->setParent(window);
4856
 central->setParent(window);
4842
 central->setObjectName("centralWidget");
4857
 central->setObjectName("centralWidget");
14600
         QScriptContext *context = engine->pushContext();
14615
         QScriptContext *context = engine->pushContext();
14601
         QScriptValue object;
14616
         QScriptValue object;
14602
         QString targetID = reportFile;
14617
         QString targetID = reportFile;
14618
+        QScriptValue arguments;
14603
         @<Display the window@>@;
14619
         @<Display the window@>@;
14604
         file.close();
14620
         file.close();
14605
         engine->popContext();
14621
         engine->popContext();

Loading…
Cancel
Save