std::vector<std::vector<SearchParameters> > Controller::runRouteSearch(SearchParameters parameters) { std::vector<std::vector<Path> > result = routeSearcher.searchRoutes(parameters.getStart(), parameters.getFinish(), parameters.toRouteCost()); std::vector<std::vector<SearchParameters> > routes; std::vector<std::vector<Path> >::iterator it; for (it = result.begin(); it != result.end(); it++) { std::vector<Path> current = (*it); std::vector<SearchParameters> route = std::vector<SearchParameters>(); for (std::vector<Path>::iterator iter = current.begin(); iter != current.end(); ++iter) { SearchParameters routeParams; routeParams.setStart(iter->getFrom().getId()); routeParams.setFinish(iter->getTo().getId()); routeParams.setMoney(parameters.getTravellersNumber()*(iter->getRouteCost().getMoneyCost())); routeParams.setTime(iter->getRouteCost().getTimeCost()); std::set<Interest> interests = iter->getRouteCost().getInterests(); std::set<Transport> transports = iter->getRouteCost().getTransport(); for (std::set<Interest>::iterator i = interests.begin(); i != interests.end(); ++i) { routeParams.addInterest(*i); } for (std::set<Transport>::iterator i = transports.begin(); i != transports.end(); ++i) { routeParams.addTransport(*i); } route.emplace_back(routeParams); } routes.emplace_back(route); } return routes; }
void MainWindow::runRouteSearching() { // Собрать всю информацию SearchParameters parameters; parameters.setStart(ui->startList->currentData().toInt()); parameters.setFinish(ui->finishList->currentData().toInt()); parameters.setTravellersNumber(ui->peopleCount->value()); parameters.setTime(ui->timeEdit->time()); if (ui->timeEdit->time() == QTime(0,0)) { QMessageBox::warning(this,"Ошибка в вводе праметров", "Не задано время! Ничего найдено не будет!"); } parameters.setMoney(ui->moneyCount->value()); int count = 0; for (int i = 0; i <= ENTERTAINMENT; i++) { if (interestsModel.item(i)->checkState()) { parameters.addInterest((Interest)i); count++; } } if (count == 0) { QMessageBox::warning(this,"Ошибка в вводе праметров", "Не выбрана ни одна категория интересов!"); } count = 0; for (int i = 0; i <= FOOT; i++) { if (transportModel.item(i)->checkState()) { parameters.addTransport((Transport)i); count++; } } if (count == 0) { QMessageBox::warning(this,"Ошибка в вводе праметров", "Не выбран ни один вид транспорта!"); } std::vector<std::vector<SearchParameters> > routes = controller.runRouteSearch(parameters); fillRoutesList(routes); }