Skip to content

Commit

Permalink
qrand is gone
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 20, 2021
1 parent 3b6497c commit 99be260
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/gui/raster/qgsrasterhistogramwidget.cpp
Expand Up @@ -30,6 +30,7 @@
#include <QDir>
#include <QPainter>
#include <QActionGroup>
#include <QRandomGenerator>

// QWT Charting widget
#include <qwt_global.h>
Expand Down Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/gui/vector/qgsdiagramproperties.cpp
Expand Up @@ -50,7 +50,7 @@
#include <QList>
#include <QMessageBox>
#include <QStyledItemDelegate>

#include <QRandomGenerator>

class EditBlockerDelegate: public QStyledItemDelegate
{
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 99be260

Please sign in to comment.