Logo Search packages:      
Sourcecode: scidavis version File versions  Download package


    File                 : Matrix.h
    Project              : SciDAVis
    Description          : Matrix worksheet class
    Copyright            : (C) 2006-2009 Tilman Benkert (thzs*gmx.net)
    Copyright            : (C) 2006-2009 Knut Franke (knut.franke*gmx.de)
    Copyright            : (C) 2006-2007 Ion Vasilief (ion_vasilief*yahoo.fr)
                           (replace * with @ in the email addresses) 


 *                                                                         *
 *  This program is free software; you can redistribute it and/or modify   *
 *  it under the terms of the GNU General Public License as published by   *
 *  the Free Software Foundation; either version 2 of the License, or      *
 *  (at your option) any later version.                                    *
 *                                                                         *
 *  This program is distributed in the hope that it will be useful,        *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *  GNU General Public License for more details.                           *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the Free Software           *
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 *   Boston, MA  02110-1301  USA                                           *
 *                                                                         *
#ifndef MATRIX_H
#define MATRIX_H

#include <QTableWidget>
#include <QContextMenuEvent>
#include <QEvent>
#include <QHeaderView>
#include <QDateTime>
#include "MyWidget.h"
#include "ScriptingEnv.h"
#include "Script.h"
#include <qwt_double_rect.h>
#include "future/matrix/future_Matrix.h"
#include "future/matrix/MatrixView.h"

// (maximum) initial matrix size
#define _Matrix_initial_rows_ 10
#define _Matrix_initial_columns_ 3

//! Matrix worksheet class
00051 class Matrix: public MatrixView, public scripted

      future::Matrix *d_future_matrix;

      //! Return the window name
00059       virtual QString name() { return d_future_matrix->name();} 
      //! Set the window name
00061       virtual void setName(const QString& s) { d_future_matrix->setName(s); }
      //! Return the window label
00063       virtual QString windowLabel() { return d_future_matrix->comment(); }
      //! Set the window label
00065       virtual void setWindowLabel(const QString& s) { d_future_matrix->setComment(s); updateCaption(); }
      //! Set the caption policy
00067       void setCaptionPolicy(CaptionPolicy policy) 
            caption_policy = policy; updateCaption(); 
            switch (policy)
                  case Name:
                  case Label:
                  case Both:
                        d_future_matrix->setCaptionSpec("%n%C{ - }%c");
      //! Set the creation date
00084       virtual void setBirthDate(const QString& s)
            birthdate = s;

       * \brief Constructor
       * \param env scripting interpreter
       * \param r initial number of rows
       * \param c initial number of columns
       * \param label window label
       * \param parent parent object
       * \param name
       * \param name window name
       * \param f window flags
      Matrix(ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);

      //! Return the number of rows
      int numRows();
      void setNumRows(int rows);

      //! Return the number of columns
      int numCols();
      void setNumCols(int cols);

      //event handlers
      //! Custom event handler
       * Currently handles SCRIPTING_CHANGE_EVENT only.
      void customEvent(QEvent *e);
      void closeEvent( QCloseEvent *);

      void updateDecimalSeparators();

      virtual QWidget *view() {return d_future_matrix->view(); }

public slots:
      void exportPDF(const QString& fileName);
      //! Print the Matrix
      void print();
      //! Print the Matrix to fileName
      void print(const QString& fileName);
      void handleChange();

      //! Set the width of all columns (obsolete, only for OPJ import)
       * Don't uses this. Use view()->setColumnWidth(column, width) instead.
      void setColumnsWidth(int width);

      //! Set the Matrix size
      void setDimensions(int rows, int cols);
      //! Transpose the matrix
      void transpose();
      //! Invert the matrix
      void invert();
      //! Calculate the determinant of the matrix
      double determinant();

      //! Calculate matrix values using the formula for all selected cells
      bool recalculate();

      //! Return the content of the cell as a string
      QString text(int row, int col);
      //! Set the content of the cell as a string
      void setText(int row, int col, const QString & new_text );
      //! Return the value of the cell as a double
      double cell(int row, int col);
      //! Set the value of the cell
      void setCell(int row, int col, double value );

       * \brief Return the text format code ('e', 'f', ...)
       * \sa setNumerFormat(), setTextFormat()
00166       QChar textFormat() {return d_future_matrix->numericFormat();};
       * \brief Return the number precision digits
       * See arguments of setNumericFormat().
       * \sa setNumericFormat(), setTextFormat()
00173       int precision() {return d_future_matrix->displayedDigits();};
       * \brief Set the number of significant digits
       * \sa precision(), setNumericFormat(), setTextFormat()
00179       void setNumericPrecision(int prec) { d_future_matrix->setDisplayedDigits(prec);};

       * \brief Set the number format for the cells
       * This method should only be called before any user
       * interaction was done. Use setTextFormat() if you
       * want to change it from a dialog.
       * \sa setTextFormat()
      void setTextFormat(const QChar &format, int precision);
        \brief Set the number format for the cells

        You must call saveCellsToMemory() before and
        forgetSavedCells() after calling this!
        Format character and precision have the same meaning as for
        \param f format character 'e', 'f', 'g'
        \param prec
        - for 'e', 'f': the number of digits after the radix character (point)
        - for 'g': the maximum number of significant digits

        \sa saveCellsToMemory(), forgetSavedCells(), dMatrix
      void setNumericFormat(const QChar & f, int prec);

      //! Return the matrix formula
      QString formula();
      //! Set the matrix forumla
      void setFormula(const QString &s);

      //! Format the matrix format in a string to save it in a template file
      QString saveAsTemplate(const QString &info);

      //! Return a string to save the matrix in a project file (<matrix> section)
      QString saveToString(const QString &info);
      //! Return a string conaining the data of the matrix (<data> section)
      QString saveText();

      // selection operations
      //! Standard cut operation
      void cutSelection();
      //! Standard copy operation
      void copySelection();
      //! Clear cells
      void clearSelection();
      //! Standard paste operation
      void pasteSelection();

      //! Insert a row before the current cell
      void insertRow();
      //! Return whether any rows are fully selected
      bool rowsSelected();
      //! Delete the selected rows
      void deleteSelectedRows();
      //! Return the number of selected rows
      int numSelectedRows();

      //! Insert a column before the current cell
      void insertColumn();
      //! Return whether any columns are fully selected
      bool columnsSelected();
      //! Delte the selected columns
      void deleteSelectedColumns();
      //! Return the number of selected columns
      int numSelectedColumns();

       * \brief Temporally save the cell values to memory
       * \sa setNumericFormat(), forgetSavedCells(), dMatrix
      void saveCellsToMemory();
       * \ brief Free memory of saved cells
       * \sa setNumericFormat(), saveCellsToMemory(), dMatrix
      void forgetSavedCells();

      //! Return the X value corresponding to column 1
00261       double xStart(){return d_future_matrix->xStart();};
      //! Return the X value corresponding to the last column
00263       double xEnd(){return d_future_matrix->xEnd();};
      //! Return the Y value corresponding to row 1
00265       double yStart(){return d_future_matrix->yStart();};
      //! Return the Y value corresponding to the last row
00267       double yEnd(){return d_future_matrix->yEnd();};

      //! Returns the bounding rect of the matrix coordinates
00270       QwtDoubleRect boundingRect() {return QwtDoubleRect(xStart(), yStart(), xEnd()-xStart(), yEnd()-yStart()).normalized();};
      //! Set the X and Y coordinate intervals
      void setCoordinates(double xs, double xe, double ys, double ye);

       //! Min and max values of the matrix.
      void range(double *min, double *max);

      //! Allocate memory for a matrix buffer
      static double** allocateMatrixData(int rows, int columns);
      //! Free memory used for a matrix buffer
      static void freeMatrixData(double **data, int rows);

      static Matrix * fromImage(const QImage & image, ScriptingEnv * env);
    void copy(Matrix *m);
      //! Return the creation date
00286       virtual QString birthDate(){return d_future_matrix->creationTime().toString(Qt::LocalDate); };

      //! Show the context menu
      void showContextMenu();

protected slots:
    void applyFormula();
      void addFunction();
      void addCell();
      void updateFunctionDoc();
      void handleAspectDescriptionChange(const AbstractAspect *aspect);

      //! Initialize the matrix
      void init(int rows, int cols);

      //! Stores the matrix data only before the user opens the matrix dialog in order to avoid data loses during number format changes.
00304       double **dMatrix;

      Matrix(future::Matrix *future_matrix, ScriptingEnv *env, int r, int c, const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);


Generated by  Doxygen 1.6.0   Back to index