From afaee94f7ddc4bd23286e54ea3c407ee5627ef7d Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Sat, 26 Jan 2019 12:35:57 +0100 Subject: [PATCH] JKQTPSingleColumnSymbolsGraph now uses fixed seed-value for random scattering plot --- .../jkqtpgraphssinglecolumnsymbols.cpp | 23 ++++--------------- .../jkqtpgraphssinglecolumnsymbols.h | 13 +++++++++++ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/jkqtplotter/jkqtpgraphssinglecolumnsymbols.cpp b/lib/jkqtplotter/jkqtpgraphssinglecolumnsymbols.cpp index fd804c8dfe..85397dc1a6 100644 --- a/lib/jkqtplotter/jkqtpgraphssinglecolumnsymbols.cpp +++ b/lib/jkqtplotter/jkqtpgraphssinglecolumnsymbols.cpp @@ -36,7 +36,7 @@ JKQTPSingleColumnSymbolsGraph::JKQTPSingleColumnSymbolsGraph(JKQTBasePlotter *parent): - JKQTPSingleColumnGraph(parent) + JKQTPSingleColumnGraph(parent), seedValue(123456) { color=QColor("red"); style=Qt::SolidLine; @@ -60,25 +60,9 @@ JKQTPSingleColumnSymbolsGraph::JKQTPSingleColumnSymbolsGraph(JKQTBasePlotter *pa JKQTPSingleColumnSymbolsGraph::JKQTPSingleColumnSymbolsGraph(JKQTPlotter *parent): - JKQTPSingleColumnGraph(parent) + JKQTPSingleColumnSymbolsGraph(parent->getPlotter()) { - color=QColor("red"); - style=Qt::SolidLine; - lineWidth=2; - parentPlotStyle=-1; - symbolSize=12; - symbolWidth=1; - symbol=JKQTPNoSymbol; - dataDirection=DataDirection::Y; - position=0; - if (parent) { // get style settings from parent object - parentPlotStyle=parent->getNextStyle(); - //std::cout<<"got style settings from parent: "<getPlotStyle(parentPlotStyle).color(); - style=parent->getPlotStyle(parentPlotStyle).style(); - } - fillColor=color; } @@ -146,7 +130,8 @@ void JKQTPSingleColumnSymbolsGraph::draw(JKQTPEnhancedPainter &painter) if (imax<0) imax=0; std::random_device rd; // random number generators: - std::mt19937 gen{rd()}; + std::minstd_rand gen{rd()}; + gen.seed(seedValue); std::uniform_real_distribution<> dRandomScatter{position-width/2.0, position+width/2.0}; const double symSize=parent->pt2px(painter, symbolSize); diff --git a/lib/jkqtplotter/jkqtpgraphssinglecolumnsymbols.h b/lib/jkqtplotter/jkqtpgraphssinglecolumnsymbols.h index 005f1f55b5..cb4e13e8d2 100644 --- a/lib/jkqtplotter/jkqtpgraphssinglecolumnsymbols.h +++ b/lib/jkqtplotter/jkqtpgraphssinglecolumnsymbols.h @@ -199,6 +199,14 @@ class LIB_EXPORT JKQTPSingleColumnSymbolsGraph: public JKQTPSingleColumnGraph { { return this->symbolSize; } + /** \copydoc seedValue */ + inline void setSeedValue(unsigned int val) { + seedValue=val; + } + /** \copydoc seedValue */ + inline unsigned int getSeedValue() const { + return seedValue; + } protected: /** \brief interpret the data from dataColumn either as X- or Y-data */ DataDirection dataDirection; @@ -216,6 +224,11 @@ class LIB_EXPORT JKQTPSingleColumnSymbolsGraph: public JKQTPSingleColumnGraph { double symbolSize; /** \brief width (in pt) of the lines used to plot the symbol for the data points */ double symbolWidth; + /** \brief seed value for the pseudo-random number generator used for drawing. + * + * This seed is used instead of e.g. the system time to ensure that replotting results in the + * same plot every time. ou can set the seed using setSeedvalue() ) */ + unsigned int seedValue; QPen getSymbolPen(JKQTPEnhancedPainter& painter) const; QBrush getBrush(JKQTPEnhancedPainter &painter) const;