kchart

kchartDataEditor.h

00001 #ifndef KCHART_DATA_EDITOR_H
00002 #define KCHART_DATA_EDITOR_H
00003 
00004 
00005 #include <qstrlist.h>
00006 #include <qspinbox.h>
00007 
00008 #include <kdialogbase.h>
00009 
00010 #include "kchart_part.h"
00011 
00012 class QLabel;
00013 class QSpinBox;
00014 class QCheckBox;
00015 
00016 
00017 namespace KChart
00018 {
00019 
00020 
00021 class KChartParams;
00022 
00023 
00024 // This class inherits QSpinBox, but fixes a problem with it.
00025 // Consider the following case:
00026 //
00027 // 1. The SpinBox for rows has the value 4.
00028 // 2. The user enters the number 2 into it.
00029 // 3. The user presses the little up arrow in the spinbox.
00030 // 4. valueChanged(2) is emitted and 2 rows are removed.
00031 // 5. valueChanged(3) is emitted and 1 row is added.
00032 // 
00033 // Now (at least) one row is removed that was never meant to be
00034 // removed and data is lost.  This class fixes that by changing the
00035 // semantics.  So instead of the behaviour of above, the
00036 // valueChanged(2) is never emitted and instead of valueChanged(3),
00037 // valueChanged(5) is emitted.
00038 //
00039 
00040 
00041 class kchartDataSpinBox : public QSpinBox
00042 {
00043     Q_OBJECT
00044 public:
00045     kchartDataSpinBox(QWidget *);
00046     ~kchartDataSpinBox();
00047 
00048 public slots:
00049     // The user pressed the Up-button
00050     void stepUp();
00051     // The user pressed the Down-button
00052     void stepDown();
00053 
00054 protected:
00055     void interpretText(){;};
00056     bool eventFilter( QObject *obj, QEvent *ev );
00057 
00058 signals:
00059     // the value is changed (stepUp/stepDown was called or the focus is lost)
00060     void valueChangedSpecial(int);
00061 
00062 private:
00063     // True if we should ignore the next value change (see above).
00064     bool  m_ignore;
00065 };
00066 
00067 // ----------------------------------------------------------------
00068 
00069 
00070 // The reason for having a special Table class is to implement
00071 // keyboard navigation in editing mode.
00072 //
00073 
00074 class kchartDataTable : public QTable
00075 {
00076     Q_OBJECT
00077 public:
00078     kchartDataTable(QWidget *);
00079     ~kchartDataTable();
00080 
00081 protected:
00082     // handles keyboard navigation
00083     bool eventFilter( QObject *obj, QEvent *ev );
00084 };
00085 
00086 
00087 // ----------------------------------------------------------------
00088 
00089 
00090 class kchartDataEditor : public KDialogBase
00091 {
00092     Q_OBJECT
00093 public:
00094     kchartDataEditor(QWidget* parent = 0);
00095     void setData(KChartParams *params, KDChartTableData *dat);
00096     void getData(KChartParams *params, KDChartTableData *dat);
00097     void setRowLabels(const QStringList &rowLabels);
00098     void getRowLabels(QStringList &rowLabels);
00099     void setColLabels(const QStringList &colLabels);
00100     void getColLabels(QStringList &colLabels);
00101 
00102     bool modified() const { return m_modified; }
00103 
00104 protected:
00109     int headerRows();
00114     int headerCols();
00115 
00120     void updateRowHeaders();
00121 
00126     void updateColHeaders();
00127 
00128 private:
00129     void  addDocs();
00130 
00131 signals:
00132     void applyClicked(kchartDataEditor *ed);
00133 
00134 private slots:
00135     void  slotApply();
00136     
00138     void  removeCurrentRow();   
00140     void  removeCurrentColumn();
00142     void  insertRow();
00144     void  insertColumn();
00145     
00146     void  setRows(int rows);
00147     void  setCols(int cols);
00148 
00149     // Called when something changes in the table.
00150     void  tableChanged(int row, int col);
00151 
00152 
00153 private:
00154     // Widgets in the editor
00155     kchartDataTable    *m_table;
00156     QLabel             *m_rowsLA;
00157     kchartDataSpinBox  *m_rowsSB;
00158     QLabel             *m_colsLA;
00159     kchartDataSpinBox  *m_colsSB;
00160     QCheckBox          *m_firstRowAsLabel;
00161     QCheckBox          *m_firstColAsLabel;
00162 
00163     // This member is set to true if the user shrinks the data table,
00164     // and confirms this by clicking OK in a warning dialog.
00165     bool  m_userWantsToShrink;
00166 
00167     bool  m_modified;
00168 };
00169 
00170 }  //KChart namespace
00171 
00172 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys