MCPcopy Create free account
hub / github.com/KDE/labplot / importTo

Method importTo

src/frontend/datasources/ImportProjectDialog.cpp:223–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223void ImportProjectDialog::importTo(QStatusBar* statusBar) const {
224 DEBUG(Q_FUNC_INFO)
225
226 // determine the selected objects.
227 // in case only the root index (first row corresponding to the project node) was selected, select all children to import everything.
228 const auto& selectedRows = ui.tvPreview->selectionModel()->selectedRows();
229 if (selectedRows.count() == 1 && selectedRows.constFirst().row() == 0)
230 ui.tvPreview->selectAll();
231
232 const auto& indexes = ui.tvPreview->selectionModel()->selectedIndexes();
233
234 // convert the model indexes to string pathes:
235 QStringList selectedPathes;
236 for (int i = 0; i < indexes.size() / 4; ++i) {
237 const auto& index = indexes.at(i * 4);
238 const auto* aspect = static_cast<const AbstractAspect*>(index.internalPointer());
239
240 // path of the current aspect and the pathes of all aspects it depends on
241 selectedPathes << aspect->path();
242 QDEBUG(" aspect path: " << aspect->path());
243 for (const auto* depAspect : aspect->dependsOn())
244 selectedPathes << depAspect->path();
245 }
246 selectedPathes.removeDuplicates();
247
248 auto* targetFolder = static_cast<Folder*>(m_cbAddTo->currentModelIndex().internalPointer());
249
250 // check whether the selected paths already exist in the target folder and warn the user
251 const auto& targetFolderPath = targetFolder->path();
252 const auto* targetProject = targetFolder->project();
253 QStringList targetAllPathes;
254 for (const auto* aspect : targetProject->children<AbstractAspect>(AbstractAspect::ChildIndexFlag::Recursive)) {
255 if (aspect && !dynamic_cast<const Folder*>(aspect))
256 targetAllPathes << aspect->path();
257 }
258
259 QStringList existingPathes;
260 for (const auto& path : selectedPathes) {
261 const QString& newPath = targetFolderPath + path.right(path.length() - path.indexOf(QLatin1Char('/')));
262 if (targetAllPathes.indexOf(newPath) != -1)
263 existingPathes << path;
264 }
265
266 QDEBUG("project objects to be imported: " << selectedPathes);
267 QDEBUG("all already available project objects: " << targetAllPathes);
268 QDEBUG("already available project objects to be overwritten: " << existingPathes);
269
270 if (!existingPathes.isEmpty()) {
271 QString msg = i18np("The object listed below already exists in target folder and will be overwritten:",
272 "The objects listed below already exist in target folder and will be overwritten:",
273 existingPathes.size());
274 msg += QLatin1Char('\n');
275 for (const auto& path : existingPathes)
276 msg += QLatin1Char('\n') + path.right(path.length() - path.indexOf(QLatin1Char('/')) - 1); // strip away the name of the root folder "Project"
277 msg += QStringLiteral("\n\n") + i18n("Do you want to proceed?");
278
279 auto status =
280 KMessageBox::warningTwoActions(nullptr, msg, i18n("Override existing objects?"), KStandardGuiItem::overwrite(), KStandardGuiItem::cancel());

Callers

nothing calls this directly

Calls 15

selectedRowsMethod · 0.80
selectionModelMethod · 0.80
currentModelIndexMethod · 0.80
lengthMethod · 0.80
setMinimumMethod · 0.80
setMaximumMethod · 0.80
showMessageMethod · 0.80
removeWidgetMethod · 0.80
countMethod · 0.45
rowMethod · 0.45

Tested by

no test coverage detected