NEW allow linear-gradient()... in brush definitions of style.ini-file

This commit is contained in:
jkriege2 2024-01-21 22:20:33 +01:00
parent eb7a068fb7
commit e5821eee3f
8 changed files with 76 additions and 17 deletions

View File

@ -304,7 +304,7 @@ inline void buildLineSymbolSampler(JKQTBasePlotter* plotExtra, JKQTBasePlotter*
double dx=(xmax-xlineend-1.0)/static_cast<double>(cntFillTests);
for (int i=0; i<cntFillTests; i++) {
const auto col=baseplot->getCurrentPlotterStyle().graphsStyle.defaultGraphColors.value(i%baseplot->getCurrentPlotterStyle().graphsStyle.defaultGraphColors.size(), Qt::black);
const auto fs=baseplot->getCurrentPlotterStyle().graphsStyle.defaultGraphFillStyles.value(i%baseplot->getCurrentPlotterStyle().graphsStyle.defaultGraphFillStyles.size(), Qt::SolidPattern);
const auto fs=baseplot->getCurrentPlotterStyle().graphsStyle.defaultGraphFillStyles.value(i%baseplot->getCurrentPlotterStyle().graphsStyle.defaultGraphFillStyles.size(), JKQTFillStyleSummmary(Qt::SolidPattern));
JKQTPGeoLine* l;
plotExtra->addGraph(l=new JKQTPGeoLine(plotExtra, x,ycoltest,x,y-0.5)); l->setStyle(col,5);
JKQTPGeoRectangle* r;

View File

@ -115,6 +115,14 @@ void JKQTPGeoBaseFilled::setStyle(QColor color, double lineWidth, Qt::PenStyle s
setFillStyle(fillStyle);
}
void JKQTPGeoBaseFilled::setStyle(QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, const JKQTFillStyleSummmary &fillStyle)
{
setLineColor(color);
setLineWidth(lineWidth);
setLineStyle(style);
setFillBrush(fillStyle.brush(fillColor));
}
void JKQTPGeoBaseFilled::setStyle(QColor color, double lineWidth, Qt::PenStyle style)
{
setLineColor(color);

View File

@ -193,6 +193,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPGeoBaseFilled: public JKQTPGeoBaseLine, public
/** \brief set several of the style properties with one call */
virtual void setStyle(QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, Qt::BrushStyle fillStyle) ;
/** \brief set several of the style properties with one call */
virtual void setStyle(QColor color, double lineWidth, Qt::PenStyle style, QColor fillColor, const JKQTFillStyleSummmary& fillStyle) ;
/** \brief set several of the style properties with one call */
virtual void setStyle(QColor color, double lineWidth, Qt::PenStyle style) override;
/** \brief set several of the style properties with one call */
virtual void setStyle(QColor color, Qt::PenStyle style) override;

View File

@ -1151,21 +1151,21 @@ JKQTBasePlotter::JKQTPPen JKQTBasePlotter::getPlotStyle(int i, JKQTPPlotStyleTyp
//std::cout<<"style "<<styleI<<std::endl;
const JKQTGraphsSpecificStyleProperties& baseProps=plotterStyle.graphsStyle.getGraphStyleByType(type);
Qt::PenStyle basePenStyle=plotterStyle.graphsStyle.defaultGraphPenStyles[styleI];
Qt::BrushStyle basebrushStyle=plotterStyle.graphsStyle.defaultGraphFillStyles[brushI];
JKQTFillStyleSummmary basebrushStyle=plotterStyle.graphsStyle.defaultGraphFillStyles[brushI];
JKQTPGraphSymbols baseSymbol=plotterStyle.graphsStyle.defaultGraphSymbols[symbolI];
QColor baseColor=plotterStyle.graphsStyle.defaultGraphColors[colorI];
double baseWidth=baseProps.defaultLineWidth;
if (type==JKQTPPlotStyleType::Annotation || type==JKQTPPlotStyleType::Geometric) {
baseColor=plotterStyle.graphsStyle.annotationStyle.defaultColor;
basePenStyle=plotterStyle.graphsStyle.annotationStyle.defaultLineStyle;
basebrushStyle=plotterStyle.graphsStyle.annotationStyle.defaultFillStyle;
basebrushStyle=JKQTFillStyleSummmary(plotterStyle.graphsStyle.annotationStyle.defaultFillStyle);
baseSymbol=plotterStyle.graphsStyle.annotationStyle.defaultSymbol;
}
if (type==JKQTPPlotStyleType::Barchart || type==JKQTPPlotStyleType::Boxplot || type==JKQTPPlotStyleType::Impulses) {
basePenStyle=Qt::SolidLine;
}
if (type==JKQTPPlotStyleType::Boxplot) {
basebrushStyle=Qt::SolidPattern;
basebrushStyle=JKQTFillStyleSummmary(Qt::SolidPattern);
}
if (type==JKQTPPlotStyleType::Impulses) {
}
@ -4965,7 +4965,7 @@ void JKQTBasePlotter::JKQTPPen::setErrorLineColor(const QColor &col)
m_errorColor=col;
}
void JKQTBasePlotter::JKQTPPen::setFillStyle(Qt::BrushStyle s) {
void JKQTBasePlotter::JKQTPPen::setFillStyle(const JKQTFillStyleSummmary &s) {
m_fillStyle=s;
}
@ -4977,7 +4977,7 @@ void JKQTBasePlotter::JKQTPPen::setSymbolFillColor(QColor c) {
m_symbolFillColor=c;
}
Qt::BrushStyle JKQTBasePlotter::JKQTPPen::fillStyle() const {
JKQTFillStyleSummmary JKQTBasePlotter::JKQTPPen::fillStyle() const {
return m_fillStyle;
}

View File

@ -773,7 +773,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
double m_symbolLineWidth;
Qt::PenStyle m_style;
double m_symbolSize;
Qt::BrushStyle m_fillStyle;
JKQTFillStyleSummmary m_fillStyle;
Qt::BrushStyle m_errorFillStyle;
JKQTPGraphSymbols m_symbol;
@ -800,9 +800,9 @@ class JKQTPLOTTER_LIB_EXPORT JKQTBasePlotter: public QObject {
void setFillColor(const QColor& col);
void setErrorFillColor(const QColor& col);
void setErrorLineColor(const QColor& col);
void setFillStyle(Qt::BrushStyle s);
void setFillStyle(const JKQTFillStyleSummmary& s);
void setErrorFillStyle(Qt::BrushStyle s);
Qt::BrushStyle fillStyle() const;
JKQTFillStyleSummmary fillStyle() const;
Qt::BrushStyle errorFillStyle() const;
JKQTPGraphSymbols symbol() const;
void setSymbolType(JKQTPGraphSymbols symbol);

View File

@ -236,9 +236,9 @@ QVector<JKQTPGraphSymbols> JKQTGraphsBaseStyle::getDefaultGraphSymbols()
return syms;
}
QVector<Qt::BrushStyle> JKQTGraphsBaseStyle::getDefaultGraphFillStyles()
QVector<JKQTFillStyleSummmary> JKQTGraphsBaseStyle::getDefaultGraphFillStyles()
{
return QVector<Qt::BrushStyle>()<<Qt::SolidPattern;
return QVector<JKQTFillStyleSummmary>()<<JKQTFillStyleSummmary(Qt::SolidPattern);
}
void JKQTGraphsBaseStyle::loadSettings(const QSettings &settings, const QString &group, const JKQTGraphsBaseStyle &defaultStyle, const JKQTBasePlotterStyle& parent)
@ -302,7 +302,7 @@ void JKQTGraphsBaseStyle::loadSettings(const QSettings &settings, const QString
}
id=readID(k, group+"auto_styles/fill_style");
if (id>=0) {
defaultGraphFillStyles.push_back(jkqtp_String2QBrushStyle(settings.value(group+"auto_styles/fill_style"+QString::number(id), jkqtp_QBrushStyle2String(Qt::SolidPattern)).toString()));
defaultGraphFillStyles.push_back(JKQTFillStyleSummmary::fromString(settings.value(group+"auto_styles/fill_style"+QString::number(id), jkqtp_QBrushStyle2String(Qt::SolidPattern)).toString()));
}
}
if (defaultGraphColors.size()==0) {
@ -398,7 +398,7 @@ void JKQTGraphsBaseStyle::saveSettings(QSettings &settings, const QString &group
for (auto& gs: defaultGraphFillStyles) {
QString num=QString::number(cnt);
while (num.size()<maxnum.size()) num.prepend('0');
settings.setValue(group+"auto_styles/fill_style"+num, jkqtp_QBrushStyle2String(gs));
settings.setValue(group+"auto_styles/fill_style"+num, jkqtp_QBrushStyle2String(gs.brushStyle));
cnt++;
}
}
@ -499,3 +499,30 @@ void JKQTImpulseSpecificStyleProperties::saveSettings(QSettings &settings, const
}
JKQTFillStyleSummmary::JKQTFillStyleSummmary(Qt::BrushStyle style, const QGradient& grad, double rotAngleDeg):
brushStyle(style), gradient(grad), rotationAngleDeg(rotAngleDeg)
{
}
QBrush JKQTFillStyleSummmary::brush(const QColor &color) const
{
QBrush b;
b.setColor(color);
if (brushStyle==Qt::LinearGradientPattern || brushStyle==Qt::RadialGradientPattern || brushStyle==Qt::ConicalGradientPattern) {
QGradient g=gradient;
g.setCoordinateMode(QGradient::ObjectMode);
b=QBrush(g);
} else {
b.setStyle(brushStyle);
}
return b;
}
JKQTFillStyleSummmary JKQTFillStyleSummmary::fromString(const QString &style)
{
JKQTFillStyleSummmary res;
res.brushStyle=jkqtp_String2QBrushStyleExt(style, nullptr, &(res.gradient), nullptr, &(res.rotationAngleDeg));
return res;
}

View File

@ -291,6 +291,29 @@ public:
};
/** \brief Support Class for JKQTBasePlotter, which summarizes a fill style
* \ingroup jkqtpplotter_styling_classes
*
* \see JKQTBasePlotter, JKQTGraphsBaseStyle, \ref jkqtpplotter_styling
*/
class JKQTPLOTTER_LIB_EXPORT JKQTFillStyleSummmary {
#ifndef JKQTPLOTTER_WORKAROUND_QGADGET_BUG
Q_GADGET
#endif
public:
JKQTFillStyleSummmary(Qt::BrushStyle style=Qt::SolidPattern, const QGradient& grad=QGradient(), double rotAngleDeg=0.0);
Qt::BrushStyle brushStyle;
QGradient gradient;
double rotationAngleDeg;
QBrush brush(const QColor& color=QColor(Qt::black)) const;
static JKQTFillStyleSummmary fromString(const QString& style);
};
/** \brief Support Class for JKQTBasePlotter, which summarizes all properties that define the visual styling of a JKQTBasePlotter
* \ingroup jkqtpplotter_styling_classes
*
@ -358,7 +381,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTGraphsBaseStyle {
/** \brief JKQTPGraphSymbols used to automatically assign to different graphs */
QVector<JKQTPGraphSymbols> defaultGraphSymbols;
/** \brief Qt::BrushStyle used to automatically style different graphs differently */
QVector<Qt::BrushStyle> defaultGraphFillStyles;
QVector<JKQTFillStyleSummmary> defaultGraphFillStyles;
/** \brief standard color palette for the default style */
static QVector<QColor> getDefaultGraphColors();
@ -367,7 +390,7 @@ class JKQTPLOTTER_LIB_EXPORT JKQTGraphsBaseStyle {
/** \brief list of JKQTPGraphSymbols used to automatically assign to different graphs in the default style */
static QVector<JKQTPGraphSymbols> getDefaultGraphSymbols();
/** \brief list of Qt::BrushStyle used to automatically style different graphs differently in the default style */
static QVector<Qt::BrushStyle> getDefaultGraphFillStyles();
static QVector<JKQTFillStyleSummmary> getDefaultGraphFillStyles();
};

View File

@ -398,8 +398,7 @@ void JKQTPGraphFillStyleMixin::initFillStyle(JKQTBasePlotter *parent, int &paren
if (parentPlotStyle<0) parentPlotStyle=parent->getNextStyle();
const JKQTBasePlotter::JKQTPPen pen=parent->getPlotStyle(parentPlotStyle, styletype);
m_fillColor=pen.fillColor();
m_fillBrush.setColor(m_fillColor);
m_fillBrush.setStyle(pen.fillStyle());
m_fillBrush=pen.fillStyle().brush(m_fillColor);
}
}