| 1176 | } |
| 1177 | |
| 1178 | bool UBFeaturesModel::dropMimeData(const QMimeData *mimeData, Qt::DropAction action, int row, int column, const QModelIndex &parent) |
| 1179 | { |
| 1180 | Q_UNUSED(row) |
| 1181 | |
| 1182 | const UBFeaturesMimeData *fMimeData = qobject_cast<const UBFeaturesMimeData*>(mimeData); |
| 1183 | UBFeaturesController *curController = qobject_cast<UBFeaturesController *>(QObject::parent()); |
| 1184 | |
| 1185 | bool dataFromSameModel = false; |
| 1186 | |
| 1187 | if (fMimeData) |
| 1188 | dataFromSameModel = true; |
| 1189 | |
| 1190 | if ((!mimeData->hasUrls() && !mimeData->hasImage()) ) |
| 1191 | return false; |
| 1192 | if ( action == Qt::IgnoreAction ) |
| 1193 | return true; |
| 1194 | if ( column > 0 ) |
| 1195 | return false; |
| 1196 | |
| 1197 | UBFeature parentFeature; |
| 1198 | if (!parent.isValid()) { |
| 1199 | parentFeature = curController->getCurrentElement(); |
| 1200 | } else { |
| 1201 | parentFeature = parent.data( Qt::UserRole + 1).value<UBFeature>(); |
| 1202 | } |
| 1203 | |
| 1204 | if (dataFromSameModel) { |
| 1205 | QList<UBFeature> featList = fMimeData->features(); |
| 1206 | for (int i = 0; i < featList.count(); i++) { |
| 1207 | UBFeature sourceElement = featList.at(i); |
| 1208 | moveData(sourceElement, parentFeature, Qt::MoveAction, true); |
| 1209 | } |
| 1210 | } else if (mimeData->hasUrls()) { |
| 1211 | QList<QUrl> urlList = mimeData->urls(); |
| 1212 | foreach (QUrl curUrl, urlList) { |
| 1213 | qDebug() << "URl catched is " << curUrl.toLocalFile(); |
| 1214 | curController->moveExternalData(curUrl, parentFeature); |
| 1215 | } |
| 1216 | } else if (mimeData->hasImage()) { |
| 1217 | const QStringList formats = mimeData->formats(); |
| 1218 | QString selectedFormat; |
| 1219 | |
| 1220 | for (const QString& format : formats) |
| 1221 | { |
| 1222 | if (format.startsWith("image/")) |
| 1223 | { |
| 1224 | selectedFormat = format; |
| 1225 | break; |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | QBuffer buffer; |
| 1230 | |
| 1231 | if (selectedFormat.isEmpty()) |
| 1232 | { |
| 1233 | // create an image and fill the buffer with PNG data |
| 1234 | QImage img = qvariant_cast<QImage> (mimeData->imageData()); |
| 1235 | img.save(&buffer, "png"); |
nothing calls this directly
no test coverage detected