| 202 | } |
| 203 | |
| 204 | void QmitkFileSaveAction::Run() |
| 205 | { |
| 206 | // get the list of selected base data objects |
| 207 | mitk::DataNodeSelection::ConstPointer selection = d->m_Window.Lock()->GetSelectionService()->GetSelection().Cast<const mitk::DataNodeSelection>(); |
| 208 | if (selection.IsNull() || selection->IsEmpty()) |
| 209 | { |
| 210 | MITK_ERROR << "Assertion failed: data node selection is nullptr or empty"; |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | std::list<mitk::DataNode::Pointer> dataNodes = selection->GetSelectedDataNodes(); |
| 215 | |
| 216 | std::vector<const mitk::BaseData*> data; |
| 217 | QStringList names; |
| 218 | for (std::list<mitk::DataNode::Pointer>::const_iterator nodeIter = dataNodes.begin(), nodeIterEnd = dataNodes.end(); nodeIter != nodeIterEnd; ++nodeIter) |
| 219 | { |
| 220 | data.push_back((*nodeIter)->GetData()); |
| 221 | std::string name; |
| 222 | (*nodeIter)->GetStringProperty("name", name); |
| 223 | names.push_back(QString::fromStdString(name)); |
| 224 | } |
| 225 | |
| 226 | QString path; |
| 227 | |
| 228 | if (1 == data.size()) |
| 229 | { |
| 230 | if (nullptr != data[0]) |
| 231 | { |
| 232 | auto pathProperty = data[0]->GetConstProperty("path"); |
| 233 | |
| 234 | if (pathProperty.IsNotNull()) |
| 235 | path = QFileInfo(QString::fromStdString(pathProperty->GetValueAsString())).canonicalPath(); |
| 236 | } |
| 237 | |
| 238 | if (path.isEmpty()) |
| 239 | path = GetParentPath(dataNodes.front()); |
| 240 | } |
| 241 | |
| 242 | if (path.isEmpty()) |
| 243 | path = d->GetLastFileSavePath(); |
| 244 | |
| 245 | try |
| 246 | { |
| 247 | auto setPathProperty = true; |
| 248 | auto fileNames = QmitkIOUtil::Save(data, names, path, qobject_cast<QWidget*>(d->m_Action->parent()), setPathProperty); |
| 249 | |
| 250 | if (!fileNames.empty()) |
| 251 | d->SetLastFileSavePath(QFileInfo(fileNames.back()).absolutePath()); |
| 252 | } |
| 253 | catch (const mitk::Exception& e) |
| 254 | { |
| 255 | MITK_INFO << e; |
| 256 | return; |
| 257 | } |
| 258 | } |
nothing calls this directly
no test coverage detected