File indexing completed on 2024-05-12 03:48:22
0001 /* 0002 File : Worksheet.h 0003 Project : LabPlot 0004 Description : Worksheet (2D visualization) part 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2009 Tilman Benkert <thzs@gmx.net> 0007 SPDX-FileCopyrightText: 2011-2022 Alexander Semke <alexander.semke@web.de> 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #ifndef WORKSHEET_H 0013 #define WORKSHEET_H 0014 0015 #include "backend/core/AbstractPart.h" 0016 #include "backend/lib/macros.h" 0017 #include "backend/worksheet/plots/cartesian/CartesianPlot.h" 0018 0019 class QGraphicsItem; 0020 class QGraphicsScene; 0021 class QRectF; 0022 0023 class Background; 0024 class WorksheetPrivate; 0025 class WorksheetView; 0026 class TreeModel; 0027 class XYCurve; 0028 0029 #ifdef SDK 0030 #include "labplot_export.h" 0031 class LABPLOT_EXPORT Worksheet : public AbstractPart { 0032 #else 0033 class Worksheet : public AbstractPart { 0034 #endif 0035 Q_OBJECT 0036 0037 public: 0038 explicit Worksheet(const QString& name, bool loading = false); 0039 ~Worksheet() override; 0040 0041 enum class Unit { Millimeter, Centimeter, Inch, Point }; 0042 enum class Layout { NoLayout, VerticalLayout, HorizontalLayout, GridLayout }; 0043 enum class CartesianPlotActionMode { ApplyActionToSelection, ApplyActionToAll, ApplyActionToAllX, ApplyActionToAllY }; 0044 enum class ZoomFit { None, Fit, FitToHeight, FitToWidth, FitToSelection }; 0045 0046 static double convertToSceneUnits(const double value, const Worksheet::Unit unit); 0047 static double convertFromSceneUnits(const double value, const Worksheet::Unit unit); 0048 0049 QIcon icon() const override; 0050 QMenu* createContextMenu() override; 0051 QWidget* view() const override; 0052 0053 QVector<AbstractAspect*> dependsOn() const override; 0054 WorksheetElement* currentSelection(); 0055 QVector<AspectType> pasteTypes() const override; 0056 0057 bool exportView() const override; 0058 bool exportView(QPixmap&) const; 0059 bool printView() override; 0060 bool printPreview() const override; 0061 0062 void save(QXmlStreamWriter*) const override; 0063 bool load(XmlStreamReader*, bool preview) override; 0064 0065 QRectF pageRect() const; 0066 void setPageRect(const QRectF&); 0067 QGraphicsScene* scene() const; 0068 double zoomFactor() const; 0069 void update(); 0070 void setPrinting(bool) const; 0071 void setThemeName(const QString&); 0072 0073 void setItemSelectedInView(const QGraphicsItem*, const bool); 0074 void setSelectedInView(const bool); 0075 void deleteAspectFromGraphicsItem(const QGraphicsItem*); 0076 void setIsClosing(); 0077 void suppressSelectionChangedEvent(bool); 0078 0079 CartesianPlotActionMode cartesianPlotActionMode() const; 0080 void setCartesianPlotActionMode(CartesianPlotActionMode mode); 0081 CartesianPlotActionMode cartesianPlotCursorMode() const; 0082 void setCartesianPlotCursorMode(CartesianPlotActionMode mode); 0083 void setInteractive(bool); 0084 void setPlotsInteractive(bool); 0085 bool plotsInteractive() const; 0086 int plotCount(); 0087 CartesianPlot* plot(int index); 0088 TreeModel* cursorModel(); 0089 0090 void cursorModelPlotAdded(const QString& name); 0091 void cursorModelPlotRemoved(const QString& name); 0092 0093 Background* background() const; 0094 BASIC_D_ACCESSOR_DECL(bool, scaleContent, ScaleContent) 0095 BASIC_D_ACCESSOR_DECL(bool, useViewSize, UseViewSize) 0096 BASIC_D_ACCESSOR_DECL(ZoomFit, zoomFit, ZoomFit) 0097 BASIC_D_ACCESSOR_DECL(Worksheet::Layout, layout, Layout) 0098 BASIC_D_ACCESSOR_DECL(double, layoutTopMargin, LayoutTopMargin) 0099 BASIC_D_ACCESSOR_DECL(double, layoutBottomMargin, LayoutBottomMargin) 0100 BASIC_D_ACCESSOR_DECL(double, layoutLeftMargin, LayoutLeftMargin) 0101 BASIC_D_ACCESSOR_DECL(double, layoutRightMargin, LayoutRightMargin) 0102 BASIC_D_ACCESSOR_DECL(double, layoutHorizontalSpacing, LayoutHorizontalSpacing) 0103 BASIC_D_ACCESSOR_DECL(double, layoutVerticalSpacing, LayoutVerticalSpacing) 0104 BASIC_D_ACCESSOR_DECL(int, layoutRowCount, LayoutRowCount) 0105 BASIC_D_ACCESSOR_DECL(int, layoutColumnCount, LayoutColumnCount) 0106 0107 QString theme() const; 0108 0109 void setSuppressLayoutUpdate(bool); 0110 void updateLayout(); 0111 0112 void registerShortcuts() override; 0113 void unregisterShortcuts() override; 0114 0115 typedef WorksheetPrivate Private; 0116 0117 public Q_SLOTS: 0118 void setTheme(const QString&); 0119 void cartesianPlotAxisShift(int delta, Dimension dim, int index); 0120 void cartesianPlotWheelEvent(const QPointF& sceneRelPos, int delta, int xIndex, int yIndex, bool considerDimension, Dimension dim); 0121 void cartesianPlotMousePressZoomSelectionMode(QPointF logicPos); 0122 void cartesianPlotMousePressCursorMode(int cursorNumber, QPointF logicPos); 0123 void cartesianPlotMouseMoveZoomSelectionMode(QPointF logicPos); 0124 void cartesianPlotMouseMoveSelectionMode(QPointF logicStart, QPointF logicEnd); 0125 void cartesianPlotMouseMoveCursorMode(int cursorNumber, QPointF logicPos); 0126 void cartesianPlotMouseReleaseZoomSelectionMode(); 0127 void cartesianPlotMouseHoverZoomSelectionMode(QPointF logicPos); 0128 void cartesianPlotMouseHoverOutsideDataRect(); 0129 void cartesianPlotMouseModeChangedSlot(CartesianPlot::MouseMode); 0130 0131 // slots needed by the cursor 0132 void updateCurveBackground(QColor, const QString& curveName); 0133 void updateCompleteCursorTreeModel(); 0134 void cursorPosChanged(int cursorNumber, double xPos); 0135 void curveAdded(const XYCurve* curve); 0136 void curveRemoved(const XYCurve* curve); 0137 void curveDataChanged(const XYCurve* curve); 0138 0139 private: 0140 void init(); 0141 WorksheetElement* aspectFromGraphicsItem(const WorksheetElement*, const QGraphicsItem*) const; 0142 void loadTheme(const QString&); 0143 0144 Q_DECLARE_PRIVATE(Worksheet) 0145 WorksheetPrivate* const d_ptr; 0146 mutable WorksheetView* m_view{nullptr}; 0147 friend class WorksheetPrivate; 0148 0149 private Q_SLOTS: 0150 void handleAspectAdded(const AbstractAspect*); 0151 void handleAspectAboutToBeRemoved(const AbstractAspect*); 0152 void handleAspectRemoved(const AbstractAspect* parent, const AbstractAspect* before, const AbstractAspect* child); 0153 0154 void childSelected(const AbstractAspect*) override; 0155 void childDeselected(const AbstractAspect*) override; 0156 0157 Q_SIGNALS: 0158 void requestProjectContextMenu(QMenu*); 0159 void itemSelected(QGraphicsItem*); 0160 void itemDeselected(QGraphicsItem*); 0161 void requestUpdate(); 0162 void cartesianPlotMouseModeChanged(CartesianPlot::MouseMode); 0163 void showCursorDock(TreeModel*, QVector<CartesianPlot*>); 0164 void propertiesExplorerRequested(); 0165 void childContextMenuRequested(AspectType, QMenu*); 0166 0167 void scaleContentChanged(bool); 0168 void useViewSizeChanged(bool); 0169 void pageRectChanged(const QRectF&); 0170 0171 void layoutChanged(Worksheet::Layout); 0172 void layoutTopMarginChanged(double); 0173 void layoutBottomMarginChanged(double); 0174 void layoutLeftMarginChanged(double); 0175 void layoutRightMarginChanged(double); 0176 void layoutVerticalSpacingChanged(double); 0177 void layoutHorizontalSpacingChanged(double); 0178 void layoutRowCountChanged(int); 0179 void layoutColumnCountChanged(int); 0180 0181 void changed(); 0182 void themeChanged(const QString&); 0183 0184 friend class WorksheetTest; 0185 }; 0186 0187 #endif