summaryrefslogtreecommitdiffstats
path: root/kugar/kudesigner_lib/command.cpp
blob: 1644868a8cdaf4df1160c3ab8b24ea472253721a (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
/* This file is part of the KDE project
 Copyright (C) 2002-2004 Alexander Dymo <adymo@mksat.net>

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public
 License as published by the Free Software Foundation; either
 version 2 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Library General Public License for more details.

 You should have received a copy of the GNU Library General Public License
 along with this library; see the file COPYING.LIB.  If not, write to
 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/
#include "command.h"

#include <klocale.h>
#include <kdebug.h>

//#include "kudesigner_doc.h"

#include <koproperty/editor.h>
#include <koproperty/property.h>

#include "view.h"
#include "canvas.h"

#include "field.h"
#include "calcfield.h"
#include "label.h"
#include "line.h"
#include "specialfield.h"

#include "kugartemplate.h"
#include "reportheader.h"
#include "reportfooter.h"
#include "pageheader.h"
#include "pagefooter.h"
#include "detailheader.h"
#include "detailfooter.h"
#include "detail.h"


namespace Kudesigner
{

//AddDetailFooterCommand

AddDetailFooterCommand::AddDetailFooterCommand( int level, Canvas *doc )
        : KNamedCommand( QObject::tr( "Insert Detail Footer Section" ) ), m_level( level ), m_doc( doc )
{}

void AddDetailFooterCommand::execute()
{
    m_section = new DetailFooter( m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                  0, m_doc->kugarTemplate() ->width() - m_doc->kugarTemplate() ->props[ "RightMargin" ].value().toInt() -
                                  m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                  50, m_level, m_doc );
    m_section->props[ "Level" ].setValue( m_level );
    m_doc->kugarTemplate() ->details[ m_level ].first.second = m_section;
    m_doc->kugarTemplate() ->arrangeSections();
    m_doc->setStructureModified();
}

void AddDetailFooterCommand::unexecute()
{
    m_doc->kugarTemplate() ->removeReportItem( m_section );
    m_doc->setStructureModified();
}

//AddDetailCommand

AddDetailCommand::AddDetailCommand( int level, Canvas *doc )
        : KNamedCommand( QObject::tr( "Insert Detail Section" ) ), m_level( level ), m_doc( doc )
{}

void AddDetailCommand::execute()
{
    m_section = new Detail( m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                            0, m_doc->kugarTemplate() ->width() - m_doc->kugarTemplate() ->props[ "RightMargin" ].value().toInt() -
                            m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                            50, m_level, m_doc );
    m_section->props[ "Level" ].setValue( m_level );
    m_doc->kugarTemplate() ->details[ m_level ].second = m_section;
    m_doc->kugarTemplate() ->arrangeSections();
    m_doc->kugarTemplate() ->detailsCount++;
    m_doc->setStructureModified();
}

void AddDetailCommand::unexecute()
{
    m_doc->kugarTemplate() ->removeReportItem( m_section );
    m_doc->setStructureModified();
}

//AddDetailHeaderCommand
AddDetailHeaderCommand::AddDetailHeaderCommand( int level, Canvas *doc )
        : KNamedCommand( QObject::tr( "Insert Detail Header Section" ) ), m_level( level ), m_doc( doc )
{}

void AddDetailHeaderCommand::execute()
{
    m_section = new DetailHeader( m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                  0, m_doc->kugarTemplate() ->width() - m_doc->kugarTemplate() ->props[ "RightMargin" ].value().toInt() -
                                  m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                  50, m_level, m_doc );
    m_section->props[ "Level" ].setValue( m_level );
    m_doc->kugarTemplate() ->details[ m_level ].first.first = m_section;
    m_doc->kugarTemplate() ->arrangeSections();
    m_doc->setStructureModified();
}

void AddDetailHeaderCommand::unexecute()
{
    m_doc->kugarTemplate() ->removeReportItem( m_section );
    m_doc->setStructureModified();
}

//AddPageFooterCommand

AddPageFooterCommand::AddPageFooterCommand( Canvas *doc )
        : KNamedCommand( QObject::tr( "Insert Page Footer Section" ) ), m_doc( doc )
{}

void AddPageFooterCommand::execute()
{
    m_section = new PageFooter( m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                0, m_doc->kugarTemplate() ->width() - m_doc->kugarTemplate() ->props[ "RightMargin" ].value().toInt() -
                                m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                50, m_doc );
    m_doc->kugarTemplate() ->pageFooter = m_section;
    m_doc->kugarTemplate() ->arrangeSections();
    m_doc->setStructureModified();
}

void AddPageFooterCommand::unexecute()
{
    m_doc->kugarTemplate() ->removeReportItem( m_section );
    m_doc->setStructureModified();
}

//AddPageHeaderCommand

AddPageHeaderCommand::AddPageHeaderCommand( Canvas *doc )
        : KNamedCommand( QObject::tr( "Insert Page Header Section" ) ), m_doc( doc )
{}

void AddPageHeaderCommand::execute()
{
    m_section = new PageHeader( m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                0, m_doc->kugarTemplate() ->width() - m_doc->kugarTemplate() ->props[ "RightMargin" ].value().toInt() -
                                m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                50, m_doc );
    m_doc->kugarTemplate() ->pageHeader = m_section;
    m_doc->kugarTemplate() ->arrangeSections();
    m_doc->setStructureModified();
}

void AddPageHeaderCommand::unexecute()
{
    m_doc->kugarTemplate() ->removeReportItem( m_section );
    m_doc->setStructureModified();
}

//AddReportFooterCommand

AddReportFooterCommand::AddReportFooterCommand( Canvas *doc )
        : KNamedCommand( QObject::tr( "Insert Report Footer Section" ) ), m_doc( doc )
{}

void AddReportFooterCommand::execute()
{
    m_section = new ReportFooter( m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                  0, m_doc->kugarTemplate() ->width() - m_doc->kugarTemplate() ->props[ "RightMargin" ].value().toInt() -
                                  m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                  50, m_doc );
    m_doc->kugarTemplate() ->reportFooter = m_section;
    m_doc->kugarTemplate() ->arrangeSections();
    m_doc->setStructureModified();
}

void AddReportFooterCommand::unexecute()
{
    m_doc->kugarTemplate() ->removeReportItem( m_section );
    m_doc->setStructureModified();
}

//AddReportHeaderCommand

AddReportHeaderCommand::AddReportHeaderCommand( Canvas *doc )
        : KNamedCommand( QObject::tr( "Insert Report Header Section" ) ), m_doc( doc )
{}

void AddReportHeaderCommand::execute()
{
    m_section = new ReportHeader( m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                  0, m_doc->kugarTemplate() ->width() - m_doc->kugarTemplate() ->props[ "RightMargin" ].value().toInt() -
                                  m_doc->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
                                  50, m_doc );
    m_doc->kugarTemplate() ->reportHeader = m_section;
    m_doc->kugarTemplate() ->arrangeSections();
    m_doc->setStructureModified();
}

void AddReportHeaderCommand::unexecute()
{
    m_doc->kugarTemplate() ->removeReportItem( m_section );
    m_doc->setStructureModified();
}

//AddReportItemCommand

AddReportItemCommand::AddReportItemCommand( Canvas *doc, View *rc, int x, int y, RttiValues section, int sectionLevel ) :
        KNamedCommand( QObject::tr( "Insert Report Item" ) ), m_doc( doc ), m_rc( rc ), m_x( x ), m_y( y ), m_section( section ), m_sectionLevel( sectionLevel )
{
    m_rtti = m_rc->itemToInsert;
    setName( "Insert " + Kudesigner::rttiName( m_rc->itemToInsert ) );
}

void AddReportItemCommand::execute()
{
    //    kdDebug() << "Execute: rtti = " << m_rtti << endl;
    switch ( m_rtti )
    {
    case Rtti_Label:
        m_item = new Label( 0, 0, DefaultItemWidth, DefaultItemHeight, m_doc );
        break;
    case Rtti_Field:
        m_item = new Field( 0, 0, DefaultItemWidth, DefaultItemHeight, m_doc );
        break;
    case Rtti_Special:
        m_item = new SpecialField( 0, 0, DefaultItemWidth, DefaultItemHeight, m_doc );
        break;
    case Rtti_Calculated:
        m_item = new CalculatedField( 0, 0, DefaultItemWidth, DefaultItemHeight, m_doc );
        break;
    case Rtti_Line:
        m_item = new Line( 0, 0, DefaultItemWidth, DefaultItemHeight, m_doc );
        break;
    default:
        m_item = 0;
        return ;
    }

    m_item->setX( m_x );
    m_item->setY( m_y );
    //    kdDebug() << "Execute: item created" << endl;
    m_item->setSection( m_doc->kugarTemplate() ->band( m_section, m_sectionLevel ) );
    m_item->updateGeomProps();

    m_doc->selectItem( m_item, false );

    m_item->show();
    m_doc->kugarTemplate() ->band( m_section, m_sectionLevel ) ->items.append( m_item );
    m_doc->setStructureModified();
}

void AddReportItemCommand::unexecute()
{
    if ( m_item )
    {
        m_doc->unselectItem( m_item );
        m_doc->kugarTemplate() ->removeReportItem( m_item );
        m_doc->setStructureModified();
    }
}

DeleteReportItemsCommand::DeleteReportItemsCommand( Canvas * doc, QValueList< Box* > & items )
        : KNamedCommand( QObject::tr( "Delete Report Item(s)" ) ), m_doc( doc ), m_items( items )
{}

void DeleteReportItemsCommand::execute( )
{
    m_doc->unselectAll();

    for ( QValueList< Box* >::iterator it = m_items.begin(); it != m_items.end(); ++it )
    {
        Box *b = *it;
        m_doc->kugarTemplate() ->removeReportItem( b );
    }

    m_doc->setStructureModified();
}

void DeleteReportItemsCommand::unexecute( )
{
    /*    Box *b;
        for (b = m_items.first(); b; b = m_items.next())
        {
            b->show();*/
    //        m_doc->kugarTemplate()->removeReportItem( b );
    //     }

    m_doc->setStructureModified();
}

}