QSet<Id> Subscription::identifiersWithout(const QMap<Id, int>& others) const { QSet<Id> resultSet; QMapIterator<Id, int> mapIt(_ids); while(mapIt.hasNext()) { mapIt.next(); if(!others.contains(mapIt.key())) resultSet << mapIt.key(); } return resultSet; }
QSet<Id> Subscription::identifiers() const { QSet<Id> resultSet; QMapIterator<Id, int> mapIt(_ids); while(mapIt.hasNext()) { mapIt.next(); resultSet << mapIt.key(); } return resultSet; }
QSet<Id> Subscription::subtractFrom(const QMap<Id, int>& others) const { QSet<Id> resultSet; QMapIterator<Id, int> mapIt(others); while(mapIt.hasNext()) { mapIt.next(); if(!_ids.contains(mapIt.key())) resultSet << mapIt.key(); } return resultSet; }
void TimeBar::mousePressEvent( QMouseEvent * event ) { if (event->y()<=25) { //如果小于25,那么就是移动当前位置 mMoveCurrTime=true; float x=event->x(); x=x/mZoom*1000; setCurrTime(x); mToopTip=QString("CurrTime:%1").arg(x); mToolTipX=event->x()+10; mToolTipY=event->y()+5; repaint(); } else { if (mSelectedTimeLine!=NULL) { return; } //检查是否选中某个TimeLine QMapIterator<int,QVector<TimeLine*>*> mapIt(mTimeLine); while (mapIt.hasNext()) { mapIt.next(); for (QVector<TimeLine*>::const_iterator it=mapIt.value()->begin();it!=mapIt.value()->end();it++) { //计算TimeLine起始位置 float startX=mZoom*((*it)->startTime/1000.0); QRectF rect(startX,28+mapIt.key()*15+mapIt.key()*3,mZoom*((*it)->len()/1000.0),15); if (rect.contains(event->posF())) { mSelectedTimeLine=(*it); break; } } if (mSelectedTimeLine!=NULL) { setCursor(QCursor(Qt::ClosedHandCursor)); mLastX=event->x(); break; } } } }
Subscription::~Subscription() { // TODO: Do I need to clearSearchResults() to avoid leaking memory? // (LFu) You bet: clearSearchResults(); // also remove this Subscription from the index if(_indexed) { MapSessions* ms = MapSessions::getInstance(); QMapIterator<Id, int> mapIt(_ids); while(mapIt.hasNext()) { ms->removeFromIndex(mapIt.next().key(), this); } } }
// This is complex as it tries to do as little as possible when // the move list hasn't changed and is sorted the same way, // so simulations can go as fast as possible. // Nevertheless, TODO clean this up void MoveBox::setMoves(const Quackle::MoveList &moves, const Quackle::Move &selectedMove) { bool resorted = false; if (m_previousMoves.size() == moves.size()) { Quackle::MoveList::const_iterator prevIt = m_previousMoves.begin(); const Quackle::MoveList::const_iterator end = moves.end(); for (Quackle::MoveList::const_iterator it = moves.begin(); it != end; ++it, ++prevIt) { if (!(*prevIt == *it)) { resorted = true; break; } } } else { resorted = true; } bool hasNewItems = false; Quackle::MoveList::const_iterator end(moves.end()); for (Quackle::MoveList::const_iterator it = moves.begin(); it != end; ++it) { QMap<Quackle::Move, QTreeWidgetItem *>::const_iterator mapEnd(m_moveMap.end()); for (QMap<Quackle::Move, QTreeWidgetItem *>::const_iterator mapIt = m_moveMap.begin(); mapIt != mapEnd; ++mapIt) { if (mapIt.key() == *it) { mapIt.value()->setText(WinPercentageColumn, formatWinPercentage((*it).win)); mapIt.value()->setText(EquityColumn, formatValuation((*it).equity)); if (resorted) { m_treeWidget->addTopLevelItem(m_treeWidget->takeTopLevelItem(m_treeWidget->indexOfTopLevelItem(mapIt.value()))); } goto foundFirstPass; } } hasNewItems = true; m_moveMap.insert(*it, createItem(*it)); foundFirstPass: continue; } if (resorted) { for (QMutableMapIterator<Quackle::Move, QTreeWidgetItem *> mapIt(m_moveMap); mapIt.hasNext(); ) { mapIt.next(); for (Quackle::MoveList::const_iterator it = moves.begin(); it != end; ++it) if (mapIt.key() == *it) goto found; delete mapIt.value(); mapIt.remove(); found: continue; } } if (moves.contains(selectedMove) && m_moveMap.contains(selectedMove)) { m_treeWidget->setCurrentItem(m_moveMap.value(selectedMove)); } selectionChanged(); if (hasNewItems) QTimer::singleShot(0, this, SLOT(checkGeometry())); m_previousMoves = moves; m_previousSelection = selectedMove; }
void TimeBar::paintEvent( QPaintEvent * event ) { QPen pen(QColor(0,0,0)); QPen GrayPen(QColor(0,0,0,50)); QBrush bush(QColor(0,0,0,70)); QPainter painter(this); pen.setWidth(1); painter.setPen(pen); painter.setBrush(bush); for(int i=0;i<100;i++) { if (mZoom*i<=event->rect().right()) { //绘制大刻度 painter.drawLine(QPointF(mZoom*i,15),QPointF(mZoom*i,25)); painter.drawText(QPointF(mZoom*i,10),QString("%1.0S").arg(i)); //绘制小刻度 for (int j=1;j<mZoom/MIN_SCALE_SIZE;j++) { painter.drawLine(QPointF(MIN_SCALE_SIZE*j+mZoom*i,20),QPointF(MIN_SCALE_SIZE*j+mZoom*i,25)); } //绘制TimeLine QMapIterator<int,QVector<TimeLine*>*> mapIt(mTimeLine); while (mapIt.hasNext()) { mapIt.next(); for (QVector<TimeLine*>::const_iterator it=mapIt.value()->begin();it!=mapIt.value()->end();it++) { if ((*it)->startTime>=i*1000 && (*it)->startTime<=(i+1)*1000) { //计算TimeLine起始位置 float startX=mZoom*((*it)->startTime/1000.0); painter.drawRoundedRect (QRectF(startX,28+mapIt.key()*15+mapIt.key()*3,mZoom*((*it)->len()/1000.0),15),5,3); } } } //绘制对齐线 painter.setPen(GrayPen); painter.drawLine(QPointF(mZoom*i,15),QPointF(mZoom*i,event->rect().bottom())); painter.setPen(pen); } else { break; } } //绘制当前位置 QPen redPen(QColor(255,0,0,125)); painter.setPen(redPen); painter.setBrush(QBrush(QColor(255,0,0,125))); float startX=mZoom*(mCurrTime/1000.0); painter.drawLine(QPointF(startX,25),QPointF(startX,event->rect().bottom())); painter.drawRect(QRect(startX-3,10,6,15)); //绘制工具提示 if(!mToopTip.isEmpty()) { redPen.setColor(QColor(255,0,0)); painter.setBrush(QBrush(QColor(255,255,255))); painter.setPen(redPen); QFontMetrics fm(painter.font()); painter.drawRect(QRect(mToolTipX-3,mToolTipY-fm.height(),fm.width(mToopTip)+3,fm.height()+6)); painter.drawText(mToolTipX,mToolTipY,mToopTip); } }