PlayModel: support for word changes in addition to coordinates.

This is not used anywhere yet.
This commit is contained in:
Olivier Teulière 2012-12-18 01:16:33 +01:00
parent 1e551207fb
commit 3f269e5bd4
2 changed files with 42 additions and 4 deletions

View file

@ -24,6 +24,13 @@
INIT_LOGGER(qt, PlayModel);
void PlayModel::clear()
{
setCoord(Coord());
setWord(L"");
}
void PlayModel::setCoord(const Coord &iCoord)
{
// Avoid useless work
@ -36,8 +43,14 @@ void PlayModel::setCoord(const Coord &iCoord)
}
void PlayModel::clear()
void PlayModel::setWord(const wstring &iWord)
{
setCoord(Coord());
// Avoid useless work
if (iWord == m_currWord)
return;
m_prevWord = m_currWord;
m_currWord = iWord;
emit wordChanged(iWord, m_prevWord);
}

View file

@ -21,29 +21,54 @@
#ifndef PLAY_MODEL_H_
#define PLAY_MODEL_H_
#include <string>
#include <QObject>
#include "coord.h"
#include "logging.h"
using std::wstring;
/**
* Encapsulate a move being played (possibly incomplete).
* There is usually only one instance of this class.
*
* A PlayModel contains the word typed by the user and the coordinates of the word.
* Signals are emitted every time one of these values changes: this allows various
* useful things, such as:
* - keeping the arrow on the board synchronized with the typed coordinates
* - keeping the word preview on the board synchronized with the typed letters,
* and with the remaining letters in the rack
*/
class PlayModel: public QObject
{
Q_OBJECT;
DEFINE_LOGGER();
public:
void setCoord(const Coord &iCoord);
/**
* Remove the word and the coordinates.
* This may emit both the wordChanged() and the coordChanged() signals.
*/
void clear();
const Coord &getCoord() const { return m_currCoord; }
void setCoord(const Coord &iCoord);
const Coord & getCoord() const { return m_currCoord; }
void setWord(const wstring &iWord);
const wstring & getWord() const { return m_currWord; }
signals:
void coordChanged(const Coord &iNewCoord, const Coord &iOldCoord);
void wordChanged(const wstring &iNewWord, const wstring &iOldWord);
private:
Coord m_currCoord;
Coord m_prevCoord;
wstring m_currWord;
wstring m_prevWord;
};
#endif