kchart

kchartDataEditor.h
1#ifndef KCHART_DATA_EDITOR_H
2#define KCHART_DATA_EDITOR_H
3
4
5#include <tqstrlist.h>
6#include <tqspinbox.h>
7
8#include <kdialogbase.h>
9
10#include "kchart_part.h"
11
12class TQLabel;
13class TQSpinBox;
14class TQCheckBox;
15
16
17namespace KChart
18{
19
20
21class KChartParams;
22
23
24// This class inherits TQSpinBox, but fixes a problem with it.
25// Consider the following case:
26//
27// 1. The SpinBox for rows has the value 4.
28// 2. The user enters the number 2 into it.
29// 3. The user presses the little up arrow in the spinbox.
30// 4. valueChanged(2) is emitted and 2 rows are removed.
31// 5. valueChanged(3) is emitted and 1 row is added.
32//
33// Now (at least) one row is removed that was never meant to be
34// removed and data is lost. This class fixes that by changing the
35// semantics. So instead of the behaviour of above, the
36// valueChanged(2) is never emitted and instead of valueChanged(3),
37// valueChanged(5) is emitted.
38//
39
40
41class kchartDataSpinBox : public TQSpinBox
42{
43 TQ_OBJECT
44
45public:
46 kchartDataSpinBox(TQWidget *);
47 ~kchartDataSpinBox();
48
49public slots:
50 // The user pressed the Up-button
51 void stepUp();
52 // The user pressed the Down-button
53 void stepDown();
54
55protected:
56 void interpretText(){;};
57 bool eventFilter( TQObject *obj, TQEvent *ev );
58
59signals:
60 // the value is changed (stepUp/stepDown was called or the focus is lost)
61 void valueChangedSpecial(int);
62
63private:
64 // True if we should ignore the next value change (see above).
65 bool m_ignore;
66};
67
68// ----------------------------------------------------------------
69
70
71// The reason for having a special Table class is to implement
72// keyboard navigation in editing mode.
73//
74
75class kchartDataTable : public TQTable
76{
77 TQ_OBJECT
78
79public:
80 kchartDataTable(TQWidget *);
81 ~kchartDataTable();
82
83protected:
84 // handles keyboard navigation
85 bool eventFilter( TQObject *obj, TQEvent *ev );
86};
87
88
89// ----------------------------------------------------------------
90
91
92class kchartDataEditor : public KDialogBase
93{
94 TQ_OBJECT
95
96public:
97 kchartDataEditor(TQWidget* parent = 0);
98 void setData(KChartParams *params, KDChartTableData *dat);
99 void getData(KChartParams *params, KDChartTableData *dat);
100 void setRowLabels(const TQStringList &rowLabels);
101 void getRowLabels(TQStringList &rowLabels);
102 void setColLabels(const TQStringList &colLabels);
103 void getColLabels(TQStringList &colLabels);
104
105 bool modified() const { return m_modified; }
106
107protected:
112 int headerRows();
117 int headerCols();
118
123 void updateRowHeaders();
124
129 void updateColHeaders();
130
131private:
132 void addDocs();
133
134signals:
135 void applyClicked(kchartDataEditor *ed);
136
137private slots:
138 void slotApply();
139
141 void removeCurrentRow();
143 void removeCurrentColumn();
145 void insertRow();
147 void insertColumn();
148
149 void setRows(int rows);
150 void setCols(int cols);
151
152 // Called when something changes in the table.
153 void tableChanged(int row, int col);
154
155 // Called when the current cell is changed
156 void currentChanged(int row, int col);
157
158private:
159 // Widgets in the editor
160 kchartDataTable *m_table;
161
162 TQPushButton *m_insertRowButton;
163 TQPushButton *m_insertColButton;
164 TQPushButton *m_removeRowButton;
165 TQPushButton *m_removeColButton;
166
167 TQLabel *m_rowsLA;
168 kchartDataSpinBox *m_rowsSB;
169 TQLabel *m_colsLA;
170 kchartDataSpinBox *m_colsSB;
171 TQCheckBox *m_firstRowAsLabel;
172 TQCheckBox *m_firstColAsLabel;
173
174 // This member is set to true if the user shrinks the data table,
175 // and confirms this by clicking OK in a warning dialog.
176 bool m_userWantsToShrink;
177
178 bool m_modified;
179};
180
181} //KChart namespace
182
183#endif