File indexing completed on 2024-05-12 15:27:38

0001 /***************************************************************************
0002     File                 : MatrixView.cpp
0003     Project              : LabPlot
0004     Description          : View class for Matrix
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2015-2019 Alexander Semke (alexander.semke@web.de)
0007     Copyright            : (C) 2008-2009 Tilman Benkert (thzs@gmx.net)
0008 
0009  ***************************************************************************/
0010 
0011 /***************************************************************************
0012  *                                                                         *
0013  *  This program is free software; you can redistribute it and/or modify   *
0014  *  it under the terms of the GNU General Public License as published by   *
0015  *  the Free Software Foundation; either version 2 of the License, or      *
0016  *  (at your option) any later version.                                    *
0017  *                                                                         *
0018  *  This program is distributed in the hope that it will be useful,        *
0019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0021  *  GNU General Public License for more details.                           *
0022  *                                                                         *
0023  *   You should have received a copy of the GNU General Public License     *
0024  *   along with this program; if not, write to the Free Software           *
0025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0026  *   Boston, MA  02110-1301  USA                                           *
0027  *                                                                         *
0028  ***************************************************************************/
0029 
0030 #ifndef MATRIXVIEW_H
0031 #define MATRIXVIEW_H
0032 
0033 #include <QWidget>
0034 #include <QList>
0035 #include <QShortcut>
0036 #include "backend/datasources/filters/FITSFilter.h"
0037 #include "kdefrontend/widgets/FITSHeaderEditWidget.h"
0038 
0039 class Matrix;
0040 class MatrixModel;
0041 
0042 class QPrinter;
0043 class QAction;
0044 class QLabel;
0045 class QMenu;
0046 class QStackedWidget;
0047 class QTableView;
0048 
0049 class MatrixView : public QWidget {
0050     Q_OBJECT
0051 
0052 public:
0053     explicit MatrixView(Matrix*);
0054     ~MatrixView() override;
0055 
0056     MatrixModel* model() const;
0057 
0058     int selectedColumnCount(bool full = false) const;
0059     bool isColumnSelected(int col, bool full = false) const;
0060     int selectedRowCount(bool full = false) const;
0061     bool isRowSelected(int row, bool full = false) const;
0062     int firstSelectedColumn(bool full = false) const;
0063     int lastSelectedColumn(bool full = false) const;
0064     int firstSelectedRow(bool full = false) const;
0065     int lastSelectedRow(bool full = false) const;
0066     bool isCellSelected(int row, int col) const;
0067     void setCellSelected(int row, int col);
0068     void setCellsSelected(int first_row, int first_col, int last_row, int last_col);
0069     void getCurrentCell(int* row, int* col) const;
0070 
0071     void resizeHeaders();
0072     void adjustHeaders();
0073     void exportToFile(const QString& path, const QString& separator, QLocale::Language) const;
0074     void exportToLaTeX(const QString&, const bool verticalHeaders, const bool horizontalHeaders,
0075                            const bool latexHeaders, const bool gridLines,
0076                            const bool entire, const bool captions) const;
0077     void exportToFits(const QString& fileName, const int exportTo) const;
0078 
0079 public slots:
0080     void createContextMenu(QMenu*) const;
0081     void print(QPrinter*) const;
0082 
0083 private:
0084     void init();
0085     void initActions();
0086     void initMenus();
0087     void connectActions();
0088     void goToCell(int row, int col);
0089     void updateImage();
0090 
0091     bool eventFilter(QObject*, QEvent*) override;
0092     void keyPressEvent(QKeyEvent*) override;
0093 
0094     QStackedWidget* m_stackedWidget;
0095     QTableView* m_tableView;
0096     QLabel* m_imageLabel;
0097     Matrix* m_matrix;
0098     MatrixModel* m_model;
0099     QImage m_image;
0100     bool m_imageIsDirty{true};
0101 
0102     //Actions
0103     QAction* action_cut_selection;
0104     QAction* action_copy_selection;
0105     QAction* action_paste_into_selection;
0106     QAction* action_clear_selection;
0107 
0108     QAction* action_select_all;
0109     QAction* action_clear_matrix;
0110     QAction* action_go_to_cell;
0111     QAction* action_set_formula;
0112     QAction* action_recalculate;
0113     QAction* action_duplicate;
0114     QAction* action_transpose;
0115     QAction* action_mirror_vertically;
0116     QAction* action_mirror_horizontally;
0117 
0118     QAction* action_add_value;
0119     QAction* action_subtract_value;
0120     QAction* action_multiply_value;
0121     QAction* action_divide_value;
0122 
0123     QAction* action_header_format_1;
0124     QAction* action_header_format_2;
0125     QAction* action_header_format_3;
0126 
0127     QAction* action_insert_columns;
0128     QAction* action_remove_columns;
0129     QAction* action_clear_columns;
0130     QAction* action_add_columns;
0131     QAction* action_statistics_columns;
0132 
0133     QAction* action_insert_rows;
0134     QAction* action_remove_rows;
0135     QAction* action_clear_rows;
0136     QAction* action_add_rows;
0137     QAction* action_statistics_rows;
0138 
0139     QAction* action_data_view;
0140     QAction* action_image_view;
0141     QAction* action_fill_function;
0142     QAction* action_fill_const;
0143 
0144     //Menus
0145     QMenu* m_selectionMenu;
0146     QMenu* m_columnMenu;
0147     QMenu* m_rowMenu;
0148     QMenu* m_matrixMenu;
0149     QMenu* m_headerFormatMenu;
0150 
0151     QShortcut* sel_all;
0152 
0153 private slots:
0154     void goToCell();
0155     void advanceCell();
0156     void handleHorizontalSectionResized(int logicalIndex, int oldSize, int newSize);
0157     void handleVerticalSectionResized(int logicalIndex, int oldSize, int newSize);
0158 
0159     void switchView(QAction*);
0160     void matrixDataChanged();
0161 
0162     void fillWithFunctionValues();
0163     void fillWithConstValues();
0164 
0165     void cutSelection();
0166     void copySelection();
0167     void pasteIntoSelection();
0168     void clearSelectedCells();
0169 
0170     void headerFormatChanged(QAction*);
0171 
0172     void modifyValues();
0173 
0174     void addColumns();
0175     void insertEmptyColumns();
0176     void removeSelectedColumns();
0177     void clearSelectedColumns();
0178     void addRows();
0179     void insertEmptyRows();
0180     void removeSelectedRows();
0181     void clearSelectedRows();
0182 
0183     void showColumnStatistics();
0184     void showRowStatistics();
0185 };
0186 
0187 #endif