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

0001 /***************************************************************************
0002     File                 : Worksheet.h
0003     Project              : LabPlot
0004     Description          : Worksheet (2D visualization) part
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2009 Tilman Benkert (thzs@gmx.net)
0007     Copyright            : (C) 2011-2019 by Alexander Semke (alexander.semke@web.de)
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 WORKSHEET_H
0030 #define WORKSHEET_H
0031 
0032 #include "backend/core/AbstractPart.h"
0033 #include "backend/worksheet/plots/PlotArea.h"
0034 #include "backend/worksheet/plots/cartesian/CartesianPlot.h"
0035 
0036 class QGraphicsItem;
0037 class QGraphicsScene;
0038 class QRectF;
0039 
0040 class WorksheetPrivate;
0041 class WorksheetView;
0042 class TreeModel;
0043 class XYCurve;
0044 class CartesianPlot;
0045 
0046 class Worksheet : public AbstractPart {
0047     Q_OBJECT
0048 
0049 public:
0050     explicit Worksheet(const QString& name, bool loading = false);
0051     ~Worksheet() override;
0052 
0053     enum class Unit {Millimeter, Centimeter, Inch, Point};
0054     enum class Layout {NoLayout, VerticalLayout, HorizontalLayout, GridLayout};
0055     enum class CartesianPlotActionMode {ApplyActionToSelection, ApplyActionToAll};
0056 
0057     static double convertToSceneUnits(const double value, const Worksheet::Unit unit);
0058     static double convertFromSceneUnits(const double value, const Worksheet::Unit unit);
0059 
0060     QIcon icon() const override;
0061     QMenu* createContextMenu() override;
0062     QWidget* view() const override;
0063     QVector<AbstractAspect*> dependsOn() const override;
0064 
0065     bool exportView() const override;
0066     bool printView() override;
0067     bool printPreview() const override;
0068 
0069     void save(QXmlStreamWriter*) const override;
0070     bool load(XmlStreamReader*, bool preview) override;
0071 
0072     QRectF pageRect() const;
0073     void setPageRect(const QRectF&);
0074     QGraphicsScene* scene() const;
0075     void update();
0076     void setPrinting(bool) const;
0077     void setThemeName(const QString&);
0078 
0079     void setItemSelectedInView(const QGraphicsItem*, const bool);
0080     void setSelectedInView(const bool);
0081     void deleteAspectFromGraphicsItem(const QGraphicsItem*);
0082     void setIsClosing();
0083     void suppressSelectionChangedEvent(bool);
0084 
0085     CartesianPlotActionMode cartesianPlotActionMode();
0086     void setCartesianPlotActionMode(CartesianPlotActionMode mode);
0087     CartesianPlotActionMode cartesianPlotCursorMode();
0088     void setCartesianPlotCursorMode(CartesianPlotActionMode mode);
0089     void setPlotsLocked(bool);
0090     bool plotsLocked();
0091     int getPlotCount();
0092     CartesianPlot* getPlot(int index);
0093     TreeModel* cursorModel();
0094 
0095     void cursorModelPlotAdded(const QString& name);
0096     void cursorModelPlotRemoved(const QString& name);
0097 
0098     BASIC_D_ACCESSOR_DECL(float, backgroundOpacity, BackgroundOpacity)
0099     BASIC_D_ACCESSOR_DECL(PlotArea::BackgroundType, backgroundType, BackgroundType)
0100     BASIC_D_ACCESSOR_DECL(PlotArea::BackgroundColorStyle, backgroundColorStyle, BackgroundColorStyle)
0101     BASIC_D_ACCESSOR_DECL(PlotArea::BackgroundImageStyle, backgroundImageStyle, BackgroundImageStyle)
0102     BASIC_D_ACCESSOR_DECL(Qt::BrushStyle, backgroundBrushStyle, BackgroundBrushStyle)
0103     CLASS_D_ACCESSOR_DECL(QColor, backgroundFirstColor, BackgroundFirstColor)
0104     CLASS_D_ACCESSOR_DECL(QColor, backgroundSecondColor, BackgroundSecondColor)
0105     CLASS_D_ACCESSOR_DECL(QString, backgroundFileName, BackgroundFileName)
0106 
0107     BASIC_D_ACCESSOR_DECL(bool, scaleContent, ScaleContent)
0108     BASIC_D_ACCESSOR_DECL(bool, useViewSize, UseViewSize)
0109     BASIC_D_ACCESSOR_DECL(Worksheet::Layout, layout, Layout)
0110     BASIC_D_ACCESSOR_DECL(float, layoutTopMargin, LayoutTopMargin)
0111     BASIC_D_ACCESSOR_DECL(float, layoutBottomMargin, LayoutBottomMargin)
0112     BASIC_D_ACCESSOR_DECL(float, layoutLeftMargin, LayoutLeftMargin)
0113     BASIC_D_ACCESSOR_DECL(float, layoutRightMargin, LayoutRightMargin)
0114     BASIC_D_ACCESSOR_DECL(float, layoutHorizontalSpacing, LayoutHorizontalSpacing)
0115     BASIC_D_ACCESSOR_DECL(float, layoutVerticalSpacing, LayoutVerticalSpacing)
0116     BASIC_D_ACCESSOR_DECL(int, layoutRowCount, LayoutRowCount)
0117     BASIC_D_ACCESSOR_DECL(int, layoutColumnCount, LayoutColumnCount)
0118 
0119     QString theme() const;
0120 
0121     void setSuppressLayoutUpdate(bool);
0122     void updateLayout();
0123 
0124     void registerShortcuts() override;
0125     void unregisterShortcuts() override;
0126 
0127     typedef WorksheetPrivate Private;
0128 
0129 public slots:
0130     void setTheme(const QString&);
0131     void cartesianPlotMousePressZoomSelectionMode(QPointF logicPos);
0132     void cartesianPlotMousePressCursorMode(int cursorNumber, QPointF logicPos);
0133     void cartesianPlotMouseMoveZoomSelectionMode(QPointF logicPos);
0134     void cartesianPlotMouseMoveCursorMode(int cursorNumber, QPointF logicPos);
0135     void cartesianPlotMouseReleaseZoomSelectionMode();
0136     void cartesianPlotMouseHoverZoomSelectionMode(QPointF logicPos);
0137     void cartesianPlotMouseHoverOutsideDataRect();
0138     void cartesianPlotMouseModeChangedSlot(CartesianPlot::MouseMode);
0139 
0140     // slots needed by the cursor
0141     void updateCurveBackground(const QPen&, const QString& curveName);
0142     void updateCompleteCursorTreeModel();
0143     void cursorPosChanged(int cursorNumber, double xPos);
0144     void curveAdded(const XYCurve* curve);
0145     void curveRemoved(const XYCurve* curve);
0146     void curveDataChanged(const XYCurve* curve);
0147 
0148 private:
0149     void init();
0150     WorksheetElement* aspectFromGraphicsItem(const WorksheetElement*, const QGraphicsItem*) const;
0151     void loadTheme(const QString&);
0152 
0153     WorksheetPrivate* const d;
0154     mutable WorksheetView* m_view{nullptr};
0155     friend class WorksheetPrivate;
0156 
0157 private slots:
0158     void handleAspectAdded(const AbstractAspect*);
0159     void handleAspectAboutToBeRemoved(const AbstractAspect*);
0160     void handleAspectRemoved(const AbstractAspect* parent, const AbstractAspect* before, const AbstractAspect* child);
0161 
0162     void childSelected(const AbstractAspect*) override;
0163     void childDeselected(const AbstractAspect*) override;
0164 
0165 signals:
0166     void requestProjectContextMenu(QMenu*);
0167     void itemSelected(QGraphicsItem*);
0168     void itemDeselected(QGraphicsItem*);
0169     void requestUpdate();
0170     void useViewSizeRequested();
0171     void cartesianPlotMouseModeChanged(CartesianPlot::MouseMode);
0172     void showCursorDock(TreeModel*, QVector<CartesianPlot*>);
0173     void propertiesExplorerRequested();
0174 
0175     void backgroundTypeChanged(PlotArea::BackgroundType);
0176     void backgroundColorStyleChanged(PlotArea::BackgroundColorStyle);
0177     void backgroundImageStyleChanged(PlotArea::BackgroundImageStyle);
0178     void backgroundBrushStyleChanged(Qt::BrushStyle);
0179     void backgroundFirstColorChanged(const QColor&);
0180     void backgroundSecondColorChanged(const QColor&);
0181     void backgroundFileNameChanged(const QString&);
0182     void backgroundOpacityChanged(float);
0183     void scaleContentChanged(bool);
0184     void pageRectChanged(const QRectF&);
0185     void layoutChanged(Worksheet::Layout);
0186     void layoutTopMarginChanged(float);
0187     void layoutBottomMarginChanged(float);
0188     void layoutLeftMarginChanged(float);
0189     void layoutRightMarginChanged(float);
0190     void layoutVerticalSpacingChanged(float);
0191     void layoutHorizontalSpacingChanged(float);
0192     void layoutRowCountChanged(int);
0193     void layoutColumnCountChanged(int);
0194     void themeChanged(const QString&);
0195 };
0196 
0197 #endif