Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QCustomDataArray Class

The QCustomDataArray class is a polymorphic array of data values suitable for use in 3D applications. More...

 #include <QCustomDataArray>

This class was introduced in Qt 4.8.

Public Types

enum ElementType { Float, Vector2D, Vector3D, Vector4D, Color }

Public Functions

QCustomDataArray()
QCustomDataArray(QCustomDataArray::ElementType type)
QCustomDataArray(QCustomDataArray::ElementType type, int size)
QCustomDataArray(const QCustomDataArray & other)
QCustomDataArray(const QArray<float> & other)
QCustomDataArray(const QArray<QVector2D> & other)
QCustomDataArray(const QArray<QVector3D> & other)
QCustomDataArray(const QArray<QVector4D> & other)
QCustomDataArray(const QArray<QColor4ub> & other)
~QCustomDataArray()
void append(const QVariant & value)
void append(qreal x)
void append(qreal x, qreal y)
void append(qreal x, qreal y, qreal z)
void append(qreal x, qreal y, qreal z, qreal w)
void append(const QVector2D & value)
void append(const QVector3D & value)
void append(const QVector4D & value)
void append(const QColor4ub & value)
void append(Qt::GlobalColor value)
void append(const QCustomDataArray & array)
QVariant at(int index) const
int capacity() const
void clear()
QColor4ub colorAt(int index) const
int count() const
const void * data() const
int elementSize() const
QCustomDataArray::ElementType elementType() const
qreal floatAt(int index) const
bool isEmpty() const
void reserve(int size)
void resize(int size)
void setAt(int index, const QVariant & value)
void setAt(int index, qreal x)
void setAt(int index, qreal x, qreal y)
void setAt(int index, qreal x, qreal y, qreal z)
void setAt(int index, qreal x, qreal y, qreal z, qreal w)
void setAt(int index, const QVector2D & value)
void setAt(int index, const QVector3D & value)
void setAt(int index, const QVector4D & value)
void setAt(int index, const QColor4ub & value)
void setAt(int index, Qt::GlobalColor value)
void setElementType(QCustomDataArray::ElementType type)
int size() const
void squeeze()
QArray<QColor4ub> toColorArray() const
QArray<float> toFloatArray() const
QArray<QVector2D> toVector2DArray() const
QArray<QVector3D> toVector3DArray() const
QArray<QVector4D> toVector4DArray() const
QVector2D vector2DAt(int index) const
QVector3D vector3DAt(int index) const
QVector4D vector4DAt(int index) const
QCustomDataArray & operator=(const QCustomDataArray & other)

Detailed Description

The QCustomDataArray class is a polymorphic array of data values suitable for use in 3D applications.

QArray is an efficient storage mechanism for vertex attributes. However, there are some situations where the element type of a custom vertex attribute is not known until runtime. QCustomDataArray is intended for use in those situations. It has a small performance penalty compared to QArray to achieve polymorphism.

The elements that may be stored in a QCustomDataArray are limited to a few types: float, QVector2D, QVector3D, QVector4D, and QColor4ub. This provides a reasonable range of efficient use cases without overloading the API. QArray can be used on any type, but is restricted to types that are known at compile time.

Like QArray, QCustomDataArray uses implicit sharing and copy-on-write semantics to support passing large arrays around an application with little overhead.

See also QArray.

Member Type Documentation

enum QCustomDataArray::ElementType

This enum defines the element type within a QCustomDataArray.

ConstantValueDescription
QCustomDataArray::Float0The elements are of type float.
QCustomDataArray::Vector2D1The elements are of type QVector2D.
QCustomDataArray::Vector3D2The elements are of type QVector3D.
QCustomDataArray::Vector4D3The elements are of type QVector4D.
QCustomDataArray::Color4The elements are of type QColor4ub, which consists of four unsigned bytes. To represent colors as four floating-point values, use Vector4D as the element type.

Member Function Documentation

QCustomDataArray::QCustomDataArray()

Constructs an empty custom data array. The elementType() will initially be QCustomDataArray::Float, which can be changed with a call to setElementType() before the elements are appended.

See also setElementType() and append().

QCustomDataArray::QCustomDataArray(QCustomDataArray::ElementType type)

Constructs an empty custom data array with elements represented by the specified type.

See also setElementType().

QCustomDataArray::QCustomDataArray(QCustomDataArray::ElementType type, int size)

Constructs an empty custom data array with elements represented by the specified type. The array is initially resized to size; filling all elements with zeroes.

See also setElementType() and resize().

QCustomDataArray::QCustomDataArray(const QCustomDataArray & other)

Constructs a copy of other.

QCustomDataArray::QCustomDataArray(const QArray<float> & other)

Constructs a copy of the floating-point QArray other.

The elementType() will be set to QCustomDataArray::Float.

See also toFloatArray().

QCustomDataArray::QCustomDataArray(const QArray<QVector2D> & other)

Constructs a copy of the 2D vector QArray other.

The elementType() will be set to QCustomDataArray::Vector2D.

This constructor needs to make a complete copy of the data in other so it may be expensive performance-wise.

See also toVector2DArray().

QCustomDataArray::QCustomDataArray(const QArray<QVector3D> & other)

Constructs a copy of the 3D vector QArray other.

The elementType() will be set to QCustomDataArray::Vector3D.

This constructor needs to make a complete copy of the data in other so it may be expensive performance-wise.

See also toVector3DArray().

QCustomDataArray::QCustomDataArray(const QArray<QVector4D> & other)

Constructs a copy of the 4D vector QArray other.

The elementType() will be set to QCustomDataArray::Vector4D.

This constructor needs to make a complete copy of the data in other so it may be expensive performance-wise.

See also toVector3DArray().

QCustomDataArray::QCustomDataArray(const QArray<QColor4ub> & other)

Constructs a copy of the color QArray other.

The elementType() will be set to QCustomDataArray::Color.

This constructor needs to make a complete copy of the data in other so it may be expensive performance-wise.

See also toColorArray().

QCustomDataArray::~QCustomDataArray()

Destroys this custom data array.

void QCustomDataArray::append(const QVariant & value)

Appends value to this custom data array.

The type of value must be consistent with elementType(). The two exceptions to this are that a Float value can be specified by either a float or double QVariant, and a Color value can be specified as either a QColor4ub or QColor QVariant.

See also at(), setAt(), and elementType().

void QCustomDataArray::append(qreal x)

This is an overloaded function.

Appends the floating-point value x to this custom data array. The elementType() must be QCustomDataArray::Float.

See also setAt() and floatAt().

void QCustomDataArray::append(qreal x, qreal y)

This is an overloaded function.

Appends the 2D vector value (x, y) to this custom data array. The elementType() must be QCustomDataArray::Vector2D.

See also setAt() and vector2DAt().

void QCustomDataArray::append(qreal x, qreal y, qreal z)

This is an overloaded function.

Appends the 3D vector value (x, y, z) to this custom data array. The elementType() must be QCustomDataArray::Vector3D.

See also setAt() and vector3DAt().

void QCustomDataArray::append(qreal x, qreal y, qreal z, qreal w)

This is an overloaded function.

Appends the 4D vector value (x, y, z, w) to this custom data array. The elementType() must be QCustomDataArray::Vector4D.

See also setAt() and vector4DAt().

void QCustomDataArray::append(const QVector2D & value)

This is an overloaded function.

Appends the 2D vector value to this custom data array. The elementType() must be QCustomDataArray::Vector2D.

See also setAt() and vector2DAt().

void QCustomDataArray::append(const QVector3D & value)

This is an overloaded function.

Appends the 3D vector value to this custom data array. The elementType() must be QCustomDataArray::Vector3D.

See also setAt() and vector3DAt().

void QCustomDataArray::append(const QVector4D & value)

This is an overloaded function.

Appends the 4D vector value to this custom data array. The elementType() must be QCustomDataArray::Vector4D.

See also setAt() and vector4DAt().

void QCustomDataArray::append(const QColor4ub & value)

This is an overloaded function.

Appends the color value to this custom data array. The elementType() must be QCustomDataArray::Color.

See also setAt() and colorAt().

void QCustomDataArray::append(Qt::GlobalColor value)

This is an overloaded function.

Appends the color value to this custom data array. The elementType() must be QCustomDataArray::Color.

See also setAt() and colorAt().

void QCustomDataArray::append(const QCustomDataArray & array)

This is an overloaded function.

Appends the values in array to this custom data array. This custom data array must have the same element type as array, unless this custom data array is empty - in which case the element type and data of array will be assigned to this.

QVariant QCustomDataArray::at(int index) const

Returns the value of the element at index in this custom data array as a QVariant.

Color elements are returned as a QVariant containing a QColor4ub, not a QColor.

See also setAt(), append(), floatAt(), vector2DAt(), vector3DAt(), vector4DAt(), and colorAt().

int QCustomDataArray::capacity() const

Returns the number of elements that can be stored in this custom data array before reallocation.

See also reserve() and size().

void QCustomDataArray::clear()

Clears all elements from this custom data array and sets the size to zero.

This function will deallocate any memory that is used on the heap to store the custom data array's elements. To reuse the same memory as before, call resize() with an argument of zero.

See also resize() and isEmpty().

QColor4ub QCustomDataArray::colorAt(int index) const

Returns the color element at index in this custom data array. The elementType() must be QCustomDataArray::Color.

See also at(), setAt(), and elementType().

int QCustomDataArray::count() const

Same as size(); provided for convenience.

const void * QCustomDataArray::data() const

Returns a const pointer to the data stored in the custom data array. The pointer can be used to access the items in the custom data array. The pointer remains valid as long as the custom data array isn't reallocated.

This function is mostly useful to pass a custom data array to a function that accepts a plain C++ array.

int QCustomDataArray::elementSize() const

Returns the size of individual elements in this custom data array, in bytes. For example, the element size of an array containing QVector3D values will be 3 * sizeof(float), normally 12.

See also setElementType().

QCustomDataArray::ElementType QCustomDataArray::elementType() const

Returns the representation type of elements in this custom data array.

See also setElementType().

qreal QCustomDataArray::floatAt(int index) const

Returns the floating-point element at index in this custom data array. The elementType() must be QCustomDataArray::Float.

See also at(), setAt(), and elementType().

bool QCustomDataArray::isEmpty() const

Returns true if this data array is empty; false otherwise.

See also size() and clear().

void QCustomDataArray::reserve(int size)

Increases the capacity of this custom data array to reserve space for at least size elements. If the capacity is already larger than size, this function does nothing; in particular, it does not remove elements from the array like resize() does.

This function can be useful when you know how roughly many elements will be appended ahead of time. Reserving the space once can avoid unnecessary realloc operations later.

See also capacity(), resize(), and squeeze().

void QCustomDataArray::resize(int size)

Sets the size of the custom data array to size. If size is greater than the current size, elements are added to the end; the new elements are initialized with all-zeroes. If size is less than the current size, elements are removed from the end.

See also size(), reserve(), and squeeze().

void QCustomDataArray::setAt(int index, const QVariant & value)

Sets the element at index in this custom data array to value.

The type of value must be consistent with elementType(). The two exceptions to this are that a Float value can be specified by either a float or double QVariant, and a Color value can be specified as either a QColor4ub or QColor QVariant.

See also at() and elementType().

void QCustomDataArray::setAt(int index, qreal x)

This is an overloaded function.

Sets the floating-point element at index in this custom data array to x. The elementType() must be QCustomDataArray::Float.

See also at(), elementType(), and floatAt().

void QCustomDataArray::setAt(int index, qreal x, qreal y)

This is an overloaded function.

Sets the 2D vector element at index in this custom data array to (x, y). The elementType() must be QCustomDataArray::Vector2D.

See also at(), elementType(), and vector2DAt().

void QCustomDataArray::setAt(int index, qreal x, qreal y, qreal z)

This is an overloaded function.

Sets the 3D vector element at index in this custom data array to (x, y, z). The elementType() must be QCustomDataArray::Vector3D.

See also at(), elementType(), and vector3DAt().

void QCustomDataArray::setAt(int index, qreal x, qreal y, qreal z, qreal w)

This is an overloaded function.

Sets the 4D vector element at index in this custom data array to (x, y, z, w). The elementType() must be QCustomDataArray::Vector4D.

See also at(), elementType(), and vector4DAt().

void QCustomDataArray::setAt(int index, const QVector2D & value)

This is an overloaded function.

Sets the 2D vector element at index in this custom data array to value. The elementType() must be QCustomDataArray::Vector2D.

See also at(), elementType(), and vector2DAt().

void QCustomDataArray::setAt(int index, const QVector3D & value)

This is an overloaded function.

Sets the 3D vector element at index in this custom data array to value. The elementType() must be QCustomDataArray::Vector3D.

See also at(), elementType(), and vector3DAt().

void QCustomDataArray::setAt(int index, const QVector4D & value)

This is an overloaded function.

Sets the 4D vector element at index in this custom data array to value. The elementType() must be QCustomDataArray::Vector4D.

See also at(), elementType(), and vector4DAt().

void QCustomDataArray::setAt(int index, const QColor4ub & value)

This is an overloaded function.

Sets the color element at index in this custom data array to value. The elementType() must be QCustomDataArray::Color.

See also at(), elementType(), and colorAt().

void QCustomDataArray::setAt(int index, Qt::GlobalColor value)

This is an overloaded function.

Sets the color element at index in this custom data array to value. The elementType() must be QCustomDataArray::Color.

See also at(), elementType(), and colorAt().

void QCustomDataArray::setElementType(QCustomDataArray::ElementType type)

Sets the representation type of elements in this custom data array. The array must be empty to change the element type.

See also elementType() and append().

int QCustomDataArray::size() const

Returns the number of elements in this custom data array.

See also resize(), capacity(), and isEmpty().

void QCustomDataArray::squeeze()

Releases any memory not required to store the custom data array's elements by reducing its capacity() to size().

This function is intended for reclaiming memory in a custom data array that is being used over and over with different contents. As elements are added to a custom data array, it will be constantly expanded in size. This function can realloc the custom data array to a smaller size to reclaim unused memory.

See also reserve() and capacity().

QArray<QColor4ub> QCustomDataArray::toColorArray() const

Returns the contents of this custom data array as a QArray of QColor4ub values.

The elementType() must be QCustomDataArray::Color.

This function needs to make a complete copy of the data in this array so it may be expensive performance-wise.

QArray<float> QCustomDataArray::toFloatArray() const

Returns the contents of this custom data array as a QArray of float values.

The elementType() must be QCustomDataArray::Float.

QArray<QVector2D> QCustomDataArray::toVector2DArray() const

Returns the contents of this custom data array as a QArray of QVector2D values.

The elementType() must be QCustomDataArray::Vector2D.

This function needs to make a complete copy of the data in this array so it may be expensive performance-wise.

QArray<QVector3D> QCustomDataArray::toVector3DArray() const

Returns the contents of this custom data array as a QArray of QVector3D values.

The elementType() must be QCustomDataArray::Vector3D.

This function needs to make a complete copy of the data in this array so it may be expensive performance-wise.

QArray<QVector4D> QCustomDataArray::toVector4DArray() const

Returns the contents of this custom data array as a QArray of QVector4D values.

The elementType() must be QCustomDataArray::Vector4D.

This function needs to make a complete copy of the data in this array so it may be expensive performance-wise.

QVector2D QCustomDataArray::vector2DAt(int index) const

Returns the 2D vector element at index in this custom data array. The elementType() must be QCustomDataArray::Vector2D.

See also at(), setAt(), and elementType().

QVector3D QCustomDataArray::vector3DAt(int index) const

Returns the 3D vector element at index in this custom data array. The elementType() must be QCustomDataArray::Vector3D.

See also at(), setAt(), and elementType().

QVector4D QCustomDataArray::vector4DAt(int index) const

Returns the 4D vector element at index in this custom data array. The elementType() must be QCustomDataArray::Vector4D.

See also at(), setAt(), and elementType().

QCustomDataArray & QCustomDataArray::operator=(const QCustomDataArray & other)

Assigns other to this custom data array and returns a reference to this custom data array.

The previous elementType() for this custom data array will be replaced with the type from other. The element data is assigned directly without conversion.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web