File indexing completed on 2024-05-12 15:27:41
0001 /*************************************************************************** 0002 File : SpreadsheetView.h 0003 Project : LabPlot 0004 Description : View class for Spreadsheet 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2010-2020 by Alexander Semke (alexander.semke@web.de) 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 0029 #ifndef SPREADSHEETVIEW_H 0030 #define SPREADSHEETVIEW_H 0031 0032 #include <QWidget> 0033 0034 #include "backend/core/AbstractColumn.h" 0035 #include "backend/lib/IntervalAttribute.h" 0036 0037 class AbstractAspect; 0038 class Column; 0039 class Spreadsheet; 0040 class SpreadsheetItemDelegate; 0041 class SpreadsheetHeaderView; 0042 class SpreadsheetModel; 0043 0044 class QActionGroup; 0045 class QItemSelection; 0046 class QMenu; 0047 class QPrinter; 0048 class QModelIndex; 0049 class QTableView; 0050 class QToolBar; 0051 0052 #ifdef Q_OS_MAC 0053 class KDMacTouchBar; 0054 #endif 0055 0056 class SpreadsheetView : public QWidget { 0057 Q_OBJECT 0058 0059 friend class SpreadsheetTest; 0060 0061 public: 0062 explicit SpreadsheetView(Spreadsheet* spreadsheet, bool readOnly = false); 0063 ~SpreadsheetView() override; 0064 0065 void resizeHeader(); 0066 0067 void showComments(bool on = true); 0068 bool areCommentsShown() const; 0069 0070 int selectedColumnCount(bool full = false) const; 0071 int selectedColumnCount(AbstractColumn::PlotDesignation) const; 0072 bool isColumnSelected(int col, bool full = false) const; 0073 QVector<Column*> selectedColumns(bool full = false) const; 0074 int firstSelectedColumn(bool full = false) const; 0075 int lastSelectedColumn(bool full = false) const; 0076 0077 bool isRowSelected(int row, bool full = false) const; 0078 int firstSelectedRow(bool full = false) const; 0079 int lastSelectedRow(bool full = false) const; 0080 IntervalAttribute<bool> selectedRows(bool full = false) const; 0081 0082 bool isCellSelected(int row, int col) const; 0083 void setCellSelected(int row, int col, bool select = true); 0084 void setCellsSelected(int first_row, int first_col, int last_row, int last_col, bool select = true); 0085 void getCurrentCell(int* row, int* col) const; 0086 0087 bool exportView(); 0088 bool printView(); 0089 bool printPreview(); 0090 0091 private: 0092 void init(); 0093 void initActions(); 0094 void initMenus(); 0095 void connectActions(); 0096 bool formulaModeActive() const; 0097 void exportToFile(const QString&, const bool, const QString&, QLocale::Language) const; 0098 void exportToLaTeX(const QString&, const bool exportHeaders, 0099 const bool gridLines, const bool captions, const bool latexHeaders, 0100 const bool skipEmptyRows,const bool exportEntire) const; 0101 void exportToFits(const QString& path, const int exportTo, const bool commentsAsUnits) const; 0102 void exportToSQLite(const QString& path) const; 0103 int maxRowToExport() const; 0104 0105 void insertColumnsLeft(int); 0106 void insertColumnsRight(int); 0107 0108 void insertRowsAbove(int); 0109 void insertRowsBelow(int); 0110 0111 QTableView* m_tableView; 0112 bool m_editorEntered{false}; 0113 Spreadsheet* m_spreadsheet; 0114 SpreadsheetItemDelegate* m_delegate; 0115 SpreadsheetModel* m_model; 0116 SpreadsheetHeaderView* m_horizontalHeader; 0117 bool m_suppressSelectionChangedEvent{false}; 0118 bool m_readOnly; 0119 bool eventFilter(QObject*, QEvent*) override; 0120 void checkSpreadsheetMenu(); 0121 void checkSpreadsheetSelectionMenu(); 0122 void checkColumnMenus(bool numeric, bool datetime, bool hasValues); 0123 0124 //selection related actions 0125 QAction* action_cut_selection; 0126 QAction* action_copy_selection; 0127 QAction* action_paste_into_selection; 0128 QAction* action_mask_selection; 0129 QAction* action_unmask_selection; 0130 QAction* action_clear_selection; 0131 // QAction* action_set_formula; 0132 // QAction* action_recalculate; 0133 QAction* action_fill_row_numbers; 0134 QAction* action_fill_random; 0135 QAction* action_fill_equidistant; 0136 QAction* action_fill_random_nonuniform; 0137 QAction* action_fill_const; 0138 QAction* action_fill_function; 0139 0140 //spreadsheet related actions 0141 QAction* action_toggle_comments; 0142 QAction* action_select_all; 0143 QAction* action_clear_spreadsheet; 0144 QAction* action_clear_masks; 0145 QAction* action_sort_spreadsheet; 0146 QAction* action_go_to_cell; 0147 QAction* action_statistics_all_columns; 0148 0149 //column related actions 0150 QAction* action_insert_column_left; 0151 QAction* action_insert_column_right; 0152 QAction* action_insert_columns_left; 0153 QAction* action_insert_columns_right; 0154 QAction* action_remove_columns; 0155 QAction* action_clear_columns; 0156 QAction* action_add_columns; 0157 QAction* action_set_as_none; 0158 QAction* action_set_as_x; 0159 QAction* action_set_as_y; 0160 QAction* action_set_as_z; 0161 QAction* action_set_as_xerr; 0162 QAction* action_set_as_xerr_plus; 0163 QAction* action_set_as_xerr_minus; 0164 QAction* action_set_as_yerr; 0165 QAction* action_set_as_yerr_plus; 0166 QAction* action_set_as_yerr_minus; 0167 QAction* action_reverse_columns; 0168 QAction* action_add_value; 0169 QAction* action_subtract_value; 0170 QAction* action_multiply_value; 0171 QAction* action_divide_value; 0172 QAction* action_drop_values; 0173 QAction* action_mask_values; 0174 QAction* action_join_columns; 0175 QActionGroup* normalizeColumnActionGroup; 0176 QActionGroup* ladderOfPowersActionGroup; 0177 QAction* action_sort_columns; 0178 QAction* action_sort_asc_column; 0179 QAction* action_sort_desc_column; 0180 QAction* action_statistics_columns; 0181 0182 //row related actions 0183 QAction* action_insert_row_above; 0184 QAction* action_insert_row_below; 0185 QAction* action_insert_rows_above; 0186 QAction* action_insert_rows_below; 0187 QAction* action_remove_rows; 0188 QAction* action_clear_rows; 0189 QAction* action_statistics_rows; 0190 0191 //analysis and plot data menu actions 0192 QAction* action_plot_data_xycurve; 0193 QAction* action_plot_data_histogram; 0194 QAction* addDataOperationAction; 0195 QAction* addDataReductionAction; 0196 QAction* addDifferentiationAction; 0197 QAction* addIntegrationAction; 0198 QAction* addInterpolationAction; 0199 QAction* addSmoothAction; 0200 QVector<QAction*> addFitAction; 0201 QAction* addFourierFilterAction; 0202 0203 //Menus 0204 QMenu* m_selectionMenu{nullptr};; 0205 QMenu* m_columnMenu{nullptr};; 0206 QMenu* m_columnSetAsMenu{nullptr}; 0207 QMenu* m_columnGenerateDataMenu{nullptr}; 0208 QMenu* m_columnManipulateDataMenu; 0209 QMenu* m_columnNormalizeMenu{nullptr}; 0210 QMenu* m_columnLadderOfPowersMenu{nullptr}; 0211 QMenu* m_columnSortMenu{nullptr}; 0212 QMenu* m_rowMenu{nullptr};; 0213 QMenu* m_spreadsheetMenu{nullptr};; 0214 QMenu* m_plotDataMenu{nullptr};; 0215 QMenu* m_analyzePlotMenu{nullptr};; 0216 0217 public slots: 0218 void createContextMenu(QMenu*); 0219 void fillToolBar(QToolBar*); 0220 #ifdef Q_OS_MAC 0221 void fillTouchBar(KDMacTouchBar*); 0222 #endif 0223 void print(QPrinter*) const; 0224 0225 private slots: 0226 void createColumnContextMenu(QMenu*); 0227 void goToCell(int row, int col); 0228 void toggleComments(); 0229 void goToNextColumn(); 0230 void goToPreviousColumn(); 0231 void goToCell(); 0232 void sortSpreadsheet(); 0233 void sortDialog(const QVector<Column*>&); 0234 0235 void cutSelection(); 0236 void copySelection(); 0237 void clearSelectedCells(); 0238 void maskSelection(); 0239 void unmaskSelection(); 0240 void pasteIntoSelection(); 0241 // void recalculateSelectedCells(); 0242 0243 void plotData(); 0244 0245 void fillSelectedCellsWithRowNumbers(); 0246 void fillWithRowNumbers(); 0247 void fillSelectedCellsWithRandomNumbers(); 0248 void fillWithRandomValues(); 0249 void fillWithEquidistantValues(); 0250 void fillWithFunctionValues(); 0251 void fillSelectedCellsWithConstValues(); 0252 0253 void insertRowAbove(); 0254 void insertRowBelow(); 0255 void insertRowsAbove(); 0256 void insertRowsBelow(); 0257 void removeSelectedRows(); 0258 void clearSelectedRows(); 0259 0260 void insertColumnLeft(); 0261 void insertColumnRight(); 0262 void insertColumnsLeft(); 0263 void insertColumnsRight(); 0264 void removeSelectedColumns(); 0265 void clearSelectedColumns(); 0266 0267 void modifyValues(); 0268 void reverseColumns(); 0269 void dropColumnValues(); 0270 void maskColumnValues(); 0271 // void joinColumns(); 0272 void normalizeSelectedColumns(QAction*); 0273 void powerTransformSelectedColumns(QAction*); 0274 0275 void sortSelectedColumns(); 0276 void sortColumnAscending(); 0277 void sortColumnDescending(); 0278 0279 void setSelectionAs(); 0280 0281 void activateFormulaMode(bool on); 0282 0283 void showColumnStatistics(bool forAll = false); 0284 void showAllColumnsStatistics(); 0285 void showRowStatistics(); 0286 0287 void handleHorizontalSectionResized(int logicalIndex, int oldSize, int newSize); 0288 void handleHorizontalSectionMoved(int index, int from, int to); 0289 void handleHorizontalHeaderDoubleClicked(int index); 0290 void handleHeaderDataChanged(Qt::Orientation orientation, int first, int last); 0291 void currentColumnChanged(const QModelIndex& current, const QModelIndex & previous); 0292 void handleAspectAdded(const AbstractAspect*); 0293 void handleAspectAboutToBeRemoved(const AbstractAspect*); 0294 void updateHeaderGeometry(Qt::Orientation o, int first, int last); 0295 0296 void selectColumn(int); 0297 void deselectColumn(int); 0298 void columnClicked(int); 0299 void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); 0300 void advanceCell(); 0301 }; 0302 0303 #endif