Pārlūkot izejas kodu

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 5 gadus atpakaļ
vecāks
revīzija
7076512317
Parakstījis: Neal Wilson <neal@typica.us> GPG atslēgas ID: 2A0BDDE701E66EB9
1 mainītis faili ar 16 papildinājumiem un 0 dzēšanām
  1. 16
    0
      src/typica.w

+ 16
- 0
src/typica.w Parādīt failu

@@ -4757,6 +4757,7 @@ multitude of objects, all of which must be passed to the scripting engine.
4757 4757
 QScriptValue createWindow(QScriptContext *context, QScriptEngine *engine)@/
4758 4758
 {
4759 4759
     QString targetID = argument<QString>(0, context);
4760
+    @<Get window arguments@>@;
4760 4761
     QDomNode element;
4761 4762
     QScriptValue object;
4762 4763
     @<Find the window element@>@;
@@ -4777,6 +4778,7 @@ window with a reports menu has been created.
4777 4778
 QScriptValue createReport(QScriptContext *context, QScriptEngine *engine)
4778 4779
 {
4779 4780
     QString targetID = argument<QString>(0, context);
4781
+    @<Get window arguments@>@;
4780 4782
     QFile file(QString("reports:%1").arg(targetID));
4781 4783
     QScriptValue object;
4782 4784
     if(file.open(QIODevice::ReadOnly))
@@ -4793,6 +4795,18 @@ QScriptValue createReport(QScriptContext *context, QScriptEngine *engine)
4793 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 4810
 @ First we must locate the {\tt <window>} element. The most sensible way to do
4797 4811
 this would require that each {\tt <window>} element has an ID attribute and
4798 4812
 search the DOM tree for that ID. Unfortunately, as of this writing,
@@ -4837,6 +4851,7 @@ ScriptQMainWindow *window = new ScriptQMainWindow;
4837 4851
 window->setObjectName(targetID);
4838 4852
 object = engine->newQObject(window);
4839 4853
 setQMainWindowProperties(object, engine);
4854
+object.setProperty("arguments", arguments);
4840 4855
 QWidget *central = new(QWidget);
4841 4856
 central->setParent(window);
4842 4857
 central->setObjectName("centralWidget");
@@ -14600,6 +14615,7 @@ void ReportAction::createReport()
14600 14615
         QScriptContext *context = engine->pushContext();
14601 14616
         QScriptValue object;
14602 14617
         QString targetID = reportFile;
14618
+        QScriptValue arguments;
14603 14619
         @<Display the window@>@;
14604 14620
         file.close();
14605 14621
         engine->popContext();

Notiek ielāde…
Atcelt
Saglabāt