summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-07-30 04:50:39 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-07-30 04:50:39 (GMT)
commit5246aeb198ccfd2a3fc94298161c24cb8f57f81f (patch)
treeefb8f3dd26cb24cd35385cfd1072fb47455defa3 /src
parentab5619c395be3fdae70042ca6f6bc93a9a6f2c80 (diff)
downloadQt-5246aeb198ccfd2a3fc94298161c24cb8f57f81f.zip
Qt-5246aeb198ccfd2a3fc94298161c24cb8f57f81f.tar.gz
Qt-5246aeb198ccfd2a3fc94298161c24cb8f57f81f.tar.bz2
Unit tests and bug fixes for QGLColormap
QGLColormap::setEntry() was inserting entries instead of replacing them; QGLColormap::setEntries() had an incorrect assert and weird behaviour for the "base". The documentation for QGLColormap::isEmpty() has been updated to reflect that it will also report empty if the colormap has not been set on a QGLWidget even if it has entries in it. This behaviour is required by existing code. Reviewed-by: Rohan McGovern
Diffstat (limited to 'src')
-rw-r--r--src/opengl/qglcolormap.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/opengl/qglcolormap.cpp b/src/opengl/qglcolormap.cpp
index 426e090..481089a 100644
--- a/src/opengl/qglcolormap.cpp
+++ b/src/opengl/qglcolormap.cpp
@@ -174,13 +174,14 @@ void QGLColormap::setEntry(int idx, QRgb color)
detach();
if (!d->cells)
d->cells = new QVector<QRgb>(256);
- d->cells->insert(idx, color);
+ d->cells->replace(idx, color);
}
/*!
Set an array of cells in this colormap. \a count is the number of
colors that should be set, \a colors is the array of colors, and
- \a base is the starting index.
+ \a base is the starting index. The first element in \a colors
+ is set at \a base in the colormap.
*/
void QGLColormap::setEntries(int count, const QRgb *colors, int base)
{
@@ -188,10 +189,10 @@ void QGLColormap::setEntries(int count, const QRgb *colors, int base)
if (!d->cells)
d->cells = new QVector<QRgb>(256);
- Q_ASSERT_X(!colors || base >= 0 || base + count < d->cells->size(), "QGLColormap::setEntries",
+ Q_ASSERT_X(colors && base >= 0 && (base + count) <= d->cells->size(), "QGLColormap::setEntries",
"preconditions not met");
- for (int i = base; i < base + count; ++i)
- setEntry(i, colors[i]);
+ for (int i = 0; i < count; ++i)
+ setEntry(base + i, colors[i]);
}
/*!
@@ -227,8 +228,17 @@ QColor QGLColormap::entryColor(int idx) const
}
/*!
- Returns true if the colormap is empty; otherwise returns false. A
- colormap with no color values set is considered to be empty.
+ Returns true if the colormap is empty or it is not in use
+ by a QGLWidget; otherwise returns false.
+
+ A colormap with no color values set is considered to be empty.
+ For historical reasons, a colormap that has color values set
+ but which is not in use by a QGLWidget is also considered empty.
+
+ Compare size() with zero to determine if the colormap is empty
+ regardless of whether it is in use by a QGLWidget or not.
+
+ \sa size()
*/
bool QGLColormap::isEmpty() const
{