void Window::applyChangedSettings() { const Settings& settings = Settings::getInstance(); QList<Settings::PlanetAddress> planets = settings.getPlanets(); //removing planets from planetList that are not presentes in settings //and removing planets in settings that are already presented in the PlanetList for (Planet* p1 : planetList) { int i; bool found = false; for (i = 0; i < planets.size(); i ++) { found = p1->getAddress() == planets.at(i).address && p1->getPort() == planets.at(i).port; if (found) { break; } } if (found) { planets.removeAt(i); } else { removePlanet(p1); delete p1; } } //planets now contains all new planets for (const Settings::PlanetAddress& p2 : planets) { addPlanet(new Planet(p2.address, p2.port)); } const QList<bool>& hideColumn = settings.getHideColumn(); for (int i = 0; i < hideColumn.size(); i ++) { bool wasHidden = planetTreeView->isColumnHidden(i); planetTreeView->setColumnHidden(i, hideColumn.at(i)); if (!hideColumn.at(i) && wasHidden && i != 0) { planetTreeView->resizeColumnToContents(i-1); } } if (settings.getAutoRefresh()) { autoRefreshTimer->start(settings.getAutoRefreshIntervalSec() * 1000); } else { autoRefreshTimer->stop(); } if (!settings.getPullPlayers()) { removeAllPlayers(); } planetTreeProxyModel->invalidate(); }
int removePlanet(Planet * planets, int * numOfPl) { int number,i; putCursor(50, 3); puts("Enter number of planet you want to remove"); putCursor(50, 4); scanf("%d", &number); if (number > *numOfPl || number < 0) { putCursor(120, 3); puts("ERROR, enter correct number of planet"); return removePlanet(planets, numOfPl); } for (i=number;i<=*numOfPl-1;i++) { planets[i-1] = planets[i]; } (*numOfPl)--; return 0; }
int main() { Sleep(1000); char * filename = "saves.bin"; char check[50]; int memSize = 20; int numOfPl = 0; Planet * planets; planets = (Planet *)malloc(memSize*(sizeof(Planet))); memSize++; planets = realloc (planets, memSize*sizeof(Planet)); deserialization(planets, &numOfPl, filename); while(1) { printPlanets(planets, &numOfPl); putCursor(50, 1); puts("Enter your command"); putCursor(50, 2); printf(">>"); scanf("%s", check); if (!strcmp(check, "addPl")) addPlanet(planets, &numOfPl, &memSize); else if (!strcmp(check, "addSp")) addSputnik(planets, &numOfPl); else if (!strcmp(check, "removePl")) removePlanet(planets, &numOfPl); else if (!strcmp(check, "removeSp")) removeSputnik(planets, &numOfPl); else if (!strcmp(check, "changePl")) changePlanet(planets, &numOfPl); else if (!strcmp(check, "changeSp")) changeSputnik(planets, &numOfPl); else if (!strcmp(check, "help")) { putCursor(50, 3); puts("List of commands :"); putCursor(50, 4); puts("addPl - Adding a new planet"); putCursor(50, 5); puts("addPl - Adding a new sputnik"); putCursor(50, 6); puts("removePl - Removing some planet"); putCursor(50, 7); puts("removeSp - Removing some sputnik"); putCursor(50, 8); puts("changePl - Changing parameter of some planet"); putCursor(50, 9); puts("changeSp - Changing parameter of some sputnik"); putCursor(50, 10); puts("exit - Stop the program"); getch(); } else if (!strcmp(check, "exit")) { freeAll(planets, &numOfPl); exit(EXIT_SUCCESS); } else { putCursor(120, 3); puts("ERROR, enter correct command"); } save(planets, &numOfPl, filename); system("cls"); } freeAll(planets, &numOfPl); return 0; }