void testSetEndPosition_Seek_Reverse(bool unique, bool inclusive) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, {key2, loc1}, // No key3 {key4, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key2, inclusive); // Directly seeking past end is considered out of range. ASSERT_EQ(cursor->seek(key1, true), boost::none); ASSERT_EQ(cursor->seekExact(key1), boost::none); // Seeking to key2 directly or indirectly is only returned if endPosition is inclusive. auto maybeKey2 = inclusive ? boost::make_optional(IndexKeyEntry(key2, loc1)) : boost::none; // direct ASSERT_EQ(cursor->seek(key2, true), maybeKey2); ASSERT_EQ(cursor->seekExact(key2), maybeKey2); // indirect ASSERT_EQ(cursor->seek(key3, true), maybeKey2); cursor->saveUnpositioned(); removeFromIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(); ASSERT_EQ(cursor->seek(key3, true), boost::none); ASSERT_EQ(cursor->seek(key2, true), boost::none); }
void testSetEndPosition_Next_Reverse(bool unique, bool inclusive) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( unique, { {key1, loc1}, {key2, loc1}, {key3, loc1}, {key4, loc1}, {key5, loc1}, }); // Dup key on end point. Illegal for unique indexes. if (!unique) insertToIndex(opCtx, sorted, {{key3, loc2}}); auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key3, inclusive); ASSERT_EQ(cursor->seek(key5, true), IndexKeyEntry(key5, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key4, loc1)); if (inclusive) { if (!unique) ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc2)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); } ASSERT_EQ(cursor->next(), boost::none); ASSERT_EQ(cursor->next(), boost::none); // don't resurrect. }
void ChoosePositionPushButton::mousePressEvent(QMouseEvent *event) { QPushButton::mousePressEvent(event); mSearching = true; update(); #ifdef Q_WS_X11 if(mMainWindow) mMainWindow->showMinimized(); #endif #ifdef Q_WS_WIN foreach(QWidget *widget, qApp->topLevelWidgets()) widget->setWindowOpacity(0.0f); #endif QCursor newCursor(*mCrossIcon); emit chooseStarted(); #ifdef Q_WS_WIN mPreviousCursor = SetCursor(newCursor.handle()); #endif #ifdef Q_WS_X11 nativeEventFilteringApp->installNativeEventFilter(this); if(XGrabPointer(QX11Info::display(), DefaultRootWindow(QX11Info::display()), True, ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, newCursor.handle(), CurrentTime) != GrabSuccess) { QMessageBox::warning(this, tr("Choose a window"), tr("Unable to grab the pointer.")); event->ignore(); } #endif }
void testSetEndPosition_RestoreEndCursor_Reverse(bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, {key4, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key3, true); ASSERT_EQ(cursor->seek(key4, true), IndexKeyEntry(key4, loc1)); cursor->saveUnpositioned(); insertToIndex(opCtx, sorted, { {key2, loc1}, // in range {key3, loc1}, // out of range }); cursor->restore(); // must restore end cursor even with saveUnpositioned(). ASSERT_EQ(cursor->seek(key4, true), IndexKeyEntry(key4, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); ASSERT_EQ(cursor->next(), boost::none); }
void testSetEndPosition_Restore_Reverse(bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface( unique, { {key1, loc1}, {key2, loc1}, {key3, loc1}, {key4, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(key2, false); // Should never see key1 or key2. ASSERT_EQ(cursor->seek(key4, true), IndexKeyEntry(key4, loc1)); cursor->save(); cursor->restore(); ASSERT_EQ(cursor->next(), IndexKeyEntry(key3, loc1)); cursor->save(); removeFromIndex(opCtx, sorted, { {key2, loc1}, {key3, loc1}, }); cursor->restore(); ASSERT_EQ(cursor->next(), boost::none); }
void newHand( Hand * p) { if(p->population > 1) { nonorphan.insert(p->id); newCursor(p); } }
void newHand(Hand * p) { if(p->population == 1) { hands[p->id]=p; newCursor(p); } }
void QWindowsOleDropSource::createCursors() { const QDrag *drag = m_drag->currentDrag(); const QPixmap pixmap = drag->pixmap(); const bool hasPixmap = !pixmap.isNull(); QList<Qt::DropAction> actions; actions << Qt::MoveAction << Qt::CopyAction << Qt::LinkAction; if (hasPixmap) actions << Qt::IgnoreAction; const QPoint hotSpot = drag->hotSpot(); for (int cnum = 0; cnum < actions.size(); ++cnum) { const Qt::DropAction action = actions.at(cnum); QPixmap cpm = drag->dragCursor(action); if (cpm.isNull()) cpm = m_drag->defaultCursor(action); if (cpm.isNull()) { qWarning("%s: Unable to obtain drag cursor for %d.", __FUNCTION__, action); continue; } int w = cpm.width(); int h = cpm.height(); if (hasPixmap) { const int x1 = qMin(-hotSpot.x(), 0); const int x2 = qMax(pixmap.width() - hotSpot.x(), cpm.width()); const int y1 = qMin(-hotSpot.y(), 0); const int y2 = qMax(pixmap.height() - hotSpot.y(), cpm.height()); w = x2 - x1 + 1; h = y2 - y1 + 1; } const QPoint newHotSpot = hotSpot; QPixmap newCursor(w, h); if (hasPixmap) { newCursor.fill(Qt::transparent); QPainter p(&newCursor); const QRect srcRect = pixmap.rect(); const QPoint pmDest = QPoint(qMax(0, -hotSpot.x()), qMax(0, -hotSpot.y())); p.drawPixmap(pmDest, pixmap, srcRect); p.drawPixmap(qMax(0,newHotSpot.x()),qMax(0,newHotSpot.y()),cpm); } else { newCursor = cpm; } const int hotX = hasPixmap ? qMax(0,newHotSpot.x()) : 0; const int hotY = hasPixmap ? qMax(0,newHotSpot.y()) : 0; if (const HCURSOR sysCursor = QWindowsCursor::createPixmapCursor(newCursor, hotX, hotY)) m_cursors.insert(actions.at(cnum), sysCursor); } if (QWindowsContext::verboseOLE) qDebug("%s %d cursors", __FUNCTION__, m_cursors.size()); }
Status RocksSortedDataImpl::dupKeyCheck(OperationContext* txn, const BSONObj& key, const DiskLoc& loc) { boost::scoped_ptr<SortedDataInterface::Cursor> cursor(newCursor(txn, 1)); cursor->locate(key, DiskLoc(0, 0)); if (cursor->isEOF() || cursor->getKey() != key || cursor->getDiskLoc() == loc) { return Status::OK(); } else { return Status(ErrorCodes::DuplicateKey, dupKeyError(key)); } }
void ChoosePositionPushButton::mousePressEvent(QMouseEvent *event) { QPushButton::mousePressEvent(event); mSearching = true; update(); #ifdef Q_OS_UNIX mShownWindows.clear(); for(QWidget *widget: qApp->topLevelWidgets()) { if(mMainWindow == widget) continue; if(widget->isVisible() && !widget->windowTitle().isEmpty()) { mShownWindows.append(widget); XUnmapWindow(QX11Info::display(), widget->winId()); } } if(mMainWindow) mMainWindow->hide(); #endif #ifdef Q_OS_WIN for(QWidget *widget: qApp->topLevelWidgets()) widget->setWindowOpacity(0.0f); #endif QCursor newCursor(*mCrossIcon); emit chooseStarted(); #ifdef Q_OS_WIN mPreviousCursor = SetCursor(LoadCursor(0, IDC_CROSS)); #endif #ifdef Q_OS_UNIX QCoreApplication::instance()->installNativeEventFilter(this); if(XGrabPointer(QX11Info::display(), DefaultRootWindow(QX11Info::display()), True, ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, mCrossCursor, CurrentTime) != GrabSuccess) { QMessageBox::warning(this, tr("Choose a window"), tr("Unable to grab the pointer.")); event->ignore(); } #endif }
void CanvasWidget::handleGameResumed() { // give feedback pauseOverlay.hide(); // move the mouse cursor to where the bar is handleResetMousePosition(); QCursor newCursor(Qt::BlankCursor); newCursor.setPos(cursor().pos()); grabMouse(newCursor); updateBarTimer.start(); }
void testSetEndPosition_Empty_Reverse(bool unique, bool inclusive) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, {key2, loc1}, {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), false); cursor->setEndPosition(BSONObj(), inclusive); ASSERT_EQ(cursor->seek(key3, true), IndexKeyEntry(key3, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc1)); ASSERT_EQ(cursor->next(), boost::none); }
void updateHand( Hand * p) { if((p->population <=1) && (nonorphan.find(p->id) != nonorphan.end())) { nonorphan.erase(p->id); removeCursor(p); } else if((p->population > 1) && (nonorphan.find(p->id) == nonorphan.end())) { nonorphan.insert(p->id); newCursor(p); } else if(nonorphan.find(p->id) != nonorphan.end()) { updateCursor(p); } }
// Tests seekExact when it doesn't hit the query. void testSeekExact_Miss(bool unique, bool forward) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, // No key2. {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), forward); ASSERT_EQ(cursor->seekExact(key2), boost::none); // Not testing iteration since the cursors position following a failed seekExact is // undefined. However, you must be able to seek somewhere else. ASSERT_EQ(cursor->seekExact(key1), IndexKeyEntry(key1, loc1)); }
// Tests seekExact on reverse cursor when it hits something with dup keys. Doesn't make sense // for unique indexes. TEST(SortedDataInterface, SeekExact_HitWithDups_Reverse) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(false, { {key1, loc1}, {key2, loc1}, {key2, loc2}, {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), false); ASSERT_EQ(cursor->seekExact(key2), IndexKeyEntry(key2, loc2)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc1)); ASSERT_EQ(cursor->next(), boost::none); }
// Tests seekExact when it hits something. void testSeekExact_Hit(bool unique, bool forward) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, {key2, loc1}, {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), forward); ASSERT_EQ(cursor->seekExact(key2), IndexKeyEntry(key2, loc1)); // Make sure iterating works. We may consider loosening this requirement if it is a hardship // for some storage engines. ASSERT_EQ(cursor->next(), IndexKeyEntry(forward ? key3 : key1, loc1)); ASSERT_EQ(cursor->next(), boost::none); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTextEdit *editor = new QTextEdit(); QTextCursor cursor(editor->textCursor()); cursor.movePosition(QTextCursor::Start); QTextCharFormat plainFormat(cursor.charFormat()); QTextCharFormat colorFormat = plainFormat; colorFormat.setForeground(Qt::red); cursor.insertText(tr("Text can be displayed in a variety of " "different character " "formats. "), plainFormat); cursor.insertText(tr("We can emphasize text by making it ")); cursor.insertText(tr("italic, give it a different color ")); cursor.insertText(tr("to the default text color, underline it, ")); cursor.insertText(tr("and use many other effects.")); QString searchString = tr("text"); QTextDocument *document = editor->document(); //! [0] QTextCursor newCursor(document); while (!newCursor.isNull() && !newCursor.atEnd()) { newCursor = document->find(searchString, newCursor); if (!newCursor.isNull()) { newCursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor); newCursor.mergeCharFormat(colorFormat); } //! [0] //! [1] } //! [1] editor->setWindowTitle(tr("Text Document Find")); editor->resize(320, 480); editor->show(); return app.exec(); }
// Ensure that restore lands as close as possible to original position, even if data inserted // while saved. void testSaveAndRestorePositionSeesNewInserts(bool forward, bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), forward); const auto seekPoint = forward ? key1 : key3; ASSERT_EQ(cursor->seek(seekPoint, true), IndexKeyEntry(seekPoint, loc1)); cursor->savePositioned(); insertToIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); }
void ChooseWindowPushButton::startMouseCapture() { mSearching = true; update(); mLastFoundWindow.setInvalid(); QCursor newCursor(*mCrossIcon); #ifdef Q_WS_WIN mPreviousCursor = SetCursor(newCursor.handle()); #endif #ifdef Q_WS_X11 if(XGrabPointer(QX11Info::display(), DefaultRootWindow(QX11Info::display()), True, ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, newCursor.handle(), CurrentTime) != GrabSuccess) { QMessageBox::warning(this, tr("Choose a window"), tr("Unable to grab the pointer.")); mSearching = false; } #endif }
KoShape *KPrPlaceholderTextStrategy::createShape(KoDocumentResourceManager *documentResources) { KoShape * shape = KPrPlaceholderStrategy::createShape(documentResources); if ( m_textShape ) { KoTextShapeData * data = qobject_cast<KoTextShapeData*>( m_textShape->userData() ); KoTextShapeData * newData = qobject_cast<KoTextShapeData*>( shape->userData() ); if ( data && newData ) { QTextCursor cursor( data->document() ); QTextCursor newCursor( newData->document() ); KoTextDocument textDocument( newData->document() ); QTextBlockFormat blockFormat( cursor.blockFormat() ); newCursor.setBlockFormat( blockFormat ); QTextCharFormat chatFormat( cursor.blockCharFormat() ); newCursor.setBlockCharFormat( chatFormat ); } } return shape; }
// Make sure we restore to a RecordId at or ahead of save point if same key on reverse cursor. void testSaveAndRestorePositionConsidersRecordId_Reverse(bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key0, loc1}, {key1, loc1}, {key2, loc2}, }); auto cursor = sorted->newCursor(opCtx.get(), false); ASSERT_EQ(cursor->seek(key2, true), IndexKeyEntry(key2, loc2)); cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key2, loc2}}); insertToIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key2, loc1}}); insertToIndex(opCtx, sorted, {{key2, loc2}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(key1, loc1)); cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key1, loc1}}); cursor->restore(opCtx.get()); cursor->savePositioned(); insertToIndex(opCtx, sorted, {{key1, loc1}}); cursor->restore(opCtx.get()); // Lands at same point as initial save. // Advances from restore point since restore didn't move position. ASSERT_EQ(cursor->next(), IndexKeyEntry(key0, loc1)); }
// Ensure that SaveUnpositioned allows later use of the cursor. TEST(SortedDataInterface, SaveUnpositionedAndRestore) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(false, { {key1, loc1}, {key2, loc1}, {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get()); ASSERT_EQ(cursor->seek(key2, true), IndexKeyEntry(key2, loc1)); cursor->saveUnpositioned(); removeFromIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); cursor->saveUnpositioned(); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->seek(key3, true), IndexKeyEntry(key3, loc1)); }
// Ensure that repeated restores lands as close as possible to original position, even if data // inserted while saved and the current position removed. void testSaveAndRestorePositionSeesNewInsertsAfterRemove(bool forward, bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(unique, { {key1, loc1}, {key3, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), forward); const auto seekPoint = forward ? key1 : key3; ASSERT_EQ(cursor->seek(seekPoint, true), IndexKeyEntry(seekPoint, loc1)); cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key1, loc1}}); cursor->restore(opCtx.get()); // The restore may have seeked since it can't return to the saved position. cursor->savePositioned(); // Should still save originally saved key as "current position". insertToIndex(opCtx, sorted, {{key2, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(key2, loc1)); }
// Ensure that repeated restores lands as close as possible to original position, even if data // inserted while saved and the current position removed in a way that temporarily makes the // cursor EOF. void testSaveAndRestorePositionSeesNewInsertsAfterEOF(bool forward, bool unique) { auto harnessHelper = newHarnessHelper(); auto opCtx = harnessHelper->newOperationContext(); auto sorted = harnessHelper->newSortedDataInterface(false, { {key1, loc1}, }); auto cursor = sorted->newCursor(opCtx.get(), forward); ASSERT_EQ(cursor->seek(key1, true), IndexKeyEntry(key1, loc1)); // next() would return EOF now. cursor->savePositioned(); removeFromIndex(opCtx, sorted, {{key1, loc1}}); cursor->restore(opCtx.get()); // The restore may have seeked to EOF. auto insertPoint = forward ? key2 : key0; cursor->savePositioned(); // Should still save key1 as "current position". insertToIndex(opCtx, sorted, {{insertPoint, loc1}}); cursor->restore(opCtx.get()); ASSERT_EQ(cursor->next(), IndexKeyEntry(insertPoint, loc1)); }
void QWindowsOleDropSource::createCursors() { const QDrag *drag = m_drag->currentDrag(); const QPixmap pixmap = drag->pixmap(); const bool hasPixmap = !pixmap.isNull(); // Find screen for drag. Could be obtained from QDrag::source(), but that might be a QWidget. const QPlatformScreen *platformScreen = QWindowsContext::instance()->screenManager().screenAtDp(QWindowsCursor::mousePosition()); if (!platformScreen) { if (const QScreen *primaryScreen = QGuiApplication::primaryScreen()) platformScreen = primaryScreen->handle(); } Q_ASSERT(platformScreen); QPlatformCursor *platformCursor = platformScreen->cursor(); qreal pixmapScaleFactor = 1; qreal hotSpotScaleFactor = 1; if (m_mode != TouchDrag) { // Touch drag: pixmap is shown in a separate QWindow, which will be scaled.) hotSpotScaleFactor = QHighDpiScaling::factor(platformScreen); pixmapScaleFactor = hotSpotScaleFactor / pixmap.devicePixelRatio(); } QPixmap scaledPixmap = qFuzzyCompare(pixmapScaleFactor, 1.0) ? pixmap : pixmap.scaled((QSizeF(pixmap.size()) * pixmapScaleFactor).toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation); scaledPixmap.setDevicePixelRatio(1); Qt::DropAction actions[] = { Qt::MoveAction, Qt::CopyAction, Qt::LinkAction, Qt::IgnoreAction }; int actionCount = int(sizeof(actions) / sizeof(actions[0])); if (!hasPixmap) --actionCount; // No Qt::IgnoreAction unless pixmap const QPoint hotSpot = qFuzzyCompare(hotSpotScaleFactor, 1.0) ? drag->hotSpot() : (QPointF(drag->hotSpot()) * hotSpotScaleFactor).toPoint(); for (int cnum = 0; cnum < actionCount; ++cnum) { const Qt::DropAction action = actions[cnum]; QPixmap cursorPixmap = drag->dragCursor(action); if (cursorPixmap.isNull() && platformCursor) cursorPixmap = static_cast<QWindowsCursor *>(platformCursor)->dragDefaultCursor(action); const qint64 cacheKey = cursorPixmap.cacheKey(); const auto it = m_cursors.find(action); if (it != m_cursors.end() && it.value().cacheKey == cacheKey) continue; if (cursorPixmap.isNull()) { qWarning("%s: Unable to obtain drag cursor for %d.", __FUNCTION__, action); continue; } QPoint newHotSpot(0, 0); QPixmap newPixmap = cursorPixmap; if (hasPixmap) { const int x1 = qMin(-hotSpot.x(), 0); const int x2 = qMax(scaledPixmap.width() - hotSpot.x(), cursorPixmap.width()); const int y1 = qMin(-hotSpot.y(), 0); const int y2 = qMax(scaledPixmap.height() - hotSpot.y(), cursorPixmap.height()); QPixmap newCursor(x2 - x1 + 1, y2 - y1 + 1); newCursor.fill(Qt::transparent); QPainter p(&newCursor); const QPoint pmDest = QPoint(qMax(0, -hotSpot.x()), qMax(0, -hotSpot.y())); p.drawPixmap(pmDest, scaledPixmap); p.drawPixmap(qMax(0, hotSpot.x()),qMax(0, hotSpot.y()), cursorPixmap); newPixmap = newCursor; newHotSpot = QPoint(qMax(0, hotSpot.x()), qMax(0, hotSpot.y())); } if (const HCURSOR sysCursor = QWindowsCursor::createPixmapCursor(newPixmap, newHotSpot)) { const CursorEntry entry(newPixmap, cacheKey, CursorHandlePtr(new CursorHandle(sysCursor)), newHotSpot); if (it == m_cursors.end()) m_cursors.insert(action, entry); else it.value() = entry; } } #ifndef QT_NO_DEBUG_OUTPUT if (lcQpaMime().isDebugEnabled()) qCDebug(lcQpaMime) << __FUNCTION__ << "pixmap" << pixmap.size() << m_cursors.size() << "cursors:\n" << m_cursors; #endif // !QT_NO_DEBUG_OUTPUT }
bool SqliteDriver::alterTable(const QString &mtd1, const QString &mtd2, const QString &key) { #ifndef FL_QUICK_CLIENT FLTableMetaData *oldMTD = 0; FLTableMetaData *newMTD = 0; QDomDocument doc("doc"); QDomElement docElem; if (!FLUtil::domDocumentSetContent(doc, mtd1)) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Error al cargar los metadatos.")); #endif } else { docElem = doc.documentElement(); oldMTD = db_->manager()->metadata(&docElem, true); } if (oldMTD && oldMTD->isQuery()) return true; if (!FLUtil::domDocumentSetContent(doc, mtd2)) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Error al cargar los metadatos.")); #endif return false; } else { docElem = doc.documentElement(); newMTD = db_->manager()->metadata(&docElem, true); } if (!oldMTD) oldMTD = newMTD; if (oldMTD->name() != newMTD->name()) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Los nombres de las tablas nueva y vieja difieren.")); #endif if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } QString oldPK = oldMTD->primaryKey(), newPK = newMTD->primaryKey(); if (oldPK != newPK) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Los nombres de las claves primarias difieren.")); #endif if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } if (oldMTD->fieldType(oldPK) != newMTD->fieldType(newPK)) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Los tipos de las claves primarias difieren.")); #endif if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } if (db_->manager()->checkMetaData(oldMTD, newMTD)) { if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return true; } if (!db_->manager()->existsTable(oldMTD->name())) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("La tabla %1 antigua de donde importar los registros no existe.").arg(oldMTD->name())); #endif if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } FLTableMetaData::FLFieldMetaDataList *fieldList = oldMTD->fieldList(); FLFieldMetaData *oldField = 0; if (!fieldList) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Los antiguos metadatos no tienen campos.")); #endif if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } QString renameOld = oldMTD->name().left(6) + "alteredtable" + QDateTime::currentDateTime().toString("ddhhssz"); if (!db_->dbAux()) { if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } db_->dbAux() ->transaction(); if (!key.isEmpty() && key.length() == 40) { QSqlCursor c("flfiles", true, db_->dbAux()); c.setForwardOnly(true); QSqlRecord *buffer; c.setFilter("nombre='" + renameOld + ".mtd'"); c.select(); if (!c.next()) { buffer = c.primeInsert(); buffer->setValue("nombre", renameOld + ".mtd"); buffer->setValue("contenido", mtd1); buffer->setValue("sha", key); c.insert(); } } QSqlQuery q(QString::null, db_->dbAux()); if (!q.exec("CREATE TABLE " + renameOld + " AS SELECT * FROM " + oldMTD->name() + ";") || !q.exec("DROP TABLE " + oldMTD->name() + ";")) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("No se ha podido renombrar la tabla antigua.")); #endif db_->dbAux() ->rollback(); if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } if (!db_->manager()->createTable(newMTD)) { db_->dbAux() ->rollback(); if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } QSqlCursor oldCursor(renameOld, true, db_->dbAux()); oldCursor.setMode(QSqlCursor::ReadOnly); QSqlCursor newCursor(newMTD->name(), true, db_->dbAux()); newCursor.setMode(QSqlCursor::Insert); oldCursor.select(); int totalSteps = oldCursor.size(); QProgressDialog progress(QApplication::tr("Reestructurando registros para %1...").arg(newMTD->alias()), 0, totalSteps, qApp->focusWidget(), 0, true); progress.setCaption(QApplication::tr("Tabla modificada")); int step = 0; QSqlRecord *newBuffer; QString sequence; fieldList = newMTD->fieldList(); FLFieldMetaData *newField = 0; if (!fieldList) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Los nuevos metadatos no tienen campos.")); #endif db_->dbAux() ->rollback(); if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } if (fieldList->isEmpty()) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Los nuevos metadatos no tienen campos.")); #endif db_->dbAux() ->rollback(); if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; return false; } QVariant v; bool ok = true; while (oldCursor.next()) { newBuffer = newCursor.primeInsert(); QDictIterator<FLFieldMetaData> it(*fieldList); while ((newField = it.current()) != 0) { ++it; oldField = oldMTD->field(newField->name()); if (!oldField || !oldCursor.field(oldField->name())) { if (!oldField) oldField = newField; v = newField->defaultValue(); v.cast(FLFieldMetaData::flDecodeType(newField->type())); } else { v = oldCursor.value(newField->name()); if ((!oldField->allowNull() || !newField->allowNull()) && (v.isNull() || !v.isValid())) { QVariant defVal(newField->defaultValue()); if (!defVal.isNull() && defVal.isValid()) v = defVal; } if (!v.cast(newBuffer->value(newField->name()).type())) { #ifdef FL_DEBUG qWarning("FLManager::alterTable : " + QApplication::tr("Los tipos del campo %1 no son compatibles. Se introducirá un valor nulo.") .arg(newField->name())); #endif } } if ((!oldField->allowNull() || !newField->allowNull()) && (v.isNull() || !v.isValid())) { switch (oldField->type()) { case QVariant::Int: case FLFieldMetaData::Serial: case QVariant::UInt: case QVariant::Bool: case FLFieldMetaData::Unlock: v = int(0); break; case QVariant::Double: v = double(0.0); break; case QVariant::Time: v = QTime::currentTime(); break; case QVariant::Date: v = QDate::currentDate(); break; default: v = QString("NULL").left(newField->length()); break; } } newBuffer->setValue(newField->name(), v); } if (!newCursor.insert()) { ok = false; break; } progress.setProgress(++step); } progress.setProgress(totalSteps); if ((oldMTD != newMTD) && oldMTD) delete oldMTD; if (newMTD) delete newMTD; if (ok) db_->dbAux() ->commit(); else { db_->dbAux() ->rollback(); return false; } #else return true; #endif //FL_QUICK_CLIENT }
void SocketMultiplexer::serviceThread(void*) { std::vector<IArchNetwork::PollEntry> pfds; IArchNetwork::PollEntry pfd; // service the connections for (;;) { Thread::testCancel(); // wait until there are jobs to handle { Lock lock(m_mutex); while (!(bool)*m_jobsReady) { m_jobsReady->wait(); } } // lock the job list lockJobListLock(); lockJobList(); // collect poll entries if (m_update) { m_update = false; pfds.clear(); pfds.reserve(m_socketJobMap.size()); JobCursor cursor = newCursor(); JobCursor jobCursor = nextCursor(cursor); while (jobCursor != m_socketJobs.end()) { ISocketMultiplexerJob* job = *jobCursor; if (job != NULL) { pfd.m_socket = job->getSocket(); pfd.m_events = 0; if (job->isReadable()) { pfd.m_events |= IArchNetwork::kPOLLIN; } if (job->isWritable()) { pfd.m_events |= IArchNetwork::kPOLLOUT; } pfds.push_back(pfd); } jobCursor = nextCursor(cursor); } deleteCursor(cursor); } int status; try { // check for status if (!pfds.empty()) { status = ARCH->pollSocket(&pfds[0], (int)pfds.size(), -1); } else { status = 0; } } catch (XArchNetwork& e) { LOG((CLOG_WARN "error in socket multiplexer: %s", e.what())); status = 0; } if (status != 0) { // iterate over socket jobs, invoking each and saving the // new job. UInt32 i = 0; JobCursor cursor = newCursor(); JobCursor jobCursor = nextCursor(cursor); while (i < pfds.size() && jobCursor != m_socketJobs.end()) { if (*jobCursor != NULL) { // get poll state unsigned short revents = pfds[i].m_revents; bool read = ((revents & IArchNetwork::kPOLLIN) != 0); bool write = ((revents & IArchNetwork::kPOLLOUT) != 0); bool error = ((revents & (IArchNetwork::kPOLLERR | IArchNetwork::kPOLLNVAL)) != 0); // run job ISocketMultiplexerJob* job = *jobCursor; ISocketMultiplexerJob* newJob = job->run(read, write, error); // save job, if different if (newJob != job) { Lock lock(m_mutex); delete job; *jobCursor = newJob; m_update = true; } ++i; } // next job jobCursor = nextCursor(cursor); } deleteCursor(cursor); } // delete any removed socket jobs for (SocketJobMap::iterator i = m_socketJobMap.begin(); i != m_socketJobMap.end();) { if (*(i->second) == NULL) { m_socketJobMap.erase(i++); m_update = true; } else { ++i; } } // unlock the job list unlockJobList(); } }
std::unique_ptr<SortedDataInterface::Cursor> AbstractIndexAccessMethod::newCursor( OperationContext* opCtx) const { return newCursor(opCtx, true); }