File indexing completed on 2024-05-12 03:48:26

0001 /*
0002     File                 : MatrixView.cpp
0003     Project              : LabPlot
0004     Description          : View class for Matrix
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2015-2021 Alexander Semke <alexander.semke@web.de>
0007     SPDX-FileCopyrightText: 2008-2009 Tilman Benkert <thzs@gmx.net>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef MATRIXVIEW_H
0012 #define MATRIXVIEW_H
0013 
0014 #include <QLocale>
0015 #include <QWidget>
0016 
0017 class Matrix;
0018 class MatrixModel;
0019 
0020 class QPrinter;
0021 class QAction;
0022 class QLabel;
0023 class QMenu;
0024 class QStackedWidget;
0025 class QTableView;
0026 
0027 class MatrixView : public QWidget {
0028     Q_OBJECT
0029 
0030 public:
0031     explicit MatrixView(Matrix*);
0032     ~MatrixView() override;
0033 
0034     MatrixModel* model() const;
0035 
0036     int selectedColumnCount(bool full = false) const;
0037     bool isColumnSelected(int col, bool full = false) const;
0038     int selectedRowCount(bool full = false) const;
0039     bool isRowSelected(int row, bool full = false) const;
0040     int firstSelectedColumn(bool full = false) const;
0041     int lastSelectedColumn(bool full = false) const;
0042     int firstSelectedRow(bool full = false) const;
0043     int lastSelectedRow(bool full = false) const;
0044     bool isCellSelected(int row, int col) const;
0045     void setCellSelected(int row, int col);
0046     void setCellsSelected(int first_row, int first_col, int last_row, int last_col);
0047     void getCurrentCell(int* row, int* col) const;
0048 
0049     void resizeHeaders();
0050     void adjustHeaders();
0051     void exportToFile(const QString& path, const QString& separator, QLocale::Language) const;
0052     void exportToLaTeX(const QString&,
0053                        const bool verticalHeaders,
0054                        const bool horizontalHeaders,
0055                        const bool latexHeaders,
0056                        const bool gridLines,
0057                        const bool entire,
0058                        const bool captions) const;
0059     void exportToFits(const QString& fileName, const int exportTo) const;
0060 
0061 public Q_SLOTS:
0062     void createContextMenu(QMenu*);
0063     void print(QPrinter*) const;
0064 
0065 private:
0066     void init();
0067     void initActions();
0068     void initMenus();
0069     void goToCell(int row, int col);
0070     void updateImage();
0071 
0072     bool eventFilter(QObject*, QEvent*) override;
0073     void keyPressEvent(QKeyEvent*) override;
0074     void wheelEvent(QWheelEvent*) override;
0075 
0076     QStackedWidget* m_stackedWidget;
0077     QTableView* m_tableView;
0078     QLabel* m_imageLabel;
0079     Matrix* m_matrix;
0080     MatrixModel* m_model;
0081     QImage m_image;
0082     bool m_imageIsDirty{true};
0083     double m_zoomFactor{1.};
0084 
0085     // Actions
0086     QAction* action_cut_selection;
0087     QAction* action_copy_selection;
0088     QAction* action_paste_into_selection;
0089     QAction* action_clear_selection;
0090 
0091     QAction* action_select_all;
0092     QAction* action_clear_matrix;
0093     QAction* action_go_to_cell;
0094     QAction* action_set_formula;
0095     QAction* action_recalculate;
0096     QAction* action_duplicate;
0097     QAction* action_transpose;
0098     QAction* action_mirror_vertically;
0099     QAction* action_mirror_horizontally;
0100 
0101     QAction* action_add_value;
0102     QAction* action_subtract_value;
0103     QAction* action_multiply_value;
0104     QAction* action_divide_value;
0105 
0106     QAction* action_header_format_1;
0107     QAction* action_header_format_2;
0108     QAction* action_header_format_3;
0109 
0110     QAction* action_insert_columns;
0111     QAction* action_remove_columns;
0112     QAction* action_clear_columns;
0113     QAction* action_add_columns;
0114     QAction* action_statistics_columns;
0115 
0116     QAction* action_insert_rows;
0117     QAction* action_remove_rows;
0118     QAction* action_clear_rows;
0119     QAction* action_add_rows;
0120     QAction* action_statistics_rows;
0121 
0122     QAction* action_data_view;
0123     QAction* action_image_view;
0124     QAction* action_fill_function;
0125     QAction* action_fill_const;
0126 
0127     QAction* zoomInAction{nullptr};
0128     QAction* zoomOutAction{nullptr};
0129     QAction* zoomOriginAction{nullptr};
0130 
0131     // Menus
0132     QMenu* m_selectionMenu{nullptr};
0133     QMenu* m_columnMenu{nullptr};
0134     QMenu* m_rowMenu{nullptr};
0135     QMenu* m_headerFormatMenu{nullptr};
0136     QMenu* m_generateDataMenu{nullptr};
0137     QMenu* m_manipulateDataMenu{nullptr};
0138     QMenu* m_viewMenu{nullptr};
0139     QMenu* m_zoomMenu{nullptr};
0140 
0141 private Q_SLOTS:
0142     void goToCell();
0143     void advanceCell();
0144     void handleHorizontalSectionResized(int logicalIndex, int oldSize, int newSize);
0145     void handleVerticalSectionResized(int logicalIndex, int oldSize, int newSize);
0146 
0147     void switchView(QAction*);
0148     void matrixDataChanged();
0149 
0150     void fillWithFunctionValues();
0151     void fillWithConstValues();
0152 
0153     void cutSelection();
0154     void copySelection();
0155     void pasteIntoSelection();
0156     void clearSelectedCells();
0157 
0158     void headerFormatChanged(QAction*);
0159 
0160     void modifyValues();
0161 
0162     void addColumns();
0163     void insertEmptyColumns();
0164     void removeSelectedColumns();
0165     void clearSelectedColumns();
0166     void addRows();
0167     void insertEmptyRows();
0168     void removeSelectedRows();
0169     void clearSelectedRows();
0170 
0171     void showColumnStatistics();
0172     void showRowStatistics();
0173 
0174     void changeZoom(QAction*);
0175 };
0176 
0177 #endif