void ObjectConstraintBallSocket::deserialize(QByteArray serializedArguments) { QDataStream dataStream(serializedArguments); EntityDynamicType type; dataStream >> type; assert(type == getType()); QUuid id; dataStream >> id; assert(id == getID()); uint16_t serializationVersion; dataStream >> serializationVersion; if (serializationVersion != ObjectConstraintBallSocket::constraintVersion) { assert(false); return; } withWriteLock([&] { quint64 serverExpires; dataStream >> serverExpires; _expires = serverTimeToLocalTime(serverExpires); dataStream >> _tag; dataStream >> _pivotInA; dataStream >> _otherID; dataStream >> _pivotInB; _active = true; });
nsresult SendData(const char * aData, nsIStreamListener* aListener, nsIRequest* request) { nsresult rv; nsCOMPtr<nsIStringInputStream> dataStream (do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); rv = dataStream->SetData(aData, strlen(aData)); NS_ENSURE_SUCCESS(rv, rv); uint64_t avail = 0; dataStream->Available(&avail); uint64_t offset = 0; while (avail > 0) { uint32_t count = saturated(avail); rv = aListener->OnDataAvailable(request, nullptr, dataStream, offset, count); if (NS_FAILED(rv)) return rv; offset += count; avail -= count; } return NS_OK; }
void WidgetListing::startDrag( Qt::DropActions /*supportedActions*/ ) { QListWidgetItem *item = currentItem(); QByteArray itemData; QDataStream dataStream( &itemData, QIODevice::WriteOnly ); int i_type = item->data( Qt::UserRole ).toInt(); int i_option = parent->getOptions(); dataStream << i_type << i_option; /* Create a new dragging event */ QDrag *drag = new QDrag( this ); /* With correct mimedata */ QMimeData *mimeData = new QMimeData; mimeData->setData( "vlc/button-bar", itemData ); drag->setMimeData( mimeData ); /* And correct pixmap */ QPixmap aPixmap = item->icon().pixmap( QSize( 22, 22 ) ); drag->setPixmap( aPixmap ); drag->setHotSpot( QPoint( 20, 20 ) ); /* We want to keep a copy */ drag->exec( Qt::CopyAction | Qt::MoveAction ); }
void GPrefsMgr::GetInboxes ( JPtrArray<JString>& inboxes ) { if (IDValid(kGInboxesID)) { std::string data; const JBoolean ok = GetData(kGInboxesID, &data); assert( ok ); std::istringstream dataStream(data); JSize count; dataStream >> count; inboxes.SetCompareFunction(CompareFileNames); for (JIndex i=1; i<=count; i++) { JString* str = new JString; assert( str != NULL ); dataStream >> *str; if (!inboxes.InsertSorted(str, kJFalse)) { delete str; } } } }
void GPrefsMgr::GetUIDList ( JPtrArray<JString>& list ) { if (IDValid(kGUIDListID)) { std::string data; const JBoolean ok = GetData(kGUIDListID, &data); assert( ok ); std::istringstream dataStream(data); JSize count; dataStream >> count; list.SetCompareFunction(JCompareStringsCaseSensitive); for (JIndex i=1; i<=count; i++) { JString* str = new JString; assert( str != NULL ); dataStream >> *str; if (!list.InsertSorted(str, kJFalse)) { delete str; } } } }
void PuzzleWidget::dropEvent(QDropEvent *event) { if (event->mimeData()->hasFormat("image/x-puzzle-piece") && findPiece(targetSquare(event->pos())) == -1) { QByteArray pieceData = event->mimeData()->data("image/x-puzzle-piece"); QDataStream dataStream(&pieceData, QIODevice::ReadOnly); QRect square = targetSquare(event->pos()); QPixmap pixmap; QPoint location; dataStream >> pixmap >> location; pieceLocations.append(location); piecePixmaps.append(pixmap); pieceRects.append(square); highlightedRect = QRect(); update(square); event->setDropAction(Qt::MoveAction); event->accept(); if (location == QPoint(square.x()/pieceSize(), square.y()/pieceSize())) { inPlace++; if (inPlace == 25) emit puzzleCompleted(); } } else {
void load(const std::string& ofileBase) { std::string hashFN = ofileBase + ".bph"; std::string dataFN = ofileBase + ".val"; if ( !FileExists_(hashFN.c_str()) ) { std::cerr << "BooM: Looking for perfect hash function file [" << hashFN << "], which doesn't exist! exiting.\n"; std::exit(1); } if ( !FileExists_(dataFN.c_str()) ) { std::cerr << "BooM: Looking for key-value file [" << dataFN << "], which doesn't exist! exiting.\n"; std::exit(1); } // load the perfect hash function { boophf_.reset(new BooPHFT); std::ifstream is(hashFN, std::ios::binary); boophf_->load(is); is.close(); } // and the values { std::ifstream dataStream(dataFN, std::ios::binary); { cereal::BinaryInputArchive inArchive(dataStream); inArchive(data_); } dataStream.close(); } built_ = true; }
void TASARIM_DESIGN_WIDGET::dropEvent(QDropEvent *event) { if (event->mimeData()->hasFormat("application/x-dnditemdata")) { QByteArray itemData = event->mimeData()->data("application/x-dnditemdata"); QDataStream dataStream(&itemData, QIODevice::ReadOnly); QPoint offset; dataStream >> offset; m_last_move_label->move(event->pos() - offset); SELECT_VARIABLE( m_last_move_label ); SET_LAST_SELECTED_VARIABLE( m_last_move_label ); emit VARIABLE_POSITION_CHANGED( m_last_move_label->objectName().split("\t").at(0).toInt(), m_last_move_label->pos().x(), m_last_move_label->pos().y() ); if (event->source() == this) { event->setDropAction(Qt::MoveAction); event->accept(); } else { event->acceptProposedAction(); } }
void DragLabel::mousePressEvent(QMouseEvent *event) { // if(this->tempo_setup){ //desabilita ação de drag para labels que representarem tempo_setup de maquina // //return; // } // qDebug() << "mousePressEvent called"; dragstart = event->pos(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); //passar variavel tamanho como float zoa o drop dataStream << labelText << tooltip << QPoint(event->pos() - rect().topLeft()) << (int)tamanho << cor.red() << cor.green() << cor.blue() << cor.alpha() << tempo_setup << coordenada; QMimeData *mimeData = new QMimeData; //pra que serve mimeData? mimeData->setData("application/x-fridgemagnet", itemData); mimeData->setText(labelText); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setHotSpot(event->pos() - rect().topLeft()); drag->setPixmap(*pixmap()); hide(); //como funciona drag->exec() ? if(drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction) close(); else show(); }
void DragTool::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { const QMargins margins = contentsMargins(); const QRect iconRect((width() - d->iconSize.width()) / 2, margins.top(), d->iconSize.width(), d->iconSize.height()); if (iconRect.contains(event->pos())) { auto drag = new QDrag(this); auto mimeData = new QMimeData; QByteArray data; QDataStream dataStream(&data, QIODevice::WriteOnly); dataStream << d->newElementId << d->title << d->stereotype; mimeData->setData(QLatin1String(qmt::MIME_TYPE_NEW_MODEL_ELEMENTS), data); drag->setMimeData(mimeData); QPixmap pixmap = d->icon.pixmap(d->iconSize, QIcon::Normal, QIcon::Off); QPainter painter(&pixmap); painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); painter.fillRect(pixmap.rect(), QColor(0, 0, 0, 96)); drag->setPixmap(pixmap); drag->setHotSpot(QPoint(drag->pixmap().width() / 2, drag->pixmap().height() / 2)); d->disableFrame = true; update(); Qt::DropAction dropAction = drag->exec(); Q_UNUSED(dropAction); d->disableFrame = false; update(); } } }
void DragWidgetBin::dropEvent(QDropEvent *event) { if (event->mimeData()->hasFormat("application/x-dnditemdata")) { QByteArray itemData = event->mimeData()->data("application/x-dnditemdata"); QDataStream dataStream(&itemData, QIODevice::ReadOnly); QPixmap pixmap; QPoint offset; dataStream >> pixmap >> offset; if (event->source() == dragwidgetptr) { if (draggedLabel->type == mQLabel::TRACK) { return; } else { dragwidgetptr->labelsInside.erase(draggedLabel); std::vector<mQLabel*> toDelete; for(std::set<mQLabel*>::iterator it = dragwidgetptr->tracksInside.begin(); it !=dragwidgetptr->tracksInside.end(); it++) if((*it)->getConn1() == draggedLabel || (*it)->getConn2() == draggedLabel) { toDelete.push_back(*it); } for(mQLabel *mQL : toDelete) { dragwidgetptr->tracksInside.erase(mQL); mQL->close(); } } draggedLabel->close(); draggedLabel = nullptr; } } else {
void ObjectActionTravelOriented::deserialize(QByteArray serializedArguments) { QDataStream dataStream(serializedArguments); EntityDynamicType type; dataStream >> type; assert(type == getType()); QUuid id; dataStream >> id; assert(id == getID()); uint16_t serializationVersion; dataStream >> serializationVersion; if (serializationVersion != ObjectActionTravelOriented::actionVersion) { assert(false); return; } withWriteLock([&] { dataStream >> _forward; dataStream >> _angularTimeScale; quint64 serverExpires; dataStream >> serverExpires; _expires = serverTimeToLocalTime(serverExpires); dataStream >> _tag; _active = (_forward != glm::vec3()); });
void SerialServer::processData(QByteArray& data) { QDataStream dataStream(&data, QIODevice::ReadOnly); QString fileName; QByteArray fileData; dataStream >> fileName; dataStream >> fileData; if(fileName.isEmpty()) return; QFileInfo fileInfo(fileName); QString projectPath = createProject(fileInfo.baseName()); writeFile(projectPath + "/" + fileName, fileData); QString mainFilePath = projectPath + "/" + fileName; while(dataStream.status() == QDataStream::Ok) { fileName.clear(); fileData.clear(); dataStream >> fileName; dataStream >> fileData; if(!fileName.isEmpty()) { writeFile(projectPath + "/" + fileName, fileData); } } emit downloadFinished(mainFilePath); }
void ClusterSummaryWidget::dropEvent(QDropEvent *event) { std::cout << "dropping elemnents!!" << std::endl; #if 0 event->ignore(); #else if (event->mimeData()->hasFormat("clustering/ImageChar")) { QByteArray pieceData = event->mimeData()->data("clustering/ImageChar"); QDataStream dataStream(&pieceData, QIODevice::ReadOnly); CharClustIt senderIt; quint64 address; dataStream >> address; senderIt = *(CharClustIt *)(address); int nElements; dataStream >> nElements; std::vector<ImageCharIt> iterators; for (int i=0; i<nElements; ++i) { dataStream >> address; ImageCharIt *pIt = (ImageCharIt *) address; iterators.push_back(*pIt); } // move elemnts: // std::cout << "moving elements from " << senderID << " to " << this->mClusterID << std::endl; emit moveToCluster(senderIt, this->mClustIt, iterators); // accept event event->setDropAction(Qt::MoveAction); event->accept(); } // end if accept
void EntityTreeWidget::mouseMoveEvent(QMouseEvent *event) { if (event->buttons() == Qt::LeftButton && (event->pos() - _startDragPos).manhattanLength() >= QApplication::startDragDistance()) { EntityTreeWidgetItem * item = dynamic_cast<EntityTreeWidgetItem *>(currentItem()); if (item&&!item->isDisabled()) { _dragEntity = item; QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); NtgEntityModel entityModel = _entityModelHash.value(item->text(1)); QPixmap pixmap = item->icon(0).pixmap(QSize(24,24)); dataStream << entityModel; QMimeData * mimeData = new QMimeData; mimeData->setData("netglub/x-node-model", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(pixmap); Qt::DropAction dropAction = drag->exec(Qt::CopyAction); Q_UNUSED(dropAction); _dragEntity = NULL; } } }
void PlayerCardListWidget::mousePressEvent(QMouseEvent *event) { PlayerCardWidget *child = static_cast<PlayerCardWidget*>(childAt(event->pos())); if (!child) return; // Float up the hierachy until the PlayerCardWidget is found, or we hit the current widget while ((!child->property("PlayerCardWidget").isValid()) && ((PlayerCardListWidget*)child != this)) { child = static_cast<PlayerCardWidget*>(child->parent()); } // If the child is not a PlayerCardWidget, return if (!child->property("PlayerCardWidget").isValid()) return; QPoint hotSpot = event->pos() - child->pos(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << child->playerNumber() << QPoint(hotSpot); QMimeData *mimeData = new QMimeData; mimeData->setData("application/x-chessplayer", itemData); mimeData->setText(child->player()->name()); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setPixmap(QPixmap::grabWidget(child)); drag->setHotSpot(hotSpot); child->hide(); if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction) child->close(); else child->show(); }
void ObjectActionSpring::deserialize(QByteArray serializedArguments) { QDataStream dataStream(serializedArguments); EntityActionType type; dataStream >> type; assert(type == getType()); QUuid id; dataStream >> id; assert(id == getID()); uint16_t serializationVersion; dataStream >> serializationVersion; if (serializationVersion != ObjectActionSpring::springVersion) { return; } dataStream >> _positionalTarget; dataStream >> _linearTimeScale; dataStream >> _positionalTargetSet; dataStream >> _rotationalTarget; dataStream >> _angularTimeScale; dataStream >> _rotationalTargetSet; _active = true; }
size_t BlockCodeReadStream::LoadBlockTo(uint blockIndex, MemoryStream& output)const { size_t blockCount = mFileEntry->CoderOffsetsCount(); if (blockIndex < blockCount) { uint nextOffset = mFileEntry->CoderOffsets()[blockIndex]; uint prevOffset = 0; if (blockIndex > 0) { prevOffset = mFileEntry->CoderOffsets()[blockIndex - 1]; } mSourceStream->SetPosition(prevOffset); #ifdef MEDUSA_SAFE_CHECK if (nextOffset<=prevOffset) { Log::AssertFailedFormat("Invalid coder offsets:{}->{}", prevOffset, nextOffset); return 0; } #endif size_t size = nextOffset - prevOffset; auto data = mSourceStream->ReadData(size); MemoryStream dataStream(data); return mCoderChain->Decode(dataStream, output); } return 0; }
void LiveDanmuHandler::parseDataToDanmu(QByteArray data) { if (!data.isNull() && !data.isEmpty()) { QDataStream dataStream(&data, QIODevice::ReadOnly); qint64 dataLength = data.length(); if (dataLength < 16) { emit actionPrepared(Intent(Intent::ACTION_LOG_ERROR,"接收到的数据异常")); } else if (dataLength > 16) { int givenLength; dataStream >> givenLength; if (dataLength == givenLength) { short param1, param2; int action, param4; dataStream >> param1 >> param2 >> action >> param4; action -= 1; // qDebug() << action; if (action == 2) { int userCount; dataStream >> userCount; // qDebug() << userCount; emit viewerCountChanged(userCount); }
QMimeData *CollectionItemModel::mimeData(const QModelIndexList &indexes) const { if (indexes.isEmpty()) { return 0; } QModelIndex index = indexes.first(); if (!index.isValid()) { return 0; } if (m_shapeTemplateList.isEmpty()) { return 0; } QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << m_shapeTemplateList[index.row()].id; const KoProperties *props = m_shapeTemplateList[index.row()].properties; if (props) { dataStream << props->store("shapes"); } else { dataStream << QString(); } QMimeData *mimeData = new QMimeData; mimeData->setData(SHAPETEMPLATE_MIMETYPE, itemData); return mimeData; }
void MainWindow::recvMsg() { QTcpSocket * tcpSocket = (QTcpSocket*)sender(); QDataStream dataStream(tcpSocket); QString str; foreach(stUserInfo user,list) { if(user.pTcpSocket == tcpSocket) { // without connect message str = processRecvMsg(tcpSocket); ui->textEdit->append(str); if(str.compare("Exit")==0||str.right(7).compare("SIGN_UP")==0 ) { tcpSocket->close(); } break; } } /* QByteArray arrIDChk(tcpSocket->readAll()); QString strIDChk(arrIDChk.data()); if(strIDChk.compare("김봉상") == 0) { } */ }
bool Foam::tabulated6DoFAcceleration::read ( const dictionary& accelerationCoeffs ) { accelerationCoeffs_ = accelerationCoeffs; // If the timeDataFileName has changed read the file fileName newTimeDataFileName ( fileName(accelerationCoeffs_.lookup("timeDataFileName")).expand() ); if (newTimeDataFileName != timeDataFileName_) { timeDataFileName_ = newTimeDataFileName; IFstream dataStream(timeDataFileName_); if (dataStream.good()) { List<Tuple2<scalar, accelerationVectors>> timeValues ( dataStream ); times_.setSize(timeValues.size()); values_.setSize(timeValues.size()); forAll(timeValues, i) { times_[i] = timeValues[i].first(); values_[i] = timeValues[i].second(); }
JString GPrefsMgr::GetSMTPUser() { if (IDValid(kSMTPUserID)) { std::string data; const JBoolean ok = GetData(kSMTPUserID, &data); assert( ok ); std::istringstream dataStream(data); JString user; dataStream >> user; if (!user.IsEmpty()) { return user; } } JCharacter* name = getenv("LOGNAME"); if (name == NULL) { return JString(); } return JString(name); }
QByteArray ObjectConstraintSlider::serialize() const { QByteArray serializedConstraintArguments; QDataStream dataStream(&serializedConstraintArguments, QIODevice::WriteOnly); dataStream << DYNAMIC_TYPE_SLIDER; dataStream << getID(); dataStream << ObjectConstraintSlider::constraintVersion; withReadLock([&] { dataStream << localTimeToServerTime(_expires); dataStream << _tag; dataStream << _pointInA; dataStream << _axisInA; dataStream << _otherID; dataStream << _pointInB; dataStream << _axisInB; dataStream << _linearLow; dataStream << _linearHigh; dataStream << _angularLow; dataStream << _angularHigh; }); return serializedConstraintArguments; }
void ActorDragTree::startDrag(Qt::DropActions /*supportedActions*/) { ActorTypeTreeWidget *item = dynamic_cast<ActorTypeTreeWidget*>(currentItem()); // Only resource items can be dragged. if (!item || !item->isLeafNode()) { return; } QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); QIcon icon = item->icon(0); QPixmap pixmap = icon.pixmap(16); dtCore::RefPtr<const dtDAL::ActorType> actorType = item->getActorType(); QString category = actorType->GetCategory().c_str(); QString name = actorType->GetName().c_str(); dataStream << category << name; QMimeData *mimeData = new QMimeData; mimeData->setData("Actor", itemData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2)); drag->setPixmap(pixmap); if (drag->exec(Qt::MoveAction) == Qt::MoveAction) { } }
void crobot::dropEvent(QDropEvent *event) { if (event->mimeData()->hasFormat("application/x-dnditemdata")) { QByteArray itemData = event->mimeData()->data("application/x-dnditemdata"); QDataStream dataStream(&itemData, QIODevice::ReadOnly); QPixmap pixmap; QPoint offset; dataStream >> pixmap >> offset; QLabel *newIcon = new QLabel(this); newIcon->setPixmap(pixmap); newIcon->move(event->pos() - offset); newIcon->show(); newIcon->setAttribute(Qt::WA_DeleteOnClose); if (event->source() == this) { event->setDropAction(Qt::MoveAction); event->accept(); } else { event->acceptProposedAction(); } } else {
void ObjectActionOffset::deserialize(QByteArray serializedArguments) { QDataStream dataStream(serializedArguments); EntityActionType type; dataStream >> type; assert(type == getType()); QUuid id; dataStream >> id; assert(id == getID()); uint16_t serializationVersion; dataStream >> serializationVersion; if (serializationVersion != ObjectActionOffset::offsetVersion) { return; } withWriteLock([&] { dataStream >> _pointToOffsetFrom; dataStream >> _linearDistance; dataStream >> _linearTimeScale; dataStream >> _positionalTargetSet; dataStream >> _expires; _expires -= getEntityServerClockSkew(); dataStream >> _tag; _active = true; });
void XMLReader::elementEnd(const char* elementName) { if (ignore_) { ignore_ -= 1; return; } assert(!stack_.empty()); // parse character data auto& current = stack_.back(); if (!current.characterData.empty()) { if (!current.value.value<Collection*>()) { FixedMemoryStream dataStream(current.characterData.c_str(), current.characterData.size()); TextStream stream(dataStream); stream >> current.value; stream.skipWhiteSpace(); if (stream.fail() || !stream.eof()) { // failed to deserialize primitive value abortParsing(); return; } } }
QMimeData *TableModelVariables::mimeData(const QModelIndexList &indexes) const { QMimeData *mimeData = new QMimeData(); QByteArray encodedData; QDataStream dataStream(&encodedData, QIODevice::WriteOnly); dataStream << indexes.length(); foreach (const QModelIndex &index, indexes) { if (index.isValid()) { Term term = _variables.at(index.row()); dataStream << term.asQString(); } } TableModelVariables* th1s = (TableModelVariables*) this; th1s->_mimeData = mimeData; mimeData->setData(_mimeType, encodedData); return mimeData; }
void ObjectActionSpring::deserialize(QByteArray serializedArguments) { QDataStream dataStream(serializedArguments); EntityActionType type; dataStream >> type; assert(type == getType()); QUuid id; dataStream >> id; assert(id == getID()); uint16_t serializationVersion; dataStream >> serializationVersion; if (serializationVersion != ObjectActionSpring::springVersion) { assert(false); return; } withWriteLock([&] { dataStream >> _positionalTarget; dataStream >> _linearTimeScale; dataStream >> _positionalTargetSet; dataStream >> _rotationalTarget; dataStream >> _angularTimeScale; dataStream >> _rotationalTargetSet; quint64 serverExpires; dataStream >> serverExpires; _expires = serverTimeToLocalTime(serverExpires); dataStream >> _tag; _active = true; });