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)
|
||||
{
|
||||
playerName1Text = "Click to edit";
|
||||
playerName2Text = "Click to edit";
|
||||
playerName3Text = "Click to edit";
|
||||
playerName4Text = "Click to edit";
|
||||
playerName5Text = "Click to edit";
|
||||
playerName6Text = "Click to edit";
|
||||
playerName7Text = "Click to edit";
|
||||
for(int i = 0; i < 7; i++){
|
||||
playerNames.append("Click to edit");
|
||||
}
|
||||
}
|
||||
|
||||
QString PlayerAreaModel::playerName1()
|
||||
QString PlayerAreaModel::getPlayerName(int n)
|
||||
{
|
||||
return playerName1Text;
|
||||
}
|
||||
|
||||
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;
|
||||
return playerNames.at(n);
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setPlayerName(QString s, int n)
|
||||
{
|
||||
switch(n) {
|
||||
case 0:
|
||||
playerNames[n] = s;
|
||||
break;
|
||||
case 1:
|
||||
playerName1Text = s;
|
||||
playerName1Changed();
|
||||
playerNames[n] = s;
|
||||
break;
|
||||
case 2:
|
||||
playerName2Text = s;
|
||||
playerName2Changed();
|
||||
playerNames[n] = s;
|
||||
break;
|
||||
case 3:
|
||||
playerName3Text = s;
|
||||
playerName3Changed();
|
||||
playerNames[n] = s;
|
||||
break;
|
||||
case 4:
|
||||
playerName4Text = s;
|
||||
playerName4Changed();
|
||||
playerNames[n] = s;
|
||||
break;
|
||||
case 5:
|
||||
playerName5Text = s;
|
||||
playerName5Changed();
|
||||
playerNames[n] = s;
|
||||
break;
|
||||
case 6:
|
||||
playerName6Text = s;
|
||||
playerName6Changed();
|
||||
break;
|
||||
case 7:
|
||||
playerName7Text = s;
|
||||
playerName7Changed();
|
||||
playerNames[n] = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setFocusedPlayer(int n)
|
||||
{
|
||||
focusedPlayer = 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_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:
|
||||
explicit PlayerAreaModel(QObject *parent = nullptr);
|
||||
QString playerName1();
|
||||
QString playerName2();
|
||||
QString playerName3();
|
||||
QString playerName4();
|
||||
QString playerName5();
|
||||
QString playerName6();
|
||||
QString playerName7();
|
||||
|
||||
enum BetType {
|
||||
RED,
|
||||
BLACK,
|
||||
|
@ -42,28 +28,33 @@ public:
|
|||
SINGLE,
|
||||
SPLIT
|
||||
};
|
||||
|
||||
Q_ENUM(BetType)
|
||||
|
||||
signals:
|
||||
void playerName1Changed();
|
||||
void playerName2Changed();
|
||||
void playerName3Changed();
|
||||
void playerName4Changed();
|
||||
void playerName5Changed();
|
||||
void playerName6Changed();
|
||||
void playerName7Changed();
|
||||
|
||||
public slots:
|
||||
void setPlayerName(QString s, int n);
|
||||
void bet(BetType b, int n);
|
||||
QString getPlayerName(int n);
|
||||
void setFocusedPlayer(int n);
|
||||
|
||||
|
||||
private:
|
||||
QString playerName1Text;
|
||||
QString playerName2Text;
|
||||
QString playerName3Text;
|
||||
QString playerName4Text;
|
||||
QString playerName5Text;
|
||||
QString playerName6Text;
|
||||
QString playerName7Text;
|
||||
|
||||
QList<QString> playerNames;
|
||||
|
||||
uint player1Bet1;
|
||||
uint player1Bet2;
|
||||
uint player2Bet1;
|
||||
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"
|
||||
}
|
||||
TextField {
|
||||
text: PlayerAreaModel.playerName1
|
||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 1)
|
||||
onTextEdited: PlayerAreaModel.setPlayerName(text, 0)
|
||||
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(0)
|
||||
}
|
||||
TextField {
|
||||
text: PlayerAreaModel.playerName2
|
||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 2)
|
||||
onTextEdited: PlayerAreaModel.setPlayerName(text, 1)
|
||||
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(1)
|
||||
}
|
||||
TextField {
|
||||
text: PlayerAreaModel.playerName3
|
||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 3)
|
||||
onTextEdited: PlayerAreaModel.setPlayerName(text, 2)
|
||||
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(2)
|
||||
}
|
||||
TextField {
|
||||
text: PlayerAreaModel.playerName4
|
||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 4)
|
||||
onTextEdited: PlayerAreaModel.setPlayerName(text, 3)
|
||||
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(3)
|
||||
}
|
||||
TextField {
|
||||
text: PlayerAreaModel.playerName5
|
||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 5)
|
||||
onTextEdited: PlayerAreaModel.setPlayerName(text, 4)
|
||||
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(4)
|
||||
}
|
||||
TextField {
|
||||
text: PlayerAreaModel.playerName6
|
||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 6)
|
||||
onTextEdited: PlayerAreaModel.setPlayerName(text, 5)
|
||||
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(5)
|
||||
}
|
||||
TextField {
|
||||
text: PlayerAreaModel.playerName7
|
||||
onEditingFinished: PlayerAreaModel.setPlayerName(text, 7)
|
||||
}
|
||||
Text {
|
||||
text: PlayerAreaModel.playerName1
|
||||
onTextEdited: PlayerAreaModel.setPlayerName(text, 6)
|
||||
onActiveFocusChanged: PlayerAreaModel.setFocusedPlayer(6)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ Item {
|
|||
TapHandler {
|
||||
id: tapHandler1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue