C

Qt Quick Ultralite滑动游戏演示

#ifndef HIGHSCOREMODEL_H
#define HIGHSCOREMODEL_H
/****************************************************************************** ** ** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
#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