Using Q_INVOKABLE with arrays.
This commit is contained in:
parent
f51623deaf
commit
5cdc225e47
4 changed files with 57 additions and 106 deletions
|
@ -2,85 +2,49 @@
|
||||||
|
|
||||||
PlayerAreaModel::PlayerAreaModel(QObject *parent)
|
PlayerAreaModel::PlayerAreaModel(QObject *parent)
|
||||||
{
|
{
|
||||||
playerName1Text = "Click to edit";
|
for(int i = 0; i < 7; i++){
|
||||||
playerName2Text = "Click to edit";
|
playerNames.append("Click to edit");
|
||||||
playerName3Text = "Click to edit";
|
}
|
||||||
playerName4Text = "Click to edit";
|
|
||||||
playerName5Text = "Click to edit";
|
|
||||||
playerName6Text = "Click to edit";
|
|
||||||
playerName7Text = "Click to edit";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PlayerAreaModel::playerName1()
|
QString PlayerAreaModel::getPlayerName(int n)
|
||||||
{
|
{
|
||||||
return playerName1Text;
|
return playerNames.at(n);
|
||||||
}
|
|
||||||
|
|
||||||
QString PlayerAreaModel::playerName2()
|
|
||||||
{
|
|
||||||
return playerName2Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PlayerAreaModel::playerName3()
|
|
||||||
{
|
|
||||||
return playerName3Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PlayerAreaModel::playerName4()
|
|
||||||
{
|
|
||||||
return playerName4Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PlayerAreaModel::playerName5()
|
|
||||||
{
|
|
||||||
return playerName5Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PlayerAreaModel::playerName6()
|
|
||||||
{
|
|
||||||
return playerName6Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString PlayerAreaModel::playerName7()
|
|
||||||
{
|
|
||||||
return playerName7Text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerAreaModel::setPlayerName(QString s, int n)
|
void PlayerAreaModel::setPlayerName(QString s, int n)
|
||||||
{
|
{
|
||||||
switch(n) {
|
switch(n) {
|
||||||
|
case 0:
|
||||||
|
playerNames[n] = s;
|
||||||
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
playerName1Text = s;
|
playerNames[n] = s;
|
||||||
playerName1Changed();
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
playerName2Text = s;
|
playerNames[n] = s;
|
||||||
playerName2Changed();
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
playerName3Text = s;
|
playerNames[n] = s;
|
||||||
playerName3Changed();
|
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
playerName4Text = s;
|
playerNames[n] = s;
|
||||||
playerName4Changed();
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
playerName5Text = s;
|
playerNames[n] = s;
|
||||||
playerName5Changed();
|
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
playerName6Text = s;
|
playerNames[n] = s;
|
||||||
playerName6Changed();
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
playerName7Text = s;
|
|
||||||
playerName7Changed();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerAreaModel::setFocusedPlayer(int n)
|
||||||
|
{
|
||||||
|
focusedPlayer = n;
|
||||||
|
}
|
||||||
|
|
||||||
void PlayerAreaModel::bet(BetType b, int n)
|
void PlayerAreaModel::bet(BetType b, int n)
|
||||||
{
|
{
|
||||||
printf("Received %d-%d\n", b, n);
|
printf("Received %d-%d for player %s\n", b, n, playerNames[focusedPlayer].toLocal8Bit().data());
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,23 +13,9 @@ class PlayerAreaModel : public QObject
|
||||||
QML_NAMED_ELEMENT(PlayerAreaModel)
|
QML_NAMED_ELEMENT(PlayerAreaModel)
|
||||||
QML_SINGLETON
|
QML_SINGLETON
|
||||||
|
|
||||||
Q_PROPERTY(QString playerName1 READ playerName1 NOTIFY playerName1Changed)
|
|
||||||
Q_PROPERTY(QString playerName2 READ playerName2 NOTIFY playerName2Changed)
|
|
||||||
Q_PROPERTY(QString playerName3 READ playerName3 NOTIFY playerName3Changed)
|
|
||||||
Q_PROPERTY(QString playerName4 READ playerName4 NOTIFY playerName4Changed)
|
|
||||||
Q_PROPERTY(QString playerName5 READ playerName5 NOTIFY playerName5Changed)
|
|
||||||
Q_PROPERTY(QString playerName6 READ playerName6 NOTIFY playerName6Changed)
|
|
||||||
Q_PROPERTY(QString playerName7 READ playerName7 NOTIFY playerName7Changed)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PlayerAreaModel(QObject *parent = nullptr);
|
explicit PlayerAreaModel(QObject *parent = nullptr);
|
||||||
QString playerName1();
|
|
||||||
QString playerName2();
|
|
||||||
QString playerName3();
|
|
||||||
QString playerName4();
|
|
||||||
QString playerName5();
|
|
||||||
QString playerName6();
|
|
||||||
QString playerName7();
|
|
||||||
enum BetType {
|
enum BetType {
|
||||||
RED,
|
RED,
|
||||||
BLACK,
|
BLACK,
|
||||||
|
@ -42,28 +28,33 @@ public:
|
||||||
SINGLE,
|
SINGLE,
|
||||||
SPLIT
|
SPLIT
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_ENUM(BetType)
|
Q_ENUM(BetType)
|
||||||
|
|
||||||
signals:
|
|
||||||
void playerName1Changed();
|
|
||||||
void playerName2Changed();
|
|
||||||
void playerName3Changed();
|
|
||||||
void playerName4Changed();
|
|
||||||
void playerName5Changed();
|
|
||||||
void playerName6Changed();
|
|
||||||
void playerName7Changed();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPlayerName(QString s, int n);
|
void setPlayerName(QString s, int n);
|
||||||
void bet(BetType b, int n);
|
void bet(BetType b, int n);
|
||||||
|
QString getPlayerName(int n);
|
||||||
|
void setFocusedPlayer(int n);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString playerName1Text;
|
|
||||||
QString playerName2Text;
|
QList<QString> playerNames;
|
||||||
QString playerName3Text;
|
|
||||||
QString playerName4Text;
|
uint player1Bet1;
|
||||||
QString playerName5Text;
|
uint player1Bet2;
|
||||||
QString playerName6Text;
|
uint player2Bet1;
|
||||||
QString playerName7Text;
|
uint player2Bet2;
|
||||||
|
uint player3Bet1;
|
||||||
|
uint player3Bet2;
|
||||||
|
uint player4Bet1;
|
||||||
|
uint player4Bet2;
|
||||||
|
uint player5Bet1;
|
||||||
|
uint player5Bet2;
|
||||||
|
uint player6Bet1;
|
||||||
|
uint player6Bet2;
|
||||||
|
uint player7Bet1;
|
||||||
|
uint player7Bet2;
|
||||||
|
|
||||||
|
int focusedPlayer;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,35 +10,32 @@ Item {
|
||||||
text: "Croupier"
|
text: "Croupier"
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
text: PlayerAreaModel.playerName1
|
onTextEdited: PlayerAreaModel.setPlayerName(text, 0)
|
||||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 1)
|
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(0)
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
text: PlayerAreaModel.playerName2
|
onTextEdited: PlayerAreaModel.setPlayerName(text, 1)
|
||||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 2)
|
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(1)
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
text: PlayerAreaModel.playerName3
|
onTextEdited: PlayerAreaModel.setPlayerName(text, 2)
|
||||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 3)
|
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(2)
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
text: PlayerAreaModel.playerName4
|
onTextEdited: PlayerAreaModel.setPlayerName(text, 3)
|
||||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 4)
|
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(3)
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
text: PlayerAreaModel.playerName5
|
onTextEdited: PlayerAreaModel.setPlayerName(text, 4)
|
||||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 5)
|
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(4)
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
text: PlayerAreaModel.playerName6
|
onTextEdited: PlayerAreaModel.setPlayerName(text, 5)
|
||||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 6)
|
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(5)
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
text: PlayerAreaModel.playerName7
|
onTextEdited: PlayerAreaModel.setPlayerName(text, 6)
|
||||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 7)
|
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(6)
|
||||||
}
|
|
||||||
Text {
|
|
||||||
text: PlayerAreaModel.playerName1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ Item {
|
||||||
TapHandler {
|
TapHandler {
|
||||||
id: tapHandler1
|
id: tapHandler1
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue