19 #include "internal/org_mitk_gui_qt_application_Activator.h"
30 #include <QFileDialog>
31 #include <QMessageBox>
33 class QmitkFileSaveActionPrivate
40 this->setEnabled(selection);
43 QScopedPointer<berry::ISelectionListener> m_SelectionListener;
47 QmitkFileSaveActionPrivate()
48 : m_SelectionListener(new
berry::NullSelectionChangedAdapter<QmitkFileSaveActionPrivate>(
49 this, &QmitkFileSaveActionPrivate::HandleSelectionChanged))
53 ~QmitkFileSaveActionPrivate()
55 if (!m_Window.Expired())
57 m_Window.Lock()->GetSelectionService()->RemoveSelectionListener(m_SelectionListener.data());
66 action->setText(
"&Save...");
67 action->setToolTip(
"Save data objects (images, surfaces,...)");
74 QObject::connect(action, SIGNAL(triggered(
bool)), action, SLOT(Run()));
80 if (prefService !=
nullptr)
87 QString getLastFileSavePath()
const
92 return prefs->Get(
"LastFileSavePath",
"");
97 void setLastFileSavePath(
const QString& path)
const
102 prefs->Put(
"LastFileSavePath", path);
110 if (nodeSelection.
IsNotNull() && !selection->IsEmpty())
113 std::list<mitk::DataNode::Pointer> dataNodes = nodeSelection->GetSelectedDataNodes();
114 for (std::list<mitk::DataNode::Pointer>::const_iterator nodeIter = dataNodes.begin(),
115 nodeIterEnd = dataNodes.end(); nodeIter != nodeIterEnd; ++nodeIter)
117 if ((*nodeIter)->GetData() != NULL)
123 m_Action->setEnabled(enable);
127 m_Action->setEnabled(
false);
136 : QAction(0), d(new QmitkFileSaveActionPrivate)
142 : QAction(0), d(new QmitkFileSaveActionPrivate)
149 : QAction(0), d(new QmitkFileSaveActionPrivate)
151 d->init(window,
this);
163 if (selection.
IsNull() || selection->IsEmpty())
165 MITK_ERROR <<
"Assertion failed: data node selection is NULL or empty";
169 std::list<mitk::DataNode::Pointer> dataNodes = selection->GetSelectedDataNodes();
171 std::vector<const mitk::BaseData*> data;
173 for (std::list<mitk::DataNode::Pointer>::const_iterator nodeIter = dataNodes.begin(),
174 nodeIterEnd = dataNodes.end(); nodeIter != nodeIterEnd; ++nodeIter)
176 data.push_back((*nodeIter)->GetData());
178 (*nodeIter)->GetStringProperty(
"name", name);
179 names.push_back(QString::fromStdString(name));
185 d->m_Action->parentWidget());
186 if (!fileNames.empty())
188 d->setLastFileSavePath(QFileInfo(fileNames.back()).absolutePath());
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
virtual ISelection::ConstPointer GetSelection() const =0
berry::SmartPointer< Self > Pointer
QmitkFileSaveAction(berry::IWorkbenchWindow::Pointer window)
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
virtual void AddSelectionListener(ISelectionListener *listener)=0
ObjectType * GetPointer() const
static QString Save(const mitk::BaseData *data, const QString &defaultBaseName, const QString &defaultPath=QString(), QWidget *parent=NULL)
SmartPointer< Other > Cast() const
berry::SmartPointer< Self > Pointer