Qt 4.8
Public Types | Public Functions | Protected Functions | Private Functions | Properties | Friends | List of all members
QDeclarativeDataBlob Class Referenceabstract

The QDeclarativeDataBlob encapsulates a data request that can be issued to a QDeclarativeDataLoader. More...

#include <qdeclarativetypeloader_p.h>

Inheritance diagram for QDeclarativeDataBlob:
QDeclarativeRefCount QDeclarativeQmldirData QDeclarativeScriptData QDeclarativeTypeData

Public Types

enum  Status {
  Null, Loading, WaitingForDependencies, Complete,
  Error
}
 This enum describes the status of the data blob. More...
 
enum  Type { QmlFile, JavaScriptFile, QmldirFile }
 This enum describes the type of the data blob. More...
 

Public Functions

void addDependency (QDeclarativeDataBlob *)
 Wait for blob to become complete or to error. More...
 
QList< QDeclarativeErrorerrors () const
 Return the errors on this blob. More...
 
QUrl finalUrl () const
 Returns the final url of the data. More...
 
bool isComplete () const
 Returns true if the status is Complete. More...
 
bool isCompleteOrError () const
 Returns true if the status is Complete or Error. More...
 
bool isError () const
 Returns true if the status is Error. More...
 
bool isLoading () const
 Returns true if the status is Loading. More...
 
bool isNull () const
 Returns true if the status is Null. More...
 
bool isWaiting () const
 Returns true if the status is WaitingForDependencies. More...
 
qreal progress () const
 Returns the data download progress from 0 to 1. More...
 
 QDeclarativeDataBlob (const QUrl &, Type)
 Create a new QDeclarativeDataBlob for url and of the provided type. More...
 
void setError (const QDeclarativeError &)
 Mark this blob as having errors. More...
 
void setError (const QList< QDeclarativeError > &errors)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
Status status () const
 Returns the blob's status. More...
 
Type type () const
 Returns the type provided to the constructor. More...
 
QUrl url () const
 Returns the blob url passed to the constructor. More...
 
virtual ~QDeclarativeDataBlob ()
 
- Public Functions inherited from QDeclarativeRefCount
void addref ()
 
 QDeclarativeRefCount ()
 
void release ()
 
virtual ~QDeclarativeRefCount ()
 

Protected Functions

virtual void allDependenciesDone ()
 Called when all blobs waited for have completed. More...
 
virtual void dataReceived (const QByteArray &)=0
 Invoked when data for the blob is received. More...
 
virtual void dependencyComplete (QDeclarativeDataBlob *)
 Called if blob, which was previously waited for, has completed. More...
 
virtual void dependencyError (QDeclarativeDataBlob *)
 Called if blob, which was previously waited for, has an error. More...
 
virtual void done ()
 Invoked once data has either been received or a network error occurred, and all dependencies are complete. More...
 
virtual void downloadProgressChanged (qreal)
 Called when the download progress of this blob changes. More...
 
virtual void networkError (QNetworkReply::NetworkError)
 Invoked if there is a network error while fetching this blob. More...
 

Private Functions

void cancelAllWaitingFor ()
 
void notifyAllWaitingOnMe ()
 
void notifyComplete (QDeclarativeDataBlob *)
 
void tryDone ()
 

Properties

QList< QDeclarativeErrorm_errors
 
QUrl m_finalUrl
 
bool m_inCallback:1
 
bool m_isDone:1
 
QDeclarativeDataLoaderm_manager
 
qreal m_progress
 
int m_redirectCount:30
 
Status m_status
 
Type m_type
 
QUrl m_url
 
QList< QDeclarativeDataBlob * > m_waitingFor
 
QList< QDeclarativeDataBlob * > m_waitingOnMe
 

Friends

class QDeclarativeDataLoader
 

Detailed Description

The QDeclarativeDataBlob encapsulates a data request that can be issued to a QDeclarativeDataLoader.

Warning
This function is not part of the public interface.

QDeclarativeDataBlob's are loaded by a QDeclarativeDataLoader. The user creates the QDeclarativeDataBlob and then calls QDeclarativeDataLoader::load() or QDeclarativeDataLoader::loadWithStaticData() to load it. The QDeclarativeDataLoader invokes callbacks on the QDeclarativeDataBlob as data becomes available.

Definition at line 74 of file qdeclarativetypeloader_p.h.

Enumerations

◆ Status

This enum describes the status of the data blob.

  • Null The blob has not yet been loaded by a QDeclarativeDataLoader
  • Loading The blob is loading network data. The QDeclarativeDataBlob::setData() callback has not yet been invoked or has not yet returned.
  • WaitingForDependencies The blob is waiting for dependencies to be done before continueing. This status only occurs after the QDeclarativeDataBlob::setData() callback has been made, and when the blob has outstanding dependencies.
  • Complete The blob's data has been loaded and all dependencies are done.
  • Error An error has been set on this blob.
Enumerator
Null 
Loading 
WaitingForDependencies 
Complete 
Error 

Definition at line 77 of file qdeclarativetypeloader_p.h.

77  {
78  Null, // Prior to QDeclarativeDataLoader::load()
79  Loading, // Prior to data being received and dataReceived() being called
80  WaitingForDependencies, // While there are outstanding addDependency()s
81  Complete, // Finished
82  Error // Error
83  };

◆ Type

This enum describes the type of the data blob.

Enumerator
QmlFile 
JavaScriptFile 
QmldirFile 

Definition at line 85 of file qdeclarativetypeloader_p.h.

Constructors and Destructors

◆ QDeclarativeDataBlob()

QDeclarativeDataBlob::QDeclarativeDataBlob ( const QUrl url,
Type  type 
)

◆ ~QDeclarativeDataBlob()

QDeclarativeDataBlob::~QDeclarativeDataBlob ( )
virtual
Warning
This function is not part of the public interface.

Definition at line 141 of file qdeclarativetypeloader.cpp.

142 {
144 
146 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< QDeclarativeDataBlob * > m_waitingOnMe
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152

Functions

◆ addDependency()

void QDeclarativeDataBlob::addDependency ( QDeclarativeDataBlob blob)

Wait for blob to become complete or to error.

If blob is already complete or in error, or this blob is already complete, this has no effect.

Definition at line 281 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeTypeData::dataReceived(), and QDeclarativeTypeData::resolveTypes().

282 {
283  Q_ASSERT(status() != Null);
284 
285  if (!blob ||
286  blob->status() == Error || blob->status() == Complete ||
287  status() == Error || status() == Complete ||
288  m_waitingFor.contains(blob))
289  return;
290 
291  blob->addref();
293  m_waitingFor.append(blob);
294  blob->m_waitingOnMe.append(this);
295 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< QDeclarativeDataBlob * > m_waitingOnMe
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QList< QDeclarativeDataBlob * > m_waitingFor
Status status() const
Returns the blob&#39;s status.

◆ allDependenciesDone()

void QDeclarativeDataBlob::allDependenciesDone ( )
protectedvirtual

Called when all blobs waited for have completed.

This occurs regardless of whether they are in error, or complete state.

The default implementation does nothing.

Reimplemented in QDeclarativeTypeData.

Definition at line 397 of file qdeclarativetypeloader.cpp.

Referenced by notifyComplete(), and QDeclarativeDataLoader::setData().

398 {
399 }

◆ cancelAllWaitingFor()

void QDeclarativeDataBlob::cancelAllWaitingFor ( )
private

Definition at line 422 of file qdeclarativetypeloader.cpp.

Referenced by setError(), and ~QDeclarativeDataBlob().

423 {
424  while (m_waitingFor.count()) {
426 
427  Q_ASSERT(blob->m_waitingOnMe.contains(this));
428 
429  blob->m_waitingOnMe.removeOne(this);
430 
431  blob->release();
432  }
433 }
The QDeclarativeDataBlob encapsulates a data request that can be issued to a QDeclarativeDataLoader.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< QDeclarativeDataBlob * > m_waitingOnMe
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QList< QDeclarativeDataBlob * > m_waitingFor
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492

◆ dataReceived()

void QDeclarativeDataBlob::dataReceived ( const QByteArray data)
protectedpure virtual

Invoked when data for the blob is received.

Implementors should use this callback to determine a blob's dependencies. Within this callback you may call setError() or addDependency().

Implemented in QDeclarativeQmldirData, QDeclarativeScriptData, and QDeclarativeTypeData.

Referenced by QDeclarativeDataLoader::setData().

◆ dependencyComplete()

void QDeclarativeDataBlob::dependencyComplete ( QDeclarativeDataBlob blob)
protectedvirtual

Called if blob, which was previously waited for, has completed.

The default implementation does nothing.

Definition at line 386 of file qdeclarativetypeloader.cpp.

Referenced by notifyComplete().

387 {
388  Q_UNUSED(blob);
389 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ dependencyError()

void QDeclarativeDataBlob::dependencyError ( QDeclarativeDataBlob blob)
protectedvirtual

Called if blob, which was previously waited for, has an error.

The default implementation does nothing.

Definition at line 376 of file qdeclarativetypeloader.cpp.

Referenced by notifyComplete().

377 {
378  Q_UNUSED(blob);
379 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ done()

void QDeclarativeDataBlob::done ( )
protectedvirtual

Invoked once data has either been received or a network error occurred, and all dependencies are complete.

You can set an error in this method, but you cannot add new dependencies. Implementors should use this callback to finalize processing of data.

The default implementation does nothing.

Reimplemented in QDeclarativeTypeData.

Definition at line 314 of file qdeclarativetypeloader.cpp.

Referenced by tryDone().

315 {
316 }

◆ downloadProgressChanged()

void QDeclarativeDataBlob::downloadProgressChanged ( qreal  progress)
protectedvirtual

Called when the download progress of this blob changes.

progress goes from 0 to 1.

Reimplemented in QDeclarativeTypeData.

Definition at line 405 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeDataLoader::load(), and QDeclarativeDataLoader::networkReplyProgress().

406 {
408 }
qreal progress() const
Returns the data download progress from 0 to 1.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ errors()

QList< QDeclarativeError > QDeclarativeDataBlob::errors ( ) const

Return the errors on this blob.

Definition at line 244 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeTypeData::done(), QDeclarativeComponentPrivate::fromTypeData(), QDeclarativeDomDocument::load(), and setError().

245 {
246  return m_errors;
247 }
QList< QDeclarativeError > m_errors

◆ finalUrl()

QUrl QDeclarativeDataBlob::finalUrl ( ) const

Returns the final url of the data.

Initially this is the same as url(), but if a network redirect happens while fetching the data, this url is updated to reflect the new location.

Definition at line 236 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeCompiler::compileTree(), QDeclarativeTypeData::dataReceived(), QDeclarativeTypeData::done(), QDeclarativeComponentPrivate::fromTypeData(), and QDeclarativeTypeData::resolveTypes().

237 {
238  return m_finalUrl;
239 }

◆ isComplete()

bool QDeclarativeDataBlob::isComplete ( ) const

Returns true if the status is Complete.

Definition at line 191 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeCompiler::buildDynamicMeta(), and isCompleteOrError().

◆ isCompleteOrError()

bool QDeclarativeDataBlob::isCompleteOrError ( ) const

Returns true if the status is Complete or Error.

Definition at line 207 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeTypeData::done(), QDeclarativeDomDocument::load(), QDeclarativeComponent::loadUrl(), and QDeclarativeComponent::setData().

208 {
209  return isComplete() || isError();
210 }
bool isError() const
Returns true if the status is Error.
bool isComplete() const
Returns true if the status is Complete.

◆ isError()

bool QDeclarativeDataBlob::isError ( ) const

◆ isLoading()

bool QDeclarativeDataBlob::isLoading ( ) const

Returns true if the status is Loading.

Definition at line 175 of file qdeclarativetypeloader.cpp.

◆ isNull()

bool QDeclarativeDataBlob::isNull ( ) const

Returns true if the status is Null.

Definition at line 167 of file qdeclarativetypeloader.cpp.

◆ isWaiting()

bool QDeclarativeDataBlob::isWaiting ( ) const

Returns true if the status is WaitingForDependencies.

Definition at line 183 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeDataLoader::setData().

◆ networkError()

void QDeclarativeDataBlob::networkError ( QNetworkReply::NetworkError  networkError)
protectedvirtual

Invoked if there is a network error while fetching this blob.

The default implementation sets an appropriate QDeclarativeError.

Definition at line 323 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeDataLoader::load(), and QDeclarativeDataLoader::networkReplyFinished().

324 {
326 
328  error.setUrl(m_finalUrl);
329 
330  const char *errorString = 0;
331  switch (networkError) {
332  default:
333  errorString = "Network error";
334  break;
336  errorString = "Connection refused";
337  break;
339  errorString = "Remote host closed the connection";
340  break;
342  errorString = "Host not found";
343  break;
345  errorString = "Timeout";
346  break;
353  errorString = "Proxy error";
354  break;
356  errorString = "Access denied";
357  break;
359  errorString = "File not found";
360  break;
362  errorString = "Authentication required";
363  break;
364  };
365 
366  error.setDescription(QLatin1String(errorString));
367 
368  setError(error);
369 }
void setDescription(const QString &)
Sets the error description.
#define error(msg)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
The QDeclarativeError class encapsulates a QML error.
void setUrl(const QUrl &)
Sets the url for the file that caused this error.
void setError(const QDeclarativeError &)
Mark this blob as having errors.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
virtual void networkError(QNetworkReply::NetworkError)
Invoked if there is a network error while fetching this blob.

◆ notifyAllWaitingOnMe()

void QDeclarativeDataBlob::notifyAllWaitingOnMe ( )
private

Definition at line 435 of file qdeclarativetypeloader.cpp.

Referenced by tryDone().

436 {
437  while (m_waitingOnMe.count()) {
439 
440  Q_ASSERT(blob->m_waitingFor.contains(this));
441 
442  blob->notifyComplete(this);
443  }
444 }
The QDeclarativeDataBlob encapsulates a data request that can be issued to a QDeclarativeDataLoader.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QList< QDeclarativeDataBlob * > m_waitingOnMe
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QList< QDeclarativeDataBlob * > m_waitingFor
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
void notifyComplete(QDeclarativeDataBlob *)

◆ notifyComplete()

void QDeclarativeDataBlob::notifyComplete ( QDeclarativeDataBlob blob)
private

Definition at line 446 of file qdeclarativetypeloader.cpp.

Referenced by notifyAllWaitingOnMe().

447 {
449  Q_ASSERT(blob->status() == Error || blob->status() == Complete);
450 
451  m_inCallback = true;
452 
453  if (blob->status() == Error) {
454  dependencyError(blob);
455  } else if (blob->status() == Complete) {
456  dependencyComplete(blob);
457  }
458 
459  m_waitingFor.removeOne(blob);
460  blob->release();
461 
462  if (!isError() && m_waitingFor.isEmpty())
464 
465  m_inCallback = false;
466 
467  tryDone();
468 }
bool isError() const
Returns true if the status is Error.
virtual void dependencyComplete(QDeclarativeDataBlob *)
Called if blob, which was previously waited for, has completed.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
QList< QDeclarativeDataBlob * > m_waitingFor
virtual void allDependenciesDone()
Called when all blobs waited for have completed.
Status status() const
Returns the blob&#39;s status.
virtual void dependencyError(QDeclarativeDataBlob *)
Called if blob, which was previously waited for, has an error.

◆ progress()

qreal QDeclarativeDataBlob::progress ( ) const

Returns the data download progress from 0 to 1.

Definition at line 215 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeComponent::loadUrl().

216 {
217  return m_progress;
218 }

◆ setError() [1/2]

void QDeclarativeDataBlob::setError ( const QDeclarativeError errors)

Mark this blob as having errors.

All outstanding dependencies will be cancelled. Requests to add new dependencies will be ignored. Entry into the Error state is irreversable, although you can change the specific errors by additional calls to setError.

Definition at line 256 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeTypeData::compile(), QDeclarativeTypeData::dataReceived(), QDeclarativeTypeData::done(), QDeclarativeDataLoader::load(), networkError(), and QDeclarativeTypeData::resolveTypes().

257 {
259  l << errors;
260  setError(l);
261 }
QList< QDeclarativeError > errors() const
Return the errors on this blob.
void setError(const QDeclarativeError &)
Mark this blob as having errors.
QFactoryLoader * l

◆ setError() [2/2]

void QDeclarativeDataBlob::setError ( const QList< QDeclarativeError > &  errors)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 266 of file qdeclarativetypeloader.cpp.

267 {
268  m_status = Error;
269  m_errors = errors;
270 
272 
273  if (!m_inCallback)
274  tryDone();
275 }
QList< QDeclarativeError > m_errors
QList< QDeclarativeError > errors() const
Return the errors on this blob.

◆ status()

QDeclarativeDataBlob::Status QDeclarativeDataBlob::status ( ) const

◆ tryDone()

void QDeclarativeDataBlob::tryDone ( )
private

Definition at line 410 of file qdeclarativetypeloader.cpp.

Referenced by notifyComplete(), QDeclarativeDataLoader::setData(), and setError().

411 {
412  if (status() != Loading && m_waitingFor.isEmpty() && !m_isDone) {
413  if (status() != Error)
414  m_status = Complete;
415 
416  m_isDone = true;
417  done();
419  }
420 }
virtual void done()
Invoked once data has either been received or a network error occurred, and all dependencies are comp...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< QDeclarativeDataBlob * > m_waitingFor
Status status() const
Returns the blob&#39;s status.

◆ type()

QDeclarativeDataBlob::Type QDeclarativeDataBlob::type ( ) const

Returns the type provided to the constructor.

Definition at line 151 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeTypeData::dataReceived(), QDeclarativeTypeData::done(), and QDeclarativeTypeData::resolveTypes().

152 {
153  return m_type;
154 }

◆ url()

QUrl QDeclarativeDataBlob::url ( ) const

Returns the blob url passed to the constructor.

If a network redirect happens while fetching the data, this url remains the same.

See also
finalUrl()

Definition at line 226 of file qdeclarativetypeloader.cpp.

Referenced by QDeclarativeTypeData::done(), QDeclarativeTypeData::qmldirForUrl(), and QDeclarativeTypeData::resolveTypes().

227 {
228  return m_url;
229 }

Friends and Related Functions

◆ QDeclarativeDataLoader

Definition at line 129 of file qdeclarativetypeloader_p.h.

Properties

◆ m_errors

QList<QDeclarativeError> QDeclarativeDataBlob::m_errors
private

Definition at line 154 of file qdeclarativetypeloader_p.h.

Referenced by errors(), and setError().

◆ m_finalUrl

QUrl QDeclarativeDataBlob::m_finalUrl
private

◆ m_inCallback

bool QDeclarativeDataBlob::m_inCallback
private

◆ m_isDone

bool QDeclarativeDataBlob::m_isDone
private

Definition at line 152 of file qdeclarativetypeloader_p.h.

Referenced by tryDone().

◆ m_manager

QDeclarativeDataLoader* QDeclarativeDataBlob::m_manager
private

◆ m_progress

qreal QDeclarativeDataBlob::m_progress
private

◆ m_redirectCount

int QDeclarativeDataBlob::m_redirectCount
private

◆ m_status

Status QDeclarativeDataBlob::m_status
private

◆ m_type

Type QDeclarativeDataBlob::m_type
private

Definition at line 135 of file qdeclarativetypeloader_p.h.

Referenced by type().

◆ m_url

QUrl QDeclarativeDataBlob::m_url
private

Definition at line 139 of file qdeclarativetypeloader_p.h.

Referenced by QDeclarativeDataLoader::load(), and url().

◆ m_waitingFor

QList<QDeclarativeDataBlob *> QDeclarativeDataBlob::m_waitingFor
private

◆ m_waitingOnMe

QList<QDeclarativeDataBlob *> QDeclarativeDataBlob::m_waitingOnMe
private

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