Skip to content

Commit

Permalink
refs #4328. Addition and Removal features.
Browse files Browse the repository at this point in the history
Can add a workspace and remove it from the memento collection. Rules applied to prevent duplicates. Most of the implementation is generic.
  • Loading branch information
OwenArnold committed Dec 19, 2011
1 parent 7d8cdee commit 2314236
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Includes
//----------------------
#include "MantidQtCustomInterfaces/QtWorkspaceMementoModel.h"
#include "MantidQtCustomInterfaces/WorkspaceMemento.h"
#include "ui_CreateMDWorkspace.h"
#include "MantidQtAPI/UserSubWindow.h"

Expand Down Expand Up @@ -37,11 +38,22 @@ namespace MantidQt
virtual void initLocalPython();
/// Run a confirmation dialog.
int runConfirmation(const std::string& message);
/// Checks the candidate is unique, then adds it to the existing data.
void addUniqueMemento(WorkspaceMemento_sptr candiate);

private slots:

void addWorkspaceClicked();

void addFileClicked();

void removeSelectedClicked();

private:
Ui::CreateMDWorkspace m_uiForm;
WorkspaceMementoCollection m_data;
WorkspaceMemento_sptr m_current;
QtWorkspaceMementoModel* m_model;
};
}
}
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>736</width>
<height>506</height>
<width>809</width>
<height>728</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -28,21 +28,57 @@
<item>
<layout class="QVBoxLayout" name="overviewLayout">
<item>
<layout class="QHBoxLayout" name="overviewControlsLayout">
<layout class="QHBoxLayout" name="fileLoadingLayout">
<item>
<widget class="QPushButton" name="btn_add_workspace">
<widget class="QPushButton" name="btn_add_file">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Add Workspace</string>
<string>Add Raw File</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="btn_remove_workspace">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remove Selected</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="workspaceLoadingLayout">
<item>
<widget class="MantidQt::MantidWidgets::WorkspaceSelector" name="workspaceSelector"/>
<widget class="QPushButton" name="btn_add_workspace">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Add Workspace</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_remove_workspace">
<property name="text">
<string>Remove Workspace</string>
<widget class="MantidQt::MantidWidgets::WorkspaceSelector" name="workspaceSelector">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
Expand All @@ -51,13 +87,13 @@
<item>
<widget class="QTableView" name="tableView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
Expand All @@ -74,12 +110,18 @@
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="workspaceEditingLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
Expand All @@ -90,36 +132,34 @@
<layout class="QHBoxLayout" name="horizontalLayout_latticeCrystal">
<item>
<widget class="QGroupBox" name="groupBox_lattice">
<property name="title">
<string>Lattice Parameters</string>
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5"/>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_orientation">
<property name="title">
<string>Crystal Orientation</string>
<string>UB Matrix</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5"/>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_logValues_Goniometer">
<item>
<widget class="QGroupBox" name="groupBox_logvalues">
<property name="title">
<string>Log Values</string>
</property>
<layout class="QHBoxLayout" name="logValueLayout"/>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_goniometeroffsets">
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
<property name="title">
<string>Goniometer Offsets</string>
<string>Goniometer Settings</string>
</property>
<zorder>tableView</zorder>
</widget>
</item>
</layout>
Expand All @@ -139,31 +179,6 @@
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_optional">
<item>
<widget class="QGroupBox" name="groupBox_instrument">
<property name="title">
<string>Instrument</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_chopper">
<property name="title">
<string>Chopper</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_sample">
<property name="title">
<string>Sample</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
Expand All @@ -174,27 +189,6 @@
</item>
<item>
<layout class="QHBoxLayout" name="controlButtonsLayout">
<item>
<widget class="QPushButton" name="btn_revert">
<property name="text">
<string>Revert All Changes</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_apply_all">
<property name="text">
<string>Apply to All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_n_selected">
<property name="text">
<string>Apply to n-selected</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_create">
<property name="text">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <QAbstractTableModel>
#include <boost/shared_ptr.hpp>
#include "MantidQtCustomInterfaces/Updateable.h"
#include "MantidQtCustomInterfaces/WorkspaceMemento.h"

// Forward declarations
namespace Mantid
Expand Down Expand Up @@ -46,7 +47,7 @@ namespace MantidQt
class QtWorkspaceMementoModel : public QAbstractTableModel, public Updateable
{
public:
QtWorkspaceMementoModel(boost::shared_ptr<Mantid::API::ITableWorkspace> displayData);
QtWorkspaceMementoModel(const WorkspaceMementoCollection& displayData);
void update();
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
Expand All @@ -57,8 +58,8 @@ namespace MantidQt

private:

/// Table workspace of display data for view.
boost::shared_ptr<Mantid::API::ITableWorkspace> m_displayData;
/// Collection of data for viewing.
const WorkspaceMementoCollection& m_displayData;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ namespace MantidQt
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const;

virtual std::string statusReport() const;

/// Destructor
virtual ~WorkspaceInADS();
private:
/// Id/name of the workspace in the ADS
std::string m_wsName;
/// Status report message.
std::string m_statusReportMessage;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#define MANTID_CUSTOMINTERFACES_MEMENTO_H_

#include "MantidKernel/System.h"
#include <string>
#include "MantidAPI/MatrixWorkspace.h"

#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>

namespace MantidQt
{
Expand Down Expand Up @@ -62,9 +63,39 @@ namespace MantidQt
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const = 0;
/**
Generates a status report based on the workspace state.
*/
virtual std::string statusReport() const = 0;
/// Destructor
virtual ~WorkspaceMemento(){};

protected:

/**
Common implementation of report generation.
@param ws : workspace to report on.
*/
std::string generateReport(Mantid::API::MatrixWorkspace_sptr ws)
{
std::string msg;
if(!ws->sample().hasOrientedLattice())
{
msg = "Has no Oriented Lattice";
}
else
{
msg = "Ready!";
}
return msg;
}

};

/// WorkspaceMemento shared_ptr
typedef boost::shared_ptr<WorkspaceMemento> WorkspaceMemento_sptr;
/// Collection of WorkspaceMementos.
typedef std::vector<WorkspaceMemento_sptr> WorkspaceMementoCollection;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MANTID_CUSTOMINTERFACES_WORKSPACE_IN_ADS_H_
#define MANTID_CUSTOMINTERFACES_WORKSPACE_IN_ADS_H_
#ifndef MANTID_CUSTOMINTERFACES_WORKSPACE_ON_DISK_H_
#define MANTID_CUSTOMINTERFACES_WORKSPACE_ON_DISK_H_

#include "MantidQtCustomInterfaces/WorkspaceMemento.h"

Expand Down Expand Up @@ -57,11 +57,18 @@ namespace MantidQt
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const;

virtual std::string statusReport() const;

/// Destructor
virtual ~WorkspaceOnDisk();
private:
/// Helper method to delete a workspace out of memory after loading.
void dumpIt(const std::string& name);
/// Path + name of file containing workspace to use.
std::string m_fileName;
/// Status report message.
std::string m_statusReportMessage;
};

}
Expand Down

0 comments on commit 2314236

Please sign in to comment.