Skip to content
Permalink
Browse files
qrand is gone
  • Loading branch information
nyalldawson committed Jul 20, 2021
1 parent 3b6497c commit 99be260ba2080e300e9d43fec266b0465a9ae8eb
Showing with 17 additions and 13 deletions.
  1. +7 −6 src/gui/raster/qgsrasterhistogramwidget.cpp
  2. +10 −7 src/gui/vector/qgsdiagramproperties.cpp
@@ -30,6 +30,7 @@
#include <QDir>
#include <QPainter>
#include <QActionGroup>
#include <QRandomGenerator>

// QWT Charting widget
#include <qwt_global.h>
@@ -417,16 +418,16 @@ void QgsRasterHistogramWidget::refreshHistogram()
mHistoColors << Qt::black; // first element, not used
QVector<QColor> myColors;
myColors << Qt::red << Qt::green << Qt::blue << Qt::magenta << Qt::darkYellow << Qt::cyan;
qsrand( myBandCountInt * 100 ); // make sure colors are always the same for a given band count

// make sure colors are always the same for a given band count
QRandomGenerator colorGenerator( myBandCountInt * 100 );
while ( myColors.size() <= myBandCountInt )
{
myColors <<
QColor( 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ),
1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ),
1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) ) );
QColor( colorGenerator.bounded( 1, 256 ),
colorGenerator.bounded( 1, 256 ),
colorGenerator.bounded( 1, 256 ) );
}
//randomise seed again
qsrand( time( nullptr ) );

// assign colors to each band, depending on the current RGB/gray band selection
// grayscale
@@ -50,7 +50,7 @@
#include <QList>
#include <QMessageBox>
#include <QStyledItemDelegate>

#include <QRandomGenerator>

class EditBlockerDelegate: public QStyledItemDelegate
{
@@ -669,9 +669,10 @@ void QgsDiagramProperties::addAttribute( QTreeWidgetItem *item )
newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );

//set initial color for diagram category
int red = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
int green = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
int blue = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
QRandomGenerator colorGenerator;
const int red = colorGenerator.bounded( 1, 256 );
const int green = colorGenerator.bounded( 1, 256 );
const int blue = colorGenerator.bounded( 1, 256 );
QColor randomColor( red, green, blue );
newItem->setData( ColumnColor, Qt::EditRole, randomColor );
mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
@@ -1020,9 +1021,11 @@ void QgsDiagramProperties::showAddAttributeExpressionDialog()
newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );

//set initial color for diagram category
int red = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
int green = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
int blue = 1 + ( int )( 255.0 * qrand() / ( RAND_MAX + 1.0 ) );
QRandomGenerator colorGenerator;
const int red = colorGenerator.bounded( 1, 256 );
const int green = colorGenerator.bounded( 1, 256 );
const int blue = colorGenerator.bounded( 1, 256 );

QColor randomColor( red, green, blue );
newItem->setData( ColumnColor, Qt::EditRole, randomColor );
mDiagramAttributesTreeWidget->addTopLevelItem( newItem );

0 comments on commit 99be260

Please sign in to comment.