Qt 4.8
Classes | Signals | Public Functions | Protected Functions | Private Slots | Private Functions | Properties | List of all members
QDeclarativePath Class Reference

#include <qdeclarativepath_p.h>

Inheritance diagram for QDeclarativePath:
QObject QDeclarativeParserStatus

Classes

struct  AttributePoint
 

Signals

void changed ()
 
void startXChanged ()
 
void startYChanged ()
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

qreal attributeAt (const QString &, qreal) const
 
QStringList attributes () const
 
bool isClosed () const
 
QPainterPath path () const
 
QDeclarativeListProperty< QDeclarativePathElementpathElements ()
 
QPointF pointAt (qreal) const
 
 QDeclarativePath (QObject *parent=0)
 
void setStartX (qreal x)
 
void setStartY (qreal y)
 
qreal startX () const
 
qreal startY () const
 
 ~QDeclarativePath ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QDeclarativeParserStatus
 QDeclarativeParserStatus ()
 
virtual ~QDeclarativeParserStatus ()
 

Protected Functions

virtual void classBegin ()
 Invoked after class creation, but before any properties have been set. More...
 
virtual void componentComplete ()
 Invoked after the root component that caused this instantiation has completed construction. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Slots

void processPath ()
 

Private Functions

void createPointCache () const
 
void endpoint (const QString &name)
 
void interpolate (int idx, const QString &name, qreal value)
 

Properties

bool closed
 
QDeclarativeListProperty< QDeclarativePathElementpathElements
 
qreal startX
 
qreal startY
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 208 of file qdeclarativepath_p.h.

Constructors and Destructors

◆ QDeclarativePath()

QDeclarativePath::QDeclarativePath ( QObject parent = 0)

Definition at line 89 of file qdeclarativepath.cpp.

90  : QObject(*(new QDeclarativePathPrivate), parent)
91 {
92 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QDeclarativePath()

QDeclarativePath::~QDeclarativePath ( )

Definition at line 94 of file qdeclarativepath.cpp.

95 {
96 }

Functions

◆ attributeAt()

qreal QDeclarativePath::attributeAt ( const QString name,
qreal  percent 
) const

Definition at line 451 of file qdeclarativepath.cpp.

452 {
453  Q_D(const QDeclarativePath);
454  if (percent < 0 || percent > 1)
455  return 0;
456 
457  for (int ii = 0; ii < d->_attributePoints.count(); ++ii) {
458  const AttributePoint &point = d->_attributePoints.at(ii);
459 
460  if (point.percent == percent) {
461  return point.values.value(name);
462  } else if (point.percent > percent) {
463  qreal lastValue =
464  ii?(d->_attributePoints.at(ii - 1).values.value(name)):0;
465  qreal lastPercent =
466  ii?(d->_attributePoints.at(ii - 1).percent):0;
467  qreal curValue = point.values.value(name);
468  qreal curPercent = point.percent;
469 
470  return lastValue + (curValue - lastValue) * (percent - lastPercent) / (curPercent - lastPercent);
471  }
472  }
473 
474  return 0;
475 }
double qreal
Definition: qglobal.h:1193
QDeclarativeParserStatus ** d
#define Q_D(Class)
Definition: qglobal.h:2482

◆ attributes()

QStringList QDeclarativePath::attributes ( ) const

Definition at line 329 of file qdeclarativepath.cpp.

330 {
331  Q_D(const QDeclarativePath);
332  if (!d->componentComplete) {
333  QSet<QString> attrs;
334 
335  // First gather up all the attributes
336  foreach (QDeclarativePathElement *pathElement, d->_pathElements) {
337  if (QDeclarativePathAttribute *attribute =
338  qobject_cast<QDeclarativePathAttribute *>(pathElement))
339  attrs.insert(attribute->name());
340  }
341  return attrs.toList();
342  }
343  return d->_attributes;
344 }
QDeclarativeParserStatus ** d
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
QList< T > toList() const
Definition: qset.h:296
const_iterator insert(const T &value)
Definition: qset.h:179

◆ changed

void QDeclarativePath::changed ( )
signal

◆ classBegin()

void QDeclarativePath::classBegin ( )
protectedvirtual

Invoked after class creation, but before any properties have been set.

Implements QDeclarativeParserStatus.

Definition at line 297 of file qdeclarativepath.cpp.

298 {
300  d->componentComplete = false;
301 }
QDeclarativeParserStatus ** d
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.

◆ componentComplete()

void QDeclarativePath::componentComplete ( )
protectedvirtual

Invoked after the root component that caused this instantiation has completed construction.

At this point all static values and binding values have been assigned to the class.

Implements QDeclarativeParserStatus.

Definition at line 303 of file qdeclarativepath.cpp.

304 {
306  QSet<QString> attrs;
307  d->componentComplete = true;
308 
309  // First gather up all the attributes
310  foreach (QDeclarativePathElement *pathElement, d->_pathElements) {
311  if (QDeclarativePathAttribute *attribute =
312  qobject_cast<QDeclarativePathAttribute *>(pathElement))
313  attrs.insert(attribute->name());
314  }
315  d->_attributes = attrs.toList();
316 
317  processPath();
318 
319  foreach (QDeclarativePathElement *pathElement, d->_pathElements)
320  connect(pathElement, SIGNAL(changed()), this, SLOT(processPath()));
321 }
QDeclarativeParserStatus ** d
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QList< T > toList() const
Definition: qset.h:296
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
const_iterator insert(const T &value)
Definition: qset.h:179

◆ createPointCache()

void QDeclarativePath::createPointCache ( ) const
private

Definition at line 383 of file qdeclarativepath.cpp.

Referenced by pointAt().

384 {
385  Q_D(const QDeclarativePath);
386  qreal pathLength = d->_path.length();
387  if (pathLength <= 0 || qIsNaN(pathLength))
388  return;
389  // more points means less jitter between items as they move along the
390  // path, but takes longer to generate
391  const int points = qCeil(pathLength*5);
392  const int lastElement = d->_path.elementCount() - 1;
393  d->_pointCache.resize(points+1);
394 
395  int currElement = 0;
396  qreal bezLength = 0;
397  QBezier currBez = nextBezier(d->_path, &currElement, &bezLength);
398  qreal currLength = bezLength;
399  qreal epc = currLength / pathLength;
400 
401  for (int i = 0; i < d->_pointCache.size(); i++) {
402  //find which set we are in
403  qreal prevPercent = 0;
404  qreal prevOrigPercent = 0;
405  for (int ii = 0; ii < d->_attributePoints.count(); ++ii) {
406  qreal percent = qreal(i)/points;
407  const AttributePoint &point = d->_attributePoints.at(ii);
408  if (percent < point.percent || ii == d->_attributePoints.count() - 1) { //### || is special case for very last item
409  qreal elementPercent = (percent - prevPercent);
410 
411  qreal spc = prevOrigPercent + elementPercent * point.scale;
412 
413  while (spc > epc) {
414  if (currElement > lastElement)
415  break;
416  currBez = nextBezier(d->_path, &currElement, &bezLength);
417  if (bezLength == 0.0) {
418  currLength = pathLength;
419  epc = 1.0;
420  break;
421  }
422  currLength += bezLength;
423  epc = currLength / pathLength;
424  }
425  qreal realT = (pathLength * spc - (currLength - bezLength)) / bezLength;
426  d->_pointCache[i] = currBez.pointAt(qBound(qreal(0), realT, qreal(1)));
427  break;
428  }
429  prevOrigPercent = point.origpercent;
430  prevPercent = point.percent;
431  }
432  }
433 }
static QBezier nextBezier(const QPainterPath &path, int *from, qreal *bezLength)
double qreal
Definition: qglobal.h:1193
QDeclarativeParserStatus ** d
int qCeil(qreal v)
Definition: qmath.h:63
QPointF pointAt(qreal t) const
Definition: qbezier_p.h:163
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219

◆ endpoint()

void QDeclarativePath::endpoint ( const QString name)
private

Definition at line 209 of file qdeclarativepath.cpp.

Referenced by processPath().

210 {
212  const AttributePoint &first = d->_attributePoints.first();
213  qreal val = first.values.value(name);
214  for (int ii = d->_attributePoints.count() - 1; ii >= 0; ii--) {
215  const AttributePoint &point = d->_attributePoints.at(ii);
216  if (point.values.contains(name)) {
217  for (int jj = ii + 1; jj < d->_attributePoints.count(); ++jj) {
218  AttributePoint &setPoint = d->_attributePoints[jj];
219  setPoint.values.insert(name, val);
220  }
221  return;
222  }
223  }
224 }
double qreal
Definition: qglobal.h:1193
QDeclarativeParserStatus ** d
#define Q_D(Class)
Definition: qglobal.h:2482

◆ interpolate()

void QDeclarativePath::interpolate ( int  idx,
const QString name,
qreal  value 
)
private

Definition at line 178 of file qdeclarativepath.cpp.

Referenced by processPath().

179 {
181  if (!idx)
182  return;
183 
184  qreal lastValue = 0;
185  qreal lastPercent = 0;
186  int search = idx - 1;
187  while(search >= 0) {
188  const AttributePoint &point = d->_attributePoints.at(search);
189  if (point.values.contains(name)) {
190  lastValue = point.values.value(name);
191  lastPercent = point.origpercent;
192  break;
193  }
194  --search;
195  }
196 
197  ++search;
198 
199  const AttributePoint &curPoint = d->_attributePoints.at(idx);
200 
201  for (int ii = search; ii < idx; ++ii) {
202  AttributePoint &point = d->_attributePoints[ii];
203 
204  qreal val = lastValue + (value - lastValue) * (point.origpercent - lastPercent) / (curPoint.origpercent - lastPercent);
205  point.values.insert(name, val);
206  }
207 }
double qreal
Definition: qglobal.h:1193
QDeclarativeParserStatus ** d
#define Q_D(Class)
Definition: qglobal.h:2482

◆ isClosed()

bool QDeclarativePath::isClosed ( ) const

Definition at line 145 of file qdeclarativepath.cpp.

146 {
147  Q_D(const QDeclarativePath);
148  return d->closed;
149 }
QDeclarativeParserStatus ** d
#define Q_D(Class)
Definition: qglobal.h:2482

◆ path()

QPainterPath QDeclarativePath::path ( ) const

Definition at line 323 of file qdeclarativepath.cpp.

324 {
325  Q_D(const QDeclarativePath);
326  return d->_path;
327 }
QDeclarativeParserStatus ** d
#define Q_D(Class)
Definition: qglobal.h:2482

◆ pathElements()

QDeclarativeListProperty<QDeclarativePathElement> QDeclarativePath::pathElements ( )

Referenced by isClosed().

◆ pointAt()

QPointF QDeclarativePath::pointAt ( qreal  p) const

Definition at line 435 of file qdeclarativepath.cpp.

Referenced by QDeclarativePathViewPrivate::pointNear().

436 {
437  Q_D(const QDeclarativePath);
438  if (d->_pointCache.isEmpty()) {
440  if (d->_pointCache.isEmpty())
441  return QPointF();
442  }
443  int idx = qRound(p*d->_pointCache.size());
444  if (idx >= d->_pointCache.size())
445  idx = d->_pointCache.size() - 1;
446  else if (idx < 0)
447  idx = 0;
448  return d->_pointCache.at(idx);
449 }
QDeclarativeParserStatus ** d
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_D(Class)
Definition: qglobal.h:2482
void createPointCache() const
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ processPath

void QDeclarativePath::processPath ( )
privateslot

Definition at line 226 of file qdeclarativepath.cpp.

Referenced by componentComplete(), setStartX(), and setStartY().

227 {
229 
230  if (!d->componentComplete)
231  return;
232 
233  d->_pointCache.clear();
234  d->_attributePoints.clear();
235  d->_path = QPainterPath();
236 
237  AttributePoint first;
238  for (int ii = 0; ii < d->_attributes.count(); ++ii)
239  first.values[d->_attributes.at(ii)] = 0;
240  d->_attributePoints << first;
241 
242  d->_path.moveTo(d->startX, d->startY);
243 
244  QDeclarativeCurve *lastCurve = 0;
245  foreach (QDeclarativePathElement *pathElement, d->_pathElements) {
246  if (QDeclarativeCurve *curve = qobject_cast<QDeclarativeCurve *>(pathElement)) {
247  curve->addToPath(d->_path);
248  AttributePoint p;
249  p.origpercent = d->_path.length();
250  d->_attributePoints << p;
251  lastCurve = curve;
252  } else if (QDeclarativePathAttribute *attribute = qobject_cast<QDeclarativePathAttribute *>(pathElement)) {
253  AttributePoint &point = d->_attributePoints.last();
254  point.values[attribute->name()] = attribute->value();
255  interpolate(d->_attributePoints.count() - 1, attribute->name(), attribute->value());
256  } else if (QDeclarativePathPercent *percent = qobject_cast<QDeclarativePathPercent *>(pathElement)) {
257  AttributePoint &point = d->_attributePoints.last();
258  point.values[QLatin1String("_qfx_percent")] = percent->value();
259  interpolate(d->_attributePoints.count() - 1, QLatin1String("_qfx_percent"), percent->value());
260  }
261  }
262 
263  // Fixup end points
264  const AttributePoint &last = d->_attributePoints.last();
265  for (int ii = 0; ii < d->_attributes.count(); ++ii) {
266  if (!last.values.contains(d->_attributes.at(ii)))
267  endpoint(d->_attributes.at(ii));
268  }
269 
270  // Adjust percent
271  qreal length = d->_path.length();
272  qreal prevpercent = 0;
273  qreal prevorigpercent = 0;
274  for (int ii = 0; ii < d->_attributePoints.count(); ++ii) {
275  const AttributePoint &point = d->_attributePoints.at(ii);
276  if (point.values.contains(QLatin1String("_qfx_percent"))) { //special string for QDeclarativePathPercent
277  if ( ii > 0) {
278  qreal scale = (d->_attributePoints[ii].origpercent/length - prevorigpercent) /
279  (point.values.value(QLatin1String("_qfx_percent"))-prevpercent);
280  d->_attributePoints[ii].scale = scale;
281  }
282  d->_attributePoints[ii].origpercent /= length;
283  d->_attributePoints[ii].percent = point.values.value(QLatin1String("_qfx_percent"));
284  prevorigpercent = d->_attributePoints[ii].origpercent;
285  prevpercent = d->_attributePoints[ii].percent;
286  } else {
287  d->_attributePoints[ii].origpercent /= length;
288  d->_attributePoints[ii].percent = d->_attributePoints[ii].origpercent;
289  }
290  }
291 
292  d->closed = lastCurve && d->startX == lastCurve->x() && d->startY == lastCurve->y();
293 
294  emit changed();
295 }
double qreal
Definition: qglobal.h:1193
QDeclarativeParserStatus ** d
void interpolate(int idx, const QString &name, qreal value)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
virtual void addToPath(QPainterPath &)
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
#define emit
Definition: qobjectdefs.h:76
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void endpoint(const QString &name)

◆ setStartX()

void QDeclarativePath::setStartX ( qreal  x)

Definition at line 112 of file qdeclarativepath.cpp.

113 {
115  if (qFuzzyCompare(x, d->startX))
116  return;
117  d->startX = x;
119  processPath();
120 }
QDeclarativeParserStatus ** d
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76

◆ setStartY()

void QDeclarativePath::setStartY ( qreal  y)

Definition at line 128 of file qdeclarativepath.cpp.

129 {
131  if (qFuzzyCompare(y, d->startY))
132  return;
133  d->startY = y;
135  processPath();
136 }
QDeclarativeParserStatus ** d
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
#define Q_D(Class)
Definition: qglobal.h:2482
#define emit
Definition: qobjectdefs.h:76

◆ startX()

qreal QDeclarativePath::startX ( ) const

Referenced by ~QDeclarativePath().

◆ startXChanged

void QDeclarativePath::startXChanged ( )
signal

Referenced by setStartX().

◆ startY()

qreal QDeclarativePath::startY ( ) const

Referenced by setStartX().

◆ startYChanged

void QDeclarativePath::startYChanged ( )
signal

Referenced by setStartY().

Properties

◆ closed

bool QDeclarativePath::closed
private

Definition at line 216 of file qdeclarativepath_p.h.

◆ pathElements

QDeclarativeListProperty< QDeclarativePathElement > QDeclarativePath::pathElements
private

Definition at line 213 of file qdeclarativepath_p.h.

◆ startX

qreal QDeclarativePath::startX
private

Definition at line 214 of file qdeclarativepath_p.h.

◆ startY

qreal QDeclarativePath::startY
private

Definition at line 215 of file qdeclarativepath_p.h.


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