Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FenPrinc.h"
- #include "Code.h"
- /* Constructeur : -Inclu les méthodes
- -Paramètres de la fenêtre
- */
- FenPrinc::FenPrinc()
- {
- creaLayout();
- creaMenus();
- initialisations();
- setFixedSize(750, 330);
- }
- /* creaLayout : -Création des FormLayout
- -Création des GroupBox
- */
- void FenPrinc::creaLayout()
- {
- definitions();
- QFormLayout *lCible = new QFormLayout;
- lCible->addRow("Nom du royaume enemi", rCible);
- lCible->addRow("Coordonné X", cX);
- lCible->addRow("Coordonné Y", cY);
- QFormLayout *lRepe = new QFormLayout;
- lRepe->addRow("Nom du royaume repère", rRepere);
- lRepe->addRow("Heure d'attaque", depart);
- lRepe->addRow("Durée de l'attaque", duree);
- lRepe->addRow("Date de l'attaque", date);
- QFormLayout *lMulti = new QFormLayout;
- lMulti->addRow(grPlan);
- lMulti->addRow(plPlan);
- QFormLayout *lSelect = new QFormLayout;
- lSelect->addRow("Alliances disponibles", nSelect);
- lSelect->addRow("Alliances sélectionnées", oSelect);
- cible = new QGroupBox("Cible de la planification");
- cible->setLayout(lCible);
- repere = new QGroupBox("Caractéristiques de la planification");
- repere->setLayout(lRepe);
- multi = new QGroupBox("Paramètres multi-alliance");
- multi->setLayout(lMulti);
- selection = new QGroupBox("Alliances");
- selection->setLayout(lSelect);
- sub1->addWidget(repere);
- sub1->addWidget(cible);
- sub2->addWidget(selection);
- sub2->addWidget(multi);
- layoutPrincipal->addLayout(sub1);
- layoutPrincipal->addLayout(sub2);
- pageRoy->setLayout(layoutPrincipal);
- setCentralWidget(onglets);
- }
- // definitions : -Définir les attributs pointeurs
- void FenPrinc::definitions()
- {
- ifis = 1;
- rCible = new QLineEdit;
- rCible->setMaximumWidth(150);
- rCible->setMinimumWidth(150);
- rRepere = new QLineEdit;
- rRepere->setMaximumWidth(150);
- rRepere->setMinimumWidth(150);
- date = new QLineEdit;
- date->setMaximumWidth(150);
- date->setMinimumWidth(150);
- cX = new QSpinBox;
- cX->setMaximumWidth(40);
- cY = new QSpinBox;
- cY->setMaximumWidth(40);
- depart = new QSpinBox;
- depart->setRange(0, 23);
- depart->setMaximumWidth(40);
- duree = new QSpinBox;
- duree->setRange(1, 5);
- duree->setMaximumWidth(40);
- pageRoy = new QWidget(this);
- onglets = new QTabWidget;
- onglets->addTab(pageRoy, "Planification");
- grPlan = new QRadioButton("Générer une grande planification");
- grPlan->setEnabled(false);
- plPlan = new QRadioButton("Générer une planification par alliance");
- plPlan->setEnabled(false);
- layoutPrincipal = new QHBoxLayout;
- sub1 = new QVBoxLayout;
- sub2 = new QVBoxLayout;
- dista = 100;
- nSelect = new QListWidget;
- connect(nSelect, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(changeS(QListWidgetItem *)));
- oSelect = new QListWidget;
- connect(oSelect, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(changeU(QListWidgetItem *)));
- alliance = new QSettings("Alliances", QSettings::IniFormat);
- allSelect = new QSettings("AllSelect", QSettings::IniFormat);
- allSelect->clear();
- generer = new QAction("Générer la planification", this);
- generer->setShortcut(tr("F12"));
- connect(generer, SIGNAL(triggered()), this, SLOT(genererCode()));
- plusAll = new QAction("Ajouter une alliance", this);
- connect(plusAll, SIGNAL(triggered()), this, SLOT(ajouterAll()));
- moinsAll = new QAction("Supprimer une alliance", this);
- connect(moinsAll, SIGNAL(triggered()), this, SLOT(deleteAll()));
- modif = new QAction("Modifier une alliance", this);
- connect(modif, SIGNAL(triggered()), this, SLOT(modifAll()));
- quitt = new QAction("Quitter", this);
- connect(quitt, SIGNAL(triggered()), qApp, SLOT(quit()));
- box = new QComboBox();
- box->setMinimumWidth(200);
- box->addItem("Delos");
- box->addItem("Thessalie");
- box->addItem("Pheres");
- textP = new QLabel("Copyright @ 2011 - xXModz' Universe - gab4powa@hotmail.com");
- statusBar()->addWidget(textP);
- statusBar()->addWidget(box);
- }
- /*creaMenus : -Définit les menus
- -Définit les actions
- */
- void FenPrinc::creaMenus()
- {
- QMenu *fichier = menuBar()->addMenu(tr("&Fichier"));
- fichier->addAction(generer);
- fichier->addAction(quitt);
- QMenu *para = menuBar()->addMenu("Paramètres alliances");
- para->addAction(plusAll);
- para->addAction(moinsAll);
- para->addAction(modif);
- }
- //genererCode : -Algorythme pour planification
- void FenPrinc::genererCode()
- {
- if(oSelect->count() == 0)
- {
- QMessageBox::critical(this,"Attention!", "Au moins une alliance doit être sélectionnée!");
- return;
- }
- int test = trouvDist();
- if(test == 2)
- return;
- if(oSelect->count() == 1)
- {
- uneAlliance();
- }
- else if(plPlan->isChecked())
- {
- plAlliance();
- }
- else if(grPlan->isChecked())
- {
- grAlliance();
- }
- }
- //initialisations : -Initialise les préférences
- void FenPrinc::initialisations()
- {
- stringstream nTl;
- int i = 1;
- nTl << i;
- string b = "Alliance" + nTl.str();
- QString end = b.c_str();
- while(alliance->contains(end))
- {
- QListWidgetItem *item = new QListWidgetItem(alliance->value(end).toString(), nSelect);
- i++;
- stringstream nTl;
- nTl << i;
- b = "Alliance" + nTl.str();
- end = b.c_str();
- }
- }
- void FenPrinc::changeU(QListWidgetItem *widget)
- {
- nSelect->addItem(widget->text());
- stringstream nTl;
- int i = 1;
- nTl << i;
- string b = "Alliance" + nTl.str();
- QString end = b.c_str();
- while(allSelect->value(end) != widget->text())
- {
- i++;
- stringstream nTl;
- nTl << i;
- b = "Alliance" + nTl.str();
- end = b.c_str();
- }
- while(true)
- {
- stringstream nTl2;
- int c = i + 1;
- nTl2 << c;
- string a = "Alliance" + nTl2.str();
- QString end2 = a.c_str();
- if(allSelect->contains(end2))
- {
- allSelect->setValue(end, allSelect->value(end2));
- i++;
- stringstream nTl;
- nTl << i;
- string b = "Alliance" + nTl.str();
- QString end = b.c_str();
- allSelect->remove(end);
- break;
- }
- else
- {
- allSelect->remove(end);
- break;
- }
- }
- if(!(allSelect->contains("Alliance2")))
- {
- if(grPlan->isEnabled())
- {
- grPlan->setEnabled(false);
- plPlan->setEnabled(false);
- }
- }
- delete widget;
- }
- int FenPrinc::trouvDist()
- {
- if(box->currentText() == "Pheres")
- {
- min = 4;
- max = 23.44;
- }
- else
- {
- min = 3;
- max = 25.44;
- }
- int i = 1;
- stringstream ss;
- ss << i;
- string trouver = "Alliance" + ss.str();
- while(allSelect->contains(trouver.c_str()))
- {
- int z = 1;
- stringstream aa;
- aa << z;
- string trouv = "Alliance" + aa.str();
- while(alliance->value(trouv.c_str()) != allSelect->value(trouver.c_str()))
- {
- z++;
- stringstream aa;
- aa << z;
- trouv = "Alliance" + aa.str();
- }
- for(int i = z * 20 - 19 ; i <= z * 20 ; i ++)
- {
- stringstream ss;
- ss << i;
- trouv = "Membre" + ss.str();
- if(alliance->value(trouv.c_str()) == rRepere->text())
- {
- string x = "x" + ss.str();
- string y = "y" + ss.str();
- int x1 = alliance->value(x.c_str()).toInt();
- int y1 = alliance->value(y.c_str()).toInt();
- int x2 = cX->value();
- int y2 = cY->value();
- x1 = fabs(x2 - x1);
- y1 = fabs(y2 - y1);
- float ans1 = sqrt(pow(x1, 2) + pow(y1, 2));
- if (ans1 < 9.44)
- {
- if(ans1 > 6.41 && ans1 < 7.22)
- dista = min+2;
- else if(ans1 >= 7.22)
- dista = min+3;
- else if(ans1 >= 2.8 && ans1 <= 6.41)
- dista = min+1;
- else
- dista = min;
- }
- else
- {
- float val = 9.44;
- int heure = min+4;
- if (ans1 > max)
- dista = 15;
- else
- {
- while(1)
- {
- if(ans1 >= val && ans1 < val+2)
- {
- dista = heure;
- break;
- }
- val += 2;
- heure++;
- }
- }
- }
- return 1;
- }
- }
- i++;
- stringstream ss;
- ss << i;
- trouver = "Alliance" + ss.str();
- }
- QMessageBox::critical(this,"Attention!", rRepere->text() + " ne fait pas parti des alliances sélectionnées!");
- return 2;
- }
- void FenPrinc::changeS(QListWidgetItem *widget)
- {
- oSelect->addItem(widget->text());
- stringstream nTl;
- int i = 1;
- nTl << i;
- string b = "Alliance" + nTl.str();
- QString end = b.c_str();
- while(allSelect->contains(end))
- {
- i++;
- stringstream nTl;
- nTl << i;
- b = "Alliance" + nTl.str();
- end = b.c_str();
- }
- allSelect->setValue(end, widget->text());
- if(allSelect->contains("Alliance2") && !grPlan->isEnabled())
- {
- grPlan->setEnabled(true);
- grPlan->setChecked(true);
- plPlan->setEnabled(true);
- }
- delete widget;
- }
- void FenPrinc::uneAlliance()
- {
- if(box->currentText() == "Pheres")
- {
- min = 4;
- max = 26;
- }
- else
- {
- min = 3;
- max = 26;
- }
- QString code;
- stringstream out;
- int dure = duree->value();
- out << dure;
- int distance = 0;
- int ifno = 0;
- int allSpot = 1;
- stringstream aa;
- aa << allSpot;
- string trouv = "Alliance" + aa.str();
- while(alliance->value(trouv.c_str()) != allSelect->value("Alliance1"))
- {
- allSpot++;
- stringstream aa;
- aa << allSpot;
- trouv = "Alliance" + aa.str();
- }
- code += allSelect->value("Alliance1").toString() + "\n\n";
- code += "Planification contre " + rCible->text() + "\nDuree de l'attaque : " + out.str().c_str() + " Heures \nDate : " + date->text()+ "\n\n\n";
- for(int b = 15 ; b > 2 ; b--)
- {
- for(int i = allSpot * 20 - 19 ; i <= allSpot * 20 ; i ++)
- {
- stringstream out;
- out << i;
- string x = "x" + out.str();
- string y = "y" + out.str();
- int x1 = alliance->value(x.c_str()).toInt();
- int y1 = alliance->value(y.c_str()).toInt();
- if(x1 != 0)
- {
- int x2 = cX->value();
- int y2 = cY->value();
- x1 = fabs(x2 - x1);
- y1 = fabs(y2 - y1);
- float ans1 = sqrt(pow(x1, 2) + pow(y1, 2));
- if (ans1 < 9.44)
- {
- if(ans1 > 6.41 && ans1 < 7.22)
- distance = min+2;
- else if(ans1 >= 7.22)
- distance = min+3;
- else if(ans1 >= 2.8 && ans1 <= 6.41)
- distance = min+1;
- else
- distance = min;
- }
- else
- {
- float val = 9.44;
- int heure = min+4;
- if (ans1 > max)
- distance = 15;
- else
- {
- while(1)
- {
- if(ans1 >= val && ans1 < val+2)
- {
- distance = heure;
- break;
- }
- val += 2;
- heure++;
- }
- }
- }
- }
- else
- distance = -1;
- if(distance == b)
- {
- int moyen = dista - b;
- int timee = depart->value() + moyen;
- if(timee < 0)
- {
- timee = 24 + timee;
- }
- else if(timee > 23)
- {
- timee = -24 + timee;
- }
- stringstream d1, d2;
- d1 << timee;
- d2 << timee + 1;
- stringstream bo;
- bo << b;
- if(ifno == 0)
- {
- code +="\n";
- code += "Ceux qui doivent partir entre ";
- code += d1.str().c_str();
- code += "h30 et " ;
- code += d2.str().c_str();
- code += "h30 (";
- code += bo.str().c_str();
- code += " Heures de distance) : ";
- code += "\n\n";
- ifno = 1;
- }
- stringstream bob;
- bob << i;
- string go = "Membre" + bob.str();
- QString boo = go.c_str();
- QString duuude = alliance->value(boo).toString();
- code += duuude;
- code += "\n";
- }
- }
- ifno = 0;
- }
- Planif *planif = new Planif(code, this);
- planif->show();
- }
- void FenPrinc::grAlliance()
- {
- if(box->currentText() == "Pheres")
- {
- min = 4;
- max = 26;
- }
- else
- {
- min = 3;
- max = 26;
- }
- QString code;
- stringstream out;
- int dure = duree->value();
- out << dure;
- int distance = 0;
- int ifno = 0;
- augAll = 0;
- stringstream nomAll;
- int nomAl = 1;
- nomAll << nomAl;
- string nomA = "Alliance" + nomAll.str();
- while(allSelect->contains(nomA.c_str()))
- {
- code += allSelect->value(nomA.c_str()).toString() + "\n";
- stringstream nomAll;
- nomAl++;
- nomAll << nomAl;
- nomA = "Alliance" + nomAll.str();
- }
- code += "\n\n";
- code += "Planification contre " + rCible->text() + "\nDuree de l'attaque : " + out.str().c_str() + " Heures \nDate : " + date->text()+ "\n\n\n";
- for(int b = 15 ; b > 2 ; b--)
- {
- augAll = 0;
- stringstream plusAll;
- plusAll << 1;
- string kelAll = "Alliance" + plusAll.str();
- int allSpot = 1;
- stringstream aa;
- aa << allSpot;
- string trouv = "Alliance" + aa.str();
- int bob = 5;
- while(alliance->value(trouv.c_str()) != allSelect->value(kelAll.c_str()))
- {
- allSpot++;
- stringstream aa;
- aa << allSpot;
- trouv = "Alliance" + aa.str();
- }
- while(true)
- {
- augAll++;
- stringstream next;
- next << augAll;
- string nextAll = "Alliance" + next.str();
- if(allSelect->contains(nextAll.c_str()))
- {
- stringstream plusAll;
- plusAll << augAll;
- string kelAll = "Alliance" + plusAll.str();
- allSpot = 1;
- stringstream aa;
- aa << allSpot;
- string trouv = "Alliance" + aa.str();
- while(alliance->value(trouv.c_str()) != allSelect->value(kelAll.c_str()))
- {
- allSpot++;
- stringstream aa;
- aa << allSpot;
- trouv = "Alliance" + aa.str();
- }
- }
- else
- break;
- for(int i = allSpot * 20 - 19 ; i <= allSpot * 20 ; i ++)
- {
- stringstream out;
- out << i;
- string x = "x" + out.str();
- string y = "y" + out.str();
- int x1 = alliance->value(x.c_str()).toInt();
- int y1 = alliance->value(y.c_str()).toInt();
- if(x1 != 0)
- {
- int x2 = cX->value();
- int y2 = cY->value();
- x1 = fabs(x2 - x1);
- y1 = fabs(y2 - y1);
- float ans1 = sqrt(pow(x1, 2) + pow(y1, 2));
- if (ans1 < 9.44)
- {
- if(ans1 > 6.41 && ans1 < 7.22)
- distance = min+2;
- else if(ans1 >= 7.22)
- distance = min+3;
- else if(ans1 >= 2.8 && ans1 <= 6.41)
- distance = min+1;
- else
- distance = min;
- }
- else
- {
- float val = 9.44;
- int heure = min+4;
- if (ans1 > max)
- distance = 15;
- else
- {
- while(1)
- {
- if(ans1 >= val && ans1 < val+2)
- {
- distance = heure;
- break;
- }
- val += 2;
- heure++;
- }
- }
- }
- }
- else
- distance = -1;
- if(distance == b)
- {
- int moyen = dista - b;
- int timee = depart->value() + moyen;
- if(timee < 0)
- {
- timee = 24 + timee;
- }
- else if(timee > 23)
- {
- timee = -24 + timee;
- }
- stringstream d1, d2;
- d1 << timee - 1;
- d2 << timee;
- stringstream bo;
- bo << b;
- if(ifno == 0)
- {
- code +="\n";
- code += "Ceux qui doivent partir entre ";
- code += d1.str().c_str();
- code += "h30 et " ;
- code += d2.str().c_str();
- code += "h30 (";
- code += bo.str().c_str();
- code += " Heures de distance) : ";
- code += "\n\n";
- ifno = 1;
- }
- stringstream bob;
- bob << i;
- string go = "Membre" + bob.str();
- QString boo = go.c_str();
- QString duuude = alliance->value(boo).toString();
- code += duuude;
- code += "\n";
- }
- }
- }
- ifno = 0;
- }
- Planif *planif = new Planif(code, this);
- planif->show();
- }
- void FenPrinc::plAlliance()
- {
- if(box->currentText() == "Pheres")
- {
- min = 4;
- max = 26;
- }
- else
- {
- min = 3;
- max = 26;
- }
- int y = 1;
- stringstream allChange;
- allChange << y;
- string boby = "Alliance" + allChange.str();
- while(allSelect->contains(boby.c_str()))
- {
- QString code;
- stringstream out;
- int dure = duree->value();
- out << dure;
- int distance = 0;
- int ifno = 0;
- int allSpot = 1;
- stringstream aa;
- aa << allSpot;
- string trouv = "Alliance" + aa.str();
- while(alliance->value(trouv.c_str()) != allSelect->value(boby.c_str()))
- {
- allSpot++;
- stringstream aa;
- aa << allSpot;
- trouv = "Alliance" + aa.str();
- }
- code += allSelect->value(boby.c_str()).toString() + "\n\n";
- code += "Planification contre " + rCible->text() + "\nDuree de l'attaque : " + out.str().c_str() + " Heures \nDate : " + date->text()+ "\n\n\n";
- for(int b = 15 ; b > 2 ; b--)
- {
- for(int i = allSpot * 20 - 19 ; i <= allSpot * 20 ; i ++)
- {
- stringstream out;
- out << i;
- string x = "x" + out.str();
- string y = "y" + out.str();
- int x1 = alliance->value(x.c_str()).toInt();
- int y1 = alliance->value(y.c_str()).toInt();
- if(x1 != 0)
- {
- int x2 = cX->value();
- int y2 = cY->value();
- x1 = fabs(x2 - x1);
- y1 = fabs(y2 - y1);
- float ans1 = sqrt(pow(x1, 2) + pow(y1, 2));
- if (ans1 < 9.44)
- {
- if(ans1 > 6.41 && ans1 < 7.22)
- distance = min+2;
- else if(ans1 >= 7.22)
- distance = min+3;
- else if(ans1 >= 2.8 && ans1 <= 6.41)
- distance = min+1;
- else
- distance = min;
- }
- else
- {
- float val = 9.44;
- int heure = min+4;
- if (ans1 > max)
- distance = 15;
- else
- {
- while(1)
- {
- if(ans1 >= val && ans1 < val+2)
- {
- distance = heure;
- break;
- }
- val += 2;
- heure++;
- }
- }
- }
- }
- else
- distance = -1;
- if(distance == b)
- {
- int moyen = dista - b;
- int timee = depart->value() + moyen;
- if(timee < 0)
- {
- timee = 24 + timee;
- }
- else if(timee > 23)
- {
- timee = -24 + timee;
- }
- stringstream d1, d2;
- d1 << timee;
- d2 << timee + 1;
- stringstream bo;
- bo << b;
- if(ifno == 0)
- {
- code +="\n";
- code += "Ceux qui doivent partir entre ";
- code += d1.str().c_str();
- code += "h30 et " ;
- code += d2.str().c_str();
- code += "h30 (";
- code += bo.str().c_str();
- code += " Heures de distance) : ";
- code += "\n\n";
- ifno = 1;
- }
- stringstream bob;
- bob << i;
- string go = "Membre" + bob.str();
- QString boo = go.c_str();
- QString duuude = alliance->value(boo).toString();
- code += duuude;
- code += "\n";
- }
- }
- ifno = 0;
- }
- Planif *planif = new Planif(code, this);
- planif->show();
- y++;
- stringstream allChange;
- allChange << y;
- boby = "Alliance" + allChange.str();
- }
- }
- void FenPrinc::ajouterAll()
- {
- fenetr = new QWidget;
- bUser = new QLineEdit;
- QPushButton *boutonC = new QPushButton;
- boutonC->setText(tr("Ajouter"));
- connect(boutonC, SIGNAL(clicked()), this, SLOT(addAll()));
- connect(boutonC, SIGNAL(clicked()), fenetr, SLOT(close()));
- QFormLayout *definitionLayout = new QFormLayout;
- definitionLayout->addRow(tr("Nom"), bUser);
- QGroupBox *rec = new QGroupBox(tr("Ajouter une alliance"));
- rec->setLayout(definitionLayout);
- rec->setFixedSize(300, 70);
- QVBoxLayout bigL;
- bigL.addWidget(rec);
- bigL.addWidget(boutonC);
- fenetr->setLayout(&bigL);
- fenetr->setFixedSize(320, 120);
- fenetr->show();
- }
- void FenPrinc::addAll()
- {
- int i = 1;
- stringstream chiffre;
- chiffre << i;
- string quelAll = "Alliance" + chiffre.str();
- while(alliance->contains(quelAll.c_str()))
- {
- if(alliance->value(quelAll.c_str()) == bUser->text())
- {
- QMessageBox::critical(this,"Erreur", "Une alliance porte déjà ce nom!");
- return;
- }
- i++;
- stringstream chiffre;
- chiffre << i;
- quelAll = "Alliance" + chiffre.str();
- }
- alliance->setValue(quelAll.c_str(), bUser->text());
- for(int l = i * 20 - 19 ; l <= i * 20 ; l++)
- {
- stringstream chiffre;
- chiffre << l;
- string memb = "Membre" + chiffre.str();
- string x1 = "x" + chiffre.str();
- string y1 = "y" + chiffre.str();
- alliance->setValue(memb.c_str(), "Emplacement vide");
- alliance->setValue(x1.c_str(), 0);
- alliance->setValue(y1.c_str(), 0);
- }
- chgAll();
- }
- void FenPrinc::chgAll()
- {
- nSelect->clear();
- oSelect->clear();
- allSelect->clear();
- initialisations();
- }
- void FenPrinc::deleteAll()
- {
- fenetre = new QWidget;
- aUser = new QLineEdit;
- QPushButton *boutonC = new QPushButton;
- boutonC->setText(tr("Supprimer"));
- connect(boutonC, SIGNAL(clicked()), this, SLOT(delAll()));
- connect(boutonC, SIGNAL(clicked()), fenetre, SLOT(close()));
- QFormLayout *definitionLayout = new QFormLayout;
- definitionLayout->addRow(tr("Nom"), aUser);
- QGroupBox *rec = new QGroupBox(tr("Supprimer une alliance"));
- rec->setLayout(definitionLayout);
- rec->setFixedSize(300, 70);
- QVBoxLayout bigL;
- bigL.addWidget(rec);
- bigL.addWidget(boutonC);
- fenetre->setLayout(&bigL);
- fenetre->setFixedSize(320, 120);
- fenetre->show();
- }
- void FenPrinc::delAll()
- {
- int reponse = QMessageBox::critical(this, "Supprimer une alliance", "Êtes-vous sur de vouloir supprimer l'alliance suivant : " + aUser->text() + " ?", QMessageBox::Yes | QMessageBox::No);
- if (reponse == QMessageBox::Yes)
- {
- int i = 1;
- stringstream chiffre;
- chiffre << i;
- string quelAll = "Alliance" + chiffre.str();
- while(alliance->value(quelAll.c_str()) != aUser->text())
- {
- i++;
- stringstream chiffre;
- chiffre << i;
- quelAll = "Alliance" + chiffre.str();
- if(!alliance->contains(quelAll.c_str()))
- {
- QMessageBox::critical(this,"Attention!", aUser->text() + " ne fait pas partit des alliances en librairie.");
- return;
- }
- }
- alliance->remove(quelAll.c_str());
- for(int l = i * 20 - 19 ; l <= i * 20 ; l++)
- {
- stringstream chiffre;
- chiffre << l;
- string memb = "Membre" + chiffre.str();
- string x1 = "x" + chiffre.str();
- string y1 = "y" + chiffre.str();
- alliance->remove(memb.c_str());
- alliance->remove(x1.c_str());
- alliance->remove(y1.c_str());
- }
- while(true)
- {
- stringstream nTl;
- nTl << i;
- string b = "Alliance" + nTl.str();
- QString end = b.c_str();
- stringstream nTl2;
- int c = i + 1;
- nTl2 << c;
- string a = "Alliance" + nTl2.str();
- QString end2 = a.c_str();
- if(alliance->contains(end2))
- {
- alliance->setValue(end, alliance->value(end2));
- for(int k = i * 20 - 19 ; k <= i * 20 ; k++)
- {
- stringstream nTl;
- nTl << k;
- string b = "x" + nTl.str();
- QString end = b.c_str();
- string a = "y" + nTl.str();
- QString end2 = a.c_str();
- string v = "Membre" + nTl.str();
- QString end3 = v.c_str();
- stringstream nTl2;
- int y = k + 20;
- nTl2 << y;
- string o = "x" + nTl2.str();
- QString boby = o.c_str();
- string p = "y" + nTl2.str();
- QString bobyy = p.c_str();
- string f = "Membre" + nTl2.str();
- QString bobyyy = f.c_str();
- alliance->setValue(end, alliance->value(boby));
- alliance->setValue(end2,alliance->value(bobyy));
- alliance->setValue(end3,alliance->value(bobyyy));
- }
- i++;
- stringstream nTl;
- nTl << i;
- string b = "Alliance" + nTl.str();
- QString end = b.c_str();
- }
- else
- {
- alliance->remove(end);
- for(int k = i * 20 - 19 ; k <= i * 20 ; k++)
- {
- stringstream nTl;
- nTl << k;
- string b = "x" + nTl.str();
- QString end = b.c_str();
- string a = "y" + nTl.str();
- QString end2 = a.c_str();
- string v = "Membre" + nTl.str();
- QString end3 = v.c_str();
- stringstream nTl2;
- alliance->remove(end);
- alliance->remove(end2);
- alliance->remove(end3);
- }
- break;
- }
- }
- chgAll();
- }
- }
- void FenPrinc::modifAll()
- {
- QWidget *fenetre = new QWidget;
- cUser = new QLineEdit;
- QPushButton *boutonC = new QPushButton;
- boutonC->setText(tr("Modifier"));
- connect(boutonC, SIGNAL(clicked()), this, SLOT(modAll()));
- connect(boutonC, SIGNAL(clicked()), fenetre, SLOT(close()));
- QFormLayout *definitionLayout = new QFormLayout;
- definitionLayout->addRow(tr("Nom"), cUser);
- QGroupBox *rec = new QGroupBox(tr("Choisir une alliance"));
- rec->setLayout(definitionLayout);
- rec->setFixedSize(300, 70);
- QVBoxLayout bigL;
- bigL.addWidget(rec);
- bigL.addWidget(boutonC);
- fenetre->setLayout(&bigL);
- fenetre->setFixedSize(320, 120);
- fenetre->show();
- }
- void FenPrinc::modAll()
- {
- rNo = new QLineEdit;
- rNo->setMaximumWidth(150);
- rNo->setMinimumWidth(150);
- rX = new QSpinBox;
- rX->setMaximumWidth(40);
- rY = new QSpinBox;
- rY->setMaximumWidth(40);
- modifi = new QPushButton("Modifier");
- modifi->setMaximumWidth(150);
- connect(modifi, SIGNAL(clicked()), this, SLOT(modCli()));
- int c = 1;
- int e = 0;
- stringstream val;
- val << c;
- string all = "Alliance" + val.str();
- while(alliance->contains(all.c_str()))
- {
- e++;
- c++;
- stringstream val;
- val << c;
- all = "Alliance" + val.str();
- }
- c = 1;
- for(int i = 1 ; i <= e; i++)
- {
- stringstream val;
- val << i;
- all = "Alliance" + val.str();
- if(alliance->value(all.c_str()) == cUser->text())
- break;
- if(i == e)
- {
- QMessageBox::critical(this,"Attention!", cUser->text() + " ne fait pas partit des alliances en librairie.");
- return;
- }
- c++;
- }
- QHBoxLayout *base1 = new QHBoxLayout;
- QWidget *fenetre = new QWidget;
- fenetre->setFixedSize(550, 186);
- lWidget = new QListWidget;
- connect(lWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(choixNom(QListWidgetItem *)));
- QFormLayout *lNoms = new QFormLayout;
- lNoms->addRow("Nom des royaumes", lWidget);
- QGroupBox *groupo = new QGroupBox("Royaumes");
- groupo->setLayout(lNoms);
- QFormLayout *lModif = new QFormLayout;
- lModif->addRow("Nom du royaume", rNo);
- lModif->addRow("Coordonné X", rX);
- lModif->addRow("Coordonné Y", rY);
- lModif->addWidget(modifi);
- QGroupBox *reper = new QGroupBox("Caractéristiques du royaume");
- reper->setLayout(lModif);
- base1->addWidget(groupo);
- base1->addWidget(reper);
- for(int i = c * 20 - 19 ; i <= c * 20 ; i++)
- {
- stringstream val;
- val << i;
- all = "Membre" + val.str();
- QListWidgetItem *item = new QListWidgetItem(alliance->value(all.c_str()).toString(), lWidget);
- }
- fenetre->setLayout(base1);
- fenetre->show();
- }
- void FenPrinc::choixNom(QListWidgetItem *item)
- {
- rowName = lWidget->row(item);
- int l = 1;
- stringstream check;
- check << l;
- string alli = "Alliance" + check.str();
- while(alliance->value(alli.c_str()) != cUser->text())
- {
- l++;
- stringstream check;
- check << l;
- alli = "Alliance" + check.str();
- }
- w = l * 20 - 19 + rowName;
- stringstream chec;
- chec << w;
- string mem = "Membre" + chec.str();
- string rx = "x" + chec.str();
- string ry = "y" + chec.str();
- rNo->setText(alliance->value(mem.c_str()).toString());
- rX->setValue(alliance->value(rx.c_str()).toInt());
- rY->setValue(alliance->value(ry.c_str()).toInt());
- pOint = new QListWidgetItem;
- pOint = item;
- }
- void FenPrinc::modCli()
- {
- stringstream check;
- check << w;
- string mem = "Membre" + check.str();
- string rx = "x" + check.str();
- string ry = "y" + check.str();
- if(rNo->text() == "")
- {
- alliance->setValue(mem.c_str(), "Emplacement vide");
- alliance->setValue(rx.c_str(), 0);
- alliance->setValue(ry.c_str(), 0);
- pOint->setText("Emplacement vide");
- return;
- }
- alliance->setValue(mem.c_str(), rNo->text());
- alliance->setValue(rx.c_str(), rX->value());
- alliance->setValue(ry.c_str(), rY->value());
- pOint->setText(rNo->text());
- }
Add Comment
Please, Sign In to add comment