C
Qt Quick Ultralite swipe_game Demo
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
#ifndef HIGHSCOREMODEL_H
#define HIGHSCOREMODEL_H
#include <qul/model.h>
#include <platforminterface/allocator.h>
#include <vector>
struct Highscore
{
Highscore()
: time(0)
, tries(0)
, score(0)
{}
Highscore(int argTime, int argTries, int argScore)
: time(argTime)
, tries(argTries)
, score(argScore)
{}
int time;
int tries;
int score;
};
inline bool operator==(const Highscore &lhs, const Highscore &rhs)
{
return lhs.time == rhs.time && lhs.tries == rhs.tries && lhs.score == rhs.score;
}
inline bool operator>(const Highscore &lhs, const Highscore &rhs)
{
return lhs.score > rhs.score;
}
inline bool operator<(const Highscore &lhs, const Highscore &rhs)
{
return lhs.score < rhs.score;
}
class HighscoreModel : public Qul::ListModel<Highscore>
{
public:
HighscoreModel();
int count() const QUL_DECL_OVERRIDE;
Highscore data(int index) const QUL_DECL_OVERRIDE;
void addEntry(int time, int tries, int score);
const static int maxSize = 10;
private:
typedef std::vector<Highscore, Qul::PlatformInterface::Allocator<Highscore> > scoreContainer;
scoreContainer m_highscores;
};
#endif // HIGHSCOREMODEL_H