void Gypsy::restart( const QList<KCard*> & cards ) { QList<KCard*> cardList = cards; for ( int round = 0; round < 8; ++round ) addCardForDeal(store[round], cardList.takeLast(), false, store[round]->pos() + QPointF(-2*deck()->cardWidth(),-1.1*deck()->cardHeight())); for ( int round = 0; round < 8; ++round ) addCardForDeal(store[round], cardList.takeLast(), true, store[round]->pos() + QPointF(-3*deck()->cardWidth(),-1.6*deck()->cardHeight())); for ( int round = 0; round < 8; ++round ) addCardForDeal(store[round], cardList.takeLast(), true, store[round]->pos() + QPointF(-4*deck()->cardWidth(),-2.1*deck()->cardHeight())); while ( !cardList.isEmpty() ) { KCard * c = cardList.takeFirst(); c->setPos( talon->pos() ); c->setFaceUp( false ); talon->add( c ); } startDealAnimation(); emit newCardsPossible(true); }
void tst_QList::takeLast() const { QList<QString> list; list << "foo" << "bar" << "baz"; QCOMPARE(list.takeLast(), QLatin1String("baz")); QCOMPARE(list.takeLast(), QLatin1String("bar")); QCOMPARE(list.takeLast(), QLatin1String("foo")); }
int ArchiveExtractor::getFileInfoList(const QString &path, std::vector<ArchiveFileInfo> &list) const { QFile archiveFile(path); // Try to open as ZIP QuaZip zip(&archiveFile); if (zip.open(QuaZip::mdUnzip)) { zip.setFileNameCodec("UTF-8"); QList<QuaZipFileInfo> zipList = zip.getFileInfoList(); while(!zipList.empty()) { const QuaZipFileInfo fi = zipList.takeLast(); list.emplace_back(fi.name, fi.dateTime, fi.uncompressedSize); } zip.close(); if (zip.getZipError() != UNZ_OK) { qWarning("testRead(): zip.close(): %d", zip.getZipError()); return 1; } return 0; } // Try to open as RAR if (ArchiveRar::loadlib()) { if (ArchiveRar::getFileInfoList(path, list) == 0) { return 0; } } return 1; }
// TODO: rename to simplify subpath void karbonSimplifyPath( KoPathShape *path, qreal error ) { if ( path->pointCount() == 0 ) return; removeDuplicates( path ); bool isClosed = path->isClosedSubpath(0); if ( isClosed ) { // insert a copy of the first point at the end KoPathPoint *firstPoint = path->pointByIndex( KoPathPointIndex(0, 0) ); KoPathPointIndex end( 0, path->pointCount() ); path->insertPoint( new KoPathPoint(*firstPoint), end ); } QList<KoSubpath *> subpaths = split( *path ); foreach ( KoSubpath *subpath, subpaths ) subdivide( subpath ); simplifySubpaths( &subpaths, error ); mergeSubpaths( subpaths, path ); while ( ! subpaths.isEmpty() ) { KoSubpath *subpath = subpaths.takeLast(); qDeleteAll( *subpath ); delete subpath; } if ( isClosed ) path->closeMerge(); }
void ArchivingRulesDialog::deleteItem() { _changed = true; saveBtn->setDisabled(false); QList<QTableWidgetItem*> selectedItems = archivingItemsTbl->selectedItems(); QList<int> itemsToRemove; QTableWidgetItem* item; if (selectedItems.size() > 0) { itemsToRemove.clear(); for(int i=0; i<selectedItems.size(); i++) { item = selectedItems.at(i); if(item->column() != 0) continue; itemsToRemove.push_front(item->row()); } qSort(itemsToRemove.begin(), itemsToRemove.end()); for(int i = 0; i < itemsToRemove.size();) archivingItemsTbl->removeRow(itemsToRemove.takeLast()); } }
void TestPointer::multiVal(int count) { QAtomicInt counter; QList<Pointer<PointerClass> > ptrList; QVERIFY(counter == 0); // Create pointer for(int i = 0; i < count; i++) { ptrList.append(Pointer<PointerClass>(new PointerClass(counter))); QVERIFY(ptrList.last() != 0); QVERIFY(counter == i + 1); QVERIFY(ptrList.last()->testFunc()); } // Remove pointer (all but one) for(int i = count - 1; i > 0; i--) { ptrList.removeLast(); QVERIFY(ptrList.last() != 0); QVERIFY(counter == i); QVERIFY(ptrList.last()->testFunc()); } Pointer<PointerClass> ptr(ptrList.takeLast()); ptr = 0; QVERIFY(ptr == 0); QVERIFY(counter == 0); }
void Fortyeight::restart( const QList<KCard*> & cards ) { lastdeal = false; QList<KCard*> cardList = cards; for ( int r = 0; r < 4; ++r ) { for ( int column = 0; column < 8; ++column ) { QPointF initPos = stack[column]->pos() - QPointF( 0, 2 * deck()->cardHeight() ); addCardForDeal( stack[column], cardList.takeLast(), true, initPos ); } } while ( !cardList.isEmpty() ) { KCard * c = cardList.takeFirst(); c->setPos( talon->pos() ); c->setFaceUp( false ); talon->add( c ); } startDealAnimation(); flipCardToPile( talon->topCard(), pile, DURATION_MOVE ); emit newCardsPossible( true ); }
void handle(const ResultRecord &r) override { const Value& stack = r["stack"]; int first = stack[0]["level"].toInt(); QList<KDevelop::FrameStackModel::FrameItem> frames; for (int i = 0; i< stack.size(); ++i) { const Value& frame = stack[i]; KDevelop::FrameStackModel::FrameItem f; f.nr = frame["level"].toInt(); f.name = getFunctionOrAddress(frame); QPair<QString, int> loc = getSource(frame); f.file = QUrl::fromLocalFile(loc.first); f.line = loc.second; frames << f; } bool hasMore = false; if (!frames.isEmpty()) { if (frames.last().nr == m_to+1) { frames.takeLast(); hasMore = true; } } if (first == 0) { model->setFrames(m_thread, frames); } else { model->insertFrames(m_thread, frames); } model->setHasMoreFrames(m_thread, hasMore); }
void HearthstoneLogWatcher::CheckForLogChanges() { QFile file( mPath ); if( !file.open( QIODevice::ReadOnly ) ) { return; } qint64 size = file.size(); if( size < mLastSeekPos ) { DBG( "Log truncation detected. This is OK if game was restarted." ); mLastSeekPos = 0; } else { // Use raw QFile instead of QTextStream // QTextStream uses buffering and seems to skip some lines (see also QTextStream#pos) file.seek( mLastSeekPos ); QByteArray buf = file.readAll(); QList< QByteArray > lines = buf.split('\n'); QByteArray lastLine = lines.takeLast(); for( const QByteArray& line : lines ) { emit LineAdded( QString::fromUtf8( line.trimmed() ) ); } mLastSeekPos = file.pos() - lastLine.size(); } }
void MainWindow::refreshData() { MultimeterAdapter::ReadingsList readings = adapter->getCurrentReadings(); QList<QLabel *> labels = ui->currentReadings->findChildren<QLabel*>("reading"); while(readings.count() > labels.count()) { QLabel *label = new QLabel(); label->setObjectName("reading"); ui->currentReadings->layout()->addWidget(label); labels.append(label); } while(readings.count() < labels.count()) { delete labels.takeLast(); } for (int i = 0; i < labels.count(); i++) { QLabel* label = labels.at(i); label->setText(QString("%1 %2").arg(readings.at(i).second,5,'f',4).arg(SampleSeries::toString(readings.at(i).first))); QPalette palette; palette.setColor(QPalette::WindowText, getColor(readings.at(i).first)); label->setPalette(palette); } ui->plot->replot(); }
void TestPointer::multiRef(int count) { QAtomicInt counter; PointerClass * ptrClass = new PointerClass(counter); QList<Pointer<PointerClass> > ptrList; QVERIFY(counter.fetchAndAddOrdered(0) == 1); // Create pointer for(int i = 0; i < count; i++) { ptrList.append(Pointer<PointerClass>(ptrClass)); QVERIFY(ptrList.last() != 0); QVERIFY(counter.fetchAndAddOrdered(0) == 1); QVERIFY(ptrList.last()->testFunc()); } // Remove pointer (all but one) for(int i = count - 1; i > 0; i--) { ptrList.removeLast(); QVERIFY(ptrList.last() != 0); QVERIFY(counter.fetchAndAddOrdered(0) == 1); QVERIFY(ptrList.last()->testFunc()); } Pointer<PointerClass> ptr(ptrList.takeLast()); ptr = 0; QVERIFY(ptr == 0); QVERIFY(counter.fetchAndAddOrdered(0) == 0); }
void MapView::getTilesInView() { if (MapSource.id == None) return; QRectF viewRect = mapToScene(0,0,width(),height()).boundingRect(); QList<QPoint> XYTileList = getXYTileInRange(currentZoom, getLongFromMercatorX(viewRect.x()+viewRect.width()), getLongFromMercatorX(viewRect.x()), getLatFromMercatorY(viewRect.y()), getLatFromMercatorY(viewRect.y()+viewRect.height()) ); QPoint p1 = XYTileList.first(); QPoint p2 = XYTileList.last(); QPointF center = QPointF( (p2.x()+p1.x()) / 2. , (p1.y()+p2.y()) / 2. ); //sorts list so that points closest to center are loaded first QMap<qreal, QPoint> map; for(int i=0;i<XYTileList.size();++i) map.insertMulti(lengthSquared((XYTileList.at(i))-center),XYTileList.at(i)); XYTileList = map.values(); QPoint p; while(XYTileList.size()>0) { if (currentRequests.count()<requestLimit) p = XYTileList.takeFirst(); else p = XYTileList.takeLast(); if (!tilePlaced(p,currentZoom)) getTile(p.x(),p.y(),currentZoom); } qDebug("Number of items in scene: "+QString::number(scene()->items().count())); }
void KNMusicTreeViewBase::removeSelections() { //Check is the current playing item is in the selection. if(KNMusicGlobal::nowPlaying()->playingModel()!=nullptr && KNMusicGlobal::nowPlaying()->playingModel()->sourceModel()== m_proxyModel->sourceModel()) { //Get the current playing index first. QModelIndex currentPlayingIndex= m_proxyModel->mapFromSource(KNMusicGlobal::nowPlaying()->currentPlayingIndex()); //Check is the playing index is in the selection. if(selectionModel()->selectedIndexes().contains(currentPlayingIndex)) { //If so, ask now playing to reset current playing. KNMusicGlobal::nowPlaying()->resetCurrentPlaying(); } } //Get the current indexes. QModelIndexList selectionList=selectionModel()->selectedRows(m_proxyModel->playingItemColumn()); //Change the model index list to persistent index. QList<QPersistentModelIndex> persistentList; while(!selectionList.isEmpty()) { persistentList.append(m_proxyModel->mapToSource(selectionList.takeLast())); } //Remove all the indexes. while(!persistentList.isEmpty()) { QPersistentModelIndex currentRemovedIndex=persistentList.takeLast(); if(currentRemovedIndex.isValid()) { m_proxyModel->removeSourceMusicRow(currentRemovedIndex.row()); } } }
void putConnection(HttpConnection* connection) { while (reservedConnections.size() >= MaximumReserveCount) delete reservedConnections.takeLast(); reservedConnections.append(connection); }
HttpConnection* takeConnection() { if (reservedConnections.isEmpty()) return createConnection(); else return reservedConnections.takeLast(); }
void KRunnerModel::matchesChanged(const QList< Plasma::QueryMatch > & m) { QList< Plasma::QueryMatch > matches = m; qSort(matches.begin(), matches.end()); clear(); while (matches.size()) { Plasma::QueryMatch match = matches.takeLast(); appendRow( StandardItemFactory::createItem( match.icon(), match.text(), match.subtext(), QString("krunner://") + match.runner()->id() + "/" + ::runnerManager()->query() + "#" + match.id(), match.relevance(), CommonModel::AddAction ) ); } sort(0, Qt::DescendingOrder); }
void pie_FreeShaders() { while (shaderProgram.size() > SHADER_MAX) { SHADER_PROGRAM program = shaderProgram.takeLast(); glDeleteShader(program.program); } }
void BoardPixmaps::clearPix() { QList<QPixmap *> values = scaledPixmap.values(); while (!values.isEmpty()) { delete values.takeLast(); } scaledPixmap.clear(); }
void BarDescriptorEditorAssetsWidget::removeAsset(const QString &fullPath) { QList<QStandardItem*> assetItems = m_assetsModel->findItems(fullPath); foreach (QStandardItem *assetItem, assetItems) { QList<QStandardItem*> assetRow = m_assetsModel->takeRow(assetItem->row()); while (!assetRow.isEmpty()) delete assetRow.takeLast(); }
const Name *operator()(const Name *name) { if (! name) return 0; accept(name); return temps.takeLast(); }
int main () { QList<QString> list; list << "A" << "B" << "C" << "D" << "E" << "F"; assert(list.takeLast() == "F"); assert(list.size() == 5); return 0; }
QList<QByteArray> LIRC::GetCodes(void) { QList<QByteArray> ret; ssize_t len = -1; uint buf_size = buf.size() + 128; buf.resize(buf_size); while (true) { len = read(d->m_lircState->lirc_lircd, buf.data() + buf_offset, 128); if (len >= 0) break; switch (errno) { case EINTR: continue; case EAGAIN: return ret; case ENOTCONN: // 107 (according to asm-generic/errno.h) if (!eofCount) LOG(VB_GENERAL, LOG_NOTICE, LOC + "GetCodes -- EOF?"); eofCount++; return ret; default: LOG(VB_GENERAL, LOG_ERR, LOC + "Could not read socket" + ENO); return ret; } } if (!len) { if (!eofCount) LOG(VB_GENERAL, LOG_NOTICE, LOC + "GetCodes -- eof?"); eofCount++; return ret; } eofCount = 0; retryCount = 0; buf_offset += len; buf.truncate(buf_offset); ret = buf.split('\n'); if (buf.endsWith('\n')) { buf_offset = 0; return ret; } buf = ret.takeLast(); buf_offset = buf.size(); return ret; }
/** * Creates and removes handle instances as necessary to adapt to a new object * selection. */ void EditPolygonTool::updateHandles() { const QSet<MapObjectItem*> &selection = mapScene()->selectedObjectItems(); // First destroy the handles for objects that are no longer selected QMutableMapIterator<MapObjectItem*, QList<PointHandle*> > i(mHandles); while (i.hasNext()) { i.next(); if (!selection.contains(i.key())) { const auto &handles = i.value(); for (PointHandle *handle : handles) { if (handle->isSelected()) mSelectedHandles.remove(handle); delete handle; } i.remove(); } } MapRenderer *renderer = mapDocument()->renderer(); for (MapObjectItem *item : selection) { const MapObject *object = item->mapObject(); if (!object->cell().isEmpty()) continue; QPolygonF polygon = object->polygon(); polygon.translate(object->position()); QList<PointHandle*> pointHandles = mHandles.value(item); // Create missing handles while (pointHandles.size() < polygon.size()) { PointHandle *handle = new PointHandle(item, pointHandles.size()); pointHandles.append(handle); mapScene()->addItem(handle); } // Remove superfluous handles while (pointHandles.size() > polygon.size()) { PointHandle *handle = pointHandles.takeLast(); if (handle->isSelected()) mSelectedHandles.remove(handle); delete handle; } // Update the position of all handles for (int i = 0; i < pointHandles.size(); ++i) { const QPointF &point = polygon.at(i); const QPointF handlePos = renderer->pixelToScreenCoords(point); const QPointF internalHandlePos = handlePos - item->pos(); pointHandles.at(i)->setPos(item->mapToScene(internalHandlePos)); } mHandles.insert(item, pointHandles); } }
QString QWsServer::composeBadRequestResponse( QList<EWebsocketVersion> versions ) { QString response; response.append( QLatin1String("HTTP/1.1 400 Bad Request\r\n") ); if ( ! versions.isEmpty() ) { QString versionsStr = QString::number( (int)versions.takeLast() ); int i = versions.size(); while ( i-- ) { versionsStr.append( QLatin1String(", ") + QString::number( (int)versions.takeLast() ) ); } response.append( QLatin1String("Sec-WebSocket-Version: ") + versionsStr + QLatin1String("\r\n") ); } return response; }
/*! \brief Update the entries for an item \param itemInfo Info for an item \param data List of legend entry attributes for the item */ void QwtLegend::updateLegend( const QVariant &itemInfo, const QList<QwtLegendData> &data ) { QList<QWidget *> widgetList = legendWidgets( itemInfo ); if ( widgetList.size() != data.size() ) { QLayout *contentsLayout = d_data->view->contentsWidget->layout(); while ( widgetList.size() > data.size() ) { QWidget *w = widgetList.takeLast(); contentsLayout->removeWidget( w ); // updates might be triggered by signals from the legend widget // itself. So we better don't delete it here. w->hide(); w->deleteLater(); } for ( int i = widgetList.size(); i < data.size(); i++ ) { QWidget *widget = createWidget( data[i] ); if ( contentsLayout ) contentsLayout->addWidget( widget ); if ( isVisible() ) { // QLayout does a delayed show, with the effect, that // the size hint will be wrong, when applications // call replot() right after changing the list // of plot items. So we better do the show now. widget->setVisible( true ); } widgetList += widget; } if ( widgetList.isEmpty() ) { d_data->itemMap.remove( itemInfo ); } else { d_data->itemMap.insert( itemInfo, widgetList ); } updateTabOrder(); } for ( int i = 0; i < data.size(); i++ ) updateWidget( widgetList[i], data[i] ); }
void QMtpFolderCollection::Destroy(){ QList<QMtpFolder *> list = folders->values(); Clear(); while(list.count()){ QMtpFolder *item = list.takeLast(); delete item; } }
QVariantMap RmKeysOperation::rmKeys(const QVariantMap &map, const QStringList &removals) { QVariantMap result = map; foreach (const QString &r, removals) { QList<QVariantMap> stack; const QStringList keys = r.split(QLatin1Char('/')); // Set up a stack of QVariantMaps along the path we take: stack.append(result); for (int i = 0; i < keys.count() - 1; ++i) { QVariantMap subMap; if (stack.last().contains(keys.at(i))) { subMap = stack.last().value(keys.at(i)).toMap(); } else { std::cerr << "Warning: Key " << qPrintable(r) << " not found." << std::endl; continue; } stack.append(subMap); } // remove Q_ASSERT(stack.count() == keys.count()); if (!stack.last().contains(keys.last())) { std::cerr << "Warning: Key " << qPrintable(r) << " not found." << std::endl; continue; } stack.last().remove(keys.last()); // Generate new resultset by folding maps back in: QVariantMap foldBack = stack.takeLast(); for (int i = keys.count() - 2; i >= 0; --i) { // skip last key, that is already taken care of const QString k = keys.at(i); QVariantMap current = stack.takeLast(); current.insert(k, foldBack); foldBack = current; } Q_ASSERT(stack.count() == 0); Q_ASSERT(foldBack != map); result = foldBack; }
void Grandf::deal( const QList<KCard*> & cardsToDeal ) { setKeyboardModeActive( false ); QList<KCard*> cards = cardsToDeal; QPointF initPos( 1.4 * 3 * deck()->cardWidth(), 1.2 * deck()->cardHeight() ); int start = 0; int stop = 7-1; int dir = 1; for (int round=0; round < 7; round++) { int i = start; do { if (!cards.isEmpty()) addCardForDeal( store[i], cards.takeLast(), (i == start), initPos ); i += dir; } while ( i != stop + dir); int t = start; start = stop; stop = t+dir; dir = -dir; } int i = 0; while (!cards.isEmpty()) { addCardForDeal( store[i+1], cards.takeLast(), true, initPos ); i = (i+1)%6; } for (int round=0; round < 7; round++) { KCard *c = store[round]->topCard(); if (c) c->setFaceUp(true); } startDealAnimation(); }
QList<Match> SequenceMatcher::get_matching_blocks() { if (!matching_blocks.isEmpty()) return matching_blocks; const int LengthA = a.count(); const int LengthB = b.count(); QList<Offsets> offsets; offsets << Offsets(0, LengthA, 0, LengthB); while (!offsets.isEmpty()) { const Offsets &offset = offsets.takeLast(); const int a_low = offset.a_low; const int a_high = offset.a_high; const int b_low = offset.b_low; const int b_high = offset.b_high; const Match match = find_longest_match(a_low, a_high, b_low, b_high); const int i = match.i; const int j = match.j; const int k = match.size; if (k) { matching_blocks.append(match); if (a_low < i && b_low < j) offsets.append(Offsets(a_low, i, b_low, j)); if (i + k < a_high && j + k < b_high) offsets.append(Offsets(i + k, a_high, j + k, b_high)); } } qSort(matching_blocks.begin(), matching_blocks.end(), matchLessThan); int i1 = 0; int j1 = 0; int k1 = 0; QList<Match> non_adjacent; foreach (const Match match, matching_blocks) { const int i2 = match.i; const int j2 = match.j; const int k2 = match.size; if (i1 + k1 == i2 && j1 + k1 == j2) k1 += k2; else { if (k1) non_adjacent.append(Match(i1, j1, k1)); i1 = i2; j1 = j2; k1 = k2; } } if (k1) non_adjacent.append(Match(i1, j1, k1)); non_adjacent.append(Match(LengthA, LengthB, 0)); matching_blocks = non_adjacent; return matching_blocks; }
UPNPSubscription::~UPNPSubscription() { m_subscriptionLock.lock(); QList<QString> usns = m_subscriptions.keys(); while (!usns.isEmpty()) Unsubscribe(usns.takeLast()); m_subscriptions.clear(); m_subscriptionLock.unlock(); LOG(VB_UPNP, LOG_DEBUG, LOC + "Finished"); }