void TB_PokemonItem::startDrag() { QMimeData * data = new QMimeData(); QVariant v; v.setValue(box); data->setProperty("Box", v); data->setProperty("Item", box->getNumOf(this)); data->setImageData(pixmap()); QDrag * drag = new QDrag(box->parentWidget()); drag->setMimeData(data); drag->setPixmap(pixmap()); drag->setHotSpot(QPoint(pixmap().width()/2,pixmap().height()/2)); drag->exec(Qt::MoveAction); }
QMimeData* BookmarksModel::mimeData(const QModelIndexList &indexes) const { QMimeData *mimeData = new QMimeData(); QStringList texts; QList<QUrl> urls; if (indexes.count() == 1) { mimeData->setProperty("x-item-index", indexes.at(0)); } for (int i = 0; i < indexes.count(); ++i) { if (indexes.at(i).isValid() && static_cast<BookmarkType>(indexes.at(i).data(TypeRole).toInt()) == UrlBookmark) { texts.append(indexes.at(i).data(UrlRole).toString()); urls.append(indexes.at(i).data(UrlRole).toUrl()); } } mimeData->setText(texts.join(QLatin1String(", "))); mimeData->setUrls(urls); return mimeData; }
void PokemonBoxButton::startDrag() { QMimeData * data = new QMimeData(); data->setProperty("TeamSlot", num); data->setImageData(px); QDrag * drag = new QDrag(this); drag->setMimeData(data); drag->setPixmap(px); drag->setHotSpot(QPoint(px.width()/2,px.height()/2)); drag->exec(Qt::MoveAction); emit dragStarted(num); }
QMimeData *DvbChannelTableModel::mimeData(const QModelIndexList &indexes) const { QList<DvbSharedChannel> selectedChannels; foreach (const QModelIndex &index, indexes) { if (index.column() == 0) { selectedChannels.append(value(index)); } } QMimeData *mimeData = new QMimeData(); mimeData->setData(QLatin1String("application/x-org.kde.kaffeine-selectedchannels"), QByteArray()); // this way the list will be properly deleted once drag and drop ends mimeData->setProperty("SelectedChannels", QVariant::fromValue(selectedChannels)); return mimeData; }
QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const { // Loop through selected indices QByteArray d; foreach(QModelIndex index, indices) { // Only export data for valid indices and only for the SQL column, i.e. only once per row if(index.isValid() && index.column() == 3) { // Add the SQL code used to create the object d = d.append(data(index, Qt::DisplayRole).toString() + ";\n"); // If it is a table also add the content if(data(index.sibling(index.row(), 1), Qt::DisplayRole).toString() == "table") { SqliteTableModel tableModel(0, m_db); tableModel.setTable(data(index.sibling(index.row(), 0), Qt::DisplayRole).toString()); for(int i=0; i < tableModel.rowCount(); ++i) { QString insertStatement = "INSERT INTO `" + data(index.sibling(index.row(), 0), Qt::DisplayRole).toString() + "` VALUES("; for(int j=1; j < tableModel.columnCount(); ++j) insertStatement += QString("'%1',").arg(tableModel.data(tableModel.index(i, j)).toString()); insertStatement.chop(1); insertStatement += ");\n"; d = d.append(insertStatement); } } } } // Create the MIME data object QMimeData* mime = new QMimeData(); mime->setProperty("db_file", m_db->curDBFilename); // Also save the file name to avoid dropping an object on the same database as it comes from mime->setData("text/plain", d); return mime; }
QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const { // We store the SQL data and the names data separately QByteArray sqlData, namesData; // Loop through selected indices for(const QModelIndex& index : indices) { // Get the item the index points at QTreeWidgetItem* item = static_cast<QTreeWidgetItem*>(index.internalPointer()); // Only export data for valid indices and only once per row (SQL column or Name column). if(index.isValid()) { QString objectType = data(index.sibling(index.row(), ColumnObjectType), Qt::DisplayRole).toString(); // For names, export a (qualified) (escaped) identifier of the item for statement composition in SQL editor. if(objectType == "field") namesData.append(getNameForDropping(item->text(ColumnSchema), item->parent()->text(ColumnName), item->text(ColumnName))); else if(objectType == "database") namesData.append(getNameForDropping(item->text(ColumnName), "", "")); else if(!objectType.isEmpty()) namesData.append(getNameForDropping(item->text(ColumnSchema), item->text(ColumnName), "")); if(objectType != "field" && index.column() == ColumnSQL) { // Add the SQL code used to create the object sqlData.append(data(index, Qt::DisplayRole).toString() + ";\n"); // If it is a table also add the content if(objectType == "table") { SqliteTableModel tableModel(m_db); sqlb::ObjectIdentifier objid(data(index.sibling(index.row(), ColumnSchema), Qt::DisplayRole).toString(), data(index.sibling(index.row(), ColumnName), Qt::DisplayRole).toString()); tableModel.setQuery(sqlb::Query(objid)); if(tableModel.completeCache()) { // Only continue if all data was fetched for(int i=0; i < tableModel.rowCount(); ++i) { QString insertStatement = "INSERT INTO " + objid.toString() + " VALUES("; for(int j=1; j < tableModel.columnCount(); ++j) insertStatement += QString("'%1',").arg(tableModel.data(tableModel.index(i, j), Qt::EditRole).toString()); insertStatement.chop(1); insertStatement += ");\n"; sqlData.append(insertStatement); } } } } } } // Create the MIME data object QMimeData* mime = new QMimeData(); mime->setProperty("db_file", m_db.currentFile()); // Also save the file name to avoid dropping an object on the same database as it comes from // When we have both SQL and Names data (probable row selection mode) we give precedence to the SQL data if (sqlData.length() == 0 && namesData.length() > 0) { // Remove last ", " or "." if (namesData.endsWith(", ")) namesData.chop(2); else if (namesData.endsWith(".")) namesData.chop(1); mime->setData("text/plain", namesData); } else mime->setData("text/plain", sqlData); return mime; }