1
/***************************************************************************
2
* Copyright (C) 2005 by Adam Treat *
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. *
10
***************************************************************************/
12
#include "reportwizardbaseimpl.h"
15
#include "datareport.h"
16
#include "datatable.h"
17
#include "asciivalidator.h"
18
#include "databaseconnection.h"
21
#include <kmessagebox.h>
23
#include <kiconloader.h>
24
#include <klineedit.h>
26
#include <kpopupmenu.h>
29
#include <kinputdialog.h>
30
#include <kicondialog.h>
31
#include <kurlrequester.h>
35
#include <qcheckbox.h>
36
#include <qlineedit.h>
39
#include <qgroupbox.h>
42
#include <qpushbutton.h>
43
#include <qmultilineedit.h>
44
#include <qlistview.h>
45
#include <qfeatures.h>
46
#include <qradiobutton.h>
48
#include <qcombobox.h>
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>
59
ReportWizard::ReportWizard( Project *project, DataReport *report, DataTable *parentTable, bool configure )
60
: ReportWizardBase( report ),
63
m_parentTable( parentTable ),
64
m_configure( configure )
67
setMinimumSize( 800, 600 );
68
setCaption( i18n("Report Wizard") );
69
setFinishEnabled( sortPage, true );
71
wizard1->setPixmap( UserIcon( "wizard_table_1" ) );
72
wizard2->setPixmap( UserIcon( "wizard_table_2" ) );
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" ) );
81
listBoxTables->setSelectionMode( QListBox::Multi );
83
connect( nextButton(), SIGNAL( clicked() ), SLOT( nextPageClicked() ) );
88
ReportWizard::~ReportWizard()
91
/****************reportPage methods****************/
92
void ReportWizard::reportTemplateChanged( const QString &temp )
94
m_report->setTemplateURL( temp );
97
void ReportWizard::reportLabelChanged( const QString &label )
99
m_report->setName( m_project->uniqueDataTableName( label ) );
102
void ReportWizard::reportIconChanged()
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 );
109
void ReportWizard::enableAllReportPage( bool b )
111
listBoxTables->setEnabled( b );
112
kURLRequesterTemplate->setEnabled( b );
113
editReport->setEnabled( b );
114
buttonIcon->setEnabled( b );
117
/****************sortPage methods****************/
118
void ReportWizard::addSortField()
120
int i = listBoxSortField->currentItem();
123
QString f = listBoxSortField->currentText();
125
listBoxSortedField->insertItem( f + " ASC" );
128
void ReportWizard::reSortSortField()
130
int i = listBoxSortedField->currentItem();
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 );
144
void ReportWizard::removeSortField()
146
int i = listBoxSortedField->currentItem();
149
listBoxSortedField->removeItem( i );
153
void ReportWizard::sortFieldUp()
155
if ( listBoxSortedField->currentItem() <= 0 ||
156
listBoxSortedField->count() < 2 )
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 );
165
void ReportWizard::sortFieldDown()
167
if ( listBoxSortedField->currentItem() == -1 ||
168
listBoxSortedField->currentItem() == ( int ) listBoxSortedField->count() - 1 ||
169
listBoxSortedField->count() < 2 )
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 );
178
void ReportWizard::enableAllSortPage( bool b )
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 );
189
void ReportWizard::nextPageClicked()
191
if ( currentPage() == reportPage )
194
enableAllReportPage( true );
196
else if ( currentPage() == sortPage )
199
enableAllSortPage( true );
203
void ReportWizard::setupFirstPage()
205
setNextEnabled( reportPage, true );
207
enableAllReportPage( true );
210
void ReportWizard::setupReportPage()
212
listBoxTables->clear();
215
DataTableList list = m_project->dataTablesInDataTableTree( m_parentTable );
216
DataTableList::Iterator it = list.begin();
217
for ( ; it != list.end(); ++it )
219
str.append( ( *it ) ->name() );
222
listBoxTables->insertStringList( str );
224
editReport->blockSignals( true );
225
editReport->setText( m_report->name() );
226
editReport->blockSignals( false );
228
comboSearch->insertItem( i18n("<Default Search>") );
229
DataSearchList searchList = m_project->searchList();
230
DataSearchList::Iterator it2 = searchList.begin();
231
for ( ; it2 != searchList.end(); ++it2 )
233
comboSearch->insertItem( ( *it2 ).name() );
238
kURLRequesterTemplate->setURL( m_report->templateURL() );
239
buttonIcon->setPixmap( SmallIcon( m_report->iconName(), 32 ) );
241
QStringList tables = m_report->tables();
242
QStringList::Iterator names = tables.begin();
243
for ( ; names != tables.end(); ++names )
245
QListBoxItem *item = listBoxTables->findItem( ( *names ) );
246
listBoxTables->setSelected( item, true );
249
if ( m_report->dataSearch().isEmpty() )
250
comboSearch->setCurrentText( i18n("<Default Search>") );
252
comboSearch->setCurrentText( m_report->dataSearch() );
256
void ReportWizard::setupSortPage()
258
listBoxSortField->clear();
259
listBoxSortedField->clear();
261
DataTableList list = m_project->dataTablesInDataTableTree( m_parentTable );
262
DataTableList::Iterator it = list.begin();
263
for ( ; it != list.end(); ++it )
265
QListBoxItem *item = listBoxTables->findItem( ( *it ) ->name() );
266
if ( item->isSelected() )
268
DataFieldList fields = ( *it ) ->fieldList();
269
DataFieldList::Iterator it2 = fields.begin();
270
for ( ; it2 != fields.end(); ++it2 )
272
if ( !( *it2 ) ->hidden() && !( *it2 ) ->isVirtual() )
273
listBoxSortField->insertItem( ( *it )->alias() + "." + ( *it2 ) ->name() );
280
listBoxSortedField->insertStringList( m_report->sort() );
284
void ReportWizard::accept()
286
m_report->clearTables();
287
DataTableList list = m_project->dataTablesInDataTableTree( m_parentTable );
288
DataTableList::Iterator it = list.begin();
289
for ( ; it != list.end(); ++it )
291
QListBoxItem *item = listBoxTables->findItem( ( *it ) ->name() );
292
if ( item->isSelected() )
293
m_report->addTable( ( *it ) ->name() );
297
QListBoxItem *item = listBoxSortedField->item( 0 );
300
sort.append( item->text() );
303
m_report->setSort( sort );
305
if ( comboSearch->currentText() == i18n("<Default Search>") )
306
m_report->setDataSearch( QString::null );
308
m_report->setDataSearch( comboSearch->currentText() );
312
m_report->initialize();
313
m_project->addDataReport( m_report );
316
m_report->refreshReport();
318
ReportWizardBase::accept();
321
#include "reportwizardbaseimpl.moc"