Browse Source

- Made sure the pixmap cannot be drawn with uninitialized data

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
6d88bb5b83
  1. 13
      src/downloadedpiecesbar.h
  2. 13
      src/pieceavailabilitybar.h

13
src/downloadedpiecesbar.h

@ -55,13 +55,13 @@ public:
void setProgress(bitfield pieces) { void setProgress(bitfield pieces) {
if(pieces.empty()) { if(pieces.empty()) {
// Empty bar // Empty bar
pixmap = QPixmap(1, 1); QPixmap pix = QPixmap(1, 1);
QPainter painter(&pixmap); pix.fill();
painter.setPen(Qt::white); pixmap = pix;
painter.drawPoint(0,0);
} else { } else {
pixmap = QPixmap(pieces.size(), 1); QPixmap pix = QPixmap(pieces.size(), 1);
QPainter painter(&pixmap); pix.fill();
QPainter painter(&pix);
for(uint i=0; i<pieces.size(); ++i) { for(uint i=0; i<pieces.size(); ++i) {
if(pieces[i]) if(pieces[i])
painter.setPen(Qt::blue); painter.setPen(Qt::blue);
@ -69,6 +69,7 @@ public:
painter.setPen(Qt::white); painter.setPen(Qt::white);
painter.drawPoint(i,0); painter.drawPoint(i,0);
} }
pixmap = pix;
} }
update(); update();
} }

13
src/pieceavailabilitybar.h

@ -54,21 +54,22 @@ public:
double average = 0; double average = 0;
if(avail.empty()) { if(avail.empty()) {
// Empty bar // Empty bar
pixmap = QPixmap(1, 1); QPixmap pix = QPixmap(1, 1);
QPainter painter(&pixmap); pix.fill();
painter.setPen(Qt::white); pixmap = pix;
painter.drawPoint(0,0);
} else { } else {
// Look for maximum value // Look for maximum value
uint nb_pieces = avail.size(); uint nb_pieces = avail.size();
average = std::accumulate(avail.begin(), avail.end(), 0)/(double)nb_pieces; average = std::accumulate(avail.begin(), avail.end(), 0)/(double)nb_pieces;
pixmap = QPixmap(nb_pieces, 1); QPixmap pix = QPixmap(nb_pieces, 1);
QPainter painter(&pixmap); pix.fill();
QPainter painter(&pix);
std::vector<int>::iterator it; std::vector<int>::iterator it;
for(uint i=0; i < nb_pieces; ++i) { for(uint i=0; i < nb_pieces; ++i) {
painter.setPen(getPieceColor(avail[i], average)); painter.setPen(getPieceColor(avail[i], average));
painter.drawPoint(i,0); painter.drawPoint(i,0);
} }
pixmap = pix;
} }
update(); update();
return average; return average;

Loading…
Cancel
Save