Skip to content
Snippets Groups Projects
Commit d48fb151 authored by Owen Arnold's avatar Owen Arnold
Browse files

Merge remote-tracking branch 'origin/feature/10431_refl_presenter_use_model'

parents 66b1c84c 69a06db5
No related merge requests found
Showing
with 186 additions and 144 deletions
......@@ -44,16 +44,20 @@ namespace MantidQt
//emit a signal saying things have changed
void update();
//row and column counts
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
//get data fro a cell
QVariant data(const QModelIndex &index, int role) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
//get header data for the table
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
//get flags for a cell
Qt::ItemFlags flags(const QModelIndex &index) const;
//chage or add data to the model
bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
//change or add data to the model
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
//add new rows to the model
bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex());
//remove rows from the model
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
private:
typedef QString ColumnNameType;
......@@ -119,6 +123,8 @@ namespace MantidQt
ColumnIndexNameMap m_columnNameMap;
};
/// Typedef for a shared pointer to \c QReflTableModel
typedef boost::shared_ptr<QReflTableModel> QReflTableModel_sptr;
} // namespace CustomInterfaces
} // namespace Mantid
......
......@@ -5,6 +5,7 @@
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidQtCustomInterfaces/ReflMainView.h"
#include "MantidQtCustomInterfaces/IReflPresenter.h"
#include "MantidQtCustomInterfaces/QReflTableModel.h"
#include <boost/scoped_ptr.hpp>
#include <QSignalMapper>
#include "ui_ReflMainWidget.h"
......@@ -49,7 +50,7 @@ namespace MantidQt
static QString categoryInfo() { return "Reflectometry"; }
//Connect the model
virtual void showTable(Mantid::API::ITableWorkspace_sptr model);
virtual void showTable(QReflTableModel_sptr model);
//Dialog/Prompt methods
virtual std::string askUserString(const std::string& prompt, const std::string& title, const std::string& defaultValue);
......@@ -63,13 +64,13 @@ namespace MantidQt
virtual void setProgress(int progress);
//Settor methods
virtual void setSelection(const std::set<size_t>& rows);
virtual void setSelection(const std::set<int>& rows);
virtual void setTableList(const std::set<std::string>& tables);
virtual void setInstrumentList(const std::vector<std::string>& instruments, const std::string& defaultInstrument);
virtual void setOptionsHintStrategy(MantidQt::MantidWidgets::HintStrategy* hintStrategy);
//Accessor methods
virtual std::set<size_t> getSelectedRows() const;
virtual std::set<int> getSelectedRows() const;
virtual std::string getSearchInstrument() const;
virtual std::string getProcessInstrument() const;
virtual std::string getWorkspaceToOpen() const;
......@@ -81,6 +82,8 @@ namespace MantidQt
virtual void initLayout();
//the presenter
boost::shared_ptr<IReflPresenter> m_presenter;
//the model
QReflTableModel_sptr m_model;
//the interface
Ui::reflMainWidget ui;
//the workspace the user selected to open
......
......@@ -2,8 +2,8 @@
#define MANTID_CUSTOMINTERFACES_REFLMAINVIEW_H
#include "MantidKernel/System.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidQtCustomInterfaces/IReflPresenter.h"
#include "MantidQtCustomInterfaces/QReflTableModel.h"
#include "MantidQtMantidWidgets/HintStrategy.h"
namespace MantidQt
......@@ -42,7 +42,7 @@ namespace MantidQt
virtual ~ReflMainView() {};
//Connect the model
virtual void showTable(Mantid::API::ITableWorkspace_sptr model) = 0;
virtual void showTable(QReflTableModel_sptr model) = 0;
//Dialog/Prompt methods
virtual std::string askUserString(const std::string& prompt, const std::string& title, const std::string& defaultValue) = 0;
......@@ -56,13 +56,13 @@ namespace MantidQt
virtual void setProgress(int progress) = 0;
//Settor methods
virtual void setSelection(const std::set<size_t>& rows) = 0;
virtual void setSelection(const std::set<int>& rows) = 0;
virtual void setTableList(const std::set<std::string>& tables) = 0;
virtual void setInstrumentList(const std::vector<std::string>& instruments, const std::string& defaultInstrument) = 0;
virtual void setOptionsHintStrategy(MantidQt::MantidWidgets::HintStrategy* hintStrategy) = 0;
//Accessor methods
virtual std::set<size_t> getSelectedRows() const = 0;
virtual std::set<int> getSelectedRows() const = 0;
virtual std::string getSearchInstrument() const = 0;
virtual std::string getProcessInstrument() const = 0;
virtual std::string getWorkspaceToOpen() const = 0;
......
......@@ -5,8 +5,9 @@
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidQtCustomInterfaces/ReflMainView.h"
#include "MantidQtCustomInterfaces/IReflPresenter.h"
#include "MantidQtCustomInterfaces/ReflMainView.h"
#include "MantidQtCustomInterfaces/QReflTableModel.h"
#include <Poco/AutoPtr.h>
#include <Poco/NObserver.h>
......@@ -50,8 +51,10 @@ namespace MantidQt
//Public for the purposes of unit testing
static std::map<std::string,std::string> parseKeyValueString(const std::string& str);
protected:
//the workspace the model is currently representing
Mantid::API::ITableWorkspace_sptr m_ws;
//the model the table is currently representing
Mantid::API::ITableWorkspace_sptr m_model;
QReflTableModel_sptr m_model;
//the name of the workspace/table/model in the ADS, blank if unsaved
std::string m_wsName;
//the view we're managing
......@@ -64,27 +67,27 @@ namespace MantidQt
//process selected rows
virtual void process();
//Reduce a row
void reduceRow(size_t rowNo);
void reduceRow(int rowNo);
//load a run into the ADS, or re-use one in the ADS if possible
Mantid::API::Workspace_sptr loadRun(const std::string& run, const std::string& instrument);
//get the run number of a TOF workspace
std::string getRunNumber(const Mantid::API::Workspace_sptr& ws);
//get an unused group id
int getUnusedGroup(std::set<size_t> ignoredRows = std::set<size_t>()) const;
int getUnusedGroup(std::set<int> ignoredRows = std::set<int>()) const;
//make a transmission workspace
Mantid::API::MatrixWorkspace_sptr makeTransWS(const std::string& transString);
//Validate a row
void validateRow(size_t rowNo) const;
void validateRow(int rowNo) const;
//Autofill a row with sensible values
void autofillRow(size_t rowNo);
void autofillRow(int rowNo);
//calculates qmin and qmax
static std::vector<double> calcQRange(Mantid::API::MatrixWorkspace_sptr ws, double theta);
//get the number of rows in a group
size_t numRowsInGroup(int groupId) const;
//Stitch some rows
void stitchRows(std::set<size_t> rows);
void stitchRows(std::set<int> rows);
//insert a row in the model before the given index
virtual void insertRow(size_t before);
virtual void insertRow(int index);
//add row(s) to the model
virtual void appendRow();
virtual void prependRow();
......
......@@ -59,7 +59,7 @@ namespace MantidQt
void QReflTableModel::invalidateDataCache(const int row) const
{
//If the row is in the cache, invalidate the cache.
if(row == m_dataCachePeakIndex)
if(row == m_dataCachePeakIndex || row == -1)
m_dataCachePeakIndex = -1;
}
......@@ -221,5 +221,51 @@ namespace MantidQt
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}
/**
Insert the given number of rows at the specified position
@param row : The row to insert before
@param count : The number of rows to insert
@param parent : The parent index
*/
bool QReflTableModel::insertRows(int row, int count, const QModelIndex& parent)
{
if(count < 1)
return true;
if(row < 0)
return false;
beginInsertRows(parent, row, row + count - 1);
for(int i = 0; i < count; ++i)
m_tWS->insertRow(row + i);
endInsertRows();
invalidateDataCache(-1);
return true;
}
/**
Remove the given number of rows from the specified position
@param row : The row index to remove from
@param count : The number of rows to remove
@param parent : The parent index
*/
bool QReflTableModel::removeRows(int row, int count, const QModelIndex& parent)
{
if(count < 1)
return true;
if(row < 0)
return false;
beginRemoveRows(parent, row, row + count - 1);
for(int i = 0; i < count; ++i)
m_tWS->removeRow(row);
endRemoveRows();
invalidateDataCache(-1);
return true;
}
} // namespace CustomInterfaces
} // namespace Mantid
......@@ -85,12 +85,12 @@ namespace MantidQt
Set a new model in the tableview
@param model : the model to be attached to the tableview
*/
void QtReflMainView::showTable(ITableWorkspace_sptr model)
void QtReflMainView::showTable(QReflTableModel_sptr model)
{
QAbstractItemModel* qModel = new QReflTableModel(model);
m_model = model;
//So we can notify the presenter when the user updates the table
connect(qModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(tableUpdated(const QModelIndex&, const QModelIndex&)));
ui.viewTable->setModel(qModel);
connect(m_model.get(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(tableUpdated(const QModelIndex&, const QModelIndex&)));
ui.viewTable->setModel(m_model.get());
ui.viewTable->resizeColumnsToContents();
}
......@@ -310,13 +310,13 @@ namespace MantidQt
Set which rows are selected
@param rows : The set of rows to select
*/
void QtReflMainView::setSelection(const std::set<size_t>& rows)
void QtReflMainView::setSelection(const std::set<int>& rows)
{
ui.viewTable->clearSelection();
auto selectionModel = ui.viewTable->selectionModel();
for(auto row = rows.begin(); row != rows.end(); ++row)
selectionModel->select(ui.viewTable->model()->index((int)(*row), 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
selectionModel->select(ui.viewTable->model()->index((*row), 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
}
/**
......@@ -372,10 +372,10 @@ namespace MantidQt
Get the indices of the highlighted rows
@returns a vector of unsigned ints contianing the highlighted row numbers
*/
std::set<size_t> QtReflMainView::getSelectedRows() const
std::set<int> QtReflMainView::getSelectedRows() const
{
auto selectedRows = ui.viewTable->selectionModel()->selectedRows();
std::set<size_t> rows;
std::set<int> rows;
for(auto it = selectedRows.begin(); it != selectedRows.end(); ++it)
rows.insert(it->row());
......
......@@ -7,6 +7,7 @@
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/Utils.h"
#include "MantidQtCustomInterfaces/ReflMainView.h"
#include "MantidQtCustomInterfaces/QReflTableModel.h"
#include "MantidQtCustomInterfaces/QtReflOptionsDialog.h"
#include "MantidQtMantidWidgets/AlgorithmHintStrategy.h"
......@@ -88,6 +89,15 @@ namespace
return ws;
}
ITableWorkspace_sptr createDefaultWorkspace()
{
//Create a blank workspace with one line and set the scale column to 1
auto ws = createWorkspace();
ws->appendRow();
ws->Double(0, MantidQt::CustomInterfaces::ReflMainViewPresenter::COL_SCALE) = 1.0;
return ws;
}
}
namespace MantidQt
......@@ -174,18 +184,18 @@ namespace MantidQt
/**
* Finds the first unused group id
*/
int ReflMainViewPresenter::getUnusedGroup(std::set<size_t> ignoredRows) const
int ReflMainViewPresenter::getUnusedGroup(std::set<int> ignoredRows) const
{
std::set<int> usedGroups;
//Scan through all the rows, working out which group ids are used
for(size_t idx = 0; idx < m_model->rowCount(); ++idx)
for(int idx = 0; idx < m_model->rowCount(); ++idx)
{
if(ignoredRows.find(idx) != ignoredRows.end())
continue;
//This is an unselected row. Add it to the list of used group ids
usedGroups.insert(m_model->Int(idx, COL_GROUP));
usedGroups.insert(m_model->data(m_model->index(idx, COL_GROUP)).toInt());
}
int groupId = 0;
......@@ -252,7 +262,7 @@ namespace MantidQt
return;
}
std::set<size_t> rows = m_view->getSelectedRows();
std::set<int> rows = m_view->getSelectedRows();
if(rows.empty())
{
if(m_options["WarnProcessAll"].toBool())
......@@ -263,20 +273,20 @@ namespace MantidQt
}
//They want to process all rows, so populate rows with every index in the model
for(size_t idx = 0; idx < m_model->rowCount(); ++idx)
for(int idx = 0; idx < m_model->rowCount(); ++idx)
rows.insert(idx);
}
//Map group numbers to the set of rows in that group we want to process
std::map<int,std::set<size_t> > groups;
std::map<int,std::set<int> > groups;
for(auto it = rows.begin(); it != rows.end(); ++it)
groups[m_model->Int(*it, COL_GROUP)].insert(*it);
groups[m_model->data(m_model->index(*it, COL_GROUP)).toInt()].insert(*it);
//Check each group and warn if we're only partially processing it
for(auto gIt = groups.begin(); gIt != groups.end(); ++gIt)
{
const int& groupId = gIt->first;
const std::set<size_t>& groupRows = gIt->second;
const std::set<int>& groupRows = gIt->second;
//Are we only partially processing a group?
if(groupRows.size() < numRowsInGroup(gIt->first))
{
......@@ -299,7 +309,7 @@ namespace MantidQt
}
catch(std::exception& ex)
{
const std::string rowNo = Mantid::Kernel::Strings::toString<size_t>(*it + 1);
const std::string rowNo = Mantid::Kernel::Strings::toString<int>(*it + 1);
m_view->giveUserCritical("Error found in row " + rowNo + ":\n" + ex.what(), "Error");
return;
}
......@@ -313,7 +323,7 @@ namespace MantidQt
for(auto gIt = groups.begin(); gIt != groups.end(); ++gIt)
{
const std::set<size_t> groupRows = gIt->second;
const std::set<int> groupRows = gIt->second;
//Reduce each row
for(auto rIt = groupRows.begin(); rIt != groupRows.end(); ++rIt)
......@@ -325,7 +335,7 @@ namespace MantidQt
}
catch(std::exception& ex)
{
const std::string rowNo = Mantid::Kernel::Strings::toString<size_t>(*rIt + 1);
const std::string rowNo = Mantid::Kernel::Strings::toString<int>(*rIt + 1);
const std::string message = "Error encountered while processing row " + rowNo + ":\n";
m_view->giveUserCritical(message + ex.what(), "Error");
m_view->setProgress(0);
......@@ -356,12 +366,12 @@ namespace MantidQt
@param rowNo : The row in the model to validate
@throws std::invalid_argument if the row fails validation
*/
void ReflMainViewPresenter::validateRow(size_t rowNo) const
void ReflMainViewPresenter::validateRow(int rowNo) const
{
if(rowNo >= m_model->rowCount())
throw std::invalid_argument("Invalid row");
if(m_model->String(rowNo, COL_RUNS).empty())
if(m_model->data(m_model->index(rowNo, COL_RUNS)).toString().isEmpty())
throw std::invalid_argument("Run column may not be empty.");
}
......@@ -370,16 +380,16 @@ namespace MantidQt
@param rowNo : The row in the model to autofill
@throws std::runtime_error if the row could not be auto-filled
*/
void ReflMainViewPresenter::autofillRow(size_t rowNo)
void ReflMainViewPresenter::autofillRow(int rowNo)
{
if(rowNo >= m_model->rowCount())
throw std::runtime_error("Invalid row");
const std::string runStr = m_model->String(rowNo, COL_RUNS);
const std::string runStr = m_model->data(m_model->index(rowNo, COL_RUNS)).toString().toStdString();
MatrixWorkspace_sptr run = boost::dynamic_pointer_cast<MatrixWorkspace>(loadRun(runStr, m_view->getProcessInstrument()));
//Fetch two theta from the log if needed
if(m_model->String(rowNo, COL_ANGLE).empty())
if(m_model->data(m_model->index(rowNo, COL_ANGLE)).toString().isEmpty())
{
Property* logData = NULL;
......@@ -405,26 +415,23 @@ namespace MantidQt
throw std::runtime_error("Value for two theta could not be found in log.");
//Update the model
m_model->String(rowNo, COL_ANGLE) = Strings::toString<double>(Utils::roundToDP(thetaVal, 3));
m_model->setData(m_model->index(rowNo, COL_ANGLE), Utils::roundToDP(thetaVal, 3));
m_tableDirty = true;
}
//If we need to calculate the resolution, do.
if(m_model->String(rowNo, COL_DQQ).empty())
if(m_model->data(m_model->index(rowNo, COL_DQQ)).toString().isEmpty())
{
IAlgorithm_sptr calcResAlg = AlgorithmManager::Instance().create("CalculateResolution");
calcResAlg->setProperty("Workspace", run);
calcResAlg->setProperty("TwoTheta", m_model->String(rowNo, COL_ANGLE));
calcResAlg->setProperty("TwoTheta", m_model->data(m_model->index(rowNo, COL_ANGLE)).toString().toStdString());
calcResAlg->execute();
//Update the model
double dqqVal = calcResAlg->getProperty("Resolution");
m_model->String(rowNo, COL_DQQ) = Strings::toString<double>(dqqVal);
m_model->setData(m_model->index(rowNo, COL_DQQ), dqqVal);
m_tableDirty = true;
}
//Make sure the view updates
m_view->showTable(m_model);
}
/**
......@@ -523,18 +530,18 @@ namespace MantidQt
@param rowNo : The row in the model to reduce
@throws std::runtime_error if reduction fails
*/
void ReflMainViewPresenter::reduceRow(size_t rowNo)
void ReflMainViewPresenter::reduceRow(int rowNo)
{
const std::string run = m_model->String(rowNo, COL_RUNS);
const std::string transStr = m_model->String(rowNo, COL_TRANSMISSION);
const std::string options = m_model->String(rowNo, COL_OPTIONS);
const std::string run = m_model->data(m_model->index(rowNo, COL_RUNS)).toString().toStdString();
const std::string transStr = m_model->data(m_model->index(rowNo, COL_TRANSMISSION)).toString().toStdString();
const std::string options = m_model->data(m_model->index(rowNo, COL_OPTIONS)).toString().toStdString();
double theta = 0;
const bool thetaGiven = !m_model->String(rowNo, COL_ANGLE).empty();
const bool thetaGiven = !m_model->data(m_model->index(rowNo, COL_ANGLE)).toString().isEmpty();
if(thetaGiven)
Mantid::Kernel::Strings::convert<double>(m_model->String(rowNo, COL_ANGLE), theta);
theta = m_model->data(m_model->index(rowNo, COL_ANGLE)).toDouble();
Workspace_sptr runWS = loadRun(run, m_view->getProcessInstrument());
const std::string runNo = getRunNumber(runWS);
......@@ -571,7 +578,7 @@ namespace MantidQt
if(!algReflOne->isExecuted())
throw std::runtime_error("Failed to run ReflectometryReductionOneAuto.");
const double scale = m_model->Double(rowNo, COL_SCALE);
const double scale = m_model->data(m_model->index(rowNo, COL_SCALE)).toDouble();
if(scale != 1.0)
{
IAlgorithm_sptr algScale = AlgorithmManager::Instance().create("Scale");
......@@ -586,19 +593,18 @@ namespace MantidQt
}
//Reduction has completed. Put Qmin and Qmax into the table if needed, for stitching.
if(m_model->String(rowNo, COL_QMIN).empty() || m_model->String(rowNo, COL_QMAX).empty())
if(m_model->data(m_model->index(rowNo, COL_QMIN)).toString().isEmpty() || m_model->data(m_model->index(rowNo, COL_QMAX)).toString().isEmpty())
{
MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("IvsQ_" + runNo);
std::vector<double> qrange = calcQRange(ws, theta);
if(m_model->String(rowNo, COL_QMIN).empty())
m_model->String(rowNo, COL_QMIN) = Strings::toString<double>(qrange[0]);
if(m_model->data(m_model->index(rowNo, COL_QMIN)).toString().isEmpty())
m_model->setData(m_model->index(rowNo, COL_QMIN), qrange[0]);
if(m_model->String(rowNo, COL_QMAX).empty())
m_model->String(rowNo, COL_QMAX) = Strings::toString<double>(qrange[1]);
if(m_model->data(m_model->index(rowNo, COL_QMAX)).toString().isEmpty())
m_model->setData(m_model->index(rowNo, COL_QMAX), qrange[1]);
m_tableDirty = true;
m_view->showTable(m_model);
}
}
......@@ -636,7 +642,7 @@ namespace MantidQt
Stitches the workspaces created by the given rows together.
@param rows : the list of rows
*/
void ReflMainViewPresenter::stitchRows(std::set<size_t> rows)
void ReflMainViewPresenter::stitchRows(std::set<int> rows)
{
//If we can get away with doing nothing, do.
if(rows.size() < 2)
......@@ -653,13 +659,9 @@ namespace MantidQt
//Go through each row and prepare the properties
for(auto rowIt = rows.begin(); rowIt != rows.end(); ++rowIt)
{
const std::string runStr = m_model->String(*rowIt, COL_RUNS);
const std::string qMinStr = m_model->String(*rowIt, COL_QMIN);
const std::string qMaxStr = m_model->String(*rowIt, COL_QMAX);
double qmin, qmax;
Mantid::Kernel::Strings::convert<double>(qMinStr, qmin);
Mantid::Kernel::Strings::convert<double>(qMaxStr, qmax);
const std::string runStr = m_model->data(m_model->index(*rowIt, COL_RUNS)).toString().toStdString();
const double qmin = m_model->data(m_model->index(*rowIt, COL_QMIN)).toDouble();
const double qmax = m_model->data(m_model->index(*rowIt, COL_QMAX)).toDouble();
Workspace_sptr runWS = loadRun(runStr);
if(runWS)
......@@ -676,9 +678,7 @@ namespace MantidQt
endOverlaps.push_back(qmax);
}
double dqq;
std::string dqqStr = m_model->String(*(rows.begin()), COL_DQQ);
Mantid::Kernel::Strings::convert<double>(dqqStr, dqq);
double dqq = m_model->data(m_model->index(*(rows.begin()), COL_DQQ)).toDouble();
//params are qmin, -dqq, qmax for the final output
params.push_back(*std::min_element(startOverlaps.begin(), startOverlaps.end()));
......@@ -759,18 +759,17 @@ namespace MantidQt
/**
Inserts a new row in the specified location
@param before The index to insert the new row before
@param index The index to insert the new row before
*/
void ReflMainViewPresenter::insertRow(size_t before)
void ReflMainViewPresenter::insertRow(int index)
{
const int groupId = getUnusedGroup();
size_t row = m_model->insertRow(before);
if(!m_model->insertRow(index))
return;
//Set the default scale to 1.0
m_model->Double(row, COL_SCALE) = 1.0;
m_model->setData(m_model->index(index, COL_SCALE), 1.0);
//Set the group id of the new row
m_model->Int(row, COL_GROUP) = groupId;
//Make sure the view updates
m_view->showTable(m_model);
m_model->setData(m_model->index(index, COL_GROUP), groupId);
}
/**
......@@ -778,7 +777,7 @@ namespace MantidQt
*/
void ReflMainViewPresenter::appendRow()
{
std::set<size_t> rows = m_view->getSelectedRows();
std::set<int> rows = m_view->getSelectedRows();
if(rows.empty())
insertRow(m_model->rowCount());
else
......@@ -791,7 +790,7 @@ namespace MantidQt
*/
void ReflMainViewPresenter::prependRow()
{
std::set<size_t> rows = m_view->getSelectedRows();
std::set<int> rows = m_view->getSelectedRows();
if(rows.empty())
insertRow(0);
else
......@@ -804,11 +803,10 @@ namespace MantidQt
*/
void ReflMainViewPresenter::deleteRow()
{
std::set<size_t> rows = m_view->getSelectedRows();
std::set<int> rows = m_view->getSelectedRows();
for(auto row = rows.rbegin(); row != rows.rend(); ++row)
m_model->removeRow(*row);
m_view->showTable(m_model);
m_tableDirty = true;
}
......@@ -817,16 +815,14 @@ namespace MantidQt
*/
void ReflMainViewPresenter::groupRows()
{
const std::set<size_t> rows = m_view->getSelectedRows();
const std::set<int> rows = m_view->getSelectedRows();
//Find the first unused group id, ignoring the selected rows
const int groupId = getUnusedGroup(rows);
//Now we just have to set the group id on the selected rows
for(auto it = rows.begin(); it != rows.end(); ++it)
m_model->Int(*it, COL_GROUP) = groupId;
m_model->setData(m_model->index(*it, COL_GROUP), groupId);
//Make sure the view updates
m_view->showTable(m_model);
m_tableDirty = true;
}
......@@ -862,7 +858,7 @@ namespace MantidQt
{
if(!m_wsName.empty())
{
AnalysisDataService::Instance().addOrReplace(m_wsName,boost::shared_ptr<ITableWorkspace>(m_model->clone()));
AnalysisDataService::Instance().addOrReplace(m_wsName,boost::shared_ptr<ITableWorkspace>(m_ws->clone()));
m_tableDirty = false;
}
else
......@@ -893,13 +889,11 @@ namespace MantidQt
if(!m_view->askUserYesNo("Your current table has unsaved changes. Are you sure you want to discard them?","Start New Table?"))
return;
m_model = createWorkspace();
m_ws = createDefaultWorkspace();
m_model.reset(new QReflTableModel(m_ws));
m_wsName.clear();
m_view->showTable(m_model);
//Start with one blank row
insertRow(0);
m_tableDirty = false;
}
......@@ -927,11 +921,12 @@ namespace MantidQt
ITableWorkspace_sptr origTable = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>(toOpen);
//We create a clone of the table for live editing. The original is not updated unless we explicitly save.
ITableWorkspace_sptr newModel = boost::shared_ptr<ITableWorkspace>(origTable->clone());
ITableWorkspace_sptr newTable = boost::shared_ptr<ITableWorkspace>(origTable->clone());
try
{
validateModel(newModel);
m_model = newModel;
validateModel(newTable);
m_ws = newTable;
m_model.reset(new QReflTableModel(m_ws));
m_wsName = toOpen;
m_view->showTable(m_model);
m_tableDirty = false;
......@@ -1023,8 +1018,8 @@ namespace MantidQt
size_t ReflMainViewPresenter::numRowsInGroup(int groupId) const
{
size_t count = 0;
for(size_t i = 0; i < m_model->rowCount(); ++i)
if(m_model->Int(i, COL_GROUP) == groupId)
for(int i = 0; i < m_model->rowCount(); ++i)
if(m_model->data(m_model->index(i, COL_GROUP)).toInt() == groupId)
count++;
return count;
}
......@@ -1034,14 +1029,14 @@ namespace MantidQt
{
std::set<int> groupIds;
std::set<size_t> rows = m_view->getSelectedRows();
std::set<int> rows = m_view->getSelectedRows();
for(auto row = rows.begin(); row != rows.end(); ++row)
groupIds.insert(m_model->Int(*row, COL_GROUP));
groupIds.insert(m_model->data(m_model->index(*row, COL_GROUP)).toInt());
std::set<size_t> selection;
std::set<int> selection;
for(size_t i = 0; i < m_model->rowCount(); ++i)
if(groupIds.find(m_model->Int(i, COL_GROUP)) != groupIds.end())
for(int i = 0; i < m_model->rowCount(); ++i)
if(groupIds.find(m_model->data(m_model->index(i, COL_GROUP)).toInt()) != groupIds.end())
selection.insert(i);
m_view->setSelection(selection);
......
......@@ -3,6 +3,7 @@
#include <gmock/gmock.h>
#include "MantidQtCustomInterfaces/ReflMainView.h"
#include "MantidQtCustomInterfaces/QReflTableModel.h"
#include "MantidAPI/TableRow.h"
using namespace MantidQt::CustomInterfaces;
......@@ -35,7 +36,8 @@ class MockView : public ReflMainView
{
public:
MockView(){};
virtual void showTable(Mantid::API::ITableWorkspace_sptr model){ m_model = model;}
virtual ~MockView(){}
virtual void showTable(QReflTableModel_sptr model){ m_model = model;}
virtual void setOptionsHintStrategy(MantidQt::MantidWidgets::HintStrategy*) {};
MOCK_METHOD3(askUserString, std::string(const std::string& prompt, const std::string& title, const std::string& defaultValue));
MOCK_METHOD2(askUserYesNo, bool(std::string, std::string));
......@@ -47,27 +49,14 @@ public:
MOCK_METHOD1(setTableList, void(const std::set<std::string>& tableList));
MOCK_METHOD2(setInstrumentList, void(const std::vector<std::string>& instruments, const std::string& defaultInstrument));
MOCK_METHOD1(setInstrument, void(const std::string&));
MOCK_METHOD1(setSelection, void(const std::set<size_t>& rows));
MOCK_CONST_METHOD0(getSelectedRows, std::set<size_t>());
MOCK_METHOD1(setSelection, void(const std::set<int>& rows));
MOCK_CONST_METHOD0(getSelectedRows, std::set<int>());
MOCK_CONST_METHOD0(getSearchInstrument, std::string());
MOCK_CONST_METHOD0(getProcessInstrument, std::string());
MOCK_CONST_METHOD0(getWorkspaceToOpen, std::string());
MOCK_CONST_METHOD0(getPresenter, boost::shared_ptr<IReflPresenter>());
virtual ~MockView(){}
void addDataForTest()
{
TableRow row = m_model->appendRow();
row << "13460" << "0.7" << "13463,13464" << "0.01" << "0.06" << "0.04" << 1.0 << 3 << "";
row = m_model->appendRow();
row << "13462" << "2.3" << "13463,13464" << "0.035" << "0.3" << "0.04" << 1.0 << 3 << "";
row = m_model->appendRow();
row << "13469" << "0.7" << "13463,13464" << "0.01" << "0.06" << "0.04" << 1.0 << 1 << "";
row = m_model->appendRow();
row << "13470" << "2.3" << "13463,13464" << "0.035" << "0.3" << "0.04" << 1.0 << 1 << "";
m_model->removeRow(0);
}
private:
Mantid::API::ITableWorkspace_sptr m_model;
QReflTableModel_sptr m_model;
};
#endif /*MANTID_CUSTOMINTERFACES_REFLMAINVIEWMOCKOBJECTS_H*/
......@@ -196,7 +196,7 @@ public:
TS_ASSERT_THROWS(ws->Int(6, GroupCol), std::runtime_error);
//The user hits "append row" twice with no rows selected
EXPECT_CALL(mockView, getSelectedRows()).Times(2).WillRepeatedly(Return(std::set<size_t>()));
EXPECT_CALL(mockView, getSelectedRows()).Times(2).WillRepeatedly(Return(std::set<int>()));
presenter.notify(AppendRowFlag);
presenter.notify(AppendRowFlag);
......@@ -229,7 +229,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(1);
//We should not receive any errors
......@@ -282,7 +282,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(1);
rowlist.insert(2);
rowlist.insert(3);
......@@ -341,7 +341,7 @@ public:
EXPECT_CALL(mockView, giveUserCritical(_,_)).Times(0);
//The user hits "prepend row" twice with no rows selected
EXPECT_CALL(mockView, getSelectedRows()).Times(2).WillRepeatedly(Return(std::set<size_t>()));
EXPECT_CALL(mockView, getSelectedRows()).Times(2).WillRepeatedly(Return(std::set<int>()));
presenter.notify(PrependRowFlag);
presenter.notify(PrependRowFlag);
......@@ -373,7 +373,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(1);
//We should not receive any errors
......@@ -412,7 +412,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(1);
rowlist.insert(2);
rowlist.insert(3);
......@@ -461,7 +461,7 @@ public:
TS_ASSERT_EQUALS(ws->Int(1, GroupCol), 3);
//The user hits "delete row" with no rows selected
EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(std::set<size_t>()));
EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(std::set<int>()));
presenter.notify(DeleteRowFlag);
//The user hits save
......@@ -488,7 +488,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(1);
//We should not receive any errors
......@@ -528,7 +528,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(0);
rowlist.insert(1);
rowlist.insert(2);
......@@ -573,7 +573,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(0);
rowlist.insert(1);
......@@ -638,7 +638,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(0);
rowlist.insert(1);
......@@ -690,7 +690,7 @@ public:
EXPECT_CALL(mockView, getWorkspaceToOpen()).Times(1).WillRepeatedly(Return("TestWorkspace"));
presenter.notify(OpenTableFlag);
std::set<size_t> rowlist;
std::set<int> rowlist;
rowlist.insert(0);
rowlist.insert(1);
......@@ -710,12 +710,12 @@ public:
//Check the table was updated as expected
ws = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("TestWorkspace");
TS_ASSERT_EQUALS(ws->String(0, ThetaCol), "0.7");
TS_ASSERT_EQUALS(ws->String(0, DQQCol), "0.0340301");
TS_ASSERT_DELTA(boost::lexical_cast<double>(ws->String(0, DQQCol)), 0.034030, 1e-6);
TS_ASSERT_EQUALS(ws->String(0, QMinCol), "0.009");
TS_ASSERT_EQUALS(ws->String(0, QMaxCol), "0.154");
TS_ASSERT_EQUALS(ws->String(1, ThetaCol), "2.3");
TS_ASSERT_EQUALS(ws->String(1, DQQCol), "0.0340505");
TS_ASSERT_DELTA(boost::lexical_cast<double>(ws->String(1, DQQCol)), 0.034050, 1e-6);
TS_ASSERT_EQUALS(ws->String(1, QMinCol), "0.03");
TS_ASSERT_EQUALS(ws->String(1, QMaxCol), "0.504");
......@@ -822,7 +822,7 @@ public:
ReflMainViewPresenter presenter(&mockView);
//User hits "append row"
EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(std::set<size_t>()));
EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(std::set<int>()));
presenter.notify(AppendRowFlag);
//The user will decide not to discard their changes
......@@ -848,7 +848,7 @@ public:
ReflMainViewPresenter presenter(&mockView);
//User hits "append row" a couple of times
EXPECT_CALL(mockView, getSelectedRows()).Times(2).WillRepeatedly(Return(std::set<size_t>()));
EXPECT_CALL(mockView, getSelectedRows()).Times(2).WillRepeatedly(Return(std::set<int>()));
presenter.notify(AppendRowFlag);
presenter.notify(AppendRowFlag);
......@@ -857,7 +857,7 @@ public:
presenter.notify(SaveFlag);
//...then deletes the 2nd row
std::set<size_t> rows;
std::set<int> rows;
rows.insert(1);
EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(rows));
presenter.notify(DeleteRowFlag);
......@@ -884,7 +884,7 @@ public:
ReflMainViewPresenter presenter(&mockView);
//User hits "append row" a couple of times
EXPECT_CALL(mockView, getSelectedRows()).Times(2).WillRepeatedly(Return(std::set<size_t>()));
EXPECT_CALL(mockView, getSelectedRows()).Times(2).WillRepeatedly(Return(std::set<int>()));
presenter.notify(AppendRowFlag);
presenter.notify(AppendRowFlag);
......@@ -907,7 +907,7 @@ public:
createPrefilledWorkspace("TestWorkspace");
//User hits "append row"
EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(std::set<size_t>()));
EXPECT_CALL(mockView, getSelectedRows()).Times(1).WillRepeatedly(Return(std::set<int>()));
presenter.notify(AppendRowFlag);
//and tries to open a workspace, but gets prompted and decides not to discard
......@@ -960,8 +960,8 @@ public:
//We should not receive any errors
EXPECT_CALL(mockView, giveUserCritical(_,_)).Times(0);
std::set<size_t> selection;
std::set<size_t> expected;
std::set<int> selection;
std::set<int> expected;
selection.insert(0);
expected.insert(0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment