labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

AbstractPlot.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  File : AbstractPlot.cpp
3  Project : LabPlot
4  Description : Base class for plots of different types
5  --------------------------------------------------------------------
6  Copyright : (C) 2009 Tilman Benkert (thzs@gmx.net)
7  Copyright : (C) 2011-2017 by Alexander Semke (alexander.semke@web.de)
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 
36 
37 #include <KLocalizedString>
38 
39 /**
40  * \class AbstractPlot
41  * \brief Second level container in a Worksheet for logical grouping
42  *
43  * TODO: decide the exact role of AbstractPlot
44  *
45  */
46 
49 
50  init();
51 }
52 
54  : WorksheetElementContainer(name, dd, type) {
55 
56  init();
57 }
58 
60  graphicsItem()->setFlag(QGraphicsItem::ItemIsMovable, true);
61  graphicsItem()->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
62  graphicsItem()->setFlag(QGraphicsItem::ItemIsSelectable, true);
63  graphicsItem()->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
64  graphicsItem()->setFlag(QGraphicsItem::ItemIsFocusable, true);
65 }
66 
68  return m_plotArea;
69 }
70 
72  return m_coordinateSystem;
73 }
74 
76  return m_title;
77 }
78 
79 void AbstractPlot::handleResize(double horizontalRatio, double verticalRatio, bool pageResize) {
80  if (isLoading())
81  return;
82  DEBUG("AbstractPlot::handleResize()");
83  Q_D(AbstractPlot);
84 
85  double ratio = 0;
86  if (horizontalRatio > 1.0 || verticalRatio > 1.0)
87  ratio = qMax(horizontalRatio, verticalRatio);
88  else
89  ratio = qMin(horizontalRatio, verticalRatio);
90 
91  d->horizontalPadding *= ratio;
92  d->verticalPadding *= ratio;
93 
94  WorksheetElementContainer::handleResize(horizontalRatio, verticalRatio, pageResize);
95 }
96 
97 BASIC_SHARED_D_READER_IMPL(AbstractPlot, float, horizontalPadding, horizontalPadding)
98 BASIC_SHARED_D_READER_IMPL(AbstractPlot, float, verticalPadding, verticalPadding)
99 BASIC_SHARED_D_READER_IMPL(AbstractPlot, double, rightPadding, rightPadding)
100 BASIC_SHARED_D_READER_IMPL(AbstractPlot, double, bottomPadding, bottomPadding)
101 BASIC_SHARED_D_READER_IMPL(AbstractPlot, bool, symmetricPadding, symmetricPadding)
102 
103 /* ============================ setter methods and undo commands ================= */
104 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetHorizontalPadding, float, horizontalPadding, retransform)
105 void AbstractPlot::setHorizontalPadding(float padding) {
106  Q_D(AbstractPlot);
107  if (padding != d->horizontalPadding)
108  exec(new AbstractPlotSetHorizontalPaddingCmd(d, padding, ki18n("%1: set horizontal padding")));
109 }
110 
111 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetVerticalPadding, float, verticalPadding, retransform)
112 void AbstractPlot::setVerticalPadding(float padding) {
113  Q_D(AbstractPlot);
114  if (padding != d->verticalPadding)
115  exec(new AbstractPlotSetVerticalPaddingCmd(d, padding, ki18n("%1: set vertical padding")));
116 }
117 
118 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetRightPadding, double, rightPadding, retransform)
119 void AbstractPlot::setRightPadding(double padding) {
120  Q_D(AbstractPlot);
121  if (padding != d->rightPadding)
122  exec(new AbstractPlotSetRightPaddingCmd(d, padding, ki18n("%1: set right padding")));
123 }
124 
125 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetBottomPadding, double, bottomPadding, retransform)
126 void AbstractPlot::setBottomPadding(double padding) {
127  Q_D(AbstractPlot);
128  if (padding != d->bottomPadding)
129  exec(new AbstractPlotSetBottomPaddingCmd(d, padding, ki18n("%1: set bottom padding")));
130 }
131 
132 STD_SETTER_CMD_IMPL_F_S(AbstractPlot, SetSymmetricPadding, bool, symmetricPadding, retransform)
133 void AbstractPlot::setSymmetricPadding(bool symmetric) {
134  Q_D(AbstractPlot);
135  if (symmetric != d->symmetricPadding)
136  exec(new AbstractPlotSetSymmetricPaddingCmd(d, symmetric, ki18n("%1: set horizontal padding")));
137 }
138 
139 //################################################################
140 //################### Private implementation #####################
141 //################################################################
144 }
145 
146 QString AbstractPlotPrivate::name() const {
147  return q->name();
148 }
AspectType
QString name() const
void exec(QUndoCommand *)
Execute the given command, pushing it on the undoStack() if available.
bool isLoading() const
AbstractAspectPrivate * d
Base class of all worksheet coordinate systems.
AbstractPlotPrivate(AbstractPlot *owner)
virtual QString name() const
Second level container in a Worksheet for logical grouping.
Definition: AbstractPlot.h:41
TextLabel * title()
PlotArea * plotArea()
PlotArea * m_plotArea
Definition: AbstractPlot.h:64
AbstractCoordinateSystem * coordinateSystem() const
AbstractCoordinateSystem * m_coordinateSystem
Definition: AbstractPlot.h:63
AbstractPlot(const QString &name, AspectType type)
TextLabel * m_title
Definition: AbstractPlot.h:65
void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override
Plot area (for background filling and clipping).
Definition: PlotArea.h:38
A label supporting rendering of html- and tex-formatted texts.
Definition: TextLabel.h:44
Worksheet element container - parent of multiple elements This class provides the functionality for a...
void handleResize(double horizontalRatio, double verticalRatio, bool pageResize=false) override
QGraphicsItem * graphicsItem() const override
Return the graphics item representing this element.
friend class AbstractPlotSetVerticalPaddingCmd
friend class AbstractPlotSetBottomPaddingCmd
friend class AbstractPlotSetSymmetricPaddingCmd
friend class AbstractPlotSetHorizontalPaddingCmd
friend class AbstractPlotSetRightPaddingCmd
#define DEBUG(x)
Definition: macros.h:50
#define STD_SETTER_CMD_IMPL_F_S(class_name, cmd_name, value_type, field_name, finalize_method)
Definition: macros.h:215
#define BASIC_SHARED_D_READER_IMPL(classname, type, method, var)
Definition: macros.h:127