Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/10548_refl_import_export…
Browse files Browse the repository at this point in the history
…_actions'
  • Loading branch information
DanNixon committed Nov 13, 2014
2 parents c008136 + a117024 commit 8835d5f
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace MantidQt
PasteSelectedFlag,
SearchFlag,
TransferFlag,
ImportTableFlag,
ExportTableFlag,
};

//Tell the presenter something happened
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace MantidQt
virtual void giveUserInfo(std::string prompt, std::string title);
virtual void giveUserWarning(std::string prompt, std::string title);
virtual void giveUserCritical(std::string prompt, std::string title);
virtual void showAlgorithmDialog(const std::string& algorithm);

//Set the status of the progress bar
virtual void setProgressRange(int min, int max);
Expand Down Expand Up @@ -114,6 +115,8 @@ namespace MantidQt
void on_actionOptionsDialog_triggered();
void on_actionSearch_triggered();
void on_actionTransfer_triggered();
void on_actionImportTable_triggered();
void on_actionExportTable_triggered();

void setModel(QString name);
void tableUpdated(const QModelIndex& topLeft, const QModelIndex& bottomRight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace MantidQt
virtual void giveUserInfo(std::string prompt, std::string title) = 0;
virtual void giveUserWarning(std::string prompt, std::string title) = 0;
virtual void giveUserCritical(std::string prompt, std::string title) = 0;
virtual void showAlgorithmDialog(const std::string& algorithm) = 0;

//Set the status of the progress bar
virtual void setProgressRange(int min, int max) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ namespace MantidQt
virtual void openTable();
virtual void saveTable();
virtual void saveTableAs();
virtual void importTable();
virtual void exportTable();
//searching
virtual void search();
virtual void transfer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>825</width>
<height>275</height>
<width>959</width>
<height>346</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -354,7 +354,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>825</width>
<width>959</width>
<height>23</height>
</rect>
</property>
Expand All @@ -379,6 +379,9 @@
<addaction name="actionSaveTable"/>
<addaction name="actionSaveTableAs"/>
<addaction name="separator"/>
<addaction name="actionImportTable"/>
<addaction name="actionExportTable"/>
<addaction name="separator"/>
<addaction name="actionOptionsDialog"/>
</widget>
<widget class="QMenu" name="menuRows">
Expand Down Expand Up @@ -615,6 +618,36 @@
<string>Transfers the selected runs into the processing table.</string>
</property>
</action>
<action name="actionImportTable">
<property name="icon">
<iconset resource="../../../../MantidPlot/icons/icons.qrc">
<normaloff>:/open_template.png</normaloff>:/open_template.png</iconset>
</property>
<property name="text">
<string>Import .TBL</string>
</property>
<property name="toolTip">
<string>Import a .TBL file</string>
</property>
<property name="whatsThis">
<string>Imports a .TBL file to a workspace using the LoadReflTBL algorithm. The resulting workspace can then be loaded as a table as normal.</string>
</property>
</action>
<action name="actionExportTable">
<property name="icon">
<iconset resource="../../../../MantidPlot/icons/icons.qrc">
<normaloff>:/save_template.png</normaloff>:/save_template.png</iconset>
</property>
<property name="text">
<string>Export .TBL</string>
</property>
<property name="toolTip">
<string>Export a .TBL file</string>
</property>
<property name="whatsThis">
<string>Exports a table workspace to a .TBL file that can be used by the ISIS Reflectometry UI in older versions of Mantid.</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>comboSearchInstrument</tabstop>
Expand Down
29 changes: 29 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/QtReflMainView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ namespace MantidQt
m_presenter->notify(IReflPresenter::TransferFlag);
}

/**
This slot notifies the presenter that the "export table" button has been pressed
*/
void QtReflMainView::on_actionExportTable_triggered()
{
m_presenter->notify(IReflPresenter::ExportTableFlag);
}

/**
This slot notifies the presenter that the "import table" button has been pressed
*/
void QtReflMainView::on_actionImportTable_triggered()
{
m_presenter->notify(IReflPresenter::ImportTableFlag);
}

/**
This slot notifies the presenter that the table has been updated/changed by the user
*/
Expand Down Expand Up @@ -357,6 +373,19 @@ namespace MantidQt
return "";
}

/**
Show the user the dialog for an algorithm
*/
void QtReflMainView::showAlgorithmDialog(const std::string& algorithm)
{
std::stringstream pythonSrc;
pythonSrc << "try:\n";
pythonSrc << " " << algorithm << "Dialog()\n";
pythonSrc << "except:\n";
pythonSrc << " pass\n";
runPythonCode(QString::fromStdString(pythonSrc.str()));
}

/**
Set the range of the progress bar
@param min : The minimum value of the bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,8 @@ namespace MantidQt
case IReflPresenter::PasteSelectedFlag: pasteSelected(); break;
case IReflPresenter::SearchFlag: search(); break;
case IReflPresenter::TransferFlag: transfer(); break;
case IReflPresenter::ImportTableFlag: importTable(); break;
case IReflPresenter::ExportTableFlag: exportTable(); break;
}
//Not having a 'default' case is deliberate. gcc issues a warning if there's a flag we aren't handling.
}
Expand Down Expand Up @@ -960,6 +962,22 @@ namespace MantidQt
}
}

/**
Import a table from TBL file
*/
void ReflMainViewPresenter::importTable()
{
m_view->showAlgorithmDialog("LoadReflTBL");
}

/**
Export a table to TBL file
*/
void ReflMainViewPresenter::exportTable()
{
m_view->showAlgorithmDialog("SaveReflTBL");
}

/**
Handle ADS add events
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class MockView : public ReflMainView
MOCK_METHOD2(giveUserInfo, void(std::string, std::string));
MOCK_METHOD2(giveUserWarning, void(std::string, std::string));

MOCK_METHOD1(showAlgorithmDialog, void(const std::string&));

//IO
MOCK_CONST_METHOD0(getWorkspaceToOpen, std::string());
MOCK_METHOD1(setSelection, void(const std::set<int>& rows));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,22 @@ class ReflMainViewPresenterTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws->Int(5, GroupCol), 2);
TS_ASSERT_EQUALS(ws->String(5, OptionsCol), "def");
}

void testImportTable()
{
MockView mockView;
ReflMainViewPresenter presenter(&mockView);
EXPECT_CALL(mockView, showAlgorithmDialog("LoadReflTBL"));
presenter.notify(IReflPresenter::ImportTableFlag);
}

void testExportTable()
{
MockView mockView;
ReflMainViewPresenter presenter(&mockView);
EXPECT_CALL(mockView, showAlgorithmDialog("SaveReflTBL"));
presenter.notify(IReflPresenter::ExportTableFlag);
}
};

#endif /* MANTID_CUSTOMINTERFACES_REFLMAINVIEWPRESENTERTEST_H */

0 comments on commit 8835d5f

Please sign in to comment.