summaryrefslogtreecommitdiffstats
path: root/koffice-i18n-sv/docs/koffice/kugar/progguide.docbook
blob: bdab067a9450db9c40cafc12247b4e6c6081a177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
<!-- If you want to validate or edit this document separately, uncomment
this prolog

<?xml version="1.0" ?>
<!DOCTYPE chapter PUBLIC "-//KDE//DTD DocBook XML V4.1-Based Variant V1.0//EN" "dtd/kdex.dtd">

-->

<chapter id="prog-guide">
<chapterinfo>
<authorgroup>
<author
><firstname
>Alexander</firstname
> <surname
>Dymo</surname
> <affiliation
> <address
><email
>cloudtemple@mksat.net</email
></address>
</affiliation>
</author>
<author
><firstname
>Phil</firstname
> <surname
>Thompson</surname
> <affiliation
> <address
><email
>phil@river-bank.demon.co.uk</email
></address>
</affiliation>
</author>
<othercredit role="translator"
> <firstname
>Stefan</firstname
> <surname
>Asserhäll</surname
> <affiliation
><address
><email
>stefan.asserhall@comhem.se</email
></address
></affiliation
> <contrib
>Översättare</contrib
></othercredit
> 
</authorgroup>
</chapterinfo>
<title
>Guide för programmerare</title>

<sect1 id="how-to-use-in-progs">
<title
>Hur &kugar; kan användas för att skapa rapporter i dina egna program</title>

<itemizedlist>
<title
>Det finns flera olika sätt att använda &kugar;</title>
<listitem>
<para
>Skapa en tillfällig fil och fyll den med data, organiserad enligt <link linkend="kugardata-dtd"
>KugarData dokumenttypdefinitionen</link
>. Anropa sedan skalkommandot <command
>kugar</command
> ( <cmdsynopsis
><command
>kugar</command
> <group
> <option
>-d <replaceable
>Kugar datafil</replaceable
></option
> </group
> <group
> <option
>-r <replaceable
>Kugar mallfil</replaceable
></option
> </group
></cmdsynopsis
>) för att förhandsgranska och skriva ut rapporten. Se avsnittet <link linkend="prog-using-for-preview"
>Använda &kugar;-skalet för att förhandsgranska rapporter</link
> för en detaljerad beskrivning. </para>
</listitem>
<listitem>
<para
>Använd &kugar; direkt i programmets kod. Se avsnittet <link linkend="prog-using-widget"
>Använda &kugar;-klasser för rapporter</link
> för en detaljerad beskrivning. </para>
</listitem>
<listitem>
<para
>Skapa en &Qt; Designer insticksmodul, använd den för att bygga programmets grafiska gränssnitt i Designer, och länka den dynamiskt till programmet. Se <link linkend="prog-designer-plugin"
>Skapa en &Qt; Designer insticksmodul</link
> för en detaljerad beskrivning. </para>
</listitem>
</itemizedlist>

<para
>De sista två sätten är användbara för &Qt;- och &kde;-utvecklare. Men &kugar; är konstruerad för att vara en rapportgenerator som är oberoende av programspråk och/eller integrerad utvecklingsmiljö. Den använder &XML;-formatet för att beskriva rapportmallar och datafiler. Så vilket program som helst kan skapa utdata på &kugar;s datafilformat som beskrivs i <link linkend="kugardata-dtd"
>KugarData <acronym
>DTD</acronym
></link
>, eller till och med på rapportmallformat (se <link linkend="template-dtd"
>KugarTemplate <acronym
>DTD</acronym
></link
>). Ett &kugar;-skal (rapportvisare) kan användas för att förhandsgranska och skriva ut skapade rapporter. </para>

</sect1>

<sect1 id="prog-using-for-preview">
<title
>Använda &kugar;-skalet för att förhandsgranska rapporter</title>

<orderedlist>
<title
>Sättet att skapa och förhandsgranska (skriva ut) en rapport är:</title>
<listitem>
<para
>Skapa en rapportmall med &kudesigner; </para>
</listitem>
<listitem>
<para
>Skapa en datafil med kolumnvärden för detaljband i rapporten. Använd <link linkend="kugardata-dtd"
>KugarData <acronym
>DTD</acronym
></link
> för att skapa riktiga datafiler. </para>
</listitem>
<listitem>
<para
>Kör &kugar;-skalet för att förhandsgranska och skriva ut en rapport. För att till exempel göra detta med språken C eller C++, anropa:</para>

<programlisting
><function
>system(<option
>"kugar -r <replaceable
>mall_fil.ktf</replaceable
>-d <replaceable
>data_fil.kdf</replaceable
>"</option
>)</function
>.
</programlisting>

<para
>Glöm inte att inkludera <filename class="headerfile"
>stdlib.h</filename
>. </para>
</listitem>
</orderedlist>
</sect1>

<sect1 id="prog-using-widget">
<title
>Använda &kugar;s klasser för rapporter</title>
<para
>&kugar;-biblioteket innefattar två grafiska komponenter som kan användas. </para>
<para
>Klassen <classname
>KReportViewer</classname
> är konstruerad för &kde;-utvecklare. Den stöder &kde;:s utskriftssystem och översättning under &UNIX; via <function
>i18n()</function
>-anrop. </para>
<para
>Klassen <classname
>MReportViewer</classname
> är konstruerad för &Qt;-utvecklare och erbjuder riktigt plattformsoberoende. Den kan inte bara användas på &UNIX;-plattformar, utan också på &Windows; och &MacOS;. </para>
<para
>För att bygga ett program som använder &kugar;-biblioteket, ska det länkas med det delade biblioteket <filename
>libkugar.so</filename
>, som tillhandahålls med &kugar;-distributioner på alla &UNIX;-plattformar. </para>
<para
>Deklarationsfiler är <filename
>kugarqt.h</filename
> och <filename
>kugar.h</filename
> för respektive &Qt;- och &kde;-program. </para>
<para
>För ett detaljerat exempel på hur &kugar;-klasser kan användas, titta i katalogen <filename class="directory"
>/shell</filename
> i &kugar;s källkod. </para>
<para
><classname
>MReportViewer</classname
> (och också <classname
>KReportViewer</classname
>) innehåller flera synliga metoder som kan användas. </para>
<funcsynopsis>
<funcprototype>
<funcdef
>void <function
>renderReport</function
></funcdef>
<void/>
</funcprototype>
<funcsynopsisinfo
>Visar rapporten på skärmen.</funcsynopsisinfo>
</funcsynopsis>

<funcsynopsis>
<funcprototype>
<funcdef
>void <function
>printReport</function
></funcdef>
<void/>
</funcprototype>
<funcsynopsisinfo
>Anropar utskriftsdialogrutan för att skriva ut rapporten.</funcsynopsisinfo>
</funcsynopsis>

<funcsynopsis>
<funcprototype>
<funcdef
>void <function
>clearReport</function
></funcdef>
<void/>
</funcprototype>
<funcsynopsisinfo
>Rensar rapporten på skärmen och frigör rapportdata. Anropa detta innan en ny rapport öppnas.</funcsynopsisinfo>
</funcsynopsis>

<funcsynopsis>
<funcprototype
><funcdef
>bool <function
>setReportData</function
></funcdef
> <paramdef
>const QString &amp;<parameter
>datafilnamn</parameter
></paramdef
> </funcprototype>
<funcsynopsisinfo
>Hämtar rapportdata från filen <replaceable
>datafilnamn</replaceable
>.</funcsynopsisinfo>
</funcsynopsis>

<funcsynopsis>
<funcprototype
><funcdef
>bool <function
>setReportData</function
></funcdef
> <paramdef
>const QIODevice &amp;<parameter
>data io-enhet</parameter
></paramdef
> </funcprototype>
<funcsynopsisinfo
>Hämtar rapportdata från filen <replaceable
>data io-enhet</replaceable
>. I/O-enheten kan vara vilken klass som helst härledd från klassen <replaceable
>QIODevice</replaceable
>. För att till exempel direkt hämta poster från databasen, skapa en härledd klass från <classname
>QIODevice</classname
> och definiera om alla nödvändiga funktioner. </funcsynopsisinfo>
</funcsynopsis>

<funcsynopsis>
<funcprototype
><funcdef
>bool <function
>setReportTemplate</function
></funcdef
> <paramdef
>const QString &amp;<parameter
>mallfilnamn</parameter
></paramdef
> </funcprototype>
<funcsynopsisinfo
>Hämtar rapportmall från filen <replaceable
>mallfilnamn</replaceable
>.</funcsynopsisinfo>
</funcsynopsis>

<funcsynopsis>
<funcprototype
><funcdef
>bool <function
>setReportTemplate</function
></funcdef
> <paramdef
>const QIODevice &amp;<parameter
>mall io-enhet</parameter
></paramdef
> </funcprototype>
<funcsynopsisinfo
>Hämtar rapportmall från filen <replaceable
>mall io-enhet</replaceable
>. I/O-enheten kan vara vilken klass som helst härledd från klassen <classname
>QIODevice</classname
>. För att till exempel direkt hämta en rapportmall från nätverket eller en databas, skapa en härledd klass från QIODevice och definiera om alla nödvändiga funktioner. </funcsynopsisinfo>
</funcsynopsis>

</sect1>

<sect1 id="prog-designer-plugin">
<title
>Skapa en &Qt; Designer insticksmodul</title>

<para
>Det här är exempelkod på hur en insticksmodul till Designer skapas. Koden nedan skapar en insticksmodul för en &kde; <classname
>KReportViewer</classname
> grafisk komponent. </para>

<para
>Om en &Qt; grafisk komponent önskas, ersätt <classname
>KReportViewer</classname
> med <classname
>MReportViewer</classname
> och <filename
>kugar.h</filename
> med <filename
>kugarqt.h</filename
> i insticksprogramkoden. </para>

<sect2 id="plugin-usage">
<title
>Användning av insticksmodulen</title>
<para
>Designer-insticksmodulen gör att &Qt; Designer kan användas för att placera den grafiska komponenten <classname
>KReportViewer</classname
> i ett fönster, och förhandsgranska den på ett riktigt sätt. </para>

<para
>Program som använder den här insticksmodulen måste länkas dynamiskt med den. Motsvarande bibliotek heter <filename
>libkugar.so</filename
>. Grafiska komponenter eller dialogrutor som innehåller komponenten <classname
>KReportViewer</classname
> måste inkludera &lt;kugar.h&gt; i en implementering och innehålla deklarationen <classname
>class KReportViewer</classname
>. Det går att inkludera med hjälp av &Qt; Designers objektutforskare (källkodsfliken). </para>

<para
>För att bygga insticksmodulen kör: <cmdsynopsis
><command
>qmake</command
> <arg
>kugar_plugin.pro</arg
> </cmdsynopsis>
<cmdsynopsis>
<command
>make</command>
</cmdsynopsis>
</para>

</sect2>

<sect2 id="plugin-code">
<title
>Insticksmodulkod</title>

<segmentedlist>
<title
>Insticksmodulkoden består av tre filer:</title>
<segtitle
><link linkend="plugin-h-source"
>kugar_plugin.h</link
></segtitle>
<segtitle
><link linkend="plugin-cpp-source"
>kugar_plugin.cpp</link
></segtitle>
<segtitle
><link linkend="plugin-pro-source"
>kugar_plugin.pro</link
></segtitle>
<seglistitem>
<seg
>En deklarationsfil för <classname
>KugarWidgetPlugin</classname
>, efterföljare till <classname
>QWidgetPlugin</classname
>.</seg>
<seg
>En källkodsfil för <classname
>KugarWidgetPlugin</classname
>, efterföljaren till <classname
>QWidgetPlugin</classname
>.</seg>
<seg
>En projektfil för verktyget <application
>Qmake</application
>.</seg>
</seglistitem>
</segmentedlist>

<sect3 id="plugin-h-source">
<title
>kugar_plugin.h</title>

<programlisting
>#include &lt;qwidgetplugin.h&gt;

class KugarWidgetPlugin:public QWidgetPlugin
{
public:
  KugarWidgetPlugin ();

  QStringList keys () const;
  QWidget *create (const QString &amp; classname, QWidget * parent =
                   0, const char *name = 0);
  QString group (const QString &amp;) const;
  QIconSet iconSet (const QString &amp;) const;
  QString includeFile (const QString &amp;) const;
  QString toolTip (const QString &amp;) const;
  QString whatsThis (const QString &amp;) const;
  bool isContainer (const QString &amp;) const;
};
</programlisting>
</sect3>


<sect3 id="plugin-cpp-source">
<title
>kugar_plugin.cpp</title>

<programlisting
>#include "kugar_plugin.h"
#include &lt;kugar.h&gt;

static const char *kugar_pixmap[] = {
  "22 22 127 2",
  ".d c #000000",
  ".c c #131313",
  ".b c #282828",
  ".a c #434241",
  ".e c #4e463a",
  ".# c #595551",
  ".G c #66553b",
  "#F c #68635f",
  "#R c #6b4f23",
  "#q c #6e6862",
  "#M c #6f5229",
  ".n c #6f6146",
  ".w c #735310",
  ".V c #755c2a",
  ".I c #775f34",
  ".0 c #77694a",
  "#n c #7e6434",
  ".o c #806f50",
  "#C c #835d2d",
  ".P c #837c75",
  "#B c #85653a",
  "#k c #85827e",
  ".x c #866d46",
  ".U c #877967",
  ".X c #888888",
  ".F c #89724d",
  "#x c #8b6d2a",
  ".S c #8d7759",
  ".z c #8e733b",
  "#L c #906e49",
  "#Q c #947b56",
  ".r c #948058",
  ".J c #957844",
  ".4 c #987736",
  ".q c #998969",
  ".k c #999897",
  ".R c #9a8a75",
  "#i c #9f8348",
  "#I c #a37c4b",
  ".u c #a38d66",
  ".E c #a58558",
  "#A c #a8834b",
  ".s c #a9967a",
  ".t c #aa9467",
  ".C c #ae9f8d",
  "#6 c #afa49d",
  "#5 c #afa9a4",
  "#W c #b18e4d",
  ".K c #b1935a",
  ".B c #b39660",
  "#V c #b49866",
  "#a c #b49d6c",
  "## c #b49d72",
  ".j c #b5b4b4",
  "#0 c #b7a597",
  ".O c #b9b1a9",
  ".L c #bb9c61",
  ".M c #bb9e6b",
  ".A c #bca778",
  "#j c #bea46b",
  ".T c #bfb37d",
  ".v c #c0b391",
  ".W c #c3a262",
  ".i c #c4c4c4",
  "#m c #c5b7aa",
  "#8 c #c69f80",
  ".D c #c6b79b",
  "#3 c #c7a589",
  ".7 c #c7a76c",
  "#u c #c7bbaf",
  ".6 c #c8ad74",
  "#7 c #c8b7a9",
  "#r c #c8beb5",
  ".m c #c8c8c8",
  "#U c #cbad96",
  "#f c #ccb681",
  "#h c #cdac6c",
  "#P c #cdb49f",
  "#X c #cdb8a6",
  "#H c #ceb7a4",
  ".y c #ceb892",
  ".N c #cecac3",
  "#Z c #cfb16f",
  "#O c #cfbdad",
  ".Z c #cfc7c0",
  "#w c #d0bcab",
  ".5 c #d1ad6b",
  "#s c #d1bfb1",
  ".h c #d5d5d5",
  "#l c #d6cdc6",
  "#D c #d8b36e",
  ".H c #dac592",
  "#t c #dbb977",
  ".g c #dcdcdc",
  ".1 c #e0dcc1",
  ".f c #e0e0df",
  "#1 c #e3c8b1",
  "#S c #e4cdb9",
  ".3 c #e4d9a3",
  "#4 c #e6c1a1",
  "#2 c #e7c4a5",
  "#K c #e9c179",
  "#g c #e9c47e",
  "#Y c #e9c8ac",
  ".2 c #eae6c0",
  "#T c #ebcdb3",
  ".Q c #ebd4b9",
  "#E c #ecca87",
  "#z c #ecd799",
  ".l c #ececeb",
  "#G c #efd7c2",
  "#e c #efe3ab",
  ".8 c #efe8e3",
  "#v c #f1dcca",
  "#. c #f2e2d4",
  ".p c #f4f4f4",
  "#y c #f5daa0",
  "#J c #f6cf7f",
  ".9 c #f7ede4",
  "#p c #f9d995",
  ".Y c #fcf9f6",
  "#d c #fefcc5",
  "#c c #fefdda",
  "#b c #fefee1",
  "#N c #ffd685",
  "#o c #fff0a9",
  "Qt c #ffffff",
  "QtQtQtQtQtQt.#.a.a.a.b.b.b.c.c.d.d.dQtQtQtQt",
  "QtQtQtQtQtQt.e.f.g.g.f.g.g.h.i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
}

QStringList KugarWidgetPlugin::keys () const
{
  QStringList list;
  list &lt;&lt; "KReportViewer";
  return list;
}

QWidget* KugarWidgetPlugin::create (const QString &amp; key, QWidget * parent,
                                    const char *name)
{
  if (key == "KReportViewer")
    return new KReportViewer (parent, name);
  return 0;
}

QString KugarWidgetPlugin::group (const QString &amp; feature) const
{
  if (feature == "KReportViewer")
    return "Display";
  return QString::null;
}

QIconSet KugarWidgetPlugin::iconSet (const QString &amp;) const
{
  return QIconSet (QPixmap (kugar_pixmap));
}

QString KugarWidgetPlugin::includeFile (const QString &amp; feature) const
{
  if (feature == "KReportViewer")
    return "kugar.h";
  return QString::null;
}

QString KugarWidgetPlugin::toolTip (const QString &amp; feature) const
{
  if (feature == "KReportViewer")
    return "Kugar report viewer widget";
  return QString::null;
}

QString KugarWidgetPlugin::whatsThis (const QString &amp; feature) const
{
  if (feature == "KReportViewer")
    return "A widget to view xml reports";
  return QString::null;
}

bool KugarWidgetPlugin::isContainer (const QString &amp;) const
{
  return FALSE;
}

Q_EXPORT_PLUGIN( KugarWidgetPlugin )
</programlisting>
</sect3>

<sect3 id="plugin-pro-source">
<title
>kugar_plugin.pro</title>

<programlisting
>SOURCES        += kugar_plugin.cpp
HEADERS        += kugar_plugin.h

DESTDIR = $(TQTDIR)/plugins/designer
TARGET  = kugar_plugin

target.path=$$plugins.path
isEmpty(target.path):target.path=$$QT_PREFIX/plugins
PROJECTNAME = KugarPlugin
TEMPLATE    = lib
CONFIG           += qt warn_on release plugin
unix:LIBS  += -lkugar
LANGUAGE    = C++
</programlisting>
</sect3>

</sect2>

</sect1>
</chapter>