File indexing completed on 2024-05-12 03:48:29
0001 /* 0002 File : SpreadsheetView.h 0003 Project : LabPlot 0004 Description : View class for Spreadsheet 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2010-2023 Alexander Semke <alexander.semke@web.de> 0007 SPDX-FileCopyrightText: 2023 Stefan Gerlach <stefan.gerlach@uni.kn> 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #ifndef SPREADSHEETVIEW_H 0012 #define SPREADSHEETVIEW_H 0013 0014 #include <QWidget> 0015 0016 #include "backend/core/AbstractColumn.h" 0017 #include "backend/lib/IntervalAttribute.h" 0018 #include <QLocale> 0019 0020 class AbstractAspect; 0021 class Column; 0022 class SearchReplaceWidget; 0023 class Spreadsheet; 0024 class SpreadsheetHeaderView; 0025 class SpreadsheetModel; 0026 0027 class QActionGroup; 0028 class QFrame; 0029 class QItemSelection; 0030 class QItemSelectionModel; 0031 class QLineEdit; 0032 class QMenu; 0033 class QPrinter; 0034 class QModelIndex; 0035 class QResizeEvent; 0036 class QTableView; 0037 class QToolBar; 0038 0039 #ifdef HAVE_TOUCHBAR 0040 class KDMacTouchBar; 0041 #endif 0042 0043 class SpreadsheetView : public QWidget { 0044 Q_OBJECT 0045 0046 friend class SpreadsheetTest; 0047 0048 public: 0049 explicit SpreadsheetView(Spreadsheet*, bool readOnly = false); 0050 ~SpreadsheetView() override; 0051 0052 void resizeHeader(); 0053 void setFocus(); 0054 0055 void showComments(bool on = true); 0056 bool areCommentsShown() const; 0057 0058 int selectedColumnCount(bool full = true) const; 0059 int selectedColumnCount(AbstractColumn::PlotDesignation) const; 0060 bool isColumnSelected(int col, bool full = false) const; 0061 QVector<Column*> selectedColumns(bool full = true) const; 0062 int firstSelectedColumn(bool full = false) const; 0063 int lastSelectedColumn(bool full = false) const; 0064 0065 int selectedRowCount(bool full = true) const; 0066 bool isRowSelected(int row, bool full = false) const; 0067 int firstSelectedRow(bool full = false) const; 0068 int lastSelectedRow(bool full = false) const; 0069 IntervalAttribute<bool> selectedRows(bool full = false) const; 0070 bool isCellSelected(int row, int col) const; 0071 void setCellSelected(int row, int col, bool select = true); 0072 void setCellsSelected(int first_row, int first_col, int last_row, int last_col, bool select = true); 0073 void getCurrentCell(int* row, int* col) const; 0074 0075 bool exportView(); 0076 bool printView(); 0077 bool printPreview(); 0078 0079 protected: 0080 void resizeEvent(QResizeEvent*) override; 0081 0082 private: 0083 void init(); 0084 void initActions(); 0085 void initMenus(); 0086 void connectActions(); 0087 bool formulaModeActive() const; 0088 void exportToFile(const QString&, bool, const QString&, QLocale::Language) const; 0089 void exportToLaTeX(const QString&, bool exportHeaders, bool gridLines, bool captions, bool latexHeaders, bool skipEmptyRows, bool exportEntire) const; 0090 void exportToFits(const QString& path, int exportTo, bool commentsAsUnits) const; 0091 void exportToXLSX(const QString& path, bool exportHeaders) const; 0092 void exportToSQLite(const QString& path) const; 0093 int maxRowToExport() const; 0094 bool hasValues(const QVector<Column*>); 0095 0096 void insertColumnsLeft(int); 0097 void insertColumnsRight(int); 0098 0099 void insertRowsAbove(int); 0100 void insertRowsBelow(int); 0101 0102 void updateFrozenTableGeometry(); 0103 0104 QItemSelectionModel* selectionModel(); 0105 0106 QTableView* m_tableView{nullptr}; 0107 QTableView* m_frozenTableView{nullptr}; 0108 bool m_editorEntered{false}; 0109 Spreadsheet* m_spreadsheet; 0110 SpreadsheetModel* m_model; 0111 SpreadsheetHeaderView* m_horizontalHeader; 0112 SearchReplaceWidget* m_searchReplaceWidget{nullptr}; 0113 bool m_suppressSelectionChangedEvent{false}; 0114 bool m_readOnly; 0115 bool eventFilter(QObject*, QEvent*) override; 0116 void checkSpreadsheetMenu(); 0117 void checkSpreadsheetSelectionMenu(); 0118 void checkColumnMenus(const QVector<Column*>&); 0119 void showSearchReplace(bool replace); 0120 0121 // selection related actions 0122 QAction* action_cut_selection{nullptr}; 0123 QAction* action_copy_selection{nullptr}; 0124 QAction* action_paste_into_selection{nullptr}; 0125 QAction* action_mask_selection{nullptr}; 0126 QAction* action_unmask_selection{nullptr}; 0127 QAction* action_clear_selection{nullptr}; 0128 // QAction* action_set_formula; 0129 // QAction* action_recalculate; 0130 QAction* action_fill_row_numbers{nullptr}; 0131 QAction* action_fill_random{nullptr}; 0132 QAction* action_fill_equidistant{nullptr}; 0133 QAction* action_fill_random_nonuniform{nullptr}; 0134 QAction* action_fill_const{nullptr}; 0135 QAction* action_fill_function{nullptr}; 0136 0137 // spreadsheet related actions 0138 QAction* action_toggle_comments{nullptr}; 0139 QAction* action_select_all{nullptr}; 0140 QAction* action_clear_spreadsheet{nullptr}; 0141 QAction* action_clear_masks{nullptr}; 0142 QAction* action_formatting_heatmap{nullptr}; 0143 QAction* action_formatting_remove{nullptr}; 0144 QAction* action_go_to_cell{nullptr}; 0145 QAction* action_search{nullptr}; 0146 QAction* action_search_replace{nullptr}; 0147 QAction* action_statistics_all_columns{nullptr}; 0148 QAction* action_statistics_spreadsheet{nullptr}; 0149 0150 // column related actions 0151 QAction* action_insert_column_left{nullptr}; 0152 QAction* action_insert_column_right{nullptr}; 0153 QAction* action_insert_columns_left{nullptr}; 0154 QAction* action_insert_columns_right{nullptr}; 0155 QAction* action_remove_columns{nullptr}; 0156 QAction* action_clear_columns{nullptr}; 0157 QAction* action_add_columns{nullptr}; 0158 QAction* action_set_as_none{nullptr}; 0159 QAction* action_set_as_x{nullptr}; 0160 QAction* action_set_as_y{nullptr}; 0161 QAction* action_set_as_z{nullptr}; 0162 QAction* action_set_as_xerr{nullptr}; 0163 QAction* action_set_as_xerr_plus{nullptr}; 0164 QAction* action_set_as_xerr_minus{nullptr}; 0165 QAction* action_set_as_yerr{nullptr}; 0166 QAction* action_set_as_yerr_plus{nullptr}; 0167 QAction* action_set_as_yerr_minus{nullptr}; 0168 QAction* action_reverse_columns{nullptr}; 0169 QAction* action_add_value{nullptr}; 0170 QAction* action_subtract_value{nullptr}; 0171 QAction* action_subtract_baseline{nullptr}; 0172 QAction* action_multiply_value{nullptr}; 0173 QAction* action_divide_value{nullptr}; 0174 QAction* action_drop_values{nullptr}; 0175 QAction* action_mask_values{nullptr}; 0176 QAction* action_sample_values{nullptr}; 0177 QAction* action_flatten_columns{nullptr}; 0178 QAction* action_join_columns{nullptr}; 0179 QActionGroup* normalizeColumnActionGroup{nullptr}; 0180 QActionGroup* ladderOfPowersActionGroup{nullptr}; 0181 QAction* action_sort{nullptr}; 0182 QAction* action_sort_asc{nullptr}; 0183 QAction* action_sort_desc{nullptr}; 0184 QAction* action_statistics_columns{nullptr}; 0185 QAction* action_freeze_columns{nullptr}; 0186 0187 // row related actions 0188 QAction* action_insert_row_above{nullptr}; 0189 QAction* action_insert_row_below{nullptr}; 0190 QAction* action_insert_rows_above{nullptr}; 0191 QAction* action_insert_rows_below{nullptr}; 0192 QAction* action_remove_rows{nullptr}; 0193 QAction* action_remove_missing_value_rows{nullptr}; 0194 QAction* action_mask_missing_value_rows{nullptr}; 0195 QAction* action_statistics_rows{nullptr}; 0196 0197 // analysis and plot data menu actions 0198 QActionGroup* plotDataActionGroup{nullptr}; 0199 QAction* addDataOperationAction{nullptr}; 0200 QAction* addDataReductionAction{nullptr}; 0201 QAction* addDifferentiationAction{nullptr}; 0202 QAction* addIntegrationAction{nullptr}; 0203 QAction* addInterpolationAction{nullptr}; 0204 QAction* addSmoothAction{nullptr}; 0205 QVector<QAction*> addFitAction; 0206 QAction* addFourierFilterAction{nullptr}; 0207 0208 // Menus 0209 QMenu* m_selectionMenu{nullptr}; 0210 QMenu* m_formattingMenu{nullptr}; 0211 QMenu* m_columnMenu{nullptr}; 0212 QMenu* m_columnSetAsMenu{nullptr}; 0213 QMenu* m_columnGenerateDataMenu{nullptr}; 0214 QMenu* m_columnManipulateDataMenu{nullptr}; 0215 QMenu* m_columnNormalizeMenu{nullptr}; 0216 QMenu* m_columnLadderOfPowersMenu{nullptr}; 0217 QMenu* m_rowMenu{nullptr}; 0218 QMenu* m_spreadsheetMenu{nullptr}; 0219 QMenu* m_plotDataMenu{nullptr}; 0220 QMenu* m_analyzePlotMenu{nullptr}; 0221 0222 bool m_suppressResize{false}; 0223 0224 public Q_SLOTS: 0225 void handleAspectsAdded(int first, int last); 0226 void createContextMenu(QMenu*); 0227 void fillColumnContextMenu(QMenu*, Column*); 0228 void fillToolBar(QToolBar*); 0229 #ifdef HAVE_TOUCHBAR 0230 void fillTouchBar(KDMacTouchBar*); 0231 #endif 0232 void print(QPrinter*) const; 0233 0234 void pasteIntoSelection(); 0235 0236 void fillWithRowNumbers(); 0237 void selectColumn(int); 0238 void deselectColumn(int); 0239 void goToCell(int row, int col); 0240 void selectCell(int row, int col); 0241 void clearSelection(); 0242 0243 private Q_SLOTS: 0244 void searchReplace(); 0245 void toggleComments(); 0246 void goToNextColumn(); 0247 void goToPreviousColumn(); 0248 void goToCell(); 0249 void formatHeatmap(); 0250 void removeFormat(); 0251 0252 void cutSelection(); 0253 void copySelection(); 0254 void clearSelectedCells(); 0255 void maskSelection(); 0256 void unmaskSelection(); 0257 // void recalculateSelectedCells(); 0258 0259 void plotData(QAction*); 0260 void plotAnalysisData(); 0261 0262 void fillSelectedCellsWithRowNumbers(); 0263 void fillSelectedCellsWithRandomNumbers(); 0264 void fillWithRandomValues(); 0265 void fillWithEquidistantValues(); 0266 void fillWithFunctionValues(); 0267 void fillSelectedCellsWithConstValues(); 0268 0269 void insertRowAbove(); 0270 void insertRowBelow(); 0271 void insertRowsAbove(); 0272 void insertRowsBelow(); 0273 void removeSelectedRows(); 0274 0275 void insertColumnLeft(); 0276 void insertColumnRight(); 0277 void insertColumnsLeft(); 0278 void insertColumnsRight(); 0279 void removeSelectedColumns(); 0280 void clearSelectedColumns(); 0281 void toggleFreezeColumn(); 0282 0283 void modifyValues(); 0284 void reverseColumns(); 0285 void dropColumnValues(); 0286 void maskColumnValues(); 0287 void sampleColumnValues(); 0288 void flattenColumns(); 0289 // void joinColumns(); 0290 void normalizeSelectedColumns(QAction*); 0291 void powerTransformSelectedColumns(QAction*); 0292 0293 void sortCustom(); 0294 void sortAscending(); 0295 void sortDescending(); 0296 0297 void setSelectionAs(); 0298 0299 void activateFormulaMode(bool on); 0300 0301 void showColumnStatistics(bool forAll = false); 0302 void showAllColumnsStatistics(); 0303 void showRowStatistics(); 0304 0305 void handleHorizontalSectionResized(int logicalIndex, int oldSize, int newSize); 0306 void handleHorizontalSectionMoved(int index, int from, int to); 0307 void handleHorizontalHeaderDoubleClicked(int index); 0308 void handleHeaderDataChanged(Qt::Orientation, int first, int last); 0309 void handleAspectAboutToBeRemoved(int first, int last); 0310 void updateHeaderGeometry(Qt::Orientation, int first, int last); 0311 0312 void columnClicked(int); 0313 void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); 0314 void advanceCell(); 0315 }; 0316 0317 #endif