summaryrefslogtreecommitdiffstats
path: root/kchart/kchartWizard.cpp
blob: 01e5bf456287e34219476bd64d13e606a49acad1 (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

#include "kchartWizard.h"
#include "kchartWizardSelectDataPage.h"
#include "kchartWizardSelectChartTypePage.h"
#include "kchartWizardSelectChartSubTypePage.h"
#include "kchartWizardSetupDataPage.h"
#include "kchartWizardLabelsLegendPage.h"
#include "kchartWizardSetupAxesPage.h"
#include "kchartWizardSelectDataFormatPage.h"

#include <tqlineedit.h>
#include <tqwidget.h>
#include <tqpushbutton.h>

#include <tdeglobal.h>
#include <kiconloader.h>
#include <kdebug.h>

#include "kchart_params.h"

namespace KChart
{

KChartWizard::KChartWizard ( KChartPart* _chart, TQWidget *parent, const char* name,
                             bool modal, WFlags f ) :
    KWizard( parent, name, modal, f ),
    m_chart( _chart )
{
    // First page: select the data range
    m_dataFormatPage = new KChartWizardSelectDataFormatPage(this, m_chart);
    addPage( m_dataFormatPage, i18n("Data"));
    setFinishEnabled(m_dataFormatPage, true);
    setHelpEnabled(m_dataFormatPage, false);
    
    // Second page: select the major chart type
    m_chartTypePage = new KChartWizardSelectChartTypePage( this, m_chart );
    addPage( m_chartTypePage, i18n( "Select Chart Type" ) );
    //finishButton()->setEnabled( TRUE );
    setFinishEnabled(m_chartTypePage, true);
    setHelpEnabled(m_chartTypePage, false);

    // Third page: select the minor chart type
    m_chartSubtypePage = new KChartWizardSelectChartSubTypePage( this, m_chart );
    addPage( m_chartSubtypePage, i18n( "Select Chart Sub-type" ) );
    setFinishEnabled(m_chartSubtypePage, true);
    setHelpEnabled(m_chartSubtypePage, false);

    // Fourth page: labels/legends setup
    m_labelsLegendPage = new KChartWizardLabelsLegendPage( this, m_chart );
    addPage( m_labelsLegendPage, i18n( "Labels & Legend" ) );
    setFinishEnabled(m_labelsLegendPage, true);
    setHelpEnabled(m_labelsLegendPage, false);

    // Fifth page: axes setup
    m_axespage = new KChartWizardSetupAxesPage( this, m_chart );
    addPage( m_axespage, i18n( "Setup Axes" ) );
    setFinishEnabled(m_axespage, true);
    setNextEnabled(m_axespage, false);
    setHelpEnabled(m_axespage, false);

    // connect( this, TQT_SIGNAL( finished() ), _selectdatapage, TQT_SLOT( apply() ) );
    connect(this, TQT_SIGNAL(finished()), m_dataFormatPage,   TQT_SLOT(apply()));
    connect(this, TQT_SIGNAL(finished()), m_chartTypePage,    TQT_SLOT(apply()));
    connect(this ,TQT_SIGNAL(finished()), m_chartSubtypePage, TQT_SLOT(apply()));
    connect(this, TQT_SIGNAL(finished()), m_labelsLegendPage, TQT_SLOT(apply()));
    connect(this, TQT_SIGNAL(finished()), m_axespage,         TQT_SLOT(apply()));

    connect( m_chartTypePage, TQT_SIGNAL( chartChange( int ) ),
             this,            TQT_SLOT( subType( int ) ) );
    adjustSize();

    subType( m_chart->params()->chartType() );
    kdDebug(35001) << "kchartwizard created" << endl;
}


KChartWizard::~KChartWizard()
{
    //  delete _selectdatapage;
    delete m_chartTypePage;
    delete m_chartSubtypePage;
    //delete _setupdatapage;
    delete m_labelsLegendPage;
    delete m_axespage;
    delete m_dataFormatPage;
}

void KChartWizard::subType(int _type)
{
    KChartParams::ChartType  type = (KChartParams::ChartType) _type;
    if (type == KChartParams::Bar ||
        type == KChartParams::Line ||
        type == KChartParams::Area ||
        type == KChartParams::HiLo ||
        type == KChartParams::Polar) {
        m_chartSubtypePage->chartSubType = true;
    } else {
        m_chartSubtypePage->chartSubType = false;
    }
    m_chartSubtypePage->changeSubTypeName( type );
    if( ( type == KChartParams::Bar && m_chart->params()->threeDBars() ) 
	|| ( type == KChartParams::Pie && m_chart->params()->threeDPies() ) ) {
	m_axespage->chart3d = true;
    } else {
        m_axespage->chart3d = false;
    }

#if 0				// No second Y axis so far /ingwa
    if ( m_chart->params()->axisVisible( KDChartAxisParams::AxisPosRight ) ) {
        m_labelsLegendPage->ytitle2 = true;
    } else {
        m_labelsLegendPage->ytitle2 = false;
    }
#endif
}


bool KChartWizard::appropriate( TQWidget * w ) const
{
    // Show the sub-type page only if has anything to show
    if ( w == m_chartSubtypePage )
        return m_chartSubtypePage->chartSubType;
    else
        return true;
}


void KChartWizard::next()
{
    // Some sort of a hack. We want the chart-subtype-page to get
    // dynamically built when it's going to be shown
    //if ( currentPage() == _charttypePage )
    //_chartSubtypePage->createChildren();

    TQWizard::next();
}

void KChartWizard::accept()
{
    emit finished();
    TQWizard::accept();
}

void KChartWizard::reject()
{
    emit cancelled();
    TQWizard::reject();
}

void KChartWizard::setDataArea( const TQString &dataArea )
{
    m_dataFormatPage->setDataArea( dataArea );
}


TQString KChartWizard::dataArea() const
{
    return m_dataFormatPage->dataArea();
}


void KChartWizard::emitNeedNewData( const char* area, int rowcol,
				    bool firstRowIsLegend,
				    bool firstColIsLabel )
{
    emit needNewData( area, rowcol, firstRowIsLegend, firstColIsLabel );
}

}  //KChart namespace

#include "kchartWizard.moc"