Engauge Digitizer 2
Loading...
Searching...
No Matches
LineStyle.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "DocumentSerialize.h"
8#include "LineStyle.h"
9#include "Logger.h"
10#include <QObject>
11#include <QSettings>
12#include <QTextStream>
13#include <QXmlStreamReader>
14#include <QXmlStreamWriter>
15#include "Settings.h"
16#include "SettingsForGraph.h"
17#include "Xml.h"
18
19const ColorPalette DEFAULT_LINE_COLOR_AXES = COLOR_PALETTE_TRANSPARENT; // Same default color as used for PointStyle axes curve default
20const ColorPalette DEFAULT_LINE_COLOR_GRAPH = COLOR_PALETTE_BLUE; // Same default color as used for PointStyle axes curve default
25
27{
28 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
29 settings.beginGroup (SETTINGS_GROUP_CURVE_AXES);
30 m_width = settings.value (SETTINGS_CURVE_LINE_WIDTH,
32 m_paletteColor = static_cast<ColorPalette> (settings.value (SETTINGS_CURVE_LINE_COLOR,
34 m_curveConnectAs = static_cast<CurveConnectAs> (settings.value (SETTINGS_CURVE_LINE_CONNECT_AS,
36}
37
41 m_width (width),
42 m_paletteColor (paletteColor),
43 m_curveConnectAs (curveConnectAs)
44{
45}
46
48 m_width (other.width ()),
49 m_paletteColor (other.paletteColor()),
50 m_curveConnectAs (other.curveConnectAs())
51{
52}
53
55{
56 m_width = other.width ();
57 m_paletteColor = other.paletteColor();
58 m_curveConnectAs = other.curveConnectAs();
59
60 return *this;
61}
62
64{
65 return m_curveConnectAs;
66}
67
69{
70 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
71 settings.beginGroup (SETTINGS_GROUP_CURVE_AXES);
72 int width = settings.value (SETTINGS_CURVE_LINE_WIDTH,
74 ColorPalette color = static_cast<ColorPalette> (settings.value (SETTINGS_CURVE_LINE_COLOR,
76 CurveConnectAs connectAs = static_cast<CurveConnectAs> (settings.value (SETTINGS_CURVE_LINE_CONNECT_AS,
78
79 return LineStyle (unsigned (width),
80 color,
81 connectAs);
82}
83
85{
86 SettingsForGraph settingsForGraph;
87 int indexOneBased = index + 1;
88 QString groupName = settingsForGraph.groupNameForNthCurve (indexOneBased);
89
90 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
91 settings.beginGroup (groupName);
92 int width = settings.value (SETTINGS_CURVE_LINE_WIDTH,
94 ColorPalette color = static_cast<ColorPalette> (settings.value (SETTINGS_CURVE_LINE_COLOR,
96 CurveConnectAs connectAs = static_cast<CurveConnectAs> (settings.value (SETTINGS_CURVE_LINE_CONNECT_AS,
98
99 return LineStyle (unsigned (width),
100 color,
101 connectAs);
102}
103
104void LineStyle::loadXml(QXmlStreamReader &reader)
105{
106 LOG4CPP_INFO_S ((*mainCat)) << "LineStyle::loadXml";
107
108 QXmlStreamAttributes attributes = reader.attributes();
109
110 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_LINE_STYLE_WIDTH) &&
111 attributes.hasAttribute(DOCUMENT_SERIALIZE_LINE_STYLE_COLOR) &&
112 attributes.hasAttribute(DOCUMENT_SERIALIZE_LINE_STYLE_CONNECT_AS)) {
113
114 setWidth (attributes.value(DOCUMENT_SERIALIZE_LINE_STYLE_WIDTH).toInt());
115 setPaletteColor (static_cast<ColorPalette> (attributes.value(DOCUMENT_SERIALIZE_LINE_STYLE_COLOR).toInt()));
116 setCurveConnectAs (static_cast<CurveConnectAs> (attributes.value(DOCUMENT_SERIALIZE_LINE_STYLE_CONNECT_AS).toInt()));
117
118 // Read until end of this subtree
119 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
120 (reader.name() != DOCUMENT_SERIALIZE_LINE_STYLE)){
121 loadNextFromReader(reader);
122 }
123 } else {
124 reader.raiseError (QObject::tr ("Cannot read line style data"));
125 }
126}
127
129{
130 return m_paletteColor;
131}
132
133void LineStyle::printStream(QString indentation,
134 QTextStream &str) const
135{
136 str << indentation << "LineStyle\n";
137
138 indentation += INDENTATION_DELTA;
139
140 str << indentation << "width=" << m_width << "\n";
141 str << indentation << "color=" << colorPaletteToString (m_paletteColor) << "\n";
142 str << indentation << "curveConnectAs=" << curveConnectAsToString (m_curveConnectAs) << "\n";
143}
144
145void LineStyle::saveXml(QXmlStreamWriter &writer) const
146{
147 LOG4CPP_INFO_S ((*mainCat)) << "LineStyle::saveXml";
148
149 writer.writeStartElement(DOCUMENT_SERIALIZE_LINE_STYLE);
150 writer.writeAttribute (DOCUMENT_SERIALIZE_LINE_STYLE_WIDTH, QString::number(m_width));
151 writer.writeAttribute (DOCUMENT_SERIALIZE_LINE_STYLE_COLOR, QString::number (m_paletteColor));
152 writer.writeAttribute (DOCUMENT_SERIALIZE_LINE_STYLE_COLOR_STRING, colorPaletteToString (m_paletteColor));
153 writer.writeAttribute (DOCUMENT_SERIALIZE_LINE_STYLE_CONNECT_AS, QString::number (m_curveConnectAs));
154 writer.writeAttribute (DOCUMENT_SERIALIZE_LINE_STYLE_CONNECT_AS_STRING, curveConnectAsToString (m_curveConnectAs));
155 writer.writeEndElement();
156}
157
162
167
169{
170 m_width = unsigned (width);
171}
172
173unsigned int LineStyle::width () const
174{
175 return m_width;
176}
QString colorPaletteToString(ColorPalette colorPalette)
ColorPalette
@ COLOR_PALETTE_TRANSPARENT
@ COLOR_PALETTE_BLUE
QString curveConnectAsToString(CurveConnectAs curveConnectAs)
CurveConnectAs
@ CONNECT_SKIP_FOR_AXIS_CURVE
@ CONNECT_AS_FUNCTION_SMOOTH
const QString DOCUMENT_SERIALIZE_LINE_STYLE
const QString DOCUMENT_SERIALIZE_LINE_STYLE_WIDTH
const QString DOCUMENT_SERIALIZE_LINE_STYLE_COLOR
const QString DOCUMENT_SERIALIZE_LINE_STYLE_COLOR_STRING
const QString DOCUMENT_SERIALIZE_LINE_STYLE_CONNECT_AS_STRING
const QString DOCUMENT_SERIALIZE_LINE_STYLE_CONNECT_AS
const CurveConnectAs DEFAULT_LINE_CONNECT_AS_GRAPH
Definition LineStyle.cpp:22
const int DEFAULT_LINE_WIDTH_AXES
Definition LineStyle.cpp:23
const CurveConnectAs DEFAULT_LINE_CONNECT_AS_AXES
Definition LineStyle.cpp:21
const ColorPalette DEFAULT_LINE_COLOR_GRAPH
Definition LineStyle.cpp:20
const ColorPalette DEFAULT_LINE_COLOR_AXES
Definition LineStyle.cpp:19
const int DEFAULT_LINE_WIDTH_GRAPH
Definition LineStyle.cpp:24
log4cpp::Category * mainCat
Definition Logger.cpp:14
const QString INDENTATION_DELTA
const QString SETTINGS_ENGAUGE
const QString SETTINGS_GROUP_CURVE_AXES
const QString SETTINGS_CURVE_LINE_WIDTH
const QString SETTINGS_CURVE_LINE_CONNECT_AS
const QString SETTINGS_CURVE_LINE_COLOR
const QString SETTINGS_DIGITIZER
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
static LineStyle defaultAxesCurve()
Initial default for axes curve.
Definition LineStyle.cpp:68
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
void setCurveConnectAs(CurveConnectAs curveConnectAs)
Set connect as.
CurveConnectAs curveConnectAs() const
Get method for connect type.
Definition LineStyle.cpp:63
unsigned int width() const
Width of line.
ColorPalette paletteColor() const
Line color.
LineStyle()
Default constructor only for use when this class is being stored by a container that requires the def...
Definition LineStyle.cpp:26
static LineStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
Definition LineStyle.cpp:84
void setWidth(int width)
Set width of line.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setPaletteColor(ColorPalette paletteColor)
Set method for line color.
void loadXml(QXmlStreamReader &reader)
Load model from serialized xml. Returns the curve name.
LineStyle & operator=(const LineStyle &other)
Assignment operator.
Definition LineStyle.cpp:54
Manage storage and retrieval of the settings for the curves.
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18