~ubuntu-branches/ubuntu/maverick/datakiosk/maverick

« back to all changes in this revision

Viewing changes to src/src/reportwizardbaseimpl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-06-27 22:48:06 UTC
  • Revision ID: james.westby@ubuntu.com-20050627224806-8farkci1dc2onhbs
Tags: upstream-0.7
ImportĀ upstreamĀ versionĀ 0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005 by Adam Treat                                      *
 
3
 *   treat@kde.org                                                         *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 ***************************************************************************/
 
11
 
 
12
#include "reportwizardbaseimpl.h"
 
13
 
 
14
#include "project.h"
 
15
#include "datareport.h"
 
16
#include "datatable.h"
 
17
#include "asciivalidator.h"
 
18
#include "databaseconnection.h"
 
19
 
 
20
#include <kconfig.h>
 
21
#include <kmessagebox.h>
 
22
#include <kurldrag.h>
 
23
#include <kiconloader.h>
 
24
#include <klineedit.h>
 
25
#include <kaction.h>
 
26
#include <kpopupmenu.h>
 
27
#include <klocale.h>
 
28
#include <kdebug.h>
 
29
#include <kinputdialog.h>
 
30
#include <kicondialog.h>
 
31
#include <kurlrequester.h>
 
32
 
 
33
#include <qlistbox.h>
 
34
#include <qwidget.h>
 
35
#include <qcheckbox.h>
 
36
#include <qlineedit.h>
 
37
 
 
38
#include <qlabel.h>
 
39
#include <qgroupbox.h>
 
40
#include <qlayout.h>
 
41
#include <qregexp.h>
 
42
#include <qpushbutton.h>
 
43
#include <qmultilineedit.h>
 
44
#include <qlistview.h>
 
45
#include <qfeatures.h>
 
46
#include <qradiobutton.h>
 
47
#include <qspinbox.h>
 
48
#include <qcombobox.h>
 
49
#include <limits.h>
 
50
 
 
51
#include <qdatatable.h>
 
52
#include <qdatabrowser.h>
 
53
#include <qdataview.h>
 
54
#include <qsqleditorfactory.h>
 
55
#include <qsqlindex.h>
 
56
#include <qsqlcursor.h>
 
57
#include <qsqldatabase.h>
 
58
 
 
59
ReportWizard::ReportWizard( Project *project, DataReport *report, DataTable *parentTable, bool configure )
 
60
        : ReportWizardBase( report ),
 
61
        m_project( project ),
 
62
        m_report( report ),
 
63
        m_parentTable( parentTable ),
 
64
        m_configure( configure )
 
65
{
 
66
 
 
67
    setMinimumSize( 800, 600 );
 
68
    setCaption( i18n("Report Wizard") );
 
69
    setFinishEnabled( sortPage, true );
 
70
 
 
71
    wizard1->setPixmap( UserIcon( "wizard_table_1" ) );
 
72
    wizard2->setPixmap( UserIcon( "wizard_table_2" ) );
 
73
 
 
74
    buttonIcon->setPixmap( SmallIcon( "kugar", 32 ) );
 
75
    buttonAddSortField->setPixmap( UserIcon( "right" ) );
 
76
    buttonRemoveSortField->setPixmap( UserIcon( "left" ) );
 
77
    buttonUpSortField->setPixmap( UserIcon( "up" ) );
 
78
    buttonDownSortField->setPixmap( UserIcon( "down" ) );
 
79
    buttonReSortField->setPixmap( UserIcon( "re-sort" ) );
 
80
 
 
81
    listBoxTables->setSelectionMode( QListBox::Multi );
 
82
 
 
83
    connect( nextButton(), SIGNAL( clicked() ), SLOT( nextPageClicked() ) );
 
84
 
 
85
    setupFirstPage();
 
86
}
 
87
 
 
88
ReportWizard::~ReportWizard()
 
89
{}
 
90
 
 
91
/****************reportPage methods****************/
 
92
void ReportWizard::reportTemplateChanged( const QString &temp )
 
93
{
 
94
    m_report->setTemplateURL( temp );
 
95
}
 
96
 
 
97
void ReportWizard::reportLabelChanged( const QString &label )
 
98
{
 
99
    m_report->setName( m_project->uniqueDataTableName( label ) );
 
100
}
 
101
 
 
102
void ReportWizard::reportIconChanged()
 
103
{
 
104
    QString iconName = KIconDialog::getIcon( KIcon::NoGroup, KIcon::Any, false, 32, true, this, i18n("Select Icon for This Report") );
 
105
    buttonIcon->setPixmap( SmallIcon( iconName, 32 ) );
 
106
    m_report->setIconName( iconName );
 
107
}
 
108
 
 
109
void ReportWizard::enableAllReportPage( bool b )
 
110
{
 
111
    listBoxTables->setEnabled( b );
 
112
    kURLRequesterTemplate->setEnabled( b );
 
113
    editReport->setEnabled( b );
 
114
    buttonIcon->setEnabled( b );
 
115
}
 
116
 
 
117
/****************sortPage methods****************/
 
118
void ReportWizard::addSortField()
 
119
{
 
120
    int i = listBoxSortField->currentItem();
 
121
    if ( i == -1 )
 
122
        return ;
 
123
    QString f = listBoxSortField->currentText();
 
124
    if ( !f.isEmpty() )
 
125
        listBoxSortedField->insertItem( f + " ASC" );
 
126
}
 
127
 
 
128
void ReportWizard::reSortSortField()
 
129
{
 
130
    int i = listBoxSortedField->currentItem();
 
131
    if ( i != -1 )
 
132
    {
 
133
        QString text = listBoxSortedField->currentText();
 
134
        if ( text.mid( text.length() - 3 ) == "ASC" )
 
135
            text = text.mid( 0, text.length() - 3 ) + "DESC";
 
136
        else if ( text.mid( text.length() - 4 ) == "DESC" )
 
137
            text = text.mid( 0, text.length() - 4 ) + "ASC";
 
138
        listBoxSortedField->removeItem( i );
 
139
        listBoxSortedField->insertItem( text, i );
 
140
        listBoxSortedField->setCurrentItem( i );
 
141
    }
 
142
}
 
143
 
 
144
void ReportWizard::removeSortField()
 
145
{
 
146
    int i = listBoxSortedField->currentItem();
 
147
    if ( i != -1 )
 
148
    {
 
149
        listBoxSortedField->removeItem( i );
 
150
    }
 
151
}
 
152
 
 
153
void ReportWizard::sortFieldUp()
 
154
{
 
155
    if ( listBoxSortedField->currentItem() <= 0 ||
 
156
         listBoxSortedField->count() < 2 )
 
157
        return ;
 
158
    int index = listBoxSortedField->currentItem() - 1;
 
159
    QListBoxItem *i = listBoxSortedField->item( listBoxSortedField->currentItem() );
 
160
    listBoxSortedField->takeItem( i );
 
161
    listBoxSortedField->insertItem( i, index );
 
162
    listBoxSortedField->setCurrentItem( i );
 
163
}
 
164
 
 
165
void ReportWizard::sortFieldDown()
 
166
{
 
167
    if ( listBoxSortedField->currentItem() == -1 ||
 
168
         listBoxSortedField->currentItem() == ( int ) listBoxSortedField->count() - 1 ||
 
169
         listBoxSortedField->count() < 2 )
 
170
        return ;
 
171
    int index = listBoxSortedField->currentItem() + 1;
 
172
    QListBoxItem *i = listBoxSortedField->item( listBoxSortedField->currentItem() );
 
173
    listBoxSortedField->takeItem( i );
 
174
    listBoxSortedField->insertItem( i, index );
 
175
    listBoxSortedField->setCurrentItem( i );
 
176
}
 
177
 
 
178
void ReportWizard::enableAllSortPage( bool b )
 
179
{
 
180
    listBoxSortField->setEnabled( b );
 
181
    listBoxSortedField->setEnabled( b );
 
182
    buttonAddSortField->setEnabled( b );
 
183
    buttonRemoveSortField->setEnabled( b );
 
184
    buttonUpSortField->setEnabled( b );
 
185
    buttonDownSortField->setEnabled( b );
 
186
    buttonReSortField->setEnabled( b );
 
187
}
 
188
 
 
189
void ReportWizard::nextPageClicked()
 
190
{
 
191
    if ( currentPage() == reportPage )
 
192
    {
 
193
        setupReportPage();
 
194
        enableAllReportPage( true );
 
195
    }
 
196
    else if ( currentPage() == sortPage )
 
197
    {
 
198
        setupSortPage();
 
199
        enableAllSortPage( true );
 
200
    }
 
201
}
 
202
 
 
203
void ReportWizard::setupFirstPage()
 
204
{
 
205
    setNextEnabled( reportPage, true );
 
206
    setupReportPage();
 
207
    enableAllReportPage( true );
 
208
}
 
209
 
 
210
void ReportWizard::setupReportPage()
 
211
{
 
212
    listBoxTables->clear();
 
213
 
 
214
    QStringList str;
 
215
    DataTableList list = m_project->dataTablesInDataTableTree( m_parentTable );
 
216
    DataTableList::Iterator it = list.begin();
 
217
    for ( ; it != list.end(); ++it )
 
218
    {
 
219
        str.append( ( *it ) ->name() );
 
220
    }
 
221
 
 
222
    listBoxTables->insertStringList( str );
 
223
 
 
224
    editReport->blockSignals( true );
 
225
    editReport->setText( m_report->name() );
 
226
    editReport->blockSignals( false );
 
227
 
 
228
    comboSearch->insertItem( i18n("<Default Search>") );
 
229
    DataSearchList searchList = m_project->searchList();
 
230
    DataSearchList::Iterator it2 = searchList.begin();
 
231
    for ( ; it2 != searchList.end(); ++it2 )
 
232
    {
 
233
        comboSearch->insertItem( ( *it2 ).name() );
 
234
    }
 
235
 
 
236
    if ( m_configure )
 
237
    {
 
238
        kURLRequesterTemplate->setURL( m_report->templateURL() );
 
239
        buttonIcon->setPixmap( SmallIcon( m_report->iconName(), 32 ) );
 
240
 
 
241
        QStringList tables = m_report->tables();
 
242
        QStringList::Iterator names = tables.begin();
 
243
        for ( ; names != tables.end(); ++names )
 
244
        {
 
245
            QListBoxItem *item = listBoxTables->findItem( ( *names ) );
 
246
            listBoxTables->setSelected( item, true );
 
247
        }
 
248
 
 
249
        if ( m_report->dataSearch().isEmpty() )
 
250
            comboSearch->setCurrentText( i18n("<Default Search>") );
 
251
        else
 
252
            comboSearch->setCurrentText( m_report->dataSearch() );
 
253
    }
 
254
}
 
255
 
 
256
void ReportWizard::setupSortPage()
 
257
{
 
258
    listBoxSortField->clear();
 
259
    listBoxSortedField->clear();
 
260
 
 
261
    DataTableList list = m_project->dataTablesInDataTableTree( m_parentTable );
 
262
    DataTableList::Iterator it = list.begin();
 
263
    for ( ; it != list.end(); ++it )
 
264
    {
 
265
        QListBoxItem *item = listBoxTables->findItem( ( *it ) ->name() );
 
266
        if ( item->isSelected() )
 
267
        {
 
268
            DataFieldList fields = ( *it ) ->fieldList();
 
269
            DataFieldList::Iterator it2 = fields.begin();
 
270
            for ( ; it2 != fields.end(); ++it2 )
 
271
            {
 
272
                if ( !( *it2 ) ->hidden() && !( *it2 ) ->isVirtual() )
 
273
                    listBoxSortField->insertItem( ( *it )->alias() + "." + ( *it2 ) ->name() );
 
274
            }
 
275
        }
 
276
    }
 
277
 
 
278
    if ( m_configure )
 
279
    {
 
280
        listBoxSortedField->insertStringList( m_report->sort() );
 
281
    }
 
282
}
 
283
 
 
284
void ReportWizard::accept()
 
285
{
 
286
    m_report->clearTables();
 
287
    DataTableList list = m_project->dataTablesInDataTableTree( m_parentTable );
 
288
    DataTableList::Iterator it = list.begin();
 
289
    for ( ; it != list.end(); ++it )
 
290
    {
 
291
        QListBoxItem *item = listBoxTables->findItem( ( *it ) ->name() );
 
292
        if ( item->isSelected() )
 
293
            m_report->addTable( ( *it ) ->name() );
 
294
    }
 
295
 
 
296
    QStringList sort;
 
297
    QListBoxItem *item = listBoxSortedField->item( 0 );
 
298
    while ( item )
 
299
    {
 
300
        sort.append( item->text() );
 
301
        item = item->next();
 
302
    }
 
303
    m_report->setSort( sort );
 
304
 
 
305
    if ( comboSearch->currentText() == i18n("<Default Search>")  )
 
306
        m_report->setDataSearch( QString::null );
 
307
    else
 
308
        m_report->setDataSearch( comboSearch->currentText() );
 
309
 
 
310
    if ( !m_configure )
 
311
    {
 
312
        m_report->initialize();
 
313
        m_project->addDataReport( m_report );
 
314
    }
 
315
    else
 
316
        m_report->refreshReport();
 
317
 
 
318
    ReportWizardBase::accept();
 
319
}
 
320
 
 
321
#include "reportwizardbaseimpl.moc"