/*! \reimp */ bool MpCollectionDataModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { Q_UNUSED(column); // check if the action is supported if (!data || action != Qt::MoveAction | row > mRowCount ) { return false; } // check if the format is supported QStringList types = mimeTypes(); if (types.isEmpty()) { return false; } QString format = types.at(0); if (!data->hasFormat(format)) { return false; } // decode and insert QByteArray encoded = data->data(format); QDataStream stream(&encoded, QIODevice::ReadOnly); int rowFrom = -1; int mpxContainerId = -1; int mpxItemId = -1; if (!stream.atEnd()) { stream >> rowFrom; stream >> mpxContainerId; stream >> mpxItemId; }
QMimeData * KPrCustomSlideShowsModel::mimeData(const QModelIndexList &indexes) const { // check if there is data to encode if (! indexes.count()) { return 0; } // check if we support a format const QStringList types = mimeTypes(); if (types.isEmpty()) { return 0; } QMimeData *data = new QMimeData(); QByteArray encoded; QDataStream stream(&encoded, QIODevice::WriteOnly); // encode the data & order slides QModelIndexList::ConstIterator it = indexes.begin(); QMap<int, KoPAPageBase*> map; for( ; it != indexes.end(); ++it) { map.insert(m_customSlideShows->indexByPage(m_activeCustomSlideShowName, (KoPAPageBase*)it->internalPointer()), (KoPAPageBase*)it->internalPointer()); } QList<KoPAPageBase *> slides = map.values(); foreach (KoPAPageBase *slide, slides) { stream << QVariant::fromValue(qulonglong((void*)slide)); }
bool pOpenedFileModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent ) { if ( parent.isValid() || ( row == -1 && column == -1 ) || action != Qt::MoveAction || !data || !data->hasFormat( mimeTypes().first() ) ) { return false; } const int fromRow = data->data( mimeTypes().first() ).toInt(); if ( row >= mDocuments.count() ) { row--; } else if ( fromRow < row ) { row--; } QList<pAbstractChild*> newDocuments = mDocuments; newDocuments.move( fromRow, row ); rebuildMapping( mDocuments, newDocuments ); if ( mSortMode != pOpenedFileModel::Custom ) { setSortMode( pOpenedFileModel::Custom ); } return true; }
QMimeData *Continuous_histo_chart_model::mimeData(const QModelIndexList &indexes) const { if (indexes.count() <= 0) return 0; QStringList types = mimeTypes(); if (types.isEmpty()) return 0; QMimeData *data = new QMimeData(); QString format = types.at(0); QByteArray encoded; QDataStream stream(&encoded, QIODevice::WriteOnly); QModelIndexList::ConstIterator it = indexes.begin(); for (; it != indexes.end(); ++it) { QModelIndex src_index = this->mapToSource(*it); GsTL_object_item* item = static_cast<GsTL_object_item*>(src_index.internalPointer()); QString name = item->item_name(); QString type = item->item_type(); if(type == "Grid") continue; QMap<int, QVariant> data_encoded; data_encoded.insert(0, name); data_encoded.insert(1, type); //Need to send the grid_name if(type.startsWith("Group:") ) { data_encoded.insert(2, item->parent()->item_name()); } else { // all other data are two steps removed from the grid (except the grid themselves) data_encoded.insert(2, item->parent()->parent()->item_name()); } stream << (*it).row() << (*it).column() << data_encoded; } data->setData(format, encoded); return data; }
bool ObjectDescriptionModelData::dropMimeData(ObjectDescriptionType type, const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { Q_UNUSED(action); Q_UNUSED(column); Q_UNUSED(parent); //pDebug() << Q_FUNC_INFO << data << action << row << column << parent; QString format = mimeTypes(type).first(); if (!data->hasFormat(format)) { return false; } if (row == -1) { row = d->data.size(); } QByteArray encodedData = data->data(format); QDataStream stream(&encodedData, QIODevice::ReadOnly); QList<QExplicitlySharedDataPointer<ObjectDescriptionData> > toInsert; while (!stream.atEnd()) { int otherIndex; stream >> otherIndex; ObjectDescriptionData *obj = ObjectDescriptionData::fromIndex(type, otherIndex); if (obj->isValid()) { toInsert << QExplicitlySharedDataPointer<ObjectDescriptionData>(obj); } } d->model->beginInsertRows(QModelIndex(), row, row + toInsert.size() - 1); foreach (const QExplicitlySharedDataPointer<ObjectDescriptionData> &obj, toInsert) { d->data.insert(row, obj); }
//! [1] void DragWidget::dropEvent(QDropEvent *event) { if (event->source() == this && event->possibleActions() & Qt::MoveAction) return; //! [1] //! [2] if (event->proposedAction() == Qt::MoveAction) { event->acceptProposedAction(); // Process the data from the event. //! [2] emit dragResult(tr("The data was moved here.")); //! [3] } else if (event->proposedAction() == Qt::CopyAction) { event->acceptProposedAction(); // Process the data from the event. //! [3] emit dragResult(tr("The data was copied here.")); //! [4] } else { // Ignore the drop. return; } //! [4] // End of quote emit mimeTypes(event->mimeData()->formats()); setData(event->mimeData()->formats()[0], event->mimeData()->data(event->mimeData()->formats()[0])); //! [5] }
QMimeData* EntryModel::mimeData(const QModelIndexList& indexes) const { if (indexes.isEmpty()) { return nullptr; } QMimeData* data = new QMimeData(); QByteArray encoded; QDataStream stream(&encoded, QIODevice::WriteOnly); QSet<Entry*> seenEntries; for (const QModelIndex& index : indexes) { if (!index.isValid()) { continue; } Entry* entry = entryFromIndex(index); if (!seenEntries.contains(entry)) { // make sure we don't add entries multiple times when we get indexes // with the same row but different columns stream << entry->group()->database()->uuid() << entry->uuid(); seenEntries.insert(entry); } } if (seenEntries.isEmpty()) { delete data; return nullptr; } else { data->setData(mimeTypes().at(0), encoded); return data; } }
bool ItemModelBase::dropAllowed( const QModelIndex &index, int, const QMimeData *data ) { if ( flags( index ) & Qt::ItemIsDropEnabled ) { foreach ( const QString &s, data->formats() ) { if ( mimeTypes().contains( s ) ) { return true; } } }
void ProcessListView::dragEnterEvent(QDragEnterEvent *_event) { QString type; qDebug() << "ProcessListView: dragEnterEvent"; foreach(type, mimeTypes()) { if(_event->mimeData()->hasFormat(type)) _event->accept(); } }
void DragWidget::setData(const QString &mimetype, const QByteArray &newData) { mimeType = mimetype; data = QByteArray(newData); dragDropLabel->setText(tr("%1 bytes").arg(data.size())); QStringList formats; formats << mimetype; emit mimeTypes(formats); }
/*! \reimp */ bool QUrlModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { if (!data->formats().contains(mimeTypes().first())) return false; Q_UNUSED(action); Q_UNUSED(column); Q_UNUSED(parent); addUrls(data->urls(), row); return true; }
QMimeData* pOpenedFileModel::mimeData( const QModelIndexList& indexes ) const { if ( indexes.count() != 1 ) { return 0; } QMimeData* data = new QMimeData(); data->setData( mimeTypes().first(), QByteArray::number( indexes.first().row() ) ); return data; }
MainWindow::OfferType MainWindow::ExternalPopup::appInfos(const DB::FileNameList& files ) { StringSet types = mimeTypes( files ); OfferType res; for ( StringSet::const_iterator mimeTypeIt = types.begin(); mimeTypeIt != types.end(); ++mimeTypeIt ) { KService::List offers = KMimeTypeTrader::self()->query( *mimeTypeIt, QLatin1String( "Application" )); for(KService::List::Iterator offerIt = offers.begin(); offerIt != offers.end(); ++offerIt) { res.insert( qMakePair( (*offerIt)->name(), (*offerIt)->icon() ) ); _appToMimeTypeMap[(*offerIt)->name()].insert( *mimeTypeIt ); } } return res; }
/*! Decide based upon the data if it should be accepted or not We only accept dirs and not files */ bool QUrlModel::canDrop(QDragEnterEvent *event) { if (!event->mimeData()->formats().contains(mimeTypes().first())) return false; const QList<QUrl> list = event->mimeData()->urls(); for (int i = 0; i < list.count(); ++i) { QModelIndex idx = fileSystemModel->index(list.at(0).toLocalFile()); if (!fileSystemModel->isDir(idx)) return false; } return true; }
/*! Decide based upon the data if it should be accepted or not We only accept dirs and not files */ bool QUrlModel::canDrop(QDragEnterEvent *event) { if (!event->mimeData()->formats().contains(mimeTypes().constFirst())) return false; const QList<QUrl> list = event->mimeData()->urls(); for (const auto &url : list) { const QModelIndex idx = fileSystemModel->index(url.toLocalFile()); if (!fileSystemModel->isDir(idx)) return false; } return true; }
bool AbstractItemDragDropHandler::acceptsMimeData(const QMimeData* mime) { QStringList modelTypes = mimeTypes(); for (int i = 0; i < modelTypes.count(); ++i) { if (mime->hasFormat(modelTypes.at(i))) //&& (e->dropAction() & model->supportedDropActions())) { return true; } } return false; }
QMimeData *ObjectDescriptionModelData::mimeData(ObjectDescriptionType type, const QModelIndexList &indexes) const { QMimeData *mimeData = new QMimeData; QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); QModelIndexList::const_iterator end = indexes.constEnd(); QModelIndexList::const_iterator index = indexes.constBegin(); for(; index!=end; ++index) { if ((*index).isValid()) { stream << d->data.at((*index).row())->index(); } } //pDebug() << Q_FUNC_INFO << "setting mimeData to" << mimeTypes(type).first() << "=>" << encodedData.toHex(); mimeData->setData(mimeTypes(type).first(), encodedData); return mimeData; }
bool JSONModel::canDropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const { for(auto& elt : data->formats()) { std::cerr << elt.toStdString() << std::endl; if(mimeTypes().contains(elt)) { return true; } } return false; }
/*! \reimp */ QMimeData *MpCollectionDataModel::mimeData(const QModelIndexList &indexes) const { if (indexes.count() != 1) return 0; QStringList types = mimeTypes(); if (types.isEmpty()) return 0; QMimeData *data = new QMimeData(); QString format = types.at(0); QByteArray encoded; QDataStream stream(&encoded, QIODevice::WriteOnly); stream << indexes.at(0).row(); stream << mCollectionData->containerId(); stream << mCollectionData->itemId( indexes.at(0).row() ); data->setData(format, encoded); return data; }
bool RSSModel::dropMimeData(const QMimeData *data, Qt::DropAction action , int row, int column, const QModelIndex &parent) { Q_UNUSED(row); Q_UNUSED(column); if (!canDropMimeData(data, action, row, column, parent)) return false; if (action == Qt::IgnoreAction) return true; // check if the format is supported const QStringList types = mimeTypes(); if (types.isEmpty()) return false; const QString format = types.at(0); Q_ASSERT(format == INTERNAL_MIME_TYPE); if (!data->hasFormat(format)) return false; RSS::Folder *destFolder = parent.isValid() ? static_cast<RSS::Folder *>(getAttachedItem(parent)) : RSS::Manager::instance()->rootFolder(); // move as much items as possible QByteArray encoded = data->data(format); QDataStream stream(&encoded, QIODevice::ReadOnly); while (!stream.atEnd()) { quintptr itemPtr; stream >> itemPtr; RSS::Item *item = reinterpret_cast<RSS::Item *>(itemPtr); Q_ASSERT(item); try { RSS::Manager::instance()->moveItem(*item, *destFolder); } catch (const RuntimeError &) {} } return true; }
KoFilter::ConversionStatus MpxjImport::convert(const QByteArray& from, const QByteArray& to) { kDebug(planMpxjDbg()) << from << to; if ( to != "application/x-vnd.kde.plan" || ! mimeTypes().contains( from ) ) { kDebug(planMpxjDbg())<<"Bad mime types:"<<from<<"->"<<to; return KoFilter::BadMimeType; } bool batch = false; if ( m_chain->manager() ) { batch = m_chain->manager()->getBatchMode(); } if (batch) { //TODO kDebug(planMpxjDbg()) << "batch mode not implemented"; return KoFilter::NotImplemented; } KoDocument *part = m_chain->outputDocument(); if ( ! part ) { kDebug(planMpxjDbg()) << "could not open document"; return KoFilter::InternalError; } QString inputFile = m_chain->inputFile(); kDebug(planMpxjDbg())<<"Import from:"<<inputFile; QTemporaryDir *tmp = new QTemporaryDir(); QString outFile( tmp->path() + "/maindoc.xml" ); kDebug(planMpxjDbg())<<"Temp file:"<<outFile; KoFilter::ConversionStatus sts = doImport( inputFile.toUtf8(), outFile.toUtf8() ); kDebug(planMpxjDbg())<<"doImport returned:"<<(sts == KoFilter::OK); if ( sts == KoFilter::OK ) { QFile file( outFile ); KoXmlDocument doc; if ( ! doc.setContent( &file ) ) { kDebug(planMpxjDbg()) << "could not read maindoc.xml"; sts = KoFilter::InternalError; } else if ( ! part->loadXML( doc, 0 ) ) { kDebug(planMpxjDbg()) << "failed to load maindoc.xml"; sts = KoFilter::InternalError; } } delete tmp; return sts; }
QMimeData *RSSModel::mimeData(const QModelIndexList &indexes) const { if (indexes.count() <= 0) return nullptr; const QStringList types = mimeTypes(); if (types.isEmpty()) return nullptr; const QString format = types.at(0); Q_ASSERT(format == INTERNAL_MIME_TYPE); QByteArray encoded; QDataStream stream {&encoded, QIODevice::WriteOnly}; for (const auto &index : indexes) stream << reinterpret_cast<quintptr>(getAttachedItem(index)); QMimeData *data = new QMimeData; data->setData(format, encoded); return data; }
IsoStringList FileFormat::MimeTypes() const { size_type count = 0; size_type maxLen = 0; (*API->FileFormat->GetFileFormatMimeTypes)( m_data->handle, 0, &count, &maxLen ); IsoStringList mimeTypes( count ); if ( count > 0 ) { Array<char*> ptrs; for ( size_type i = 0; i < count; ++i ) { mimeTypes[i].Reserve( maxLen ); ptrs.Add( mimeTypes[i].c_str() ); } if ( (*API->FileFormat->GetFileFormatMimeTypes)( m_data->handle, ptrs.Begin(), &count, &maxLen ) == api_false ) throw APIFunctionError( "GetFileFormatMimeTypes" ); for ( IsoStringList::iterator i = mimeTypes.Begin(); i != mimeTypes.End(); ++i ) i->ResizeToNullTerminated(); } return mimeTypes; }
/** * @return TRUE if the document can handle the requested mimetype. */ bool KisDocumentEntry::supportsMimeType(const QString & _mimetype) const { return mimeTypes().contains(_mimetype); }
void PhononEngine::mimeTypes() { emit mimeTypes(Phonon::BackendCapabilities::availableMimeTypes()); }