Skip to content

Commit

Permalink
refs #4328. Multiselect input files.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 17, 2012
1 parent 6cea8e6 commit 2e0f904
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace MantidQt
void addUniqueMemento(WorkspaceMemento_sptr candidate);
/// Get the first selected memento.
WorkspaceMemento_sptr getFirstSelected();
/// Find files of a certain type
QStringList findFiles(const std::string fileType) const;

private slots:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
</sizepolicy>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
Expand Down
77 changes: 51 additions & 26 deletions Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,50 +356,75 @@ void CreateMDWorkspace::addUniqueMemento(WorkspaceMemento_sptr candidate)
}

/*
Add a nexus file from the ADS
Select and return files with a given file extension.
*/
QStringList CreateMDWorkspace::findFiles(const std::string fileType) const
{
QFileDialog dialog;
dialog.setDirectory(QDir::homePath());
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setNameFilter(QString(fileType.c_str()));
QStringList fileNames;
if (dialog.exec())
{
fileNames = dialog.selectedFiles();
}
return fileNames;
}

/*
Add a nexus files on disk
*/
void CreateMDWorkspace::addNexusFileClicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"/home",
tr("Raw Files (*.nxs)"));
QStringList fileNames = findFiles("Raw Files (*.nxs)");

std::string name = fileName.toStdString();
if(!name.empty())
QStringList::iterator it = fileNames.begin();
QStringList::const_iterator end = fileNames.end();
while(it != fileNames.end())
{
try
{
WorkspaceMemento_sptr candidate(new RawFileMemento(name));
addUniqueMemento(candidate);
}
catch(std::invalid_argument& arg)
std::string name = (*it).toStdString();
if(!name.empty())
{
this->runConfirmation(arg.what());
try
{
WorkspaceMemento_sptr candidate(new RawFileMemento(name));
addUniqueMemento(candidate);
}
catch(std::invalid_argument& arg)
{
this->runConfirmation(arg.what());
}
}
++it;
}
}

/*
Add an Event nexus file from the ADS
Add an Event nexus files on disk
*/
void CreateMDWorkspace::addEventNexusFileClicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"/home",
tr("Event Nexus files (*.nxs)"));
QStringList fileNames = findFiles("Event Nexus files (*.nxs)");

std::string name = fileName.toStdString();
if(!name.empty())
QStringList::iterator it = fileNames.begin();
QStringList::const_iterator end = fileNames.end();
while(it != fileNames.end())
{
try
{
WorkspaceMemento_sptr candidate(new EventNexusFileMemento(name));
addUniqueMemento(candidate);
}
catch(std::invalid_argument& arg)
std::string name = (*it).toStdString();
if(!name.empty())
{
this->runConfirmation(arg.what());
try
{
WorkspaceMemento_sptr candidate(new EventNexusFileMemento(name));
addUniqueMemento(candidate);
}
catch(std::invalid_argument& arg)
{
this->runConfirmation(arg.what());
}
}
++it;
}
}

Expand Down

0 comments on commit 2e0f904

Please sign in to comment.