Qt 4.8
Public Functions | Static Public Functions | Static Public Variables | Protected Functions | Private Functions | Properties | Static Private Attributes | Friends | List of all members
QDeclarativePixmapReader Class Reference
Inheritance diagram for QDeclarativePixmapReader:
QThread QObject

Public Functions

void cancel (QDeclarativePixmapReply *rep)
 
QDeclarativePixmapReplygetImage (QDeclarativePixmapData *)
 
 QDeclarativePixmapReader (QDeclarativeEngine *eng)
 
 ~QDeclarativePixmapReader ()
 
- Public Functions inherited from QThread
void exit (int retcode=0)
 Tells the thread's event loop to exit with a return code. More...
 
bool isFinished () const
 Returns true if the thread is finished; otherwise returns false. More...
 
bool isRunning () const
 Returns true if the thread is running; otherwise returns false. More...
 
Priority priority () const
 Returns the priority for a running thread. More...
 
 QThread (QObject *parent=0)
 Constructs a new QThread to manage a new thread. More...
 
void setPriority (Priority priority)
 This function sets the priority for a running thread. More...
 
void setStackSize (uint stackSize)
 Sets the maximum stack size for the thread to stackSize. More...
 
uint stackSize () const
 Returns the maximum stack size for the thread (if set with setStackSize()); otherwise returns zero. More...
 
bool wait (unsigned long time=ULONG_MAX)
 Blocks the thread until either of these conditions is met: More...
 
 ~QThread ()
 Destroys the QThread. More...
 
- 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...
 

Static Public Functions

static QDeclarativePixmapReaderexistingInstance (QDeclarativeEngine *engine)
 
static QDeclarativePixmapReaderinstance (QDeclarativeEngine *engine)
 
- Static Public Functions inherited from QThread
static QThreadcurrentThread ()
 Returns a pointer to a QThread which manages the currently executing thread. More...
 
static Qt::HANDLE currentThreadId ()
 Returns the thread handle of the currently executing thread. More...
 
static int idealThreadCount ()
 Returns the ideal number of threads that can be run on the system. More...
 
static void yieldCurrentThread ()
 Yields execution of the current thread to another runnable thread, if any. 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

static QMutex readerMutex
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 

Protected Functions

void run ()
 The starting point for the thread. More...
 
- Protected Functions inherited from QThread
int exec ()
 Enters the event loop and waits until exit() is called, returning the value that was passed to exit(). More...
 
 QThread (QThreadPrivate &dd, QObject *parent=0)
 
- 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 Functions

QNetworkAccessManagernetworkAccessManager ()
 
void networkRequestDone (QNetworkReply *)
 
void processJob (QDeclarativePixmapReply *, const QUrl &, const QSize &)
 
void processJobs ()
 

Properties

QNetworkAccessManageraccessManager
 
QList< QDeclarativePixmapReply * > cancelled
 
QDeclarativeEngineengine
 
QObjecteventLoopQuitHack
 
QList< QDeclarativePixmapReply * > jobs
 
QMutex mutex
 
QHash< QNetworkReply *, QDeclarativePixmapReply * > replies
 
QDeclarativePixmapReaderThreadObjectthreadObject
 
QWaitCondition waitCondition
 

Static Private Attributes

static int downloadProgress = -1
 
static QHash< QDeclarativeEngine *, QDeclarativePixmapReader * > readers
 
static int replyDownloadProgress = -1
 
static int replyFinished = -1
 
static int threadNetworkRequestDone = -1
 

Friends

class QDeclarativePixmapReaderThreadObject
 

Additional Inherited Members

- Public Types inherited from QThread
enum  Priority {
  IdlePriority, LowestPriority, LowPriority, NormalPriority,
  HighPriority, HighestPriority, TimeCriticalPriority, InheritPriority
}
 This enum type indicates how the operating system should schedule newly created threads. More...
 
- Public Slots inherited from QThread
void quit ()
 Tells the thread's event loop to exit with return code 0 (success). More...
 
void start (Priority=InheritPriority)
 Begins execution of the thread by calling run(). More...
 
void terminate ()
 Terminates the execution of the thread. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QThread
void finished ()
 This signal is emitted when the thread has finished executing. More...
 
void started ()
 This signal is emitted when the thread starts executing. More...
 
void terminated ()
 This signal is emitted when the thread is terminated. More...
 
- 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...
 
- Static Protected Functions inherited from QThread
static void msleep (unsigned long)
 Forces the current thread to sleep for msecs milliseconds. More...
 
static void setTerminationEnabled (bool enabled=true)
 Enables or disables termination of the current thread based on the enabled parameter. More...
 
static void sleep (unsigned long)
 Forces the current thread to sleep for secs seconds. More...
 
static void usleep (unsigned long)
 Forces the current thread to sleep for usecs microseconds. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 140 of file qdeclarativepixmapcache.cpp.

Constructors and Destructors

◆ QDeclarativePixmapReader()

QDeclarativePixmapReader::QDeclarativePixmapReader ( QDeclarativeEngine eng)

Definition at line 317 of file qdeclarativepixmapcache.cpp.

318 : QThread(eng), engine(eng), threadObject(0), accessManager(0)
319 {
324 }
QThread(QObject *parent=0)
Constructs a new QThread to manage a new thread.
Definition: qthread.cpp:433
#define SLOT(a)
Definition: qobjectdefs.h:226
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void quit()
Tells the thread&#39;s event loop to exit with return code 0 (success).
Definition: qthread.cpp:614
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void destroyed(QObject *=0)
This signal is emitted immediately before the object obj is destroyed, and can not be blocked...
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
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition: qobject.cpp:1458
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QNetworkAccessManager * accessManager
QDeclarativePixmapReaderThreadObject * threadObject

◆ ~QDeclarativePixmapReader()

QDeclarativePixmapReader::~QDeclarativePixmapReader ( )

Definition at line 326 of file qdeclarativepixmapcache.cpp.

327 {
328  readerMutex.lock();
331 
332  mutex.lock();
333  // manually cancel all outstanding jobs.
334  foreach (QDeclarativePixmapReply *reply, jobs) {
335  delete reply;
336  }
337  jobs.clear();
339  foreach (QDeclarativePixmapReply *reply, activeJobs) {
340  if (reply->loading) {
341  cancelled.append(reply);
342  reply->data = 0;
343  }
344  }
346  mutex.unlock();
347 
349  wait();
350 }
QHash< QNetworkReply *, QDeclarativePixmapReply * > replies
QDeclarativePixmapData * data
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QDeclarativePixmapReply * > jobs
void clear()
Removes all items from the list.
Definition: qlist.h:764
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
Definition: qhash.h:693
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:
static QHash< QDeclarativeEngine *, QDeclarativePixmapReader * > readers
QList< QDeclarativePixmapReply * > cancelled
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QDeclarativePixmapReaderThreadObject * threadObject

Functions

◆ cancel()

void QDeclarativePixmapReader::cancel ( QDeclarativePixmapReply rep)

Definition at line 544 of file qdeclarativepixmapcache.cpp.

Referenced by QDeclarativePixmapData::release().

545 {
546  mutex.lock();
547  if (reply->loading) {
548  cancelled.append(reply);
549  reply->data = 0;
550  // XXX
552  } else {
553  jobs.removeAll(reply);
554  delete reply;
555  }
556  mutex.unlock();
557 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QDeclarativePixmapReply * > jobs
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
QList< QDeclarativePixmapReply * > cancelled
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
QDeclarativePixmapReaderThreadObject * threadObject

◆ existingInstance()

QDeclarativePixmapReader * QDeclarativePixmapReader::existingInstance ( QDeclarativeEngine engine)
static

Definition at line 526 of file qdeclarativepixmapcache.cpp.

Referenced by QDeclarativePixmapData::release().

527 {
528  // XXX NOTE: must be called within readerMutex locking.
529  return readers.value(engine, 0);
530 }
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
static QHash< QDeclarativeEngine *, QDeclarativePixmapReader * > readers

◆ getImage()

QDeclarativePixmapReply * QDeclarativePixmapReader::getImage ( QDeclarativePixmapData data)

Definition at line 532 of file qdeclarativepixmapcache.cpp.

Referenced by QDeclarativePixmap::load().

533 {
534  mutex.lock();
536  reply->engineForReader = engine;
537  jobs.append(reply);
538  // XXX
540  mutex.unlock();
541  return reply;
542 }
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
QDeclarativeEngine * engineForReader
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QDeclarativePixmapReply * > jobs
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
QDeclarativePixmapReaderThreadObject * threadObject

◆ instance()

QDeclarativePixmapReader * QDeclarativePixmapReader::instance ( QDeclarativeEngine engine)
static

Definition at line 514 of file qdeclarativepixmapcache.cpp.

Referenced by QDeclarativePixmap::load().

515 {
516  // XXX NOTE: must be called within readerMutex locking.
517  QDeclarativePixmapReader *reader = readers.value(engine);
518  if (!reader) {
519  reader = new QDeclarativePixmapReader(engine);
520  readers.insert(engine, reader);
521  }
522 
523  return reader;
524 }
QDeclarativePixmapReader(QDeclarativeEngine *eng)
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
static QHash< QDeclarativeEngine *, QDeclarativePixmapReader * > readers

◆ networkAccessManager()

QNetworkAccessManager * QDeclarativePixmapReader::networkAccessManager ( )
private

Definition at line 266 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone().

267 {
268  if (!accessManager) {
271  }
272  return accessManager;
273 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QNetworkAccessManager * accessManager
QNetworkAccessManager * createNetworkAccessManager(QObject *parent) const
QDeclarativePixmapReaderThreadObject * threadObject

◆ networkRequestDone()

void QDeclarativePixmapReader::networkRequestDone ( QNetworkReply reply)
private

Definition at line 352 of file qdeclarativepixmapcache.cpp.

Referenced by QDeclarativePixmapReaderThreadObject::networkRequestDone().

353 {
354  QDeclarativePixmapReply *job = replies.take(reply);
355 
356  if (job) {
357  job->redirectCount++;
360  if (redirect.isValid()) {
361  QUrl url = reply->url().resolved(redirect.toUrl());
362  QNetworkRequest req(url);
363  req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
364 
365  reply->deleteLater();
366  reply = networkAccessManager()->get(req);
367 
370 
371  replies.insert(reply, job);
372  return;
373  }
374  }
375 
376  QImage image;
379  QSize readSize;
380  if (reply->error()) {
382  errorString = reply->errorString();
383  } else {
384  QByteArray all = reply->readAll();
385  QBuffer buff(&all);
386  buff.open(QIODevice::ReadOnly);
387  if (!readImage(reply->url(), &buff, &image, &errorString, &readSize, job->requestSize)) {
389  }
390  }
391  // send completion event to the QDeclarativePixmapReply
392  mutex.lock();
393  if (!cancelled.contains(job)) job->postReply(error, errorString, readSize, image);
394  mutex.unlock();
395  }
396  reply->deleteLater();
397 
398  // kick off event loop again incase we have dropped below max request count
400 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QHash< QNetworkReply *, QDeclarativePixmapReply * > replies
NetworkError error() const
Returns the error that was found during the processing of this request.
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
QVariant attribute(QNetworkRequest::Attribute code) const
Returns the attribute associated with the code code.
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Definition: qiodevice.cpp:1671
The QBuffer class provides a QIODevice interface for a QByteArray.
Definition: qbuffer.h:57
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
void postReply(ReadError, const QString &, const QSize &, const QImage &)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QNetworkAccessManager * networkAccessManager()
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
QUrl toUrl() const
Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl...
Definition: qvariant.cpp:2528
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define IMAGEREQUEST_MAX_REDIRECT_RECURSION
QList< QDeclarativePixmapReply * > cancelled
QUrl url() const
Returns the URL of the content downloaded or uploaded.
static bool readImage(const QUrl &url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize, const QSize &requestSize)
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
QDeclarativePixmapReaderThreadObject * threadObject

◆ processJob()

void QDeclarativePixmapReader::processJob ( QDeclarativePixmapReply runningJob,
const QUrl url,
const QSize requestSize 
)
private

Definition at line 464 of file qdeclarativepixmapcache.cpp.

466 {
467  // fetch
468  if (url.scheme() == QLatin1String("image")) {
469  // Use QmlImageProvider
470  QSize readSize;
472  QImage image = ep->getImageFromProvider(url, &readSize, requestSize);
473 
475  QString errorStr;
476  if (image.isNull()) {
478  errorStr = QDeclarativePixmap::tr("Failed to get image from provider: %1").arg(url.toString());
479  }
480  mutex.lock();
481  if (!cancelled.contains(runningJob)) runningJob->postReply(errorCode, errorStr, readSize, image);
482  mutex.unlock();
483  } else {
485  if (!lf.isEmpty()) {
486  // Image is local - load/decode immediately
487  QImage image;
489  QString errorStr;
490  QFile f(lf);
491  QSize readSize;
492  if (f.open(QIODevice::ReadOnly)) {
493  if (!readImage(url, &f, &image, &errorStr, &readSize, requestSize))
495  } else {
496  errorStr = QDeclarativePixmap::tr("Cannot open: %1").arg(url.toString());
498  }
499  mutex.lock();
500  if (!cancelled.contains(runningJob)) runningJob->postReply(errorCode, errorStr, readSize, image);
501  mutex.unlock();
502  } else {
503  // Network resource
504  QNetworkRequest req(url);
505  req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
506  QNetworkReply *reply = networkAccessManager()->get(req);
509  replies.insert(reply, runningJob);
510  }
511  }
512 }
static QString urlToLocalFileOrQrc(const QUrl &url)
QHash< QNetworkReply *, QDeclarativePixmapReply * > replies
static bool connect(const QObject *sender, int signal_index, const QObject *receiver, int method_index, int type=0, int *types=0)
Definition: qobject.cpp:3194
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
bool isNull() const
Returns true if it is a null image, otherwise returns false.
Definition: qimage.cpp:1542
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
void postReply(ReadError, const QString &, const QSize &, const QImage &)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QNetworkAccessManager * networkAccessManager()
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize &req_size)
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QList< QDeclarativePixmapReply * > cancelled
static bool readImage(const QUrl &url, QIODevice *dev, QImage *image, QString *errorString, QSize *impsize, const QSize &requestSize)
QDeclarativePixmapReaderThreadObject * threadObject

◆ processJobs()

void QDeclarativePixmapReader::processJobs ( )
private

Definition at line 428 of file qdeclarativepixmapcache.cpp.

Referenced by QDeclarativePixmapReaderThreadObject::event().

429 {
430  QMutexLocker locker(&mutex);
431 
432  while (true) {
434  return; // Nothing else to do
435 
436  // Clean cancelled jobs
437  if (cancelled.count()) {
438  for (int i = 0; i < cancelled.count(); ++i) {
440  QNetworkReply *reply = replies.key(job, 0);
441  if (reply && reply->isRunning()) {
442  // cancel any jobs already started
443  replies.remove(reply);
444  reply->close();
445  }
446  // deleteLater, since not owned by this thread
447  job->deleteLater();
448  }
449  cancelled.clear();
450  }
451 
453  QDeclarativePixmapReply *runningJob = jobs.takeLast();
454  runningJob->loading = true;
455  QUrl url = runningJob->url;
456  QSize requestSize = runningJob->requestSize;
457  locker.unlock();
458  processJob(runningJob, url, requestSize);
459  locker.relock();
460  }
461  }
462 }
QHash< QNetworkReply *, QDeclarativePixmapReply * > replies
void processJob(QDeclarativePixmapReply *, const QUrl &, const QSize &)
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
#define IMAGEREQUEST_MAX_REQUEST_COUNT
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
bool isRunning() const
Returns true when the request is still processing and the reply has not finished or was aborted yet...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
QList< QDeclarativePixmapReply * > jobs
virtual void close()
Closes this device for reading.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void clear()
Removes all items from the list.
Definition: qlist.h:764
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
const Key key(const T &value) const
Returns the first key mapped to value.
Definition: qhash.h:674
T takeLast()
Removes the last item in the list and returns it.
Definition: qlist.h:492
int count(const Key &key) const
Returns the number of items associated with the key.
Definition: qhash.h:719
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QList< QDeclarativePixmapReply * > cancelled
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145

◆ run()

void QDeclarativePixmapReader::run ( void  )
protectedvirtual

The starting point for the thread.

After calling start(), the newly created thread calls this function. The default implementation simply calls exec().

You can reimplement this function to facilitate advanced thread management. Returning from this method will end the execution of the thread.

See also
start() wait()

Reimplemented from QThread.

Definition at line 559 of file qdeclarativepixmapcache.cpp.

560 {
561  if (replyDownloadProgress == -1) {
565  replyDownloadProgress = nr->indexOfSignal("downloadProgress(qint64,qint64)");
566  replyFinished = nr->indexOfSignal("finished()");
567  downloadProgress = pr->indexOfSignal("downloadProgress(qint64,qint64)");
568  threadNetworkRequestDone = ir->indexOfSlot("networkRequestDone()");
569  }
570 
571  mutex.lock();
573  mutex.unlock();
574 
575  processJobs();
576  exec();
577 
578  delete threadObject;
579  threadObject = 0;
580 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
void lock()
Locks the mutex.
Definition: qmutex.cpp:151
static const QMetaObject staticMetaObject
This variable stores the meta-object for the class.
Definition: qobject.h:128
int indexOfSlot(const char *slot) const
Finds slot and returns its index; otherwise returns -1.
int indexOfSignal(const char *signal) const
Finds signal and returns its index; otherwise returns -1.
void unlock()
Unlocks the mutex.
Definition: qmutex.cpp:296
int exec()
Enters the event loop and waits until exit() is called, returning the value that was passed to exit()...
Definition: qthread.cpp:551
QDeclarativePixmapReaderThreadObject * threadObject

Friends and Related Functions

◆ QDeclarativePixmapReaderThreadObject

Definition at line 157 of file qdeclarativepixmapcache.cpp.

Properties

◆ accessManager

QNetworkAccessManager* QDeclarativePixmapReader::accessManager
private

Definition at line 172 of file qdeclarativepixmapcache.cpp.

◆ cancelled

QList<QDeclarativePixmapReply*> QDeclarativePixmapReader::cancelled
private

Definition at line 163 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone(), and ~QDeclarativePixmapReader().

◆ downloadProgress

int QDeclarativePixmapReader::downloadProgress = -1
staticprivate

Definition at line 178 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone().

◆ engine

QDeclarativeEngine* QDeclarativePixmapReader::engine
private

Definition at line 164 of file qdeclarativepixmapcache.cpp.

Referenced by ~QDeclarativePixmapReader().

◆ eventLoopQuitHack

QObject* QDeclarativePixmapReader::eventLoopQuitHack
private

◆ jobs

QList<QDeclarativePixmapReply*> QDeclarativePixmapReader::jobs
private

Definition at line 162 of file qdeclarativepixmapcache.cpp.

Referenced by ~QDeclarativePixmapReader().

◆ mutex

QMutex QDeclarativePixmapReader::mutex
private

Definition at line 167 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone(), and ~QDeclarativePixmapReader().

◆ readerMutex

QMutex QDeclarativePixmapReader::readerMutex
static

Definition at line 182 of file qdeclarativepixmapcache.cpp.

Referenced by ~QDeclarativePixmapReader().

◆ readers

QHash< QDeclarativeEngine *, QDeclarativePixmapReader * > QDeclarativePixmapReader::readers
staticprivate

Definition at line 180 of file qdeclarativepixmapcache.cpp.

Referenced by ~QDeclarativePixmapReader().

◆ replies

QHash<QNetworkReply*,QDeclarativePixmapReply*> QDeclarativePixmapReader::replies
private

Definition at line 174 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone(), and ~QDeclarativePixmapReader().

◆ replyDownloadProgress

int QDeclarativePixmapReader::replyDownloadProgress = -1
staticprivate

Definition at line 176 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone().

◆ replyFinished

int QDeclarativePixmapReader::replyFinished = -1
staticprivate

Definition at line 177 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone().

◆ threadNetworkRequestDone

int QDeclarativePixmapReader::threadNetworkRequestDone = -1
staticprivate

Definition at line 179 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone().

◆ threadObject

QDeclarativePixmapReaderThreadObject* QDeclarativePixmapReader::threadObject
private

Definition at line 168 of file qdeclarativepixmapcache.cpp.

Referenced by networkRequestDone(), and ~QDeclarativePixmapReader().

◆ waitCondition

QWaitCondition QDeclarativePixmapReader::waitCondition
private

Definition at line 169 of file qdeclarativepixmapcache.cpp.


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