JKQTPlotter: added property drawLineInForeground to JKQTPXYLineGraph and JKQTPXYParametrizedScatterGraph

This commit is contained in:
jkriege2 2022-09-07 21:12:26 +02:00
parent 04284af94c
commit 7846bbecf0
5 changed files with 72 additions and 11 deletions

View File

@ -45,6 +45,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: Using JKQTMathText::useGuiFonts() for FONT rendering by default</li>
<li>NEW: added the option to draw a character from a font as symbol (<code>JKQTPCharacterSymbol+QChar('C').unicode()</code> and <code>JKQTPFilledCharacterSymbol+QChar('C').unicode()</code>)</li>
<li>NEW: added the option to register a custom symbol using JKQTPRegisterCustomGraphSymbol() </li>
<li>NEW: added property drawLineInForeground to JKQTPXYLineGraph and JKQTPXYParametrizedScatterGraph</li>
</ul></li>
<li>JKQTMathText:<ul>

View File

@ -50,7 +50,8 @@ JKQTPXYLineGraph::JKQTPXYLineGraph(JKQTPlotter* parent):
JKQTPXYLineGraph::JKQTPXYLineGraph(JKQTBasePlotter* parent):
JKQTPXYGraph(parent),
drawLine(true)
drawLine(true),
drawLineInForeground(true)
{
sortData=JKQTPXYGraph::Unsorted;
@ -91,6 +92,7 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) {
if (getIndexRange(imin, imax)) {
QVector<QPointF> symbols;
QList<QPolygonF> vec_linesP;
vec_linesP.push_back(QPolygonF());
intSortData();
@ -107,7 +109,10 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) {
//JKQTPPlotSymbol(painter, x, y, JKQTPFilledCircle, parent->pt2px(painter, symbolSize*1.5), parent->pt2px(painter, symbolWidth*parent->getLineWidthMultiplier()), penSelection.color(), penSelection.color(),getSymbolFont());
//}
if ((!parent->getXAxis()->isLogAxis() || xv>0.0) && (!parent->getYAxis()->isLogAxis() || yv>0.0) ) {
if (symType!=JKQTPNoSymbol && cliprect.contains(x,y)) plotStyledSymbol(parent, painter, x, y);
if (symType!=JKQTPNoSymbol && cliprect.contains(x,y)) {
if (drawLineInForeground) plotStyledSymbol(parent, painter, x, y);
else symbols.push_back({x,y});
}
if (drawLine) {
vec_linesP.last() << QPointF(x,y);
}
@ -141,6 +146,9 @@ void JKQTPXYLineGraph::draw(JKQTPEnhancedPainter& painter) {
}
}
}
for (const auto& s: symbols) {
plotStyledSymbol(parent, painter, s.x(), s.y());
}
//qDebug()<<"JKQTPXYLineGraph::draw(): "<<6;
}
}
@ -155,8 +163,9 @@ void JKQTPXYLineGraph::drawKeyMarker(JKQTPEnhancedPainter& painter, QRectF& rect
p.setWidthF(getKeyLineWidthPx(painter,rect,parent));
painter.setPen(p);
double y=rect.top()+rect.height()/2.0;
if (drawLine) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
if (drawLine && !drawLineInForeground) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
JKQTPPlotSymbol(painter, rect.left()+rect.width()/2.0, rect.top()+rect.height()/2.0, getSymbolType(), getKeySymbolSizePx(painter, rect, parent), getKeySymbolLineWidthPx(painter, rect, parent), getKeyLabelColor(), getSymbolFillColor(),getSymbolFont());
if (drawLine && drawLineInForeground) painter.drawLine(QLineF(rect.left(), y, rect.right(), y));
}
QColor JKQTPXYLineGraph::getKeyLabelColor() const {
@ -173,6 +182,16 @@ bool JKQTPXYLineGraph::getDrawLine() const
return this->drawLine;
}
void JKQTPXYLineGraph::setDrawLineInForeground(bool __value)
{
drawLineInForeground=__value;
}
bool JKQTPXYLineGraph::getDrawLineInForeground() const
{
return drawLineInForeground;
}
void JKQTPXYLineGraph::setColor(QColor c)
{
setLineColor(c);

View File

@ -77,6 +77,10 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXYLineGraph: public JKQTPXYGraph, public JKQTP
void setDrawLine(bool __value);
/** \copydoc drawLine */
bool getDrawLine() const;
/** \copydoc drawLineInForeground */
void setDrawLineInForeground(bool __value);
/** \copydoc drawLineInForeground */
bool getDrawLineInForeground() const;
/** \brief set color of line and symbol */
void setColor(QColor c);
@ -85,8 +89,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXYLineGraph: public JKQTPXYGraph, public JKQTP
/** \brief indicates whether to draw a line or not */
bool drawLine;
/** \brief indicates whether to draw the line behind or above the symbols */
bool drawLineInForeground;
};

View File

@ -251,7 +251,8 @@ void JKQTPXYScatterErrorGraph::drawErrorsBefore(JKQTPEnhancedPainter &painter)
JKQTPXYParametrizedScatterGraph::JKQTPXYParametrizedScatterGraph(JKQTBasePlotter *parent):
JKQTPXYGraph(parent),
JKQTPColorPaletteStyleAndToolsMixin(parent),
drawLine(false)
drawLine(false),
drawLineInForeground(true)
{
sizeColumn=-1;
colorColumn=-1;
@ -312,6 +313,7 @@ void JKQTPXYParametrizedScatterGraph::draw(JKQTPEnhancedPainter &painter)
QVector<QColor> linecols;
QVector<QColor> linecolss;
QVector<double> linewidths;
QVector<SymbolDescription> symbols;
//qDebug()<<"JKQTPXYLineGraph::draw(): "<<3<<" imin="<<imin<<" imax="<<imax;
{
painter.save(); auto __finalpaintinner=JKQTPFinally([&painter]() {painter.restore();});
@ -364,9 +366,10 @@ void JKQTPXYParametrizedScatterGraph::draw(JKQTPEnhancedPainter &painter)
if ((!parent->getXAxis()->isLogAxis() || xv>0.0) && (!parent->getYAxis()->isLogAxis() || yv>0.0) ) {
if (isHighlighted() && getSymbolType()!=JKQTPNoSymbol && symbolColumn<0) {
JKQTPPlotSymbol(painter, x, y, JKQTPFilledCircle,symbSize, parent->pt2px(painter, getSymbolLineWidth()*parent->getLineWidthMultiplier()), penSelection.color(), penSelection.color(),getSymbolFont());
JKQTPPlotSymbol(painter, x, y, JKQTPFilledCircle,symbSize*1.25, parent->pt2px(painter, getSymbolLineWidth()*parent->getLineWidthMultiplier()), penSelection.color(), penSelection.color(),getSymbolFont());
} else {
JKQTPPlotSymbol(painter, x, y, getLocalSymbolType(i), symbSize, parent->pt2px(painter, getSymbolLineWidth()*parent->getLineWidthMultiplier()), symbColor, symbFillColor,getSymbolFont());
if (drawLineInForeground) JKQTPPlotSymbol(painter, x, y, getLocalSymbolType(i), symbSize, parent->pt2px(painter, getSymbolLineWidth()*parent->getLineWidthMultiplier()), symbColor, symbFillColor,getSymbolFont());
else symbols.push_back({x, y, getLocalSymbolType(i), symbSize, symbColor, symbFillColor});
}
}
@ -409,7 +412,9 @@ void JKQTPXYParametrizedScatterGraph::draw(JKQTPEnhancedPainter &painter)
painter.setPen(pp);
painter.drawPolylineFast(linesP);
}
}
for (auto& s: symbols) {
JKQTPPlotSymbol(painter, s.x, s.y, s.type, s.size, parent->pt2px(painter, getSymbolLineWidth()*parent->getLineWidthMultiplier()), s.color, s.fillColor, getSymbolFont());
}
}
@ -447,9 +452,15 @@ void JKQTPXYParametrizedScatterGraph::drawKeyMarker(JKQTPEnhancedPainter &painte
if (symbolColumn>=0) {
symbol1=JKQTPFilledCircle;
symbol2=JKQTPFilledRect;
JKQTPDatastore* datastore=parent->getDatastore();
if (datastore && datastore->getRows(symbolColumn)>0) {
symbol1=getLocalSymbolType(0);
symbol2=getLocalSymbolType(datastore->getRows(symbolColumn)-1);
}
}
double lineWidth=getKeyLineWidthPx(painter, rect, parent)*0.75;
const double lineWidth=getKeyLineWidthPx(painter, rect, parent)*0.75;
painter.save(); auto __finalpaint=JKQTPFinally([&painter]() {painter.restore();});
QPen p=painter.pen();
@ -461,9 +472,10 @@ void JKQTPXYParametrizedScatterGraph::drawKeyMarker(JKQTPEnhancedPainter &painte
const double y1=rect.top()+symbolSize1/2.0;
const double x2=rect.right()-symbolSize2/2.0;
const double y2=rect.bottom()-symbolSize2/2.0;
if (drawLine && !drawLineInForeground) painter.drawLine(QLineF(x1,y1, x2,y2));
JKQTPPlotSymbol(painter, x1, y1, symbol1, symbolSize1, getKeySymbolLineWidthPx(painter, rect, parent,0.5), color1, JKQTPGetDerivedColor(symbolFillDerivationMode, color1),getSymbolFont());
JKQTPPlotSymbol(painter, x2, y2, symbol2, symbolSize2, getKeySymbolLineWidthPx(painter, rect, parent,0.5), color2, JKQTPGetDerivedColor(symbolFillDerivationMode, color2),getSymbolFont());
if (drawLine) painter.drawLine(QLineF(x1,y1, x2,y2));
if (drawLine && drawLineInForeground) painter.drawLine(QLineF(x1,y1, x2,y2));
}
@ -744,6 +756,16 @@ bool JKQTPXYParametrizedScatterGraph::getDrawLine() const
return drawLine;
}
void JKQTPXYParametrizedScatterGraph::setDrawLineInForeground(bool __value)
{
drawLineInForeground=__value;
}
bool JKQTPXYParametrizedScatterGraph::getDrawLineInForeground() const
{
return drawLineInForeground;
}
void JKQTPXYParametrizedScatterGraph::setColor(QColor c)
{
setLineColor(c);

View File

@ -343,6 +343,10 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXYParametrizedScatterGraph: public JKQTPXYGrap
void setDrawLine(bool __value);
/** \copydoc drawLine */
bool getDrawLine() const;
/** \copydoc drawLineInForeground */
void setDrawLineInForeground(bool __value);
/** \copydoc drawLineInForeground */
bool getDrawLineInForeground() const;
/** \brief set color of line and symbol */
void setColor(QColor c);
@ -351,6 +355,8 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXYParametrizedScatterGraph: public JKQTPXYGrap
/** \brief indicates whether to draw a line or not */
bool drawLine;
/** \brief indicates whether to draw the line behind or above the symbols */
bool drawLineInForeground;
/** \brief this column contains the symbol size in pt */
int sizeColumn;
/** \brief this column contains the symbol color */
@ -405,6 +411,15 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPXYParametrizedScatterGraph: public JKQTPXYGrap
JKQTPGraphSymbols operator()(double x, double y, double symcolumn) const;
};
/** \brief helper struct, which describes a single symbol */
struct SymbolDescription {
double x;
double y;
JKQTPGraphSymbols type;
double size;
QColor color;
QColor fillColor;
};
};