| 1946 | |
| 1947 | |
| 1948 | void MapEditorController::paste() |
| 1949 | { |
| 1950 | if (editing_in_progress) |
| 1951 | return; |
| 1952 | if (!QApplication::clipboard()->mimeData()->hasFormat(MimeType::OpenOrienteeringObjects())) |
| 1953 | { |
| 1954 | QMessageBox::warning(nullptr, tr("Error"), tr("There are no objects in clipboard which could be pasted!")); |
| 1955 | return; |
| 1956 | } |
| 1957 | |
| 1958 | // Get buffer from clipboard |
| 1959 | QByteArray byte_array = QApplication::clipboard()->mimeData()->data(MimeType::OpenOrienteeringObjects()); |
| 1960 | QBuffer buffer(&byte_array); |
| 1961 | buffer.open(QIODevice::ReadOnly); |
| 1962 | |
| 1963 | // Create map from buffer |
| 1964 | Map paste_map; |
| 1965 | if (!paste_map.importFromIODevice(buffer)) |
| 1966 | { |
| 1967 | QMessageBox::warning(nullptr, tr("Error"), tr("An internal error occurred, sorry!")); |
| 1968 | return; |
| 1969 | } |
| 1970 | |
| 1971 | // Move objects in paste_map so their bounding box center is at this map's viewport center. |
| 1972 | // This makes the pasted objects appear at the center of the viewport. |
| 1973 | QRectF paste_extent = paste_map.calculateExtent(true, false, nullptr); |
| 1974 | auto offset = main_view->center() - paste_extent.center(); |
| 1975 | |
| 1976 | MapPart* part = paste_map.getCurrentPart(); |
| 1977 | for (int i = 0; i < part->getNumObjects(); ++i) |
| 1978 | part->getObject(i)->move(offset); |
| 1979 | |
| 1980 | // Import pasted map. Do not blindly import all colors. |
| 1981 | importMap(paste_map, Map::MinimalObjectImport, window); |
| 1982 | |
| 1983 | // Show message |
| 1984 | window->showStatusBarMessage(tr("Pasted %n object(s)", nullptr, paste_map.getNumObjects()), 2000); |
| 1985 | } |
| 1986 | |
| 1987 | |
| 1988 | void MapEditorController::clearUndoRedoHistory() |
nothing calls this directly
no test coverage detected