Changed how player names are changed.
This commit is contained in:
parent
8307e4eec4
commit
8bb03932d2
5 changed files with 48 additions and 69 deletions
|
@ -11,5 +11,4 @@ class MainWindow : public QQuickView
|
|||
|
||||
public:
|
||||
explicit MainWindow(QWindow *parent = nullptr);
|
||||
|
||||
};
|
||||
|
|
|
@ -46,44 +46,36 @@ QString PlayerAreaModel::playerName7()
|
|||
return playerName7Text;
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setPlayerName1(QString s)
|
||||
void PlayerAreaModel::setPlayerName(QString s, int n)
|
||||
{
|
||||
playerName1Text = s;
|
||||
emit playerName1Changed();
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setPlayerName2(QString s)
|
||||
{
|
||||
playerName2Text = s;
|
||||
emit playerName2Changed();
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setPlayerName3(QString s)
|
||||
{
|
||||
playerName3Text = s;
|
||||
emit playerName3Changed();
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setPlayerName4(QString s)
|
||||
{
|
||||
playerName4Text = s;
|
||||
emit playerName4Changed();
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setPlayerName5(QString s)
|
||||
{
|
||||
playerName5Text = s;
|
||||
emit playerName5Changed();
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setPlayerName6(QString s)
|
||||
{
|
||||
playerName6Text = s;
|
||||
emit playerName6Changed();
|
||||
}
|
||||
|
||||
void PlayerAreaModel::setPlayerName7(QString s)
|
||||
{
|
||||
playerName7Text = s;
|
||||
emit playerName7Changed();
|
||||
switch(n) {
|
||||
case 1:
|
||||
playerName1Text = s;
|
||||
playerName1Changed();
|
||||
break;
|
||||
case 2:
|
||||
playerName2Text = s;
|
||||
playerName2Changed();
|
||||
break;
|
||||
case 3:
|
||||
playerName3Text = s;
|
||||
playerName3Changed();
|
||||
break;
|
||||
case 4:
|
||||
playerName4Text = s;
|
||||
playerName4Changed();
|
||||
break;
|
||||
case 5:
|
||||
playerName5Text = s;
|
||||
playerName5Changed();
|
||||
break;
|
||||
case 6:
|
||||
playerName6Text = s;
|
||||
playerName6Changed();
|
||||
break;
|
||||
case 7:
|
||||
playerName7Text = s;
|
||||
playerName7Changed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@ class PlayerAreaModel : public QObject
|
|||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
|
||||
Q_PROPERTY(QString playerName1 READ playerName1 WRITE setPlayerName1 NOTIFY playerName1Changed)
|
||||
Q_PROPERTY(QString playerName2 READ playerName2 WRITE setPlayerName2 NOTIFY playerName2Changed)
|
||||
Q_PROPERTY(QString playerName3 READ playerName3 WRITE setPlayerName3 NOTIFY playerName3Changed)
|
||||
Q_PROPERTY(QString playerName4 READ playerName4 WRITE setPlayerName4 NOTIFY playerName4Changed)
|
||||
Q_PROPERTY(QString playerName5 READ playerName5 WRITE setPlayerName5 NOTIFY playerName5Changed)
|
||||
Q_PROPERTY(QString playerName6 READ playerName6 WRITE setPlayerName6 NOTIFY playerName6Changed)
|
||||
Q_PROPERTY(QString playerName7 READ playerName7 WRITE setPlayerName7 NOTIFY playerName7Changed)
|
||||
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);
|
||||
|
@ -27,13 +27,6 @@ public:
|
|||
QString playerName5();
|
||||
QString playerName6();
|
||||
QString playerName7();
|
||||
void setPlayerName1(QString s);
|
||||
void setPlayerName2(QString s);
|
||||
void setPlayerName3(QString s);
|
||||
void setPlayerName4(QString s);
|
||||
void setPlayerName5(QString s);
|
||||
void setPlayerName6(QString s);
|
||||
void setPlayerName7(QString s);
|
||||
|
||||
signals:
|
||||
void playerName1Changed();
|
||||
|
@ -44,6 +37,9 @@ signals:
|
|||
void playerName6Changed();
|
||||
void playerName7Changed();
|
||||
|
||||
public slots:
|
||||
void setPlayerName(QString s, int n);
|
||||
|
||||
private:
|
||||
QString playerName1Text;
|
||||
QString playerName2Text;
|
||||
|
|
|
@ -14,32 +14,31 @@ Item {
|
|||
}
|
||||
TextField {
|
||||
text: playerAreaModel.playerName1
|
||||
onEditingFinished: playerAreaModel.playerName1 = text
|
||||
selectByMouse: true
|
||||
onEditingFinished: playerAreaModel.setPlayerName(text, 1)
|
||||
}
|
||||
TextField {
|
||||
text: playerAreaModel.playerName2
|
||||
onEditingFinished: playerAreaModel.playerName2 = text
|
||||
onEditingFinished: playerAreaModel.setPlayerName(text, 2)
|
||||
}
|
||||
TextField {
|
||||
text: playerAreaModel.playerName3
|
||||
onEditingFinished: playerAreaModel.playerName3 = text
|
||||
onEditingFinished: playerAreaModel.setPlayerName(text, 3)
|
||||
}
|
||||
TextField {
|
||||
text: playerAreaModel.playerName4
|
||||
onEditingFinished: playerAreaModel.playerName4 = text
|
||||
onEditingFinished: playerAreaModel.setPlayerName(text, 4)
|
||||
}
|
||||
TextField {
|
||||
text: playerAreaModel.playerName5
|
||||
onEditingFinished: playerAreaModel.playerName5 = text
|
||||
onEditingFinished: playerAreaModel.setPlayerName(text, 5)
|
||||
}
|
||||
TextField {
|
||||
text: playerAreaModel.playerName6
|
||||
onEditingFinished: playerAreaModel.playerName6 = text
|
||||
onEditingFinished: playerAreaModel.setPlayerName(text, 6)
|
||||
}
|
||||
TextField {
|
||||
text: playerAreaModel.playerName7
|
||||
onEditingFinished: playerAreaModel.playerName7 = text
|
||||
onEditingFinished: playerAreaModel.setPlayerName(text, 7)
|
||||
}
|
||||
Text {
|
||||
text: playerAreaModel.playerName1
|
||||
|
|
7
Root.qml
7
Root.qml
|
@ -11,11 +11,4 @@ Pane {
|
|||
width: 1000
|
||||
PlayerAreaView {
|
||||
}
|
||||
/*
|
||||
* Dentro do Text não podes mudar directamente
|
||||
* o text do playerAreaModel;
|
||||
* Para fazer isso tens que mandar um sinal
|
||||
* que está ligado a um slot do playerAreaModel
|
||||
* que vá mudar esse atributo
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue