~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/Matrix.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2008-04-04 15:11:55 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080404151155-rjp12ziov4tryj0o
Tags: 0.9.4-1
* New upstream release.
* Refresh patches.
* Remove 04_homepage_url patch. Merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <QHeaderView>
36
36
#include <QTableView>
37
37
#include <QPrinter>
38
 
#include "MyWidget.h"
 
38
#include <QMessageBox>
 
39
 
 
40
#include "MatrixModel.h"
 
41
#include "MdiSubWindow.h"
39
42
#include "ScriptingEnv.h"
40
43
#include "Script.h"
 
44
 
41
45
#include <qwt_double_rect.h>
42
46
#include <qwt_color_map.h>
43
47
 
47
51
#define _Matrix_initial_rows_ 10
48
52
#define _Matrix_initial_columns_ 3
49
53
 
50
 
class MatrixModel;
51
54
class QLabel;
52
55
class QStackedWidget;
53
56
class QShortcut;
 
57
class QUndoStack;
54
58
 
55
59
//! Matrix worksheet class
56
 
class Matrix: public MyWidget, public scripted
 
60
class Matrix: public MdiSubWindow, public scripted
57
61
{
58
62
    Q_OBJECT
59
63
 
71
75
         * \param name window name
72
76
         * \param f window flags
73
77
         */
74
 
        Matrix(ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent=0, const QString& name = QString(), Qt::WFlags f=0);
75
 
    Matrix(ScriptingEnv *env, const QImage& image, const QString& label, QWidget* parent=0, const QString& name = QString(), Qt::WFlags f=0);
76
 
 
 
78
        Matrix(ScriptingEnv *env, int r, int c, const QString& label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
 
79
    Matrix(ScriptingEnv *env, const QImage& image, const QString& label, ApplicationWindow* parent, const QString& name = QString(), Qt::WFlags f=0);
 
80
    ~Matrix();
 
81
 
 
82
        enum Operation{Transpose, Invert, FlipHorizontally, FlipVertically, RotateClockwise,
 
83
                                  RotateCounterClockwise, FFT, Clear, Calculate, MuParserCalculate, SetImage, ImportAscii};
77
84
    enum HeaderViewType{ColumnRow, XY};
78
85
        enum ViewType{TableView, ImageView};
79
86
        enum ColorMapType{GrayScale, Rainbow, Custom};
 
87
        enum ImportMode {
 
88
                NewColumns, //!< add file as new columns to the current matrix
 
89
                NewRows, //!< add file as new rows to the current matrix
 
90
                Overwrite //!< replace content of current matrix with the imported file
 
91
        };
80
92
 
81
 
        void setViewType(ViewType);
 
93
        void setViewType(ViewType, bool renderImage = true);
82
94
        ViewType viewType(){return d_view_type;};
83
95
 
84
96
    HeaderViewType headerViewType(){return d_header_view_type;};
85
97
    void setHeaderViewType(HeaderViewType type);
86
98
 
87
99
        QImage image();
88
 
        void setImage(const QImage& image);
 
100
        void displayImage(const QImage& image);
89
101
        void importImage(const QString& fn);
90
102
        void exportRasterImage(const QString& fileName, int quality = 100);
91
103
        void exportSVG(const QString& fileName);
92
104
        void exportToFile(const QString& fileName);
93
105
        void exportVector(const QString& fileName, int res = 0, bool color = true, bool keepAspect = true, QPrinter::PageSize pageSize = QPrinter::Custom);
94
106
 
95
 
        MatrixModel * matrixModel(){return d_matrix_model;};
 
107
        MatrixModel * matrixModel(){return d_matrix_model;};
 
108
    QUndoStack *undoStack(){return d_undo_stack;};
 
109
 
96
110
        QItemSelectionModel * selectionModel(){return d_table_view->selectionModel();};
97
111
 
98
112
        //! Return the number of rows
99
 
        int numRows();
100
 
        void setNumRows(int rows);
 
113
        int numRows(){return d_matrix_model->rowCount();};
 
114
        void setNumRows(int rows){d_matrix_model->setRowCount(rows);};
101
115
 
102
116
        //! Return the number of columns
103
 
        int numCols();
104
 
        void setNumCols(int cols);
 
117
        int numCols(){return d_matrix_model->columnCount();};
 
118
        void setNumCols(int cols){d_matrix_model->setColumnCount(cols);};
105
119
 
106
120
        //event handlers
107
 
        /*!
108
 
         * \brief Event filter
109
 
         *
110
 
         * Currently only reacts to events of the
111
 
         * title bar.
112
 
         */
113
 
        bool eventFilter(QObject *object, QEvent *e);
114
 
        //! Context menu event handler
115
 
        void contextMenuEvent(QContextMenuEvent *e);
116
121
        //! Custom event handler
117
122
        /**
118
123
         * Currently handles SCRIPTING_CHANGE_EVENT only.
124
129
 
125
130
        void flipVertically();
126
131
        void flipHorizontally();
127
 
        void rotate90(bool clockwise = true);
128
 
 
129
 
#ifdef QTIPLOT_PRO
 
132
        void rotate90(bool clockwise = true);
130
133
    void fft(bool inverse = false);
131
 
#endif
132
134
 
133
135
    ColorMapType colorMapType(){return d_color_map_type;};
134
136
        void setColorMapType(ColorMapType mapType);
139
141
        void setColorMap(const QStringList& lst);
140
142
 
141
143
        void setGrayScale();
142
 
        void setRainbowColorMap();
 
144
        void setRainbowColorMap();
 
145
        //! Calculate the volume integral
 
146
        double integrate();
 
147
        //! Calculate the determinant of the matrix
 
148
        double determinant();
 
149
        //! Transpose the matrix
 
150
        void transpose();
 
151
        //! Invert the matrix
 
152
        void invert();
 
153
 
 
154
        //! Calculate matrix values using the #formula_str.
 
155
        bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1, bool forceMuParser = true);
 
156
        //! Calculate matrix values using the #formula_str (optimization for muParser).
 
157
        bool muParserCalculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
 
158
 
 
159
        bool exportASCII(const QString& fname, const QString& separator, bool exportSelection);
 
160
        void importASCII(const QString &fname, const QString &sep, int ignoredLines, bool stripSpaces,
 
161
                                        bool simplifySpaces, const QString& commentString, ImportMode importAs = Overwrite,
 
162
                                        const QLocale& l = QLocale(), int endLineChar = 0, int maxRows = -1);
143
163
 
144
164
public slots:
145
165
        void exportPDF(const QString& fileName);
155
175
 
156
176
        //! Set the Matrix size
157
177
        void setDimensions(int rows, int cols);
158
 
        //! Transpose the matrix
159
 
        void transpose();
160
 
        //! Invert the matrix
161
 
        void invert();
162
 
        //! Calculate the determinant of the matrix
163
 
        double determinant();
164
 
 
165
 
        //! Calculate matrix values using the #formula_str
166
 
        bool calculate(int startRow = 0, int endRow = -1, int startCol = 0, int endCol = -1);
167
178
 
168
179
        //! Return the content of the cell as a string
169
180
        QString text(int row, int col);
265
276
        void range(double *min, double *max);
266
277
 
267
278
        //! Scroll to row (row starts with 1)
268
 
        void goToRow(int row);
 
279
        void goToRow(int row);
 
280
        //! Scroll to column (column starts with 1)
 
281
        void goToColumn(int col);
269
282
 
270
283
        //! Allocate memory for a matrix buffer
271
284
        static double** allocateMatrixData(int rows, int columns);
275
288
        int verticalHeaderWidth(){return d_table_view->verticalHeader()->width();}
276
289
 
277
290
    void copy(Matrix *m);
278
 
 
279
 
signals:
280
 
        //! Show the context menu
281
 
        void showContextMenu();
 
291
        //! Tries to allocate memory for the workspace. Returns a NULL pointer if failure.
 
292
        double *initWorkspace(int size);
 
293
        void freeWorkspace(){free(d_workspace); d_workspace = NULL;};
 
294
        
 
295
        bool canCalculate(bool useMuParser = true);
282
296
 
283
297
private:
284
298
        //! Initialize the matrix
287
301
        void initImageView();
288
302
        void initTableView();
289
303
    void initGlobals();
 
304
        bool ignoreUndo();
290
305
 
291
306
    QStackedWidget *d_stack;
292
307
    MatrixModel *d_matrix_model;
309
324
        ViewType d_view_type;
310
325
        //! Keeps track of the header view type;
311
326
        HeaderViewType d_header_view_type;
312
 
 
313
 
        QwtLinearColorMap d_color_map;
 
327
        //! The color map used to display images.
 
328
        QwtLinearColorMap d_color_map;
 
329
        //! The color map type.
314
330
        ColorMapType d_color_map_type;
315
 
 
316
331
        //! Column width in pixels;
317
332
        int d_column_width;
318
 
 
319
 
        QShortcut *d_select_all_shortcut;
 
333
        QShortcut *d_select_all_shortcut;
 
334
    //! Undo/Redo commands stack
 
335
        QUndoStack *d_undo_stack;
 
336
        //! Pointer to a data buffer used for matrix operations.
 
337
        double *d_workspace;
320
338
};
321
339
 
322
340
#endif