void Astar::addtoopen(int col,int row,int id) { //向open列表中加入点 AstarItem * temp = new AstarItem(); temp->setpos(col,row); temp->setfid(id); int g = getG(col, row, id); int h = getH(col, row); temp->setg(g); temp->seth(h); temp->setf(g + h); open->addObject(temp); resetSort(open->count() - 1); }
void Astar::addToOpen(int col, int row, int id) { CC_ASSERT(_open != nullptr && "the open is nullptr"); AstarItem* temp = AstarItem::create(); temp->setPos(col, row); temp->setFid(id); int g = getG(col, row, id); int h = getH(col, row); temp->setG(g); temp->setH(h); temp->setF(g +h); _open->addObject(temp); resetSort(_open->count() - 1); }
bool Astar::checkOpen(int col,int row,int id) { //检查open列表中是否有更小的步长,并排序 for(int i = open->count() - 1;i > 0;i --){ if(((AstarItem *)open->objectAtIndex(i))->getcol() == col && ((AstarItem *)open->objectAtIndex(i))->getrow() == row){ int tempG = getG(col,row,id); if(tempG < ((AstarItem *)open->objectAtIndex(i))->getg()){ ((AstarItem *)open->objectAtIndex(i))->setg(tempG); ((AstarItem *)open->objectAtIndex(i))->setfid(id); ((AstarItem *)open->objectAtIndex(i))->setf(tempG + ((AstarItem *)open->objectAtIndex(i))->geth()); resetSort(i); } return false; } } return true; }
bool Astar::checkOpen(int col, int row, int id) { // 检查open列表中是否有更小的步长,并排序 for(int i = _open->count() - 1; i > 0; i--) { auto item = (AstarItem*)_open->getObjectAtIndex(i); if(item->getCol() == col && item->getRow() == row) { int tempG = getG(col, row, id); if(tempG < item->getG()) { item->setG(tempG); item->setFid(id); item->setF(tempG + item->getH()); resetSort(i); } return false; } } return true; }
void ResTable::createHeaderPopupMenu(const QPoint& pos) { LOGDEB(("ResTable::createHeaderPopupMenu(%d, %d)\n", pos.x(), pos.y())); QHeaderView *header = tableView->horizontalHeader(); if (!header || !m_model) return; m_popcolumn = header->logicalIndexAt(pos); if (m_popcolumn < 0) return; const map<string, QString>& allfields = m_model->getAllFields(); const vector<string>& fields = m_model->getFields(); QMenu *popup = new QMenu(this); popup->addAction(tr("&Reset sort"), this, SLOT(resetSort())); popup->addSeparator(); popup->addAction(tr("&Save as CSV"), this, SLOT(saveAsCSV())); popup->addSeparator(); popup->addAction(tr("&Delete column"), this, SLOT(deleteColumn())); popup->addSeparator(); QAction *act; for (map<string, QString>::const_iterator it = allfields.begin(); it != allfields.end(); it++) { if (std::find(fields.begin(), fields.end(), it->first) != fields.end()) continue; act = new QAction(tr("Add \"%1\" column").arg(it->second), popup); act->setData(QString::fromUtf8(it->first.c_str())); connect(act, SIGNAL(triggered(bool)), this , SLOT(addColumn())); popup->addAction(act); } popup->popup(mapToGlobal(pos)); }