File indexing completed on 2025-01-26 03:34:22
0001 /* 0002 File : AbstractPlot.cpp 0003 Project : LabPlot 0004 Description : Base class for plots of different types 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2009 Tilman Benkert <thzs@gmx.net> 0007 SPDX-FileCopyrightText: 2011-2017 Alexander Semke <alexander.semke@web.de> 0008 SPDX-FileCopyrightText: 2020 Stefan Gerlach <stefan.gerlach@uni.kn> 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #include "backend/worksheet/plots/AbstractPlot.h" 0013 #include "backend/lib/commandtemplates.h" 0014 #include "backend/worksheet/WorksheetElementContainerPrivate.h" 0015 #include "backend/worksheet/plots/AbstractCoordinateSystem.h" 0016 #include "backend/worksheet/plots/AbstractPlotPrivate.h" 0017 #include "backend/worksheet/plots/PlotArea.h" 0018 0019 #include <KLocalizedString> 0020 0021 /** 0022 * \class AbstractPlot 0023 * \brief Second level container in a Worksheet for logical grouping 0024 * 0025 * TODO: decide the exact role of AbstractPlot 0026 * 0027 */ 0028 0029 AbstractPlot::AbstractPlot(const QString& name, AspectType type) 0030 : WorksheetElementContainer(name, new AbstractPlotPrivate(this), type) { 0031 init(); 0032 } 0033 0034 AbstractPlot::AbstractPlot(const QString& name, AbstractPlotPrivate* dd, AspectType type) 0035 : WorksheetElementContainer(name, dd, type) { 0036 init(); 0037 } 0038 0039 void AbstractPlot::init() { 0040 graphicsItem()->setFlag(QGraphicsItem::ItemIsMovable, true); 0041 graphicsItem()->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); 0042 graphicsItem()->setFlag(QGraphicsItem::ItemIsSelectable, true); 0043 graphicsItem()->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); 0044 graphicsItem()->setFlag(QGraphicsItem::ItemIsFocusable, true); 0045 } 0046 0047 PlotArea* AbstractPlot::plotArea() { 0048 return m_plotArea; 0049 } 0050 0051 AbstractCoordinateSystem* AbstractPlot::coordinateSystem(const int index) const { 0052 // TODO: use default when not specified? 0053 return m_coordinateSystems.at(index); 0054 } 0055 0056 QVector<AbstractCoordinateSystem*> AbstractPlot::coordinateSystems() const { 0057 return m_coordinateSystems; 0058 } 0059 0060 TextLabel* AbstractPlot::title() { 0061 return m_title; 0062 } 0063 0064 void AbstractPlot::handleResize(double horizontalRatio, double verticalRatio, bool /*pageResize*/) { 0065 if (isLoading()) 0066 return; 0067 DEBUG(Q_FUNC_INFO); 0068 Q_D(AbstractPlot); 0069 0070 // qDebug()<<name() << ": ratios - " << horizontalRatio << " " << verticalRatio; 0071 0072 if (horizontalRatio < 1 && horizontalRatio > 0.2) { 0073 // qDebug()<<name() << ": old hor padding - " << d->horizontalPadding; 0074 d->horizontalPadding *= horizontalRatio; 0075 // qDebug()<<name() << ": new hor padding - " << d->horizontalPadding; 0076 Q_EMIT horizontalPaddingChanged(d->horizontalPadding); 0077 } 0078 0079 if (verticalRatio < 1 && verticalRatio > 0.2) { 0080 // qDebug()<<name() << ": old ver padding - " << d->verticalPadding; 0081 d->verticalPadding *= verticalRatio; 0082 // qDebug()<<name() << ": new ver padding - " << d->verticalPadding; 0083 Q_EMIT verticalPaddingChanged(d->verticalPadding); 0084 } 0085 0086 // WorksheetElementContainer::handleResize(horizontalRatio, verticalRatio, pageResize); 0087 } 0088 0089 BASIC_SHARED_D_READER_IMPL(AbstractPlot, double, horizontalPadding, horizontalPadding) 0090 BASIC_SHARED_D_READER_IMPL(AbstractPlot, double, verticalPadding, verticalPadding) 0091 BASIC_SHARED_D_READER_IMPL(AbstractPlot, double, rightPadding, rightPadding) 0092 BASIC_SHARED_D_READER_IMPL(AbstractPlot, double, bottomPadding, bottomPadding) 0093 BASIC_SHARED_D_READER_IMPL(AbstractPlot, bool, symmetricPadding, symmetricPadding) 0094 0095 /* ============================ setter methods and undo commands ================= */ 0096 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetHorizontalPadding, double, horizontalPadding, retransform) 0097 void AbstractPlot::setHorizontalPadding(double padding) { 0098 Q_D(AbstractPlot); 0099 if (padding != d->horizontalPadding) 0100 exec(new AbstractPlotSetHorizontalPaddingCmd(d, padding, ki18n("%1: set horizontal padding"))); 0101 } 0102 0103 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetVerticalPadding, double, verticalPadding, retransform) 0104 void AbstractPlot::setVerticalPadding(double padding) { 0105 Q_D(AbstractPlot); 0106 if (padding != d->verticalPadding) 0107 exec(new AbstractPlotSetVerticalPaddingCmd(d, padding, ki18n("%1: set vertical padding"))); 0108 } 0109 0110 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetRightPadding, double, rightPadding, retransform) 0111 void AbstractPlot::setRightPadding(double padding) { 0112 Q_D(AbstractPlot); 0113 if (padding != d->rightPadding) 0114 exec(new AbstractPlotSetRightPaddingCmd(d, padding, ki18n("%1: set right padding"))); 0115 } 0116 0117 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetBottomPadding, double, bottomPadding, retransform) 0118 void AbstractPlot::setBottomPadding(double padding) { 0119 Q_D(AbstractPlot); 0120 if (padding != d->bottomPadding) 0121 exec(new AbstractPlotSetBottomPaddingCmd(d, padding, ki18n("%1: set bottom padding"))); 0122 } 0123 0124 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetSymmetricPadding, bool, symmetricPadding, retransform) 0125 void AbstractPlot::setSymmetricPadding(bool symmetric) { 0126 Q_D(AbstractPlot); 0127 if (symmetric != d->symmetricPadding) 0128 exec(new AbstractPlotSetSymmetricPaddingCmd(d, symmetric, ki18n("%1: set horizontal padding"))); 0129 } 0130 0131 // ################################################################ 0132 // ################### Private implementation ##################### 0133 // ################################################################ 0134 AbstractPlotPrivate::AbstractPlotPrivate(AbstractPlot* owner) 0135 : WorksheetElementContainerPrivate(owner) 0136 , q(owner) { 0137 }