summaryrefslogtreecommitdiffstats
path: root/kchart/kchart_part.h
blob: 2eb4a75fb9a189ccebea26f54f7cac43571bb44e (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
/**
 * Kalle Dalheimer <kalle@kde.org>
 */

#ifndef KCHART_PART_H
#define KCHART_PART_H


#include <tdeconfig.h>

#include <koChart.h>
#include "kchart_params.h"
#include "koffice_export.h"

class KoXmlWriter;
class KoGenStyles;
namespace KChart
{

class KChartParams;


class KCHART_EXPORT KChartPart : public KoChart::Part
{
    Q_OBJECT
  

public:
    KChartPart( TQWidget *parentWidget = 0, const char *widgetName = 0,
		TQObject* parent = 0, const char* name = 0,
		bool singleViewMode = false );
    ~KChartPart();

    // Methods inherited from KoDocument:

    virtual bool  initDoc(InitDocFlags flags, TQWidget* parentWidget=0);

    virtual void  paintContent( TQPainter& painter, const TQRect& rect,
				bool transparent = false,
				double zoomX = 1.0, double zoomY = 1.0 );

    // Methods unique to KChart, and available in the new interface
    // (see ../interfaces/koChart.h.)

    virtual void  resizeData( int rows, int columns );
    virtual void  setCellData( int row, int column, const TQVariant &);
    virtual void  analyzeHeaders( );
    virtual void  setCanChangeValue( bool b )  { m_bCanChangeValue = b;    }

    // ----------------------------------------------------------------

    void  analyzeHeaders( const KDChartTableData& data );
    void  doSetData( const KDChartTableData&  data,
		     bool  firstColHeader,
		     bool  firstRowHeader );

    bool showWizard( TQString &dataArea );
    void initLabelAndLegend();
    void loadConfig(TDEConfig *conf);
    void saveConfig(TDEConfig *conf);
    void defaultConfig();

    KChartParams::ChartType  chartType() const { return (KChartParams::ChartType) params()->chartType(); }
    KDChartTableData  *data()                  { return &m_currentData; }
    KChartParams      *params() const          { return m_params;       }

    TQStringList       &rowLabelTexts()         { return m_rowLabels;  }
    TQStringList       &colLabelTexts()         { return m_colLabels;  }

    // Save and load
    virtual TQDomDocument  saveXML();
    virtual bool          loadXML( TQIODevice *, const TQDomDocument& doc );
    virtual bool          loadOasis( const TQDomDocument& doc,
				     KoOasisStyles& oasisStyles,
				     const TQDomDocument& settings,
				     KoStore *store );
    virtual bool          saveOasis( KoStore* store,
                                     KoXmlWriter* manifestWriter );

    bool  canChangeValue()   const             { return m_bCanChangeValue; }

    void  initNullChart();

    // Functions that generate templates (not used yet):
    void  generateBarChartTemplate();

    virtual bool showEmbedInitDialog(TQWidget* parent);

public slots:
    void  slotModified();
    virtual void initEmpty();

signals:
    void docChanged();

protected:
    virtual KoView* createViewInstance( TQWidget* parent, const char* name );
    bool  loadOldXML( const TQDomDocument& doc );
    bool  loadAuxiliary( const TQDomDocument& doc );
    bool  loadData( const TQDomDocument& doc, KDChartTableData& currentData );
    bool  loadOasisData( const TQDomElement& tableElem );
    void  saveOasisData( KoXmlWriter* bodyWriter, KoGenStyles& mainStyles ) const;
    void writeAutomaticStyles( KoXmlWriter& contentWriter, KoGenStyles& mainStyles ) const;

private:
    // Helper methods for painting.
    int          createDisplayData();
    void         createLabelsAndLegend( TQStringList  &longLabels,
					TQStringList  &shortLabels );


    TQDomElement  createElement(const TQString &tagName,
			       const TQFont &font,
			       TQDomDocument &doc) const;
    TQFont        toFont(TQDomElement &element)     const;

    void         setChartDefaults();

private:
    // The chart and its contents
    KChartParams            *m_params;      // Everything about the chart
    KDChartTableData         m_currentData; // The data in the chart.
    TQStringList              m_rowLabels;
    TQStringList              m_colLabels;
    //TQString                  m_regionName;

    // Other auxiliary values
    bool                     m_bCanChangeValue;

    // Graphics
    TQWidget                 *m_parentWidget;

    // Used when displaying.
    KDChartTableData         m_displayData;

    TQPixmap                  m_bufferPixmap;
};


class WizardExt : public KoChart::WizardExtension
{
public:
    WizardExt( KoChart::Part *part )
        : KoChart::WizardExtension( part ) {};

    virtual bool show( TQString &dataArea ) {
        return static_cast<KChartPart *>( part() )->showWizard( dataArea );
    }
};

}  //KChart namespace

#endif