diff --git a/src/backend/datapicker/DatapickerImage.h b/src/backend/datapicker/DatapickerImage.h index 723746bf6..44c924a02 100644 --- a/src/backend/datapicker/DatapickerImage.h +++ b/src/backend/datapicker/DatapickerImage.h @@ -1,174 +1,161 @@ /*************************************************************************** File : DatapickerImage.h Project : LabPlot Description : Worksheet for Datapicker -------------------------------------------------------------------- Copyright : (C) 2015 by Ankit Wagadre (wagadre.ankit@gmail.com) Copyright : (C) 2015-2016 by Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef DATAPICKERIMAGE_H #define DATAPICKERIMAGE_H #include "backend/core/AbstractPart.h" #include "backend/core/AbstractScriptingEngine.h" #include "backend/lib/macros.h" #include "backend/worksheet/plots/cartesian/Symbol.h" #include #include #include #include class DatapickerImagePrivate; class DatapickerImageView; class ImageEditor; class Segments; class QGraphicsScene; class QGraphicsPixmapItem; class DatapickerImage: public AbstractPart, public scripted { Q_OBJECT public: DatapickerImage(AbstractScriptingEngine* engine, const QString& name, bool loading = false); ~DatapickerImage() override; enum GraphType { Cartesian, PolarInDegree, PolarInRadians, LogarithmicX, LogarithmicY, Ternary}; enum ColorAttributes { None, Intensity, Foreground, Hue, Saturation, Value }; enum PlotImageType { NoImage, OriginalImage, ProcessedImage }; enum PointsType { AxisPoints, CurvePoints, SegmentPoints }; struct ReferencePoints { GraphType type; QPointF scenePos[3]; QVector3D logicalPos[3]; double ternaryScale; }; struct EditorSettings { int intensityThresholdLow; int intensityThresholdHigh; int foregroundThresholdLow; int foregroundThresholdHigh; int hueThresholdLow; int hueThresholdHigh; int saturationThresholdLow; int saturationThresholdHigh; int valueThresholdLow; int valueThresholdHigh; }; QIcon icon() const override; QMenu* createContextMenu() override; void createContextMenu(QMenu*); QWidget* view() const override; bool exportView() const override; bool printView() override; bool printPreview() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; QRectF pageRect() const; void setPageRect(const QRectF&); QGraphicsScene *scene() const; void setPrinting(bool) const; void setSelectedInView(const bool); void setSegmentsHoverEvent(const bool); void setPlotImageType(const DatapickerImage::PlotImageType); DatapickerImage::PlotImageType plotImageType(); bool isLoaded; QImage originalPlotImage; QImage processedPlotImage; QColor background; int *foregroundBins; int *hueBins; int *saturationBins; int *valueBins; int *intensityBins; QGraphicsPixmapItem* m_magnificationWindow; CLASS_D_ACCESSOR_DECL(QString, fileName, FileName) CLASS_D_ACCESSOR_DECL(DatapickerImage::ReferencePoints, axisPoints, AxisPoints) CLASS_D_ACCESSOR_DECL(DatapickerImage::EditorSettings, settings, Settings) BASIC_D_ACCESSOR_DECL(float, rotationAngle, RotationAngle) BASIC_D_ACCESSOR_DECL(PointsType, plotPointsType, PlotPointsType) BASIC_D_ACCESSOR_DECL(int, pointSeparation, PointSeparation) BASIC_D_ACCESSOR_DECL(int, minSegmentLength, minSegmentLength) BASIC_D_ACCESSOR_DECL(Symbol::Style, pointStyle, PointStyle) BASIC_D_ACCESSOR_DECL(qreal, pointOpacity, PointOpacity) BASIC_D_ACCESSOR_DECL(qreal, pointRotationAngle, PointRotationAngle) BASIC_D_ACCESSOR_DECL(qreal, pointSize, PointSize) CLASS_D_ACCESSOR_DECL(QBrush, pointBrush, PointBrush) CLASS_D_ACCESSOR_DECL(QPen, pointPen, PointPen) BASIC_D_ACCESSOR_DECL(bool, pointVisibility, PointVisibility) typedef DatapickerImagePrivate Private; private: void init(); void initSceneParameters(); DatapickerImagePrivate* const d; mutable DatapickerImageView* m_view; friend class DatapickerImagePrivate; Segments* m_segments; signals: void requestProjectContextMenu(QMenu*); void requestUpdate(); void requestUpdateActions(); void fileNameChanged(const QString&); void rotationAngleChanged(float); void axisPointsChanged(const DatapickerImage::ReferencePoints&); void settingsChanged(const DatapickerImage::EditorSettings&); void minSegmentLengthChanged(const int); void pointStyleChanged(Symbol::Style); void pointSizeChanged(qreal); void pointRotationAngleChanged(qreal); void pointOpacityChanged(qreal); void pointBrushChanged(QBrush); void pointPenChanged(const QPen&); void pointVisibilityChanged(bool); - - friend class DatapickerImageSetFileNameCmd; - friend class DatapickerImageSetRotationAngleCmd; - friend class DatapickerImageSetAxisPointsCmd; - friend class DatapickerImageSetSettingsCmd; - friend class DatapickerImageSetMinSegmentLengthCmd; - friend class DatapickerImageSetPointStyleCmd; - friend class DatapickerImageSetPointSizeCmd; - friend class DatapickerImageSetPointRotationAngleCmd; - friend class DatapickerImageSetPointOpacityCmd; - friend class DatapickerImageSetPointBrushCmd; - friend class DatapickerImageSetPointPenCmd; - friend class DatapickerImageSetPointVisibilityCmd; }; #endif diff --git a/src/backend/datapicker/DatapickerPoint.h b/src/backend/datapicker/DatapickerPoint.h index 2361c6495..7c0f649e0 100644 --- a/src/backend/datapicker/DatapickerPoint.h +++ b/src/backend/datapicker/DatapickerPoint.h @@ -1,120 +1,114 @@ /*************************************************************************** File : DatapickerPoint.h Project : LabPlot Description : Graphic Item for coordinate points of Datapicker -------------------------------------------------------------------- Copyright : (C) 2015 by Ankit Wagadre (wagadre.ankit@gmail.com) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef DATAPICKERPOINT_H #define DATAPICKERPOINT_H #include #include #include #include "backend/core/AbstractAspect.h" #include "backend/lib/macros.h" #include "backend/datapicker/DatapickerCurve.h" #include #include "backend/worksheet/plots/cartesian/Symbol.h" class DatapickerPoint; class ErrorBarItem : public QObject, public QGraphicsRectItem { Q_OBJECT public: enum ErrorBarType { PlusDeltaX, MinusDeltaX, PlusDeltaY, MinusDeltaY}; explicit ErrorBarItem(DatapickerPoint* parent = 0, const ErrorBarType& type = PlusDeltaX); QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; void setRectSize(const qreal); public slots: void setPosition(const QPointF&); private: void initRect(); void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override; QGraphicsLineItem* barLineItem; QRectF m_rect; ErrorBarType m_type; DatapickerPoint* m_parentItem; }; class DatapickerPointPrivate; class DatapickerPoint : public AbstractAspect { Q_OBJECT public: explicit DatapickerPoint(const QString& name ); ~DatapickerPoint() override; QIcon icon() const override; QMenu* createContextMenu() override; QGraphicsItem *graphicsItem() const; void setParentGraphicsItem(QGraphicsItem*); void setPrinting(bool); void initErrorBar(const DatapickerCurve::Errors&); void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; CLASS_D_ACCESSOR_DECL(QPointF, position, Position) CLASS_D_ACCESSOR_DECL(QPointF, plusDeltaXPos, PlusDeltaXPos) CLASS_D_ACCESSOR_DECL(QPointF, minusDeltaXPos, MinusDeltaXPos) CLASS_D_ACCESSOR_DECL(QPointF, plusDeltaYPos, PlusDeltaYPos) CLASS_D_ACCESSOR_DECL(QPointF, minusDeltaYPos, MinusDeltaYPos) typedef DatapickerPointPrivate Private; public slots: void retransform(); protected: DatapickerPointPrivate* const d_ptr; DatapickerPoint(const QString &name, DatapickerPointPrivate *dd); static QPen selectedPen; static float selectedOpacity; private: Q_DECLARE_PRIVATE(DatapickerPoint) void init(); QList m_errorBarItemList; signals: - friend class DatapickerPointSetPositionCmd; void positionChanged(QPointF); - - friend class DatapickerPointSetPlusDeltaXPosCmd; - friend class DatapickerPointSetMinusDeltaXPosCmd; - friend class DatapickerPointSetPlusDeltaYPosCmd; - friend class DatapickerPointSetMinusDeltaYPosCmd; void plusDeltaXPosChanged(QPointF); void minusDeltaXPosChanged(QPointF); void plusDeltaYPosChanged(QPointF); void minusDeltaYPosChanged(QPointF); }; #endif diff --git a/src/backend/matrix/Matrix.h b/src/backend/matrix/Matrix.h index 969316e75..27495c6c2 100644 --- a/src/backend/matrix/Matrix.h +++ b/src/backend/matrix/Matrix.h @@ -1,175 +1,165 @@ /*************************************************************************** File : Matrix.h Project : Matrix Description : Spreadsheet with a MxN matrix data model -------------------------------------------------------------------- Copyright : (C) 2008-2009 Tilman Benkert (thzs@gmx.net) Copyright : (C) 2015-2017 Alexander Semke (alexander.semke@web.de) Copyright : (C) 2017 Stefan Gerlach (stefan.gerlach@uni.kn) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef MATRIX_H #define MATRIX_H #include "backend/datasources/AbstractDataSource.h" #include "backend/datasources/filters/AbstractFileFilter.h" #include "backend/lib/macros.h" class MatrixPrivate; class MatrixModel; class MatrixView; class Matrix : public AbstractDataSource { Q_OBJECT Q_ENUMS(HeaderFormat) public: enum HeaderFormat {HeaderRowsColumns, HeaderValues, HeaderRowsColumnsValues}; Matrix(AbstractScriptingEngine* engine, const QString& name, bool loading = false, const AbstractColumn::ColumnMode = AbstractColumn::Numeric); Matrix(AbstractScriptingEngine* engine, int rows, int cols, const QString& name, const AbstractColumn::ColumnMode = AbstractColumn::Numeric); ~Matrix() override; QIcon icon() const override; QMenu* createContextMenu() override; QWidget* view() const override; bool exportView() const override; bool printView() override; bool printPreview() const override; void* data() const; void setData(void*); BASIC_D_ACCESSOR_DECL(AbstractColumn::ColumnMode, mode, Mode) BASIC_D_ACCESSOR_DECL(int, rowCount, RowCount) BASIC_D_ACCESSOR_DECL(int, columnCount, ColumnCount) BASIC_D_ACCESSOR_DECL(char, numericFormat, NumericFormat) BASIC_D_ACCESSOR_DECL(int, precision, Precision) BASIC_D_ACCESSOR_DECL(HeaderFormat, headerFormat, HeaderFormat) BASIC_D_ACCESSOR_DECL(double, xStart, XStart) BASIC_D_ACCESSOR_DECL(double, xEnd, XEnd) BASIC_D_ACCESSOR_DECL(double, yStart, YStart) BASIC_D_ACCESSOR_DECL(double, yEnd, YEnd) CLASS_D_ACCESSOR_DECL(QString, formula, Formula) void setSuppressDataChangedSignal(bool); void setChanged(); int rowHeight(int row) const; void setRowHeight(int row, int height); int columnWidth(int col) const; void setColumnWidth(int col, int width); void setDimensions(int rows, int cols); void setCoordinates(double x1, double x2, double y1, double y2); void insertColumns(int before, int count); void appendColumns(int count); void removeColumns(int first, int count); void clearColumn(int); void insertRows(int before, int count); void appendRows(int count); void removeRows(int first, int count); void clearRow(int); template T cell(int row, int col) const; template QString text(int row, int col); template void setCell(int row, int col, T value); void clearCell(int row, int col); template QVector columnCells(int col, int first_row, int last_row); template void setColumnCells(int col, int first_row, int last_row, const QVector& values); template QVector rowCells(int row, int first_column, int last_column); template void setRowCells(int row, int first_column, int last_column, const QVector& values); void copy(Matrix* other); void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; int prepareImport(QVector& dataContainer, AbstractFileFilter::ImportMode, int rows, int cols, QStringList colNameList, QVector) override; void finalizeImport(int columnOffset, int startColumn, int endColumn, int numRows, const QString& dateTimeFormat, AbstractFileFilter::ImportMode) override; typedef MatrixPrivate Private; public slots: void clear(); void transpose(); void mirrorVertically(); void mirrorHorizontally(); void addColumns(); void addRows(); void duplicate(); signals: void requestProjectContextMenu(QMenu*); void columnsAboutToBeInserted(int before, int count); void columnsInserted(int first, int count); void columnsAboutToBeRemoved(int first, int count); void columnsRemoved(int first, int count); void rowsAboutToBeInserted(int before, int count); void rowsInserted(int first, int count); void rowsAboutToBeRemoved(int first, int count); void rowsRemoved(int first, int count); void dataChanged(int top, int left, int bottom, int right); void coordinatesChanged(); - friend class MatrixInsertRowsCmd; - friend class MatrixInsertColumnsCmd; void rowCountChanged(int); void columnCountChanged(int); - friend class MatrixSetXStartCmd; - friend class MatrixSetXEndCmd; - friend class MatrixSetYStartCmd; - friend class MatrixSetYEndCmd; void xStartChanged(double); void xEndChanged(double); void yStartChanged(double); void yEndChanged(double); - friend class MatrixSetNumericFormatCmd; - friend class MatrixSetPrecisionCmd; void numericFormatChanged(char); void precisionChanged(int); void headerFormatChanged(Matrix::HeaderFormat); private: void init(); MatrixPrivate* const d; mutable MatrixModel* m_model; mutable MatrixView* m_view; friend class MatrixPrivate; - template friend class MatrixRemoveColumnsCmd; - template friend class MatrixRemoveRowsCmd; }; #endif diff --git a/src/backend/worksheet/TextLabel.h b/src/backend/worksheet/TextLabel.h index 3a196206b..33c9649d7 100644 --- a/src/backend/worksheet/TextLabel.h +++ b/src/backend/worksheet/TextLabel.h @@ -1,145 +1,137 @@ /*************************************************************************** File : TextLabel.h Project : LabPlot Description : Text label supporting reach text and latex formatting -------------------------------------------------------------------- Copyright : (C) 2009 Tilman Benkert (thzs@gmx.net) Copyright : (C) 2012-2014 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef TEXTLABEL_H #define TEXTLABEL_H #include "backend/lib/macros.h" #include "tools/TeXRenderer.h" #include "backend/worksheet/WorksheetElement.h" #include #include #include class TextLabelPrivate; class TextLabel : public WorksheetElement { - Q_OBJECT - - public: - enum Type {General, PlotTitle, AxisTitle, PlotLegendTitle}; - - enum HorizontalPosition {hPositionLeft, hPositionCenter, hPositionRight, hPositionCustom}; - enum VerticalPosition {vPositionTop, vPositionCenter, vPositionBottom, vPositionCustom}; - - enum HorizontalAlignment {hAlignLeft, hAlignCenter, hAlignRight}; - enum VerticalAlignment {vAlignTop, vAlignCenter, vAlignBottom}; - - struct TextWrapper { - TextWrapper() : teXUsed(false) {} - TextWrapper(const QString& t, bool b) : text(t), teXUsed(b) {} - TextWrapper(const QString& t) : text(t), teXUsed(false) {} - - QString text; - bool teXUsed; - }; - - struct PositionWrapper { - QPointF point; - HorizontalPosition horizontalPosition; - VerticalPosition verticalPosition; - }; - - explicit TextLabel(const QString& name, Type type = General); - ~TextLabel() override; - - Type type() const; - QIcon icon() const override; - QMenu* createContextMenu() override; - QGraphicsItem* graphicsItem() const override; - void setParentGraphicsItem(QGraphicsItem*); - - void save(QXmlStreamWriter*) const override; - bool load(XmlStreamReader*, bool preview) override; - void loadThemeConfig(const KConfig& config) override; - void saveThemeConfig(const KConfig& config) override; - - CLASS_D_ACCESSOR_DECL(TextWrapper, text, Text) - BASIC_D_ACCESSOR_DECL(QColor, teXFontColor, TeXFontColor) - BASIC_D_ACCESSOR_DECL(QColor, teXBackgroundColor, TeXBackgroundColor) - CLASS_D_ACCESSOR_DECL(QFont, teXFont, TeXFont) - CLASS_D_ACCESSOR_DECL(PositionWrapper, position, Position) - void setPosition(QPointF); - void setPositionInvalid(bool); - BASIC_D_ACCESSOR_DECL(HorizontalAlignment, horizontalAlignment, HorizontalAlignment) - BASIC_D_ACCESSOR_DECL(VerticalAlignment, verticalAlignment, VerticalAlignment) - BASIC_D_ACCESSOR_DECL(qreal, rotationAngle, RotationAngle) - - void setVisible(bool on) override; - bool isVisible() const override; - void setPrinting(bool) override; - - void retransform() override; - void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override; - - typedef TextLabelPrivate Private; - - private slots: - void updateTeXImage(); - - //SLOTs for changes triggered via QActions in the context menu - void visibilityChanged(); - - protected: - TextLabelPrivate* const d_ptr; - TextLabel(const QString& name, TextLabelPrivate* dd, Type type = General); - - private: - Q_DECLARE_PRIVATE(TextLabel) - void init(); - - Type m_type; - QAction* visibilityAction; - - signals: - friend class TextLabelSetTextCmd; - friend class TextLabelSetTeXFontCmd; - friend class TextLabelSetTeXFontColorCmd; - friend class TextLabelSetTeXBackgroundColorCmd; - friend class TextLabelSetPositionCmd; - friend class TextLabelSetHorizontalAlignmentCmd; - friend class TextLabelSetVerticalAlignmentCmd; - friend class TextLabelSetRotationAngleCmd; - void textWrapperChanged(const TextLabel::TextWrapper&); - void teXFontSizeChanged(const int); - void teXFontChanged(const QFont); - void teXFontColorChanged(const QColor); - void teXBackgroundColorChanged(const QColor); - void positionChanged(const TextLabel::PositionWrapper&); - void horizontalAlignmentChanged(TextLabel::HorizontalAlignment); - void verticalAlignmentChanged(TextLabel::VerticalAlignment); - void rotationAngleChanged(qreal); - void visibleChanged(bool); - - void teXImageUpdated(bool); - void changed(); +Q_OBJECT + +public: + enum Type {General, PlotTitle, AxisTitle, PlotLegendTitle}; + + enum HorizontalPosition {hPositionLeft, hPositionCenter, hPositionRight, hPositionCustom}; + enum VerticalPosition {vPositionTop, vPositionCenter, vPositionBottom, vPositionCustom}; + + enum HorizontalAlignment {hAlignLeft, hAlignCenter, hAlignRight}; + enum VerticalAlignment {vAlignTop, vAlignCenter, vAlignBottom}; + + struct TextWrapper { + TextWrapper() : teXUsed(false) {} + TextWrapper(const QString& t, bool b) : text(t), teXUsed(b) {} + TextWrapper(const QString& t) : text(t), teXUsed(false) {} + + QString text; + bool teXUsed; + }; + + struct PositionWrapper { + QPointF point; + HorizontalPosition horizontalPosition; + VerticalPosition verticalPosition; + }; + + explicit TextLabel(const QString& name, Type type = General); + ~TextLabel() override; + + Type type() const; + QIcon icon() const override; + QMenu* createContextMenu() override; + QGraphicsItem* graphicsItem() const override; + void setParentGraphicsItem(QGraphicsItem*); + + void save(QXmlStreamWriter*) const override; + bool load(XmlStreamReader*, bool preview) override; + void loadThemeConfig(const KConfig& config) override; + void saveThemeConfig(const KConfig& config) override; + + CLASS_D_ACCESSOR_DECL(TextWrapper, text, Text) + BASIC_D_ACCESSOR_DECL(QColor, teXFontColor, TeXFontColor) + BASIC_D_ACCESSOR_DECL(QColor, teXBackgroundColor, TeXBackgroundColor) + CLASS_D_ACCESSOR_DECL(QFont, teXFont, TeXFont) + CLASS_D_ACCESSOR_DECL(PositionWrapper, position, Position) + void setPosition(QPointF); + void setPositionInvalid(bool); + BASIC_D_ACCESSOR_DECL(HorizontalAlignment, horizontalAlignment, HorizontalAlignment) + BASIC_D_ACCESSOR_DECL(VerticalAlignment, verticalAlignment, VerticalAlignment) + BASIC_D_ACCESSOR_DECL(qreal, rotationAngle, RotationAngle) + + void setVisible(bool on) override; + bool isVisible() const override; + void setPrinting(bool) override; + + void retransform() override; + void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override; + + typedef TextLabelPrivate Private; + +private slots: + void updateTeXImage(); + + //SLOTs for changes triggered via QActions in the context menu + void visibilityChanged(); + +protected: + TextLabelPrivate* const d_ptr; + TextLabel(const QString& name, TextLabelPrivate* dd, Type type = General); + +private: + Q_DECLARE_PRIVATE(TextLabel) + void init(); + + Type m_type; + QAction* visibilityAction; + +signals: + void textWrapperChanged(const TextLabel::TextWrapper&); + void teXFontSizeChanged(const int); + void teXFontChanged(const QFont); + void teXFontColorChanged(const QColor); + void teXBackgroundColorChanged(const QColor); + void positionChanged(const TextLabel::PositionWrapper&); + void horizontalAlignmentChanged(TextLabel::HorizontalAlignment); + void verticalAlignmentChanged(TextLabel::VerticalAlignment); + void rotationAngleChanged(qreal); + void visibleChanged(bool); + + void teXImageUpdated(bool); + void changed(); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/CartesianPlotLegend.cpp b/src/backend/worksheet/plots/cartesian/CartesianPlotLegend.cpp index b943e520f..95145f68c 100644 --- a/src/backend/worksheet/plots/cartesian/CartesianPlotLegend.cpp +++ b/src/backend/worksheet/plots/cartesian/CartesianPlotLegend.cpp @@ -1,1174 +1,1195 @@ /*************************************************************************** File : CartesianPlotLegend.cpp Project : LabPlot Description : Legend for the cartesian plot -------------------------------------------------------------------- Copyright : (C) 2013-2018 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ /*! \class CartesianPlotLegend \brief Legend for the cartesian plot. \ingroup kdefrontend */ #include "CartesianPlotLegend.h" #include "backend/worksheet/plots/cartesian/CartesianPlotLegendPrivate.h" #include "backend/worksheet/plots/cartesian/CartesianPlot.h" #include "backend/worksheet/plots/cartesian/XYCurve.h" #include "backend/worksheet/Worksheet.h" #include "backend/lib/XmlStreamReader.h" #include "backend/worksheet/TextLabel.h" #include "backend/lib/commandtemplates.h" #include #include #include #include #include #include #include CartesianPlotLegend::CartesianPlotLegend(CartesianPlot* plot, const QString &name) : WorksheetElement(name), d_ptr(new CartesianPlotLegendPrivate(this)), m_plot(plot) { init(); } CartesianPlotLegend::CartesianPlotLegend(CartesianPlot* plot, const QString &name, CartesianPlotLegendPrivate *dd) : WorksheetElement(name), d_ptr(dd), m_plot(plot) { init(); } CartesianPlotLegend::~CartesianPlotLegend() { //no need to delete the d-pointer here - it inherits from QGraphicsItem //and is deleted during the cleanup in QGraphicsScene } void CartesianPlotLegend::init() { Q_D(CartesianPlotLegend); KConfig config; KConfigGroup group = config.group( "CartesianPlotLegend" ); d->labelFont = group.readEntry("LabelsFont", QFont()); d->labelFont.setPixelSize( Worksheet::convertToSceneUnits( 10, Worksheet::Point ) ); d->labelColor = Qt::black; d->labelColumnMajor = true; d->lineSymbolWidth = group.readEntry("LineSymbolWidth", Worksheet::convertToSceneUnits(1, Worksheet::Centimeter)); d->rowCount = 0; d->columnCount = 0; d->position.horizontalPosition = CartesianPlotLegend::hPositionRight; d->position.verticalPosition = CartesianPlotLegend::vPositionBottom; d->rotationAngle = group.readEntry("Rotation", 0.0); //Title d->title = new TextLabel(this->name(), TextLabel::PlotLegendTitle); addChild(d->title); d->title->setHidden(true); d->title->setParentGraphicsItem(graphicsItem()); d->title->graphicsItem()->setFlag(QGraphicsItem::ItemIsMovable, false); connect(d->title, &TextLabel::changed, this, &CartesianPlotLegend::retransform); //Background d->backgroundType = (PlotArea::BackgroundType) group.readEntry("BackgroundType", (int) PlotArea::Color); d->backgroundColorStyle = (PlotArea::BackgroundColorStyle) group.readEntry("BackgroundColorStyle", (int) PlotArea::SingleColor); d->backgroundImageStyle = (PlotArea::BackgroundImageStyle) group.readEntry("BackgroundImageStyle", (int) PlotArea::Scaled); d->backgroundBrushStyle = (Qt::BrushStyle) group.readEntry("BackgroundBrushStyle", (int) Qt::SolidPattern); d->backgroundFileName = group.readEntry("BackgroundFileName", QString()); d->backgroundFirstColor = group.readEntry("BackgroundFirstColor", QColor(Qt::white)); d->backgroundSecondColor = group.readEntry("BackgroundSecondColor", QColor(Qt::black)); d->backgroundOpacity = group.readEntry("BackgroundOpacity", 1.0); //Border d->borderPen = QPen(group.readEntry("BorderColor", QColor(Qt::black)), group.readEntry("BorderWidth", Worksheet::convertToSceneUnits(1.0, Worksheet::Point)), (Qt::PenStyle) group.readEntry("BorderStyle", (int)Qt::SolidLine)); d->borderCornerRadius = group.readEntry("BorderCornerRadius", 0.0); d->borderOpacity = group.readEntry("BorderOpacity", 1.0); //Layout d->layoutTopMargin = group.readEntry("LayoutTopMargin", Worksheet::convertToSceneUnits(0.2f, Worksheet::Centimeter)); d->layoutBottomMargin = group.readEntry("LayoutBottomMargin", Worksheet::convertToSceneUnits(0.2f, Worksheet::Centimeter)); d->layoutLeftMargin = group.readEntry("LayoutLeftMargin", Worksheet::convertToSceneUnits(0.2f, Worksheet::Centimeter)); d->layoutRightMargin = group.readEntry("LayoutRightMargin", Worksheet::convertToSceneUnits(0.2f, Worksheet::Centimeter)); d->layoutVerticalSpacing = group.readEntry("LayoutVerticalSpacing", Worksheet::convertToSceneUnits(0.1f, Worksheet::Centimeter)); d->layoutHorizontalSpacing = group.readEntry("LayoutHorizontalSpacing", Worksheet::convertToSceneUnits(0.1f, Worksheet::Centimeter)); d->layoutColumnCount = group.readEntry("LayoutColumnCount", 1); graphicsItem()->setFlag(QGraphicsItem::ItemIsSelectable, true); graphicsItem()->setFlag(QGraphicsItem::ItemIsMovable); graphicsItem()->setFlag(QGraphicsItem::ItemSendsGeometryChanges); this->initActions(); } void CartesianPlotLegend::initActions() { visibilityAction = new QAction(i18n("Visible"), this); visibilityAction->setCheckable(true); connect(visibilityAction, &QAction::triggered, this, &CartesianPlotLegend::visibilityChanged); } QMenu* CartesianPlotLegend::createContextMenu() { QMenu *menu = WorksheetElement::createContextMenu(); QAction* firstAction = menu->actions().at(1); //skip the first action because of the "title-action" visibilityAction->setChecked(isVisible()); menu->insertAction(firstAction, visibilityAction); return menu; } /*! Returns an icon to be used in the project explorer. */ QIcon CartesianPlotLegend::icon() const{ return QIcon::fromTheme("text-field"); } STD_SWAP_METHOD_SETTER_CMD_IMPL(CartesianPlotLegend, SetVisible, bool, swapVisible) void CartesianPlotLegend::setVisible(bool on) { Q_D(CartesianPlotLegend); exec(new CartesianPlotLegendSetVisibleCmd(d, on, on ? ki18n("%1: set visible") : ki18n("%1: set invisible"))); } bool CartesianPlotLegend::isVisible() const{ Q_D(const CartesianPlotLegend); return d->isVisible(); } void CartesianPlotLegend::setPrinting(bool on) { Q_D(CartesianPlotLegend); d->m_printing = on; } QGraphicsItem *CartesianPlotLegend::graphicsItem() const{ return d_ptr; } void CartesianPlotLegend::retransform() { d_ptr->retransform(); } void CartesianPlotLegend::handleResize(double horizontalRatio, double verticalRatio, bool pageResize) { Q_UNUSED(horizontalRatio); Q_UNUSED(verticalRatio); Q_UNUSED(pageResize); //TODO // Q_D(const CartesianPlotLegend); } //############################################################################## //################################ getter methods ############################ //############################################################################## CLASS_SHARED_D_READER_IMPL(CartesianPlotLegend, QFont, labelFont, labelFont) CLASS_SHARED_D_READER_IMPL(CartesianPlotLegend, QColor, labelColor, labelColor) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, bool, labelColumnMajor, labelColumnMajor) CLASS_SHARED_D_READER_IMPL(CartesianPlotLegend, CartesianPlotLegend::PositionWrapper, position, position) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, qreal, rotationAngle, rotationAngle) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, lineSymbolWidth, lineSymbolWidth) //Title TextLabel* CartesianPlotLegend::title() { return d_ptr->title; } //Background BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, PlotArea::BackgroundType, backgroundType, backgroundType) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, PlotArea::BackgroundColorStyle, backgroundColorStyle, backgroundColorStyle) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, PlotArea::BackgroundImageStyle, backgroundImageStyle, backgroundImageStyle) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, Qt::BrushStyle, backgroundBrushStyle, backgroundBrushStyle) CLASS_SHARED_D_READER_IMPL(CartesianPlotLegend, QColor, backgroundFirstColor, backgroundFirstColor) CLASS_SHARED_D_READER_IMPL(CartesianPlotLegend, QColor, backgroundSecondColor, backgroundSecondColor) CLASS_SHARED_D_READER_IMPL(CartesianPlotLegend, QString, backgroundFileName, backgroundFileName) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, backgroundOpacity, backgroundOpacity) //Border CLASS_SHARED_D_READER_IMPL(CartesianPlotLegend, QPen, borderPen, borderPen) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, borderCornerRadius, borderCornerRadius) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, borderOpacity, borderOpacity) //Layout BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, layoutTopMargin, layoutTopMargin) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, layoutBottomMargin, layoutBottomMargin) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, layoutLeftMargin, layoutLeftMargin) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, layoutRightMargin, layoutRightMargin) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, layoutHorizontalSpacing, layoutHorizontalSpacing) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, float, layoutVerticalSpacing, layoutVerticalSpacing) BASIC_SHARED_D_READER_IMPL(CartesianPlotLegend, int, layoutColumnCount, layoutColumnCount) //############################################################################## //###################### setter methods and undo commands #################### //############################################################################## STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLabelFont, QFont, labelFont, retransform) void CartesianPlotLegend::setLabelFont(const QFont& font) { Q_D(CartesianPlotLegend); if (font!= d->labelFont) exec(new CartesianPlotLegendSetLabelFontCmd(d, font, ki18n("%1: set font"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLabelColor, QColor, labelColor, update) void CartesianPlotLegend::setLabelColor(const QColor& color) { Q_D(CartesianPlotLegend); if (color!= d->labelColor) exec(new CartesianPlotLegendSetLabelColorCmd(d, color, ki18n("%1: set font color"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLabelColumnMajor, bool, labelColumnMajor, retransform) void CartesianPlotLegend::setLabelColumnMajor(bool columnMajor) { Q_D(CartesianPlotLegend); if (columnMajor != d->labelColumnMajor) exec(new CartesianPlotLegendSetLabelColumnMajorCmd(d, columnMajor, ki18n("%1: change column order"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLineSymbolWidth, float, lineSymbolWidth, retransform) void CartesianPlotLegend::setLineSymbolWidth(float width) { Q_D(CartesianPlotLegend); if (width != d->lineSymbolWidth) exec(new CartesianPlotLegendSetLineSymbolWidthCmd(d, width, ki18n("%1: change line+symbol width"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetPosition, CartesianPlotLegend::PositionWrapper, position, updatePosition); void CartesianPlotLegend::setPosition(const PositionWrapper& pos) { Q_D(CartesianPlotLegend); if (pos.point!=d->position.point || pos.horizontalPosition!=d->position.horizontalPosition || pos.verticalPosition!=d->position.verticalPosition) exec(new CartesianPlotLegendSetPositionCmd(d, pos, ki18n("%1: set position"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetRotationAngle, qreal, rotationAngle, retransform) void CartesianPlotLegend::setRotationAngle(qreal angle) { Q_D(CartesianPlotLegend); - if (angle != d->rotationAngle) + if (angle != d->rotationAngle) { exec(new CartesianPlotLegendSetRotationAngleCmd(d, angle, ki18n("%1: set rotation angle"))); + d->title->setRotationAngle(angle); + } } //Background STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBackgroundType, PlotArea::BackgroundType, backgroundType, update) void CartesianPlotLegend::setBackgroundType(PlotArea::BackgroundType type) { Q_D(CartesianPlotLegend); if (type != d->backgroundType) exec(new CartesianPlotLegendSetBackgroundTypeCmd(d, type, ki18n("%1: background type changed"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBackgroundColorStyle, PlotArea::BackgroundColorStyle, backgroundColorStyle, update) void CartesianPlotLegend::setBackgroundColorStyle(PlotArea::BackgroundColorStyle style) { Q_D(CartesianPlotLegend); if (style != d->backgroundColorStyle) exec(new CartesianPlotLegendSetBackgroundColorStyleCmd(d, style, ki18n("%1: background color style changed"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBackgroundImageStyle, PlotArea::BackgroundImageStyle, backgroundImageStyle, update) void CartesianPlotLegend::setBackgroundImageStyle(PlotArea::BackgroundImageStyle style) { Q_D(CartesianPlotLegend); if (style != d->backgroundImageStyle) exec(new CartesianPlotLegendSetBackgroundImageStyleCmd(d, style, ki18n("%1: background image style changed"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBackgroundBrushStyle, Qt::BrushStyle, backgroundBrushStyle, update) void CartesianPlotLegend::setBackgroundBrushStyle(Qt::BrushStyle style) { Q_D(CartesianPlotLegend); if (style != d->backgroundBrushStyle) exec(new CartesianPlotLegendSetBackgroundBrushStyleCmd(d, style, ki18n("%1: background brush style changed"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBackgroundFirstColor, QColor, backgroundFirstColor, update) void CartesianPlotLegend::setBackgroundFirstColor(const QColor &color) { Q_D(CartesianPlotLegend); if (color!= d->backgroundFirstColor) exec(new CartesianPlotLegendSetBackgroundFirstColorCmd(d, color, ki18n("%1: set background first color"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBackgroundSecondColor, QColor, backgroundSecondColor, update) void CartesianPlotLegend::setBackgroundSecondColor(const QColor &color) { Q_D(CartesianPlotLegend); if (color!= d->backgroundSecondColor) exec(new CartesianPlotLegendSetBackgroundSecondColorCmd(d, color, ki18n("%1: set background second color"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBackgroundFileName, QString, backgroundFileName, update) void CartesianPlotLegend::setBackgroundFileName(const QString& fileName) { Q_D(CartesianPlotLegend); if (fileName!= d->backgroundFileName) exec(new CartesianPlotLegendSetBackgroundFileNameCmd(d, fileName, ki18n("%1: set background image"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBackgroundOpacity, float, backgroundOpacity, update) void CartesianPlotLegend::setBackgroundOpacity(float opacity) { Q_D(CartesianPlotLegend); if (opacity != d->backgroundOpacity) exec(new CartesianPlotLegendSetBackgroundOpacityCmd(d, opacity, ki18n("%1: set opacity"))); } //Border STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBorderPen, QPen, borderPen, update) void CartesianPlotLegend::setBorderPen(const QPen &pen) { Q_D(CartesianPlotLegend); if (pen != d->borderPen) exec(new CartesianPlotLegendSetBorderPenCmd(d, pen, ki18n("%1: set border style"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBorderCornerRadius, qreal, borderCornerRadius, update) void CartesianPlotLegend::setBorderCornerRadius(float radius) { Q_D(CartesianPlotLegend); if (radius != d->borderCornerRadius) exec(new CartesianPlotLegendSetBorderCornerRadiusCmd(d, radius, ki18n("%1: set border corner radius"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetBorderOpacity, qreal, borderOpacity, update) void CartesianPlotLegend::setBorderOpacity(float opacity) { Q_D(CartesianPlotLegend); if (opacity != d->borderOpacity) exec(new CartesianPlotLegendSetBorderOpacityCmd(d, opacity, ki18n("%1: set border opacity"))); } //Layout STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLayoutTopMargin, float, layoutTopMargin, retransform) void CartesianPlotLegend::setLayoutTopMargin(float margin) { Q_D(CartesianPlotLegend); if (margin != d->layoutTopMargin) exec(new CartesianPlotLegendSetLayoutTopMarginCmd(d, margin, ki18n("%1: set layout top margin"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLayoutBottomMargin, float, layoutBottomMargin, retransform) void CartesianPlotLegend::setLayoutBottomMargin(float margin) { Q_D(CartesianPlotLegend); if (margin != d->layoutBottomMargin) exec(new CartesianPlotLegendSetLayoutBottomMarginCmd(d, margin, ki18n("%1: set layout bottom margin"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLayoutLeftMargin, float, layoutLeftMargin, retransform) void CartesianPlotLegend::setLayoutLeftMargin(float margin) { Q_D(CartesianPlotLegend); if (margin != d->layoutLeftMargin) exec(new CartesianPlotLegendSetLayoutLeftMarginCmd(d, margin, ki18n("%1: set layout left margin"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLayoutRightMargin, float, layoutRightMargin, retransform) void CartesianPlotLegend::setLayoutRightMargin(float margin) { Q_D(CartesianPlotLegend); if (margin != d->layoutRightMargin) exec(new CartesianPlotLegendSetLayoutRightMarginCmd(d, margin, ki18n("%1: set layout right margin"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLayoutVerticalSpacing, float, layoutVerticalSpacing, retransform) void CartesianPlotLegend::setLayoutVerticalSpacing(float spacing) { Q_D(CartesianPlotLegend); if (spacing != d->layoutVerticalSpacing) exec(new CartesianPlotLegendSetLayoutVerticalSpacingCmd(d, spacing, ki18n("%1: set layout vertical spacing"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLayoutHorizontalSpacing, float, layoutHorizontalSpacing, retransform) void CartesianPlotLegend::setLayoutHorizontalSpacing(float spacing) { Q_D(CartesianPlotLegend); if (spacing != d->layoutHorizontalSpacing) exec(new CartesianPlotLegendSetLayoutHorizontalSpacingCmd(d, spacing, ki18n("%1: set layout horizontal spacing"))); } STD_SETTER_CMD_IMPL_F_S(CartesianPlotLegend, SetLayoutColumnCount, int, layoutColumnCount, retransform) void CartesianPlotLegend::setLayoutColumnCount(int count) { Q_D(CartesianPlotLegend); if (count != d->layoutColumnCount) exec(new CartesianPlotLegendSetLayoutColumnCountCmd(d, count, ki18n("%1: set layout column count"))); } //############################################################################## //################################# SLOTS #################################### //############################################################################## //############################################################################## //###### SLOTs for changes triggered via QActions in the context menu ######## //############################################################################## void CartesianPlotLegend::visibilityChangedSlot() { Q_D(const CartesianPlotLegend); this->setVisible(!d->isVisible()); } //############################################################################## //######################### Private implementation ############################# //############################################################################## CartesianPlotLegendPrivate::CartesianPlotLegendPrivate(CartesianPlotLegend *owner):q(owner), suppressItemChangeEvent(false), suppressRetransform(false), m_printing(false), m_hovered(false) { setAcceptHoverEvents(true); } QString CartesianPlotLegendPrivate::name() const { return q->name(); } QRectF CartesianPlotLegendPrivate::boundingRect() const { if (rotationAngle != 0) { QMatrix matrix; matrix.rotate(-rotationAngle); return matrix.mapRect(rect); } else return rect; } void CartesianPlotLegendPrivate::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) { q->createContextMenu()->exec(event->screenPos()); } /*! Returns the shape of the CartesianPlotLegend as a QPainterPath in local coordinates */ QPainterPath CartesianPlotLegendPrivate::shape() const { QPainterPath path; if ( qFuzzyIsNull(borderCornerRadius) ) path.addRect(rect); else path.addRoundedRect(rect, borderCornerRadius, borderCornerRadius); if (rotationAngle != 0) { QTransform trafo; - trafo.rotate(rotationAngle); + trafo.rotate(-rotationAngle); path = trafo.map(path); } return path; } bool CartesianPlotLegendPrivate::swapVisible(bool on) { bool oldValue = isVisible(); setVisible(on); emit q->visibilityChanged(on); return oldValue; } /*! recalculates the rectangular of the legend. */ void CartesianPlotLegendPrivate::retransform() { if (suppressRetransform) return; prepareGeometryChange(); curvesList.clear(); for (auto* curve : q->m_plot->children()) { if (curve && curve->isVisible()) curvesList.push_back(curve); } int curveCount = curvesList.size(); columnCount = (curveCount= curveCount ) break; curve = curvesList.at(index); if (curve) { if (!curve->isVisible()) continue; w = fm.width(curve->name()); if (w>maxTextWidth) maxTextWidth = w; } } maxColumnTextWidths.append(maxTextWidth); legendWidth += maxTextWidth; } legendWidth += layoutLeftMargin + layoutRightMargin; //margins legendWidth += columnCount*lineSymbolWidth + layoutHorizontalSpacing; //width of the columns without the text legendWidth += (columnCount-1)*2*layoutHorizontalSpacing; //spacings between the columns if (title->isVisible() && !title->text().text.isEmpty()) { - float titleWidth = title->graphicsItem()->boundingRect().width(); + float titleWidth; + if (rotationAngle == 0.0) + titleWidth = title->graphicsItem()->boundingRect().width(); + else { + QRectF rect = title->graphicsItem()->boundingRect(); + QMatrix matrix; + matrix.rotate(-rotationAngle); + rect = matrix.mapRect(rect); + titleWidth = rect.width(); + } + if (titleWidth > legendWidth) legendWidth = titleWidth; } //determine the height of the legend float legendHeight = layoutTopMargin + layoutBottomMargin; //margins legendHeight += rowCount*h; //height of the rows legendHeight += (rowCount-1)*layoutVerticalSpacing; //spacing between the rows - if (title->isVisible() && !title->text().text.isEmpty()) - legendHeight += title->graphicsItem()->boundingRect().height(); //legend title + if (title->isVisible() && !title->text().text.isEmpty()) { + if (rotationAngle == 0.0) + legendHeight += title->graphicsItem()->boundingRect().height(); //legend title + else { + QRectF rect = title->graphicsItem()->boundingRect(); + QMatrix matrix; + matrix.rotate(-rotationAngle); + rect = matrix.mapRect(rect); + legendHeight += rect.height(); //legend title + } + } rect.setX(-legendWidth/2); rect.setY(-legendHeight/2); rect.setWidth(legendWidth); rect.setHeight(legendHeight); updatePosition(); } /*! calculates the position of the legend, when the position relative to the parent was specified (left, right, etc.) */ void CartesianPlotLegendPrivate::updatePosition() { //position the legend relative to the actual plot size minus small offset //TODO: make the offset dependent on the size of axis ticks. const QRectF parentRect = q->m_plot->dataRect(); float hOffset = Worksheet::convertToSceneUnits(10, Worksheet::Point); float vOffset = Worksheet::convertToSceneUnits(10, Worksheet::Point); if (position.horizontalPosition != CartesianPlotLegend::hPositionCustom) { if (position.horizontalPosition == CartesianPlotLegend::hPositionLeft) position.point.setX(parentRect.x() + rect.width()/2 + hOffset); else if (position.horizontalPosition == CartesianPlotLegend::hPositionCenter) position.point.setX(parentRect.x() + parentRect.width()/2); else if (position.horizontalPosition == CartesianPlotLegend::hPositionRight) position.point.setX(parentRect.x() + parentRect.width() - rect.width()/2 - hOffset); } if (position.verticalPosition != CartesianPlotLegend::vPositionCustom) { if (position.verticalPosition == CartesianPlotLegend::vPositionTop) position.point.setY(parentRect.y() + rect.height()/2 + vOffset); else if (position.verticalPosition == CartesianPlotLegend::vPositionCenter) position.point.setY(parentRect.y() + parentRect.height()/2); else if (position.verticalPosition == CartesianPlotLegend::vPositionBottom) position.point.setY(parentRect.y() + parentRect.height() - rect.height()/2 -vOffset); } suppressItemChangeEvent=true; setPos(position.point); suppressItemChangeEvent=false; emit q->positionChanged(position); suppressRetransform = true; title->retransform(); suppressRetransform = false; } /*! Reimplementation of QGraphicsItem::paint(). This function does the actual painting of the legend. \sa QGraphicsItem::paint(). */ void CartesianPlotLegendPrivate::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); if (!isVisible()) return; painter->save(); painter->rotate(-rotationAngle); //draw the area painter->setOpacity(backgroundOpacity); painter->setPen(Qt::NoPen); if (backgroundType == PlotArea::Color) { switch (backgroundColorStyle) { case PlotArea::SingleColor:{ painter->setBrush(QBrush(backgroundFirstColor)); break; } case PlotArea::HorizontalLinearGradient:{ QLinearGradient linearGrad(rect.topLeft(), rect.topRight()); linearGrad.setColorAt(0, backgroundFirstColor); linearGrad.setColorAt(1, backgroundSecondColor); painter->setBrush(QBrush(linearGrad)); break; } case PlotArea::VerticalLinearGradient:{ QLinearGradient linearGrad(rect.topLeft(), rect.bottomLeft()); linearGrad.setColorAt(0, backgroundFirstColor); linearGrad.setColorAt(1, backgroundSecondColor); painter->setBrush(QBrush(linearGrad)); break; } case PlotArea::TopLeftDiagonalLinearGradient:{ QLinearGradient linearGrad(rect.topLeft(), rect.bottomRight()); linearGrad.setColorAt(0, backgroundFirstColor); linearGrad.setColorAt(1, backgroundSecondColor); painter->setBrush(QBrush(linearGrad)); break; } case PlotArea::BottomLeftDiagonalLinearGradient:{ QLinearGradient linearGrad(rect.bottomLeft(), rect.topRight()); linearGrad.setColorAt(0, backgroundFirstColor); linearGrad.setColorAt(1, backgroundSecondColor); painter->setBrush(QBrush(linearGrad)); break; } case PlotArea::RadialGradient:{ QRadialGradient radialGrad(rect.center(), rect.width()/2); radialGrad.setColorAt(0, backgroundFirstColor); radialGrad.setColorAt(1, backgroundSecondColor); painter->setBrush(QBrush(radialGrad)); break; } } } else if (backgroundType == PlotArea::Image) { if ( !backgroundFileName.trimmed().isEmpty() ) { QPixmap pix(backgroundFileName); switch (backgroundImageStyle) { case PlotArea::ScaledCropped: pix = pix.scaled(rect.size().toSize(),Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation); painter->drawPixmap(rect.topLeft(),pix); break; case PlotArea::Scaled: pix = pix.scaled(rect.size().toSize(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation); painter->drawPixmap(rect.topLeft(),pix); break; case PlotArea::ScaledAspectRatio: pix = pix.scaled(rect.size().toSize(),Qt::KeepAspectRatio,Qt::SmoothTransformation); painter->drawPixmap(rect.topLeft(),pix); break; case PlotArea::Centered: painter->drawPixmap(QPointF(rect.center().x()-pix.size().width()/2,rect.center().y()-pix.size().height()/2),pix); break; case PlotArea::Tiled: painter->drawTiledPixmap(rect,pix); break; case PlotArea::CenterTiled: painter->drawTiledPixmap(rect,pix,QPoint(rect.size().width()/2,rect.size().height()/2)); } } } else if (backgroundType == PlotArea::Pattern) { painter->setBrush(QBrush(backgroundFirstColor,backgroundBrushStyle)); } if ( qFuzzyIsNull(borderCornerRadius) ) painter->drawRect(rect); else painter->drawRoundedRect(rect, borderCornerRadius, borderCornerRadius); //draw the border if (borderPen.style() != Qt::NoPen) { painter->setPen(borderPen); painter->setBrush(Qt::NoBrush); painter->setOpacity(borderOpacity); if ( qFuzzyIsNull(borderCornerRadius) ) painter->drawRect(rect); else painter->drawRoundedRect(rect, borderCornerRadius, borderCornerRadius); } //draw curve's line+symbol and the names int curveCount = curvesList.size(); QFontMetrics fm(labelFont); float h=fm.ascent(); XYCurve* curve; painter->setFont(labelFont); //translate to left upper conner of the bounding rect plus the layout offset and the height of the title painter->translate(-rect.width()/2+layoutLeftMargin, -rect.height()/2+layoutTopMargin); if (title->isVisible() && !title->text().text.isEmpty()) painter->translate(0, title->graphicsItem()->boundingRect().height()); painter->save(); int index; for (int c=0; c= curveCount ) break; curve = curvesList.at(index); //curve's line (painted at the half of the ascent size) if (curve->lineType() != XYCurve::NoLine) { painter->setPen(curve->linePen()); painter->setOpacity(curve->lineOpacity()); painter->drawLine(0, h/2, lineSymbolWidth, h/2); } //error bars if ( (curve->xErrorType() != XYCurve::NoError && curve->xErrorPlusColumn()) || (curve->yErrorType() != XYCurve::NoError && curve->yErrorPlusColumn()) ) { painter->setOpacity(curve->errorBarsOpacity()); painter->setPen(curve->errorBarsPen()); //curve's error bars for x float errorBarsSize = Worksheet::convertToSceneUnits(10, Worksheet::Point); if (curve->symbolsStyle()!=Symbol::NoSymbols && errorBarsSizesymbolsSize()*1.4) errorBarsSize = curve->symbolsSize()*1.4; switch (curve->errorBarsType()) { case XYCurve::ErrorBarsSimple: //horiz. line if (curve->xErrorType() != XYCurve::NoError) painter->drawLine(lineSymbolWidth/2-errorBarsSize/2, h/2, lineSymbolWidth/2+errorBarsSize/2, h/2); //vert. line if (curve->yErrorType() != XYCurve::NoError) painter->drawLine(lineSymbolWidth/2, h/2-errorBarsSize/2, lineSymbolWidth/2, h/2+errorBarsSize/2); break; case XYCurve::ErrorBarsWithEnds: //horiz. line if (curve->xErrorType() != XYCurve::NoError) { painter->drawLine(lineSymbolWidth/2-errorBarsSize/2, h/2, lineSymbolWidth/2+errorBarsSize/2, h/2); //caps for the horiz. line painter->drawLine(lineSymbolWidth/2-errorBarsSize/2, h/2-errorBarsSize/4, lineSymbolWidth/2-errorBarsSize/2, h/2+errorBarsSize/4); painter->drawLine(lineSymbolWidth/2+errorBarsSize/2, h/2-errorBarsSize/4, lineSymbolWidth/2+errorBarsSize/2, h/2+errorBarsSize/4); } //vert. line if (curve->yErrorType() != XYCurve::NoError) { painter->drawLine(lineSymbolWidth/2, h/2-errorBarsSize/2, lineSymbolWidth/2, h/2+errorBarsSize/2); //caps for the vert. line painter->drawLine(lineSymbolWidth/2-errorBarsSize/4, h/2-errorBarsSize/2, lineSymbolWidth/2+errorBarsSize/4, h/2-errorBarsSize/2); painter->drawLine(lineSymbolWidth/2-errorBarsSize/4, h/2+errorBarsSize/2, lineSymbolWidth/2+errorBarsSize/4, h/2+errorBarsSize/2); } break; } } //curve's symbol if (curve->symbolsStyle()!=Symbol::NoSymbols) { painter->setOpacity(curve->symbolsOpacity()); painter->setBrush(curve->symbolsBrush()); painter->setPen(curve->symbolsPen()); QPainterPath path = Symbol::pathFromStyle(curve->symbolsStyle()); QTransform trafo; trafo.scale(curve->symbolsSize(), curve->symbolsSize()); path = trafo.map(path); if (curve->symbolsRotationAngle() != 0) { trafo.reset(); trafo.rotate(curve->symbolsRotationAngle()); path = trafo.map(path); } painter->translate(QPointF(lineSymbolWidth/2, h/2)); painter->drawPath(path); painter->translate(-QPointF(lineSymbolWidth/2, h/2)); } //curve's name painter->setPen(QPen(labelColor)); painter->setOpacity(1.0); //TODO: support HTML text? painter->drawText(QPoint(lineSymbolWidth+layoutHorizontalSpacing, h), curve->name()); painter->translate(0,layoutVerticalSpacing+h); } //translate to the beginning of the next column painter->restore(); int deltaX = lineSymbolWidth+layoutHorizontalSpacing+maxColumnTextWidths.at(c); //the width of the current columns deltaX += 2*layoutHorizontalSpacing; //spacing between two columns painter->translate(deltaX,0); painter->save(); } painter->restore(); painter->restore(); if (m_hovered && !isSelected() && !m_printing){ painter->setPen(QPen(QApplication::palette().color(QPalette::Shadow), 2, Qt::SolidLine)); painter->drawPath(shape()); } if (isSelected() && !m_printing){ painter->setPen(QPen(QApplication::palette().color(QPalette::Highlight), 2, Qt::SolidLine)); painter->drawPath(shape()); } } QVariant CartesianPlotLegendPrivate::itemChange(GraphicsItemChange change, const QVariant &value) { if (suppressItemChangeEvent) return value; if (change == QGraphicsItem::ItemPositionChange) { //convert item's center point in parent's coordinates CartesianPlotLegend::PositionWrapper tempPosition; tempPosition.point = value.toPointF(); tempPosition.horizontalPosition = CartesianPlotLegend::hPositionCustom; tempPosition.verticalPosition = CartesianPlotLegend::vPositionCustom; //emit the signals in order to notify the UI. //we don't set the position related member variables during the mouse movements. //this is done on mouse release events only. emit q->positionChanged(tempPosition); } return QGraphicsItem::itemChange(change, value); } void CartesianPlotLegendPrivate::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) { //convert position of the item in parent coordinates to label's position QPointF point = pos(); if (point!=position.point) { //position was changed -> set the position related member variables suppressRetransform = true; CartesianPlotLegend::PositionWrapper tempPosition; tempPosition.point = point; tempPosition.horizontalPosition = CartesianPlotLegend::hPositionCustom; tempPosition.verticalPosition = CartesianPlotLegend::vPositionCustom; q->setPosition(tempPosition); suppressRetransform = false; } QGraphicsItem::mouseReleaseEvent(event); } void CartesianPlotLegendPrivate::hoverEnterEvent(QGraphicsSceneHoverEvent*) { if (!isSelected()) { m_hovered = true; emit q->hovered(); update(); } } void CartesianPlotLegendPrivate::hoverLeaveEvent(QGraphicsSceneHoverEvent*) { if (m_hovered) { m_hovered = false; emit q->unhovered(); update(); } } //############################################################################## //################## Serialization/Deserialization ########################### //############################################################################## //! Save as XML void CartesianPlotLegend::save(QXmlStreamWriter* writer) const { Q_D(const CartesianPlotLegend); writer->writeStartElement( "cartesianPlotLegend" ); writeBasicAttributes( writer ); writeCommentElement( writer ); //general writer->writeStartElement( "general" ); WRITE_QCOLOR(d->labelColor); WRITE_QFONT(d->labelFont); writer->writeAttribute( "columnMajor", QString::number(d->labelColumnMajor) ); writer->writeAttribute( "lineSymbolWidth", QString::number(d->lineSymbolWidth) ); writer->writeAttribute( "visible", QString::number(d->isVisible()) ); writer->writeEndElement(); //geometry writer->writeStartElement( "geometry" ); writer->writeAttribute( "x", QString::number(d->position.point.x()) ); writer->writeAttribute( "y", QString::number(d->position.point.y()) ); writer->writeAttribute( "horizontalPosition", QString::number(d->position.horizontalPosition) ); writer->writeAttribute( "verticalPosition", QString::number(d->position.verticalPosition) ); writer->writeAttribute( "rotation", QString::number(d->rotationAngle) ); writer->writeEndElement(); //title d->title->save(writer); //background writer->writeStartElement( "background" ); writer->writeAttribute( "type", QString::number(d->backgroundType) ); writer->writeAttribute( "colorStyle", QString::number(d->backgroundColorStyle) ); writer->writeAttribute( "imageStyle", QString::number(d->backgroundImageStyle) ); writer->writeAttribute( "brushStyle", QString::number(d->backgroundBrushStyle) ); writer->writeAttribute( "firstColor_r", QString::number(d->backgroundFirstColor.red()) ); writer->writeAttribute( "firstColor_g", QString::number(d->backgroundFirstColor.green()) ); writer->writeAttribute( "firstColor_b", QString::number(d->backgroundFirstColor.blue()) ); writer->writeAttribute( "secondColor_r", QString::number(d->backgroundSecondColor.red()) ); writer->writeAttribute( "secondColor_g", QString::number(d->backgroundSecondColor.green()) ); writer->writeAttribute( "secondColor_b", QString::number(d->backgroundSecondColor.blue()) ); writer->writeAttribute( "fileName", d->backgroundFileName ); writer->writeAttribute( "opacity", QString::number(d->backgroundOpacity) ); writer->writeEndElement(); //border writer->writeStartElement( "border" ); WRITE_QPEN(d->borderPen); writer->writeAttribute( "borderOpacity", QString::number(d->borderOpacity) ); writer->writeEndElement(); //layout writer->writeStartElement( "layout" ); writer->writeAttribute( "topMargin", QString::number(d->layoutTopMargin) ); writer->writeAttribute( "bottomMargin", QString::number(d->layoutBottomMargin) ); writer->writeAttribute( "leftMargin", QString::number(d->layoutLeftMargin) ); writer->writeAttribute( "rightMargin", QString::number(d->layoutRightMargin) ); writer->writeAttribute( "verticalSpacing", QString::number(d->layoutVerticalSpacing) ); writer->writeAttribute( "horizontalSpacing", QString::number(d->layoutHorizontalSpacing) ); writer->writeAttribute( "columnCount", QString::number(d->layoutColumnCount) ); writer->writeEndElement(); writer->writeEndElement(); // close "cartesianPlotLegend" section } //! Load from XML bool CartesianPlotLegend::load(XmlStreamReader* reader, bool preview) { Q_D(CartesianPlotLegend); if (!readBasicAttributes(reader)) return false; KLocalizedString attributeWarning = ki18n("Attribute '%1' missing or empty, default value is used"); QXmlStreamAttributes attribs; QString str; while (!reader->atEnd()) { reader->readNext(); if (reader->isEndElement() && reader->name() == "cartesianPlotLegend") break; if (!reader->isStartElement()) continue; if (!preview && reader->name() == "comment") { if (!readCommentElement(reader)) return false; } else if (!preview && reader->name() == "general") { attribs = reader->attributes(); READ_QCOLOR(d->labelColor); READ_QFONT(d->labelFont); str = attribs.value("columnMajor").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("columnMajor").toString()); else d->labelColumnMajor = str.toInt(); str = attribs.value("lineSymbolWidth").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("lineSymbolWidth").toString()); else d->lineSymbolWidth = str.toDouble(); str = attribs.value("visible").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("visible").toString()); else d->setVisible(str.toInt()); } else if (!preview && reader->name() == "geometry") { attribs = reader->attributes(); str = attribs.value("x").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("x").toString()); else d->position.point.setX(str.toDouble()); str = attribs.value("y").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("y").toString()); else d->position.point.setY(str.toDouble()); str = attribs.value("horizontalPosition").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("horizontalPosition").toString()); else d->position.horizontalPosition = (CartesianPlotLegend::HorizontalPosition)str.toInt(); str = attribs.value("verticalPosition").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("verticalPosition").toString()); else d->position.verticalPosition = (CartesianPlotLegend::VerticalPosition)str.toInt(); READ_DOUBLE_VALUE("rotation", rotationAngle); } else if (reader->name() == "textLabel") { if (!d->title->load(reader, preview)) { delete d->title; d->title=0; return false; } } else if (!preview && reader->name() == "background") { attribs = reader->attributes(); str = attribs.value("type").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("type").toString()); else d->backgroundType = PlotArea::BackgroundType(str.toInt()); str = attribs.value("colorStyle").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("colorStyle").toString()); else d->backgroundColorStyle = PlotArea::BackgroundColorStyle(str.toInt()); str = attribs.value("imageStyle").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("imageStyle").toString()); else d->backgroundImageStyle = PlotArea::BackgroundImageStyle(str.toInt()); str = attribs.value("brushStyle").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("brushStyle").toString()); else d->backgroundBrushStyle = Qt::BrushStyle(str.toInt()); str = attribs.value("firstColor_r").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("firstColor_r").toString()); else d->backgroundFirstColor.setRed(str.toInt()); str = attribs.value("firstColor_g").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("firstColor_g").toString()); else d->backgroundFirstColor.setGreen(str.toInt()); str = attribs.value("firstColor_b").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("firstColor_b").toString()); else d->backgroundFirstColor.setBlue(str.toInt()); str = attribs.value("secondColor_r").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("secondColor_r").toString()); else d->backgroundSecondColor.setRed(str.toInt()); str = attribs.value("secondColor_g").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("secondColor_g").toString()); else d->backgroundSecondColor.setGreen(str.toInt()); str = attribs.value("secondColor_b").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("secondColor_b").toString()); else d->backgroundSecondColor.setBlue(str.toInt()); str = attribs.value("fileName").toString(); d->backgroundFileName = str; str = attribs.value("opacity").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("opacity").toString()); else d->backgroundOpacity = str.toDouble(); } else if (!preview && reader->name() == "border") { attribs = reader->attributes(); READ_QPEN(d->borderPen); str = attribs.value("borderOpacity").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("borderOpacity").toString()); else d->borderOpacity = str.toDouble(); } else if (!preview && reader->name() == "layout") { attribs = reader->attributes(); str = attribs.value("topMargin").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("topMargin").toString()); else d->layoutTopMargin = str.toDouble(); str = attribs.value("bottomMargin").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("bottomMargin").toString()); else d->layoutBottomMargin = str.toDouble(); str = attribs.value("leftMargin").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("leftMargin").toString()); else d->layoutLeftMargin = str.toDouble(); str = attribs.value("rightMargin").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("rightMargin").toString()); else d->layoutRightMargin = str.toDouble(); str = attribs.value("verticalSpacing").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("verticalSpacing").toString()); else d->layoutVerticalSpacing = str.toDouble(); str = attribs.value("horizontalSpacing").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("horizontalSpacing").toString()); else d->layoutHorizontalSpacing = str.toDouble(); str = attribs.value("columnCount").toString(); if (str.isEmpty()) reader->raiseWarning(attributeWarning.subs("columnCount").toString()); else d->layoutColumnCount = str.toInt(); } } return true; } void CartesianPlotLegend::loadThemeConfig(const KConfig& config) { KConfigGroup groupLabel = config.group("Label"); this->setLabelColor(groupLabel.readEntry("FontColor", QColor(Qt::white))); const KConfigGroup group = config.group("CartesianPlot"); this->setBackgroundBrushStyle((Qt::BrushStyle)group.readEntry("BackgroundBrushStyle",(int) this->backgroundBrushStyle())); this->setBackgroundColorStyle((PlotArea::BackgroundColorStyle)(group.readEntry("BackgroundColorStyle",(int) this->backgroundColorStyle()))); this->setBackgroundFirstColor(group.readEntry("BackgroundFirstColor",(QColor) this->backgroundFirstColor())); this->setBackgroundImageStyle((PlotArea::BackgroundImageStyle)group.readEntry("BackgroundImageStyle",(int) this->backgroundImageStyle())); this->setBackgroundOpacity(group.readEntry("BackgroundOpacity", this->backgroundOpacity())); this->setBackgroundSecondColor(group.readEntry("BackgroundSecondColor",(QColor) this->backgroundSecondColor())); this->setBackgroundType((PlotArea::BackgroundType)(group.readEntry("BackgroundType",(int) this->backgroundType()))); this->borderPen().setColor(group.readEntry("BorderColor",(QColor) this->borderPen().color())); this->setBorderCornerRadius(group.readEntry("BorderCornerRadius", this->borderCornerRadius())); this->setBorderOpacity(group.readEntry("BorderOpacity", this->borderOpacity())); this->borderPen().setStyle((Qt::PenStyle)(group.readEntry("BorderStyle", (int) this->borderPen().style()))); this->borderPen().setWidthF(group.readEntry("BorderWidth", this->borderPen().widthF())); title()->loadThemeConfig(config); } diff --git a/src/backend/worksheet/plots/cartesian/CustomPoint.h b/src/backend/worksheet/plots/cartesian/CustomPoint.h index 459dacdb6..efda1e045 100644 --- a/src/backend/worksheet/plots/cartesian/CustomPoint.h +++ b/src/backend/worksheet/plots/cartesian/CustomPoint.h @@ -1,106 +1,100 @@ /*************************************************************************** File : CustomPoint.h Project : LabPlot Description : Custom user-defined point on the plot -------------------------------------------------------------------- Copyright : (C) 2015 Ankit Wagadre (wagadre.ankit@gmail.com) Copyright : (C) 2015 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef CUSTOMPOINT_H #define CUSTOMPOINT_H #include #include #include "backend/lib/macros.h" #include "backend/worksheet/plots/cartesian/Symbol.h" #include "backend/worksheet/WorksheetElement.h" class CustomPointPrivate; class CartesianPlot; class CustomPoint : public WorksheetElement { - Q_OBJECT - - public: - explicit CustomPoint(const CartesianPlot*, const QString&); - ~CustomPoint() override; - - QIcon icon() const override; - QMenu* createContextMenu() override; - QGraphicsItem* graphicsItem() const override; - - void save(QXmlStreamWriter*) const override; - bool load(XmlStreamReader*, bool preview) override; - - CLASS_D_ACCESSOR_DECL(QPointF, position, Position) - BASIC_D_ACCESSOR_DECL(Symbol::Style, symbolStyle, SymbolStyle) - BASIC_D_ACCESSOR_DECL(qreal, symbolOpacity, SymbolOpacity) - BASIC_D_ACCESSOR_DECL(qreal, symbolRotationAngle, SymbolRotationAngle) - BASIC_D_ACCESSOR_DECL(qreal, symbolSize, SymbolSize) - CLASS_D_ACCESSOR_DECL(QBrush, symbolBrush, SymbolBrush) - CLASS_D_ACCESSOR_DECL(QPen, symbolPen, SymbolPen) - - void setVisible(bool on) override; - bool isVisible() const override; - void setPrinting(bool) override; - - void retransform() override; - void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override; - - typedef CustomPointPrivate Private; - - private slots: - void visibilityChanged(); - - protected: - CustomPointPrivate* const d_ptr; - CustomPoint(const QString& name, CustomPointPrivate* dd); - - private: - Q_DECLARE_PRIVATE(CustomPoint) - void init(); - void initActions(); - - QAction* visibilityAction; - - signals: - friend class CustomPointSetPositionCmd; - void positionChanged(const QPointF&); - void visibleChanged(bool); - void changed(); - - friend class CustomPointSetSymbolStyleCmd; - friend class CustomPointSetSymbolSizeCmd; - friend class CustomPointSetSymbolRotationAngleCmd; - friend class CustomPointSetSymbolOpacityCmd; - friend class CustomPointSetSymbolBrushCmd; - friend class CustomPointSetSymbolPenCmd; - void symbolStyleChanged(Symbol::Style); - void symbolSizeChanged(qreal); - void symbolRotationAngleChanged(qreal); - void symbolOpacityChanged(qreal); - void symbolBrushChanged(QBrush); - void symbolPenChanged(const QPen&); +Q_OBJECT + +public: + explicit CustomPoint(const CartesianPlot*, const QString&); + ~CustomPoint() override; + + QIcon icon() const override; + QMenu* createContextMenu() override; + QGraphicsItem* graphicsItem() const override; + + void save(QXmlStreamWriter*) const override; + bool load(XmlStreamReader*, bool preview) override; + + CLASS_D_ACCESSOR_DECL(QPointF, position, Position) + BASIC_D_ACCESSOR_DECL(Symbol::Style, symbolStyle, SymbolStyle) + BASIC_D_ACCESSOR_DECL(qreal, symbolOpacity, SymbolOpacity) + BASIC_D_ACCESSOR_DECL(qreal, symbolRotationAngle, SymbolRotationAngle) + BASIC_D_ACCESSOR_DECL(qreal, symbolSize, SymbolSize) + CLASS_D_ACCESSOR_DECL(QBrush, symbolBrush, SymbolBrush) + CLASS_D_ACCESSOR_DECL(QPen, symbolPen, SymbolPen) + + void setVisible(bool on) override; + bool isVisible() const override; + void setPrinting(bool) override; + + void retransform() override; + void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override; + + typedef CustomPointPrivate Private; + +private slots: + void visibilityChanged(); + +protected: + CustomPointPrivate* const d_ptr; + CustomPoint(const QString& name, CustomPointPrivate* dd); + +private: + Q_DECLARE_PRIVATE(CustomPoint) + void init(); + void initActions(); + + QAction* visibilityAction; + +signals: + friend class CustomPointSetPositionCmd; + void positionChanged(const QPointF&); + void visibleChanged(bool); + void changed(); + + void symbolStyleChanged(Symbol::Style); + void symbolSizeChanged(qreal); + void symbolRotationAngleChanged(qreal); + void symbolOpacityChanged(qreal); + void symbolBrushChanged(QBrush); + void symbolPenChanged(const QPen&); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYAnalysisCurve.h b/src/backend/worksheet/plots/cartesian/XYAnalysisCurve.h index da55c1bec..429d8b375 100644 --- a/src/backend/worksheet/plots/cartesian/XYAnalysisCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYAnalysisCurve.h @@ -1,83 +1,78 @@ /*************************************************************************** File : XYAnalysisCurve.h Project : LabPlot Description : Base class for all analysis curves -------------------------------------------------------------------- Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYANALYSISCURVE_H #define XYANALYSISCURVE_H #include "backend/worksheet/plots/cartesian/XYCurve.h" class XYAnalysisCurvePrivate; class XYAnalysisCurve : public XYCurve { Q_OBJECT public: enum DataSourceType {DataSourceSpreadsheet, DataSourceCurve}; explicit XYAnalysisCurve(const QString&); ~XYAnalysisCurve() override; virtual void recalculate() = 0; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; BASIC_D_ACCESSOR_DECL(DataSourceType, dataSourceType, DataSourceType) POINTER_D_ACCESSOR_DECL(const XYCurve, dataSourceCurve, DataSourceCurve) const QString& dataSourceCurvePath() const; POINTER_D_ACCESSOR_DECL(const AbstractColumn, xDataColumn, XDataColumn) POINTER_D_ACCESSOR_DECL(const AbstractColumn, yDataColumn, YDataColumn) const QString& xDataColumnPath() const; const QString& yDataColumnPath() const; typedef XYAnalysisCurvePrivate Private; protected: XYAnalysisCurve(const QString& name, XYAnalysisCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYAnalysisCurve) void init(); public slots: void handleSourceDataChanged(); signals: void sourceDataChanged(); //emitted when the source data used in the analysis curves was changed to enable the recalculation in the dock widgets - - friend class XYAnalysisCurveSetDataSourceTypeCmd; - friend class XYAnalysisCurveSetDataSourceCurveCmd; - friend class XYAnalysisCurveSetXDataColumnCmd; - friend class XYAnalysisCurveSetYDataColumnCmd; void dataSourceTypeChanged(XYAnalysisCurve::DataSourceType); void dataSourceCurveChanged(const XYCurve*); void xDataColumnChanged(const AbstractColumn*); void yDataColumnChanged(const AbstractColumn*); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYDataReductionCurve.h b/src/backend/worksheet/plots/cartesian/XYDataReductionCurve.h index 2e2710f0c..2d47f75d1 100644 --- a/src/backend/worksheet/plots/cartesian/XYDataReductionCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYDataReductionCurve.h @@ -1,92 +1,91 @@ /*************************************************************************** File : XYDataReductionCurve.h Project : LabPlot Description : A xy-curve defined by a data reduction -------------------------------------------------------------------- Copyright : (C) 2016 Stefan Gerlach (stefan.gerlach@uni.kn) Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYDATAREDUCTIONCURVE_H #define XYDATAREDUCTIONCURVE_H #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h" extern "C" { #include "backend/nsl/nsl_geom_linesim.h" } class XYDataReductionCurvePrivate; class XYDataReductionCurve : public XYAnalysisCurve { Q_OBJECT public: struct DataReductionData { DataReductionData() : type(nsl_geom_linesim_type_douglas_peucker_variant), autoTolerance(true), tolerance(0.0), autoTolerance2(true), tolerance2(0.0), autoRange(true), xRange(2) {}; nsl_geom_linesim_type type; // type of simplification bool autoTolerance; // automatic tolerance double tolerance; // tolerance bool autoTolerance2; // automatic tolerance2 double tolerance2; // tolerance2 bool autoRange; // use all data? QVector xRange; // x range for integration }; struct DataReductionResult { DataReductionResult() : available(false), valid(false), elapsedTime(0), npoints(0), posError(0), areaError(0) {}; bool available; bool valid; QString status; qint64 elapsedTime; size_t npoints; double posError; double areaError; }; explicit XYDataReductionCurve(const QString& name); ~XYDataReductionCurve() override; void recalculate() override; QIcon icon() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; CLASS_D_ACCESSOR_DECL(DataReductionData, dataReductionData, DataReductionData) const DataReductionResult& dataReductionResult() const; typedef XYDataReductionCurvePrivate Private; protected: XYDataReductionCurve(const QString& name, XYDataReductionCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYDataReductionCurve) signals: - friend class XYDataReductionCurveSetDataReductionDataCmd; void dataReductionDataChanged(const XYDataReductionCurve::DataReductionData&); void completed(int); //!< int ranging from 0 to 100 notifies about the status of the analysis process }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYDifferentiationCurve.h b/src/backend/worksheet/plots/cartesian/XYDifferentiationCurve.h index a36ce9f5e..8a2182c0d 100644 --- a/src/backend/worksheet/plots/cartesian/XYDifferentiationCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYDifferentiationCurve.h @@ -1,86 +1,85 @@ /*************************************************************************** File : XYDifferentiationCurve.h Project : LabPlot Description : A xy-curve defined by an differentiation -------------------------------------------------------------------- Copyright : (C) 2016 Stefan Gerlach (stefan.gerlach@uni.kn) Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYDIFFERENTIATIONCURVE_H #define XYDIFFERENTIATIONCURVE_H #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h" extern "C" { #include "backend/nsl/nsl_diff.h" } class XYDifferentiationCurvePrivate; class XYDifferentiationCurve : public XYAnalysisCurve { Q_OBJECT public: struct DifferentiationData { DifferentiationData() : derivOrder(nsl_diff_deriv_order_first), accOrder(2), autoRange(true), xRange(2) {}; nsl_diff_deriv_order_type derivOrder; // order of differentiation int accOrder; // order ofaccuracy bool autoRange; // use all data? QVector xRange; // x range for integration }; struct DifferentiationResult { DifferentiationResult() : available(false), valid(false), elapsedTime(0) {}; bool available; bool valid; QString status; qint64 elapsedTime; }; explicit XYDifferentiationCurve(const QString& name); ~XYDifferentiationCurve() override; void recalculate() override; QIcon icon() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; CLASS_D_ACCESSOR_DECL(DifferentiationData, differentiationData, DifferentiationData) const DifferentiationResult& differentiationResult() const; typedef XYDifferentiationCurvePrivate Private; protected: XYDifferentiationCurve(const QString& name, XYDifferentiationCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYDifferentiationCurve) signals: - friend class XYDifferentiationCurveSetDifferentiationDataCmd; void differentiationDataChanged(const XYDifferentiationCurve::DifferentiationData&); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYEquationCurve.h b/src/backend/worksheet/plots/cartesian/XYEquationCurve.h index 90fde03e5..a448abfe9 100644 --- a/src/backend/worksheet/plots/cartesian/XYEquationCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYEquationCurve.h @@ -1,76 +1,75 @@ /*************************************************************************** File : XYEquationCurve.h Project : LabPlot Description : A xy-curve defined by a mathematical equation -------------------------------------------------------------------- Copyright : (C) 2014-2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYEQUATIONCURVE_H #define XYEQUATIONCURVE_H #include "backend/worksheet/plots/cartesian/XYCurve.h" class XYEquationCurvePrivate; class XYEquationCurve : public XYCurve { - Q_OBJECT +Q_OBJECT - public: - enum EquationType {Cartesian, Polar, Parametric, Implicit, Neutral}; +public: + enum EquationType {Cartesian, Polar, Parametric, Implicit, Neutral}; - struct EquationData { - EquationData() : type(Cartesian), min("0"), max("1"), count(1000) {}; + struct EquationData { + EquationData() : type(Cartesian), min("0"), max("1"), count(1000) {}; - EquationType type; - QString expression1; - QString expression2; - QString min; - QString max; - int count; - }; + EquationType type; + QString expression1; + QString expression2; + QString min; + QString max; + int count; + }; - explicit XYEquationCurve(const QString& name); - ~XYEquationCurve() override; + explicit XYEquationCurve(const QString& name); + ~XYEquationCurve() override; - void recalculate(); - QIcon icon() const override; - void save(QXmlStreamWriter*) const override; - bool load(XmlStreamReader*, bool preview) override; + void recalculate(); + QIcon icon() const override; + void save(QXmlStreamWriter*) const override; + bool load(XmlStreamReader*, bool preview) override; - CLASS_D_ACCESSOR_DECL(EquationData, equationData, EquationData) + CLASS_D_ACCESSOR_DECL(EquationData, equationData, EquationData) - typedef XYEquationCurvePrivate Private; + typedef XYEquationCurvePrivate Private; - protected: - XYEquationCurve(const QString& name, XYEquationCurvePrivate* dd); +protected: + XYEquationCurve(const QString& name, XYEquationCurvePrivate* dd); - private: - Q_DECLARE_PRIVATE(XYEquationCurve) - void init(); +private: + Q_DECLARE_PRIVATE(XYEquationCurve) + void init(); - signals: - friend class XYEquationCurveSetEquationDataCmd; - void equationDataChanged(const XYEquationCurve::EquationData&); +signals: + void equationDataChanged(const XYEquationCurve::EquationData&); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYFitCurve.h b/src/backend/worksheet/plots/cartesian/XYFitCurve.h index 0e53376e5..f87d2e8e3 100644 --- a/src/backend/worksheet/plots/cartesian/XYFitCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYFitCurve.h @@ -1,162 +1,158 @@ /*************************************************************************** File : XYFitCurve.h Project : LabPlot Description : A xy-curve defined by a fit model -------------------------------------------------------------------- Copyright : (C) 2014-2017 Alexander Semke (alexander.semke@web.de) Copyright : (C) 2016-2018 Stefan Gerlach (stefan.gerlach@uni.kn) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYFITCURVE_H #define XYFITCURVE_H #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h" #include "kdefrontend/spreadsheet/PlotDataDialog.h" //for PlotDataDialog::AnalysisAction. TODO: find a better place for this enum. extern "C" { #include "backend/nsl/nsl_fit.h" } class XYFitCurvePrivate; class XYFitCurve : public XYAnalysisCurve { Q_OBJECT public: struct FitData { FitData() : modelCategory(nsl_fit_model_basic), modelType(0), xWeightsType(nsl_fit_weight_no), yWeightsType(nsl_fit_weight_no), degree(1), maxIterations(500), eps(1e-4), evaluatedPoints(1000), useDataErrors(true), useResults(true), autoRange(true), autoEvalRange(true), fitRange(2), evalRange(2) {}; nsl_fit_model_category modelCategory; int modelType; nsl_fit_weight_type xWeightsType; nsl_fit_weight_type yWeightsType; int degree; QString model; QStringList paramNames; QStringList paramNamesUtf8; // Utf8 version of paramNames QVector paramStartValues; QVector paramLowerLimits; QVector paramUpperLimits; QVector paramFixed; int maxIterations; double eps; size_t evaluatedPoints; bool useDataErrors; // use given data errors when fitting (default) bool useResults; // use results as new start values (default) bool autoRange; // use all data points? (default) bool autoEvalRange; // evaluate fit function on full data range (default) QVector fitRange; // x fit range QVector evalRange; // x evaluation range }; struct FitResult { FitResult() : available(false), valid(false), iterations(0), elapsedTime(0), dof(0), sse(0), sst(0), rms(0), rsd(0), mse(0), rmse(0), mae(0), rsquare(0), rsquareAdj(0), chisq_p(0), fdist_F(0), fdist_p(0), logLik(0), aic(0), bic(0) {}; bool available; bool valid; QString status; int iterations; qint64 elapsedTime; double dof; //degrees of freedom // residuals: r_i = y_i - Y_i double sse; // sum of squared errors (SSE) / residual sum of squares (RSS) / sum of sq. residuals (SSR) / S = chi^2 = \sum_i^n r_i^2 double sst; // total sum of squares (SST) = \sum_i^n (y_i - )^2 double rms; // residual mean square / reduced chi^2 = SSE/dof double rsd; // residual standard deviation = sqrt(SSE/dof) double mse; // mean squared error = SSE/n double rmse; // root-mean squared error = \sqrt(mse) double mae; // mean absolute error = \sum_i^n |r_i| double rsquare; double rsquareAdj; double chisq_p; // chi^2 distribution p-value double fdist_F; // F distribution F-value double fdist_p; // F distribution p-value double logLik; // log likelihood double aic; // Akaike information criterion double bic; // Schwarz Bayesian information criterion // see also http://www.originlab.com/doc/Origin-Help/NLFit-Algorithm QVector paramValues; QVector errorValues; QVector tdist_tValues; QVector tdist_pValues; QVector tdist_marginValues; QString solverOutput; }; explicit XYFitCurve(const QString& name); ~XYFitCurve() override; void recalculate() override; void evaluate(bool preview); void initFitData(PlotDataDialog::AnalysisAction); static void initFitData(XYFitCurve::FitData&); void initStartValues(const XYCurve*); static void initStartValues(XYFitCurve::FitData&, const XYCurve*); QIcon icon() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; POINTER_D_ACCESSOR_DECL(const AbstractColumn, xErrorColumn, XErrorColumn) POINTER_D_ACCESSOR_DECL(const AbstractColumn, yErrorColumn, YErrorColumn) const QString& xErrorColumnPath() const; const QString& yErrorColumnPath() const; CLASS_D_ACCESSOR_DECL(FitData, fitData, FitData) const FitResult& fitResult() const; typedef XYFitCurvePrivate Private; protected: XYFitCurve(const QString& name, XYFitCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYFitCurve) signals: - friend class XYFitCurveSetXErrorColumnCmd; - friend class XYFitCurveSetYErrorColumnCmd; void xErrorColumnChanged(const AbstractColumn*); void yErrorColumnChanged(const AbstractColumn*); - - friend class XYFitCurveSetFitDataCmd; void fitDataChanged(const XYFitCurve::FitData&); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYFourierFilterCurve.h b/src/backend/worksheet/plots/cartesian/XYFourierFilterCurve.h index 3f208e171..675008b53 100644 --- a/src/backend/worksheet/plots/cartesian/XYFourierFilterCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYFourierFilterCurve.h @@ -1,91 +1,90 @@ /*************************************************************************** File : XYFourierFilterCurve.h Project : LabPlot Description : A xy-curve defined by a Fourier filter -------------------------------------------------------------------- Copyright : (C) 2016 Stefan Gerlach (stefan.gerlach@uni.kn) Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYFOURIERFILTERCURVE_H #define XYFOURIERFILTERCURVE_H #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h" extern "C" { #include "backend/nsl/nsl_filter.h" } class XYFourierFilterCurvePrivate; class XYFourierFilterCurve : public XYAnalysisCurve { Q_OBJECT public: struct FilterData { FilterData() : type(nsl_filter_type_low_pass), form(nsl_filter_form_ideal), order(1), cutoff(0), unit(nsl_filter_cutoff_unit_frequency), cutoff2(0), unit2(nsl_filter_cutoff_unit_frequency), autoRange(true), xRange(2) {}; nsl_filter_type type; nsl_filter_form form; int order; double cutoff; // (low) cutoff nsl_filter_cutoff_unit unit; // (low) value unit double cutoff2; // high cutoff nsl_filter_cutoff_unit unit2; // high value unit bool autoRange; // use all data? QVector xRange; // x range for integration }; struct FilterResult { FilterResult() : available(false), valid(false), elapsedTime(0) {}; bool available; bool valid; QString status; qint64 elapsedTime; }; explicit XYFourierFilterCurve(const QString& name); ~XYFourierFilterCurve() override; void recalculate() override; QIcon icon() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; CLASS_D_ACCESSOR_DECL(FilterData, filterData, FilterData) const FilterResult& filterResult() const; typedef XYFourierFilterCurvePrivate Private; protected: XYFourierFilterCurve(const QString& name, XYFourierFilterCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYFourierFilterCurve) signals: - friend class XYFourierFilterCurveSetFilterDataCmd; void filterDataChanged(const XYFourierFilterCurve::FilterData&); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYFourierTransformCurve.h b/src/backend/worksheet/plots/cartesian/XYFourierTransformCurve.h index 45232d16a..fb6683e4a 100644 --- a/src/backend/worksheet/plots/cartesian/XYFourierTransformCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYFourierTransformCurve.h @@ -1,89 +1,88 @@ /*************************************************************************** File : XYFourierTransformCurve.h Project : LabPlot Description : A xy-curve defined by a Fourier transform -------------------------------------------------------------------- Copyright : (C) 2016 Stefan Gerlach (stefan.gerlach@uni.kn) Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYFOURIERTRANSFORMCURVE_H #define XYFOURIERTRANSFORMCURVE_H #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h" extern "C" { #include "backend/nsl/nsl_dft.h" #include "backend/nsl/nsl_sf_window.h" } class XYFourierTransformCurvePrivate; class XYFourierTransformCurve : public XYAnalysisCurve { Q_OBJECT public: struct TransformData { TransformData() : type(nsl_dft_result_magnitude), twoSided(false), shifted(false), xScale(nsl_dft_xscale_frequency), windowType(nsl_sf_window_uniform), autoRange(true), xRange(2) {}; nsl_dft_result_type type; bool twoSided; bool shifted; nsl_dft_xscale xScale; nsl_sf_window_type windowType; bool autoRange; // use all data? QVector xRange; // x range for transform }; struct TransformResult { TransformResult() : available(false), valid(false), elapsedTime(0) {}; bool available; bool valid; QString status; qint64 elapsedTime; }; explicit XYFourierTransformCurve(const QString& name); ~XYFourierTransformCurve() override; void recalculate() override; QIcon icon() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; CLASS_D_ACCESSOR_DECL(TransformData, transformData, TransformData) const TransformResult& transformResult() const; typedef XYFourierTransformCurvePrivate Private; protected: XYFourierTransformCurve(const QString& name, XYFourierTransformCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYFourierTransformCurve) signals: - friend class XYFourierTransformCurveSetTransformDataCmd; void transformDataChanged(const XYFourierTransformCurve::TransformData&); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYIntegrationCurve.h b/src/backend/worksheet/plots/cartesian/XYIntegrationCurve.h index c3023b277..297424161 100644 --- a/src/backend/worksheet/plots/cartesian/XYIntegrationCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYIntegrationCurve.h @@ -1,85 +1,84 @@ /*************************************************************************** File : XYIntegrationCurve.h Project : LabPlot Description : A xy-curve defined by an integration -------------------------------------------------------------------- Copyright : (C) 2016 Stefan Gerlach (stefan.gerlach@uni.kn) Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYINTEGRATIONCURVE_H #define XYINTEGRATIONCURVE_H #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h" extern "C" { #include "backend/nsl/nsl_int.h" } class XYIntegrationCurvePrivate; class XYIntegrationCurve : public XYAnalysisCurve { Q_OBJECT public: struct IntegrationData { IntegrationData() : method(nsl_int_method_trapezoid), absolute(false), autoRange(true), xRange(2) {}; nsl_int_method_type method; // method for integration bool absolute; // absolute area? bool autoRange; // use all data? QVector xRange; // x range for integration }; struct IntegrationResult { IntegrationResult() : available(false), valid(false), elapsedTime(0), value(0) {}; bool available; bool valid; QString status; qint64 elapsedTime; double value; // final result of integration }; explicit XYIntegrationCurve(const QString& name); ~XYIntegrationCurve() override; void recalculate() override; QIcon icon() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; CLASS_D_ACCESSOR_DECL(IntegrationData, integrationData, IntegrationData) const IntegrationResult& integrationResult() const; typedef XYIntegrationCurvePrivate Private; protected: XYIntegrationCurve(const QString& name, XYIntegrationCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYIntegrationCurve) signals: - friend class XYIntegrationCurveSetIntegrationDataCmd; void integrationDataChanged(const XYIntegrationCurve::IntegrationData&); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYInterpolationCurve.h b/src/backend/worksheet/plots/cartesian/XYInterpolationCurve.h index 482ab221d..72ca53888 100644 --- a/src/backend/worksheet/plots/cartesian/XYInterpolationCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYInterpolationCurve.h @@ -1,92 +1,91 @@ /*************************************************************************** File : XYInterpolationCurve.h Project : LabPlot Description : A xy-curve defined by an interpolation -------------------------------------------------------------------- Copyright : (C) 2016 Stefan Gerlach (stefan.gerlach@uni.kn) Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYINTERPOLATIONCURVE_H #define XYINTERPOLATIONCURVE_H #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h" extern "C" { #include #include "backend/nsl/nsl_interp.h" } class XYInterpolationCurvePrivate; class XYInterpolationCurve : public XYAnalysisCurve { Q_OBJECT public: enum PointsMode {Auto, Multiple, Custom}; struct InterpolationData { InterpolationData() : type(nsl_interp_type_linear), variant(nsl_interp_pch_variant_finite_difference), tension(0.0), continuity(0.0), bias(0.0), evaluate(nsl_interp_evaluate_function), npoints(100), pointsMode(XYInterpolationCurve::Auto), autoRange(true), xRange(2) {}; nsl_interp_type type; // type of interpolation nsl_interp_pch_variant variant; // variant of cubic Hermite interpolation double tension, continuity, bias; // TCB values nsl_interp_evaluate evaluate; // what to evaluate size_t npoints; // nr. of points XYInterpolationCurve::PointsMode pointsMode; // mode to interpret points bool autoRange; // use all data? QVector xRange; // x range for interpolation }; struct InterpolationResult { InterpolationResult() : available(false), valid(false), elapsedTime(0) {}; bool available; bool valid; QString status; qint64 elapsedTime; }; explicit XYInterpolationCurve(const QString& name); ~XYInterpolationCurve() override; void recalculate() override; QIcon icon() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; CLASS_D_ACCESSOR_DECL(InterpolationData, interpolationData, InterpolationData) const InterpolationResult& interpolationResult() const; typedef XYInterpolationCurvePrivate Private; protected: XYInterpolationCurve(const QString& name, XYInterpolationCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYInterpolationCurve) signals: - friend class XYInterpolationCurveSetInterpolationDataCmd; void interpolationDataChanged(const XYInterpolationCurve::InterpolationData&); }; #endif diff --git a/src/backend/worksheet/plots/cartesian/XYSmoothCurve.h b/src/backend/worksheet/plots/cartesian/XYSmoothCurve.h index 0cd4a9ff0..526671492 100644 --- a/src/backend/worksheet/plots/cartesian/XYSmoothCurve.h +++ b/src/backend/worksheet/plots/cartesian/XYSmoothCurve.h @@ -1,91 +1,90 @@ /*************************************************************************** File : XYSmoothCurve.h Project : LabPlot Description : A xy-curve defined by a smooth -------------------------------------------------------------------- Copyright : (C) 2016 Stefan Gerlach (stefan.gerlach@uni.kn) Copyright : (C) 2017 Alexander Semke (alexander.semke@web.de) ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * ***************************************************************************/ #ifndef XYSMOOTHCURVE_H #define XYSMOOTHCURVE_H #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h" extern "C" { #include "backend/nsl/nsl_smooth.h" } class XYSmoothCurvePrivate; class XYSmoothCurve : public XYAnalysisCurve { Q_OBJECT public: struct SmoothData { SmoothData() : type(nsl_smooth_type_moving_average), points(5), weight(nsl_smooth_weight_uniform), percentile(0.5), order(2), mode(nsl_smooth_pad_none), lvalue(0.0), rvalue(0.0), autoRange(true), xRange(2) {}; nsl_smooth_type type; // type of smoothing size_t points; // number of points nsl_smooth_weight_type weight; // type of weight double percentile; // percentile for percentile filter (0.0 .. 1.0) int order; // order for Savitzky-Golay filter nsl_smooth_pad_mode mode; // mode of padding for edges double lvalue, rvalue; // values for constant padding bool autoRange; // use all data? QVector xRange; // x range for integration }; struct SmoothResult { SmoothResult() : available(false), valid(false), elapsedTime(0) {}; bool available; bool valid; QString status; qint64 elapsedTime; }; explicit XYSmoothCurve(const QString& name); ~XYSmoothCurve() override; void recalculate() override; QIcon icon() const override; void save(QXmlStreamWriter*) const override; bool load(XmlStreamReader*, bool preview) override; CLASS_D_ACCESSOR_DECL(SmoothData, smoothData, SmoothData) const SmoothResult& smoothResult() const; typedef XYSmoothCurvePrivate Private; protected: XYSmoothCurve(const QString& name, XYSmoothCurvePrivate* dd); private: Q_DECLARE_PRIVATE(XYSmoothCurve) signals: - friend class XYSmoothCurveSetSmoothDataCmd; void smoothDataChanged(const XYSmoothCurve::SmoothData&); }; #endif