|
@@ -3877,12 +3877,16 @@ any {\tt <program>} elements that are immediate children of the
|
3877
|
3877
|
{\tt <window>} element into a window displayed on screen, the script in the
|
3878
|
3878
|
{\tt <program>} elements must call a function to display a specified window.
|
3879
|
3879
|
|
|
3880
|
+Report windows can be produced by scripts in a similar, but slightly different
|
|
3881
|
+manner.
|
|
3882
|
+
|
3880
|
3883
|
\danger This design works, but it'@q'@>s not particularly good design. It was written
|
3881
|
3884
|
under severe time constraints and should be redesigned or at least cleaned up
|
3882
|
3885
|
and reorganized.\endanger
|
3883
|
3886
|
|
3884
|
3887
|
@<Function prototypes for scripting@>=
|
3885
|
3888
|
QScriptValue createWindow(QScriptContext *context, QScriptEngine *engine);
|
|
3889
|
+QScriptValue createReport(QScriptContext *context, QScriptEngine *engine);
|
3886
|
3890
|
void addLayoutToWidget(QDomElement element, QStack<QWidget*> *widgetStack,
|
3887
|
3891
|
QStack<QLayout*> *layoutStack);
|
3888
|
3892
|
void addLayoutToLayout(QDomElement element, QStack<QWidget *> *widgetStack,
|
|
@@ -3942,12 +3946,14 @@ void addCalendarToLayout(QDomElement element, QStack<QWidget *> *widgetStack,
|
3942
|
3946
|
void addSpinBoxToLayout(QDomElement element, QStack<QWidget *> *widgetStack,
|
3943
|
3947
|
QStack<QLayout *> *layoutStack);
|
3944
|
3948
|
|
3945
|
|
-@ The function for creating the window must be made available to the scripting
|
|
3949
|
+@ The functions for creating windows must be made available to the scripting
|
3946
|
3950
|
engine.
|
3947
|
3951
|
|
3948
|
3952
|
@<Set up the scripting engine@>=
|
3949
|
3953
|
engine->globalObject().setProperty("createWindow",
|
3950
|
3954
|
engine->newFunction(createWindow));
|
|
3955
|
+engine->globalObject().setProperty("createReport",
|
|
3956
|
+ engine->newFunction(createReport));
|
3951
|
3957
|
|
3952
|
3958
|
@ This function must examine the configuration document in search of the
|
3953
|
3959
|
appropriate window element, parse the contents of that element, and create a
|
|
@@ -3967,6 +3973,32 @@ QScriptValue createWindow(QScriptContext *context, QScriptEngine *engine)@/
|
3967
|
3973
|
return object;
|
3968
|
3974
|
}
|
3969
|
3975
|
|
|
3976
|
+@ Report files are not part of the configuration document and must be created
|
|
3977
|
+differently. While there is a special menu type that handles all of this
|
|
3978
|
+without involving the host environment, scripted generation and manipulation of
|
|
3979
|
+report windows requires another function. This function will only work after a
|
|
3980
|
+window with a reports menu has been created.
|
|
3981
|
+
|
|
3982
|
+@<Functions for scripting@>=
|
|
3983
|
+QScriptValue createReport(QScriptContext *context, QScriptEngine *engine)
|
|
3984
|
+{
|
|
3985
|
+ QString targetID = argument<QString>(0, context);
|
|
3986
|
+ QFile file(QString("reports:%1").arg(targetID));
|
|
3987
|
+ QScriptValue object;
|
|
3988
|
+ if(file.open(QIODevice::ReadOnly))
|
|
3989
|
+ {
|
|
3990
|
+ QDomDocument document;
|
|
3991
|
+ document.setContent(&file, true);
|
|
3992
|
+ QDomElement element = document.documentElement();
|
|
3993
|
+ if(!element.isNull())
|
|
3994
|
+ {
|
|
3995
|
+ @<Display the window@>@;
|
|
3996
|
+ }
|
|
3997
|
+ file.close();
|
|
3998
|
+ }
|
|
3999
|
+ return object;
|
|
4000
|
+}
|
|
4001
|
+
|
3970
|
4002
|
@ First we must locate the {\tt <window>} element. The most sensible way to do
|
3971
|
4003
|
this would require that each {\tt <window>} element has an ID attribute and
|
3972
|
4004
|
search the DOM tree for that ID. Unfortunately, as of this writing,
|
|
@@ -13001,10 +13033,18 @@ presently distributed with Typica, the approach taken to implementing this menu
|
13001
|
13033
|
type is highly inefficient. There are many optimizations available if this
|
13002
|
13034
|
becomes problematic.\endanger
|
13003
|
13035
|
|
|
13036
|
+When a report menu is generated, the directory used for this is added as a
|
|
13037
|
+search path for the |"reports"| prefix. This is used by the |createReport()|
|
|
13038
|
+script method and is intended to allow access to reports from outside of the
|
|
13039
|
+Report menu.
|
|
13040
|
+
|
13004
|
13041
|
@<Populate reports menu@>=
|
13005
|
13042
|
QSettings settings;
|
13006
|
|
-QDir directory(QString("%1/%2").arg(settings.value("config").toString()).
|
13007
|
|
- arg(element.attribute("src")));
|
|
13043
|
+QString reportDirectory = QString("%1/%2").arg(settings.value("config").
|
|
13044
|
+ toString()).
|
|
13045
|
+ arg(element.attribute("src"));
|
|
13046
|
+QDir::addSearchPath("reports", reportDirectory);
|
|
13047
|
+QDir directory(reportDirectory);
|
13008
|
13048
|
directory.setFilter(QDir::Files);
|
13009
|
13049
|
directory.setSorting(QDir::Name);
|
13010
|
13050
|
QStringList nameFilter;
|