~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to doc/kugar/progguide.docbook

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!-- If you want to validate or edit this document separately, uncomment
 
2
this prolog
 
3
 
 
4
<?xml version="1.0" ?>
 
5
<!DOCTYPE chapter PUBLIC "-//KDE//DTD DocBook XML V4.1-Based Variant V1.0//EN" "dtd/kdex.dtd">
 
6
 
 
7
-->
 
8
 
 
9
<chapter id="prog-guide">
 
10
<title>Programmer's Guide</title>
 
11
 
 
12
<sect1 id="how-to-use-in-progs">
 
13
<title>How to use &kugar; for reporting in own programs</title>
 
14
 
 
15
<itemizedlist>
 
16
<title>There are several ways to use &kugar;</title>
 
17
<listitem>
 
18
<para>
 
19
Create a temporary file and fill it with data, organized according to the
 
20
<link linkend="kugardata-dtd">KugarData Document Type Definition</link>. Then
 
21
call the <command>kugar</command> shell command (
 
22
<cmdsynopsis>
 
23
<command>kugar</command>
 
24
<group>
 
25
<option>-d <replaceable>Kugar data file</replaceable></option>
 
26
</group>
 
27
<group>
 
28
<option>-r <replaceable>Kugar template file</replaceable></option>
 
29
</group>
 
30
</cmdsynopsis>
 
31
) to preview and print the report.
 
32
See <link linkend="prog-using-for-preview">Using &kugar; shell for previewing reports</link>
 
33
section for a detailed description.
 
34
</para>
 
35
</listitem>
 
36
<listitem>
 
37
<para>
 
38
Use &kugar; directly in the application's code.
 
39
See <link linkend="prog-using-widget">Using a &kugar; classes for reporting</link>
 
40
section for a detailed description.
 
41
</para>
 
42
</listitem>
 
43
<listitem>
 
44
<para>
 
45
Create a &Qt; designer plugin, use it to build application &GUI; in the designer and
 
46
link it to the program dynamically.
 
47
See <link linkend="prog-designer-plugin">Creating &Qt; designer plugin</link>
 
48
section for a detailed description.
 
49
</para>
 
50
</listitem>
 
51
</itemizedlist>
 
52
 
 
53
<para> The last two ways are acceptable for &Qt; and &kde; developers.
 
54
But &kugar; is designed to be a report generator, independent from a
 
55
programming language or/and <acronym>IDE</acronym>. It uses &XML;
 
56
format for describing report templates and data files. So any program
 
57
can produce output in &kugar; data file format as described in <link
 
58
linkend="kugardata-dtd">KugarData <acronym>DTD</acronym></link> or
 
59
even a report template file format (see <link
 
60
linkend="template-dtd">KugarTemplate <acronym>DTD</acronym></link>).
 
61
A &kugar; shell (report viewer) can be used to preview and print
 
62
generated report.  </para>
 
63
 
 
64
</sect1>
 
65
 
 
66
<sect1 id="prog-using-for-preview">
 
67
<title>Using &kugar; shell for previewing reports</title>
 
68
 
 
69
<orderedlist>
 
70
<title>The way to create and preview (print) report is:</title>
 
71
<listitem>
 
72
<para>
 
73
Create a report template file with &kudesigner;
 
74
</para>
 
75
</listitem>
 
76
<listitem>
 
77
<para>
 
78
Create a data file with column values for detail bands of the report.
 
79
Use <link linkend="kugardata-dtd">KugarData <acronym>DTD</acronym></link> to produce correct data files.
 
80
</para>
 
81
</listitem>
 
82
<listitem>
 
83
<para>
 
84
Run &kugar; shell to preview and print report. For example, to do this, in c or c++
 
85
languages call:</para>
 
86
 
 
87
<programlisting>
 
88
<function>system(<option>"kugar -r <replaceable>template_file.kut</replaceable>-d <replaceable>data_file.kud</replaceable>"</option>)</function>.
 
89
</programlisting>
 
90
 
 
91
<para>
 
92
Don't forget to include <filename class="headerfile">stdlib.h</filename>.
 
93
</para>
 
94
</listitem>
 
95
</orderedlist>
 
96
</sect1>
 
97
 
 
98
<sect1 id="prog-using-widget">
 
99
<title>Using a &kugar; classes for reporting</title>
 
100
<para>
 
101
&kugar; library includes two widgets for use.
 
102
</para>
 
103
<para>
 
104
<classname>KReportViewer</classname> class is designed for &kde;
 
105
developers. It supports a &kde; printing system and &UNIX; localization
 
106
via <function>i18n()</function> calls.
 
107
</para>
 
108
<para>
 
109
<classname>MReportViewer</classname> class is designed for &Qt;
 
110
developers and provide real crossplatforming. It can be used not
 
111
only on &UNIX; platforms. but on &Windows; and &Mac; too.
 
112
</para>
 
113
<para>
 
114
In order to build program that uses kugar library, it should be linked
 
115
with <filename>libkugar.so</filename> shared library, that is provided with kugar distribution on all
 
116
&UNIX; plaforms.
 
117
</para>
 
118
<para>
 
119
Include files are <filename>kugarqt.h</filename> and <filename>kugar.h</filename>
 
120
for &Qt; and &kde; programs accordingly.
 
121
</para>
 
122
<para>For a detailed example of how &kugar; classes can be used, see <filename class="directory">/shell</filename>
 
123
directory in the &kugar; sources.
 
124
</para>
 
125
<para>
 
126
The <classname>MReportViewer</classname> (and <classname>KReportViewer</classname> too)
 
127
contains several public methods that can be used.
 
128
</para>
 
129
<funcsynopsis>
 
130
<funcprototype>
 
131
<funcdef>void <function>renderReport</function></funcdef>
 
132
<void/>
 
133
</funcprototype>
 
134
<funcsynopsisinfo>Renders the report onto a screen.</funcsynopsisinfo>
 
135
</funcsynopsis>
 
136
 
 
137
<funcsynopsis>
 
138
<funcprototype>
 
139
<funcdef>void <function>printReport</function></funcdef>
 
140
<void/>
 
141
</funcprototype>
 
142
<funcsynopsisinfo>Calls print dialog to print the report.</funcsynopsisinfo>
 
143
</funcsynopsis>
 
144
 
 
145
<funcsynopsis>
 
146
<funcprototype>
 
147
<funcdef>void <function>clearReport</function></funcdef>
 
148
<void/>
 
149
</funcprototype>
 
150
<funcsynopsisinfo>Clears the report on a screen and frees report data.
 
151
Call this before opening the new report.</funcsynopsisinfo>
 
152
</funcsynopsis>
 
153
 
 
154
<funcsynopsis>
 
155
<funcprototype>
 
156
<funcdef>bool <function>setReportData</function></funcdef>
 
157
<paramdef>const QString &amp;<parameter>data_file_name</parameter></paramdef>
 
158
</funcprototype>
 
159
<funcsynopsisinfo>Sets report data from <replaceable>data_file_name</replaceable> file.</funcsynopsisinfo>
 
160
</funcsynopsis>
 
161
 
 
162
<funcsynopsis>
 
163
<funcprototype>
 
164
<funcdef>bool <function>setReportData</function></funcdef>
 
165
<paramdef>const QIODevice &amp;<parameter>data_io_device</parameter></paramdef>
 
166
</funcprototype>
 
167
<funcsynopsisinfo>Sets report data from <replaceable>data_io_device</replaceable> file.
 
168
IO device can be any succesor of <classname>QIODevice</classname> class.
 
169
For example, to fetch records directly from the database,
 
170
create a <classname>QIODevice</classname> successor and redefine all nessesary
 
171
functionality.
 
172
</funcsynopsisinfo>
 
173
</funcsynopsis>
 
174
 
 
175
<funcsynopsis>
 
176
<funcprototype>
 
177
<funcdef>bool <function>setReportTemplate</function></funcdef>
 
178
<paramdef>const QString &amp;<parameter>template_file_name</parameter></paramdef>
 
179
</funcprototype>
 
180
<funcsynopsisinfo>Sets report template from <replaceable>template_file_name</replaceable> file.</funcsynopsisinfo>
 
181
</funcsynopsis>
 
182
 
 
183
<funcsynopsis>
 
184
<funcprototype>
 
185
<funcdef>bool <function>setReportTemplate</function></funcdef>
 
186
<paramdef>const QIODevice &amp;<parameter>template_io_device</parameter></paramdef>
 
187
</funcprototype>
 
188
<funcsynopsisinfo>Sets report template from <replaceable>template_io_device</replaceable> file.
 
189
IO device can be any succesor of <classname>QIODevice</classname> class.
 
190
For example, to obtail report template from network storage or database,
 
191
create a QIODevice successor and redefine all nessesary functionality.
 
192
</funcsynopsisinfo>
 
193
</funcsynopsis>
 
194
 
 
195
</sect1>
 
196
 
 
197
<sect1 id="prog-designer-plugin">
 
198
<title>Creating &Qt; designer plugin</title>
 
199
 
 
200
<para>
 
201
This is the example code of how is designer plugin created. The code below creates plugin for
 
202
a &kde; <classname>KReportViewer</classname> widget.
 
203
</para>
 
204
 
 
205
<para>
 
206
If a &Qt;
 
207
widget is desired, replace <classname>KReportViewer</classname> to
 
208
<classname>MReportViewer</classname> and <filename>kugar.h</filename> to
 
209
<filename>kugarqt.h</filename> in the plugin code.
 
210
</para>
 
211
 
 
212
<sect2 id="plugin-usage">
 
213
<title>Plugin usage</title>
 
214
<para>
 
215
Designer plugin will allow the usage of &Qt; Designer to place <classname>KReportViewer</classname>
 
216
widget onto a window and preview it correctly.
 
217
</para>
 
218
 
 
219
<para>
 
220
Programs that make use of this plugin must be linked dynamically with it.
 
221
The corresponding library called <filename>libkugar_plugin.so</filename>.
 
222
Widgets or dialogs that include <classname>KReportViewer</classname>
 
223
widget must include &lt;kugar.h&gt; in implementation and have a forward declaration
 
224
of <classname>class KReportViewer</classname>. Includes can be done with &Qt;
 
225
Designer's Object Explorer (Source tab).
 
226
</para>
 
227
 
 
228
<para>
 
229
To build plugin run:
 
230
<cmdsynopsis>
 
231
<command>qmake</command>
 
232
<arg>kugar_plugin.pro</arg>
 
233
</cmdsynopsis>
 
234
<cmdsynopsis>
 
235
<command>make</command>
 
236
</cmdsynopsis>
 
237
</para>
 
238
 
 
239
</sect2>
 
240
 
 
241
<sect2 id="plugin-code">
 
242
<title>Plugin code</title>
 
243
 
 
244
<segmentedlist>
 
245
<title>The plugin code consists of three files:</title>
 
246
<segtitle><link linkend="plugin-h-source">kugar_plugin.h</link></segtitle>
 
247
<segtitle><link linkend="plugin-cpp-source">kugar_plugin.cpp</link></segtitle>
 
248
<segtitle><link linkend="plugin-pro-source">kugar_plugin.pro</link></segtitle>
 
249
<seglistitem>
 
250
<seg>A header file for <classname>KugarWidgetPlugin</classname>, <classname>QWidgetPlugin</classname> successor;</seg>
 
251
<seg>A source file for <classname>KugarWidgetPlugin</classname>, <classname>QWidgetPlugin</classname> successor;</seg>
 
252
<seg>Project file for <application>QMake</application> utility.</seg>
 
253
</seglistitem>
 
254
</segmentedlist>
 
255
 
 
256
<sect3 id="plugin-h-source">
 
257
<title>kugar_plugin.h</title>
 
258
 
 
259
<programlisting>
 
260
#include &lt;qwidgetplugin.h>&gt;
 
261
 
 
262
class KugarWidgetPlugin:public QWidgetPlugin
 
263
{
 
264
public:
 
265
  KugarWidgetPlugin ();
 
266
 
 
267
  QStringList keys () const;
 
268
  QWidget *create (const QString &amp; classname, QWidget * parent =
 
269
                   0, const char *name = 0);
 
270
  QString group (const QString &amp;) const;
 
271
  QIconSet iconSet (const QString &amp;) const;
 
272
  QString includeFile (const QString &amp;) const;
 
273
  QString toolTip (const QString &amp;) const;
 
274
  QString whatsThis (const QString &amp;) const;
 
275
  bool isContainer (const QString &amp;) const;
 
276
};
 
277
</programlisting>
 
278
</sect3>
 
279
 
 
280
 
 
281
<sect3 id="plugin-cpp-source">
 
282
<title>kugar_plugin.cpp</title>
 
283
 
 
284
<programlisting>
 
285
#include "kugar_plugin.h"
 
286
#include &lt;kugar.h&gt;
 
287
 
 
288
static const char *kugar_pixmap[] = {
 
289
  "22 22 127 2",
 
290
  ".d c #000000",
 
291
  ".c c #131313",
 
292
  ".b c #282828",
 
293
  ".a c #434241",
 
294
  ".e c #4e463a",
 
295
  ".# c #595551",
 
296
  ".G c #66553b",
 
297
  "#F c #68635f",
 
298
  "#R c #6b4f23",
 
299
  "#q c #6e6862",
 
300
  "#M c #6f5229",
 
301
  ".n c #6f6146",
 
302
  ".w c #735310",
 
303
  ".V c #755c2a",
 
304
  ".I c #775f34",
 
305
  ".0 c #77694a",
 
306
  "#n c #7e6434",
 
307
  ".o c #806f50",
 
308
  "#C c #835d2d",
 
309
  ".P c #837c75",
 
310
  "#B c #85653a",
 
311
  "#k c #85827e",
 
312
  ".x c #866d46",
 
313
  ".U c #877967",
 
314
  ".X c #888888",
 
315
  ".F c #89724d",
 
316
  "#x c #8b6d2a",
 
317
  ".S c #8d7759",
 
318
  ".z c #8e733b",
 
319
  "#L c #906e49",
 
320
  "#Q c #947b56",
 
321
  ".r c #948058",
 
322
  ".J c #957844",
 
323
  ".4 c #987736",
 
324
  ".q c #998969",
 
325
  ".k c #999897",
 
326
  ".R c #9a8a75",
 
327
  "#i c #9f8348",
 
328
  "#I c #a37c4b",
 
329
  ".u c #a38d66",
 
330
  ".E c #a58558",
 
331
  "#A c #a8834b",
 
332
  ".s c #a9967a",
 
333
  ".t c #aa9467",
 
334
  ".C c #ae9f8d",
 
335
  "#6 c #afa49d",
 
336
  "#5 c #afa9a4",
 
337
  "#W c #b18e4d",
 
338
  ".K c #b1935a",
 
339
  ".B c #b39660",
 
340
  "#V c #b49866",
 
341
  "#a c #b49d6c",
 
342
  "## c #b49d72",
 
343
  ".j c #b5b4b4",
 
344
  "#0 c #b7a597",
 
345
  ".O c #b9b1a9",
 
346
  ".L c #bb9c61",
 
347
  ".M c #bb9e6b",
 
348
  ".A c #bca778",
 
349
  "#j c #bea46b",
 
350
  ".T c #bfb37d",
 
351
  ".v c #c0b391",
 
352
  ".W c #c3a262",
 
353
  ".i c #c4c4c4",
 
354
  "#m c #c5b7aa",
 
355
  "#8 c #c69f80",
 
356
  ".D c #c6b79b",
 
357
  "#3 c #c7a589",
 
358
  ".7 c #c7a76c",
 
359
  "#u c #c7bbaf",
 
360
  ".6 c #c8ad74",
 
361
  "#7 c #c8b7a9",
 
362
  "#r c #c8beb5",
 
363
  ".m c #c8c8c8",
 
364
  "#U c #cbad96",
 
365
  "#f c #ccb681",
 
366
  "#h c #cdac6c",
 
367
  "#P c #cdb49f",
 
368
  "#X c #cdb8a6",
 
369
  "#H c #ceb7a4",
 
370
  ".y c #ceb892",
 
371
  ".N c #cecac3",
 
372
  "#Z c #cfb16f",
 
373
  "#O c #cfbdad",
 
374
  ".Z c #cfc7c0",
 
375
  "#w c #d0bcab",
 
376
  ".5 c #d1ad6b",
 
377
  "#s c #d1bfb1",
 
378
  ".h c #d5d5d5",
 
379
  "#l c #d6cdc6",
 
380
  "#D c #d8b36e",
 
381
  ".H c #dac592",
 
382
  "#t c #dbb977",
 
383
  ".g c #dcdcdc",
 
384
  ".1 c #e0dcc1",
 
385
  ".f c #e0e0df",
 
386
  "#1 c #e3c8b1",
 
387
  "#S c #e4cdb9",
 
388
  ".3 c #e4d9a3",
 
389
  "#4 c #e6c1a1",
 
390
  "#2 c #e7c4a5",
 
391
  "#K c #e9c179",
 
392
  "#g c #e9c47e",
 
393
  "#Y c #e9c8ac",
 
394
  ".2 c #eae6c0",
 
395
  "#T c #ebcdb3",
 
396
  ".Q c #ebd4b9",
 
397
  "#E c #ecca87",
 
398
  "#z c #ecd799",
 
399
  ".l c #ececeb",
 
400
  "#G c #efd7c2",
 
401
  "#e c #efe3ab",
 
402
  ".8 c #efe8e3",
 
403
  "#v c #f1dcca",
 
404
  "#. c #f2e2d4",
 
405
  ".p c #f4f4f4",
 
406
  "#y c #f5daa0",
 
407
  "#J c #f6cf7f",
 
408
  ".9 c #f7ede4",
 
409
  "#p c #f9d995",
 
410
  ".Y c #fcf9f6",
 
411
  "#d c #fefcc5",
 
412
  "#c c #fefdda",
 
413
  "#b c #fefee1",
 
414
  "#N c #ffd685",
 
415
  "#o c #fff0a9",
 
416
  "Qt c #ffffff",
 
417
  "QtQtQtQtQtQt.#.a.a.a.b.b.b.c.c.d.d.dQtQtQtQt",
 
418
  "QtQtQtQtQtQt.e.f.g.g.f.g.g.h.i.j.d.k.dQtQtQt",
 
419
  "QtQtQtQtQtQt.a.gQtQtQtQtQtQt.l.f.c.m.k.dQtQt",
 
420
  "QtQtQtQtQt.n.n.n.n.n.o.g.pQtQt.l.bQt.m.k.dQt",
 
421
  "QtQtQt.q.q.r.q.s.t.r.q.u.u.g.pQt.a.fQt.m.k.d",
 
422
  "QtQt.s.s.v.w.x.y.y.t.z.A.t.B.i.p.#.a.b.c.d.d",
 
423
  "Qt.C.C.D.E.F.G.A.H.F.I.J.K.L.M.i.p.l.N.O.P.d",
 
424
  "Qt.s.v.Q.q.R.S.T.A.R.U.V.L.W.W.X.g.Y.f.Z.k.d",
 
425
  ".0.s.t.Q.1.U.R.2.3.S.U.4.5.6.6.7.j.8.9#..O.d",
 
426
  ".G##.V#a#b.1#c#c#d#e#f#g#h#i#j.W#k#l.9#.#m.d",
 
427
  ".G.4.F#n#c#c#c#d#d#o#p#g.x.w#i.L#q#r#.#.#s.d",
 
428
  ".e.J.J.I.3#d.H#j.6#f#p#t#n.w.E.L#q#u#.#v#w.d",
 
429
  ".G.A#x.z#y#z#A#B#B#C#D#E.4.4.6#h#F#m#v#G#H.d",
 
430
  ".o.s.A#j#E#t#I#I#I#C#A#J#p#p#K#t#F#m#v#G#H.d",
 
431
  "Qt##.A.6.7#I#I#A.E#L#M.W#N#J#K.a.U#O#G.Q#P.d",
 
432
  "Qt#a.M.L.J#A#I.4.E#Q.x#R#D#J#g.#.C#S.Q#T#U.d",
 
433
  "QtQt#V.K.z#Q.s.S.x.S#B#M#W#E.a.U#X.Q#T#Y#U.d",
 
434
  "QtQtQt.M#i#B.r#Q#Q.r#Q.z#Z.a#q#0#1#T#Y#2#3.d",
 
435
  "QtQtQtQtQt#j.L.L.W.5#t.a.#.U#0#1#T#Y#2#4#3.d",
 
436
  "QtQtQtQtQtQt.d#F#q#q#q.P.C#O#S.Q#T#Y#2#4#3.d",
 
437
  "QtQtQtQtQtQt.d#5#5#6#6#0#7#w#H#P#U#U#3#3#8.d",
 
438
  "QtQtQtQtQtQt.d.d.d.d.d.d.d.d.d.d.d.d.d.d.d.d"
 
439
};
 
440
 
 
441
KugarWidgetPlugin::KugarWidgetPlugin ()
 
442
{
 
443
}
 
444
 
 
445
QStringList KugarWidgetPlugin::keys () const
 
446
{
 
447
  QStringList list;
 
448
  list &lt;&lt; "KReportViewer";
 
449
  return list;
 
450
}
 
451
 
 
452
QWidget* KugarWidgetPlugin::create (const QString &amp; key, QWidget * parent,
 
453
                                    const char *name)
 
454
{
 
455
  if (key == "KReportViewer")
 
456
    return new KReportViewer (parent, name);
 
457
  return 0;
 
458
}
 
459
 
 
460
QString KugarWidgetPlugin::group (const QString &amp; feature) const
 
461
{
 
462
  if (feature == "KReportViewer")
 
463
    return "Display";
 
464
  return QString::null;
 
465
}
 
466
 
 
467
QIconSet KugarWidgetPlugin::iconSet (const QString &amp;) const
 
468
{
 
469
  return QIconSet (QPixmap (kugar_pixmap));
 
470
}
 
471
 
 
472
QString KugarWidgetPlugin::includeFile (const QString &amp; feature) const
 
473
{
 
474
  if (feature == "KReportViewer")
 
475
    return "kugar.h";
 
476
  return QString::null;
 
477
}
 
478
 
 
479
QString KugarWidgetPlugin::toolTip (const QString &amp; feature) const
 
480
{
 
481
  if (feature == "KReportViewer")
 
482
    return "Kugar report viewer widget";
 
483
  return QString::null;
 
484
}
 
485
 
 
486
QString KugarWidgetPlugin::whatsThis (const QString &amp; feature) const
 
487
{
 
488
  if (feature == "KReportViewer")
 
489
    return "A widget to view xml reports";
 
490
  return QString::null;
 
491
}
 
492
 
 
493
bool KugarWidgetPlugin::isContainer (const QString &amp;) const
 
494
{
 
495
  return FALSE;
 
496
}
 
497
 
 
498
Q_EXPORT_PLUGIN( KugarWidgetPlugin )
 
499
</programlisting>
 
500
</sect3>
 
501
 
 
502
<sect3 id="plugin-pro-source">
 
503
<title>kugar_plugin.pro</title>
 
504
 
 
505
<programlisting>
 
506
SOURCES += kugar_plugin.cpp
 
507
HEADERS += kugar_plugin.h
 
508
 
 
509
DESTDIR = $(QTDIR)/plugins/designer
 
510
TARGET  = kugar_plugin
 
511
 
 
512
target.path=$$plugins.path
 
513
isEmpty(target.path):target.path=$$QT_PREFIX/plugins
 
514
PROJECTNAME = KugarPlugin
 
515
TEMPLATE    = lib
 
516
CONFIG     += qt warn_on release plugin
 
517
unix:LIBS  += -lkugar
 
518
LANGUAGE    = C++
 
519
</programlisting>
 
520
</sect3>
 
521
 
 
522
</sect2>
 
523
 
 
524
</sect1>
 
525
</chapter>