levelmodel.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation.
  3. */
  4. #ifndef LEVELMODEL_H
  5. #define LEVELMODEL_H
  6. #include <QAbstractListModel>
  7. #include "leveldata.h"
  8. /***************************************************************************************************
  9. *Class representing an item model, used for IAP user interaction. *
  10. ***************************************************************************************************/
  11. class LevelModel : public QAbstractListModel
  12. {
  13. Q_OBJECT
  14. public:
  15. /***********************************************************************************************
  16. *Custom model roles. *
  17. ***********************************************************************************************/
  18. enum LevelRole
  19. {
  20. LevelIdRole = Qt::UserRole + 1,
  21. LevelNameRole,
  22. LevelPriceRole,
  23. LevelUnlockedRole,
  24. LevelShortDescriptionRole,
  25. LevelLongDescriptionRole,
  26. LevelType
  27. };
  28. /**********************************************************************************************/
  29. explicit LevelModel(QObject *parent = 0);
  30. /***********************************************************************************************
  31. *Standard Qt model view methods. *
  32. ***********************************************************************************************/
  33. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  34. QVariant data(const QModelIndex &index, int role) const;
  35. bool setData(const QModelIndex &index, const QVariant &value, int role);
  36. Qt::ItemFlags flags(const QModelIndex &index) const;
  37. bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
  38. bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
  39. /**********************************************************************************************/
  40. /***********************************************************************************************
  41. *A method used to overwrite the entire model data. *
  42. ***********************************************************************************************/
  43. void setModelData(const QList<LevelData>& data);
  44. /***********************************************************************************************
  45. *A method used to overwrite/add a single model item. *
  46. ***********************************************************************************************/
  47. void setLevelData(const LevelData& data);
  48. /***********************************************************************************************
  49. *A method used to retrieve the leveldata withe the given id. *
  50. ***********************************************************************************************/
  51. LevelData getById(QString itemId) const;
  52. private:
  53. /***********************************************************************************************
  54. *A simple list representing the models data. *
  55. ***********************************************************************************************/
  56. QList<LevelData> modelData;
  57. };
  58. #endif // LEVELMODEL_H