itemstatusimageprovider.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. *
  5. * For the applicable distribution terms see the license.txt -file, included in
  6. * the distribution.
  7. */
  8. #include <QDebug>
  9. #include "itemstatusimageprovider.h"
  10. #include "declarativepurchaselistmodel.h"
  11. #include "purchasableitembase.h"
  12. ItemstatusImageProvider::ItemstatusImageProvider(DeclarativePurchaseListModel& model):
  13. QDeclarativeImageProvider(QDeclarativeImageProvider::Image),
  14. m_model(&model)
  15. {
  16. }
  17. QImage ItemstatusImageProvider::requestImage(const QString & url, QSize * size, const QSize & requestedSize)
  18. {
  19. bool ok = false;
  20. //NOTE: see workaround for http://bugreports.qt.nokia.com/browse/QTBUG-14900 in 'main.qml'
  21. int ignorelength = url.indexOf("ignoringpart");
  22. QString id((ignorelength > 0) ? url.left(ignorelength) : url);
  23. int index = id.toInt(&ok);
  24. Q_ASSERT(ok); //design time sanity check
  25. qDebug() << "requested index " << index;
  26. QImage image = m_model->record(index)->stateIcon(); //NOTE: return value is created in the stack and uses copy constructor
  27. if (size)
  28. *size = QSize(image.width(), image.height());
  29. return image;
  30. }