Qt 4.8
Classes | Public Functions | Protected Functions | Protected Variables | Private Types | List of all members
QGLStrokeCache Class Reference

Classes

struct  CacheInfo
 

Public Functions

QPainterPath getStrokedPath (const QPainterPath &path, const QPen &pen)
 

Protected Functions

QPainterPath addCacheElement (quint64 hash_val, QPainterPath path, const QPen &pen)
 
int maxCacheSize () const
 

Protected Variables

QGLStrokeTableHash cache
 

Private Types

typedef QMultiHash< quint64, CacheInfoQGLStrokeTableHash
 

Detailed Description

Definition at line 939 of file qpaintengine_opengl.cpp.

Typedefs

◆ QGLStrokeTableHash

Definition at line 950 of file qpaintengine_opengl.cpp.

Functions

◆ addCacheElement()

QPainterPath QGLStrokeCache::addCacheElement ( quint64  hash_val,
QPainterPath  path,
const QPen pen 
)
inlineprotected

Definition at line 979 of file qpaintengine_opengl.cpp.

979  {
980  if (cache.size() == maxCacheSize()) {
981  int elem_to_remove = qrand() % maxCacheSize();
982  cache.remove(cache.keys()[elem_to_remove]); // may remove more than 1, but OK
983  }
984  QPainterPath stroke = strokeForPath(path, pen);
985  CacheInfo cache_entry(path, stroke, pen);
986  return cache.insert(hash_val, cache_entry).value().stroked_path;
987  }
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
Q_CORE_EXPORT int qrand()
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QGLStrokeTableHash cache
QHash< Key, T >::iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:934
int remove(const Key &key, const T &value)
Removes all the items that have the key and the value value from the hash.
Definition: qhash.h:1006
int size() const
Returns the number of items in the hash.
Definition: qhash.h:295
QList< Key > keys() const
Returns a list containing all the keys in the hash, in an arbitrary order.
Definition: qhash.h:648
static QPainterPath strokeForPath(const QPainterPath &path, const QPen &cpen)

◆ getStrokedPath()

QPainterPath QGLStrokeCache::getStrokedPath ( const QPainterPath path,
const QPen pen 
)
inline

Definition at line 953 of file qpaintengine_opengl.cpp.

953  {
954  quint64 hash_val = 0;
955 
956  for (int i = 0; i < path.elementCount() && i <= 2; i++) {
957  hash_val += quint64(path.elementAt(i).x);
958  hash_val += quint64(path.elementAt(i).y);
959  }
960 
962 
963  if (it == cache.constEnd())
964  return addCacheElement(hash_val, path, pen);
965  else {
966  do {
967  const CacheInfo &cache_info = it.value();
968  if (cache_info.path == path && cache_info.pen == pen)
969  return cache_info.stroked_path;
970  ++it;
971  } while (it != cache.constEnd() && it.key() == hash_val);
972  // an exact match for this path was not found, create new cache element
973  return addCacheElement(hash_val, path, pen);
974  }
975  }
QHash< Key, T >::const_iterator constFind(const Key &key, const T &value) const
Returns an iterator pointing to the item with the key and the value in the hash.
Definition: qhash.h:992
#define it(className, varName)
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
unsigned __int64 quint64
Definition: qglobal.h:943
QGLStrokeTableHash cache
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:469
QPainterPath addCacheElement(quint64 hash_val, QPainterPath path, const QPen &pen)
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397
friend class const_iterator
Definition: qhash.h:461

◆ maxCacheSize()

int QGLStrokeCache::maxCacheSize ( ) const
inlineprotected

Definition at line 978 of file qpaintengine_opengl.cpp.

978 { return 500; }

Properties

◆ cache

QGLStrokeTableHash QGLStrokeCache::cache
protected

Definition at line 989 of file qpaintengine_opengl.cpp.


The documentation for this class was generated from the following file: