Commit 0fc8e466 authored by Dimitar Tasev's avatar Dimitar Tasev
Browse files

Added int/sigint column, extended peakWS, delete row, re #24007

parent bd226698
......@@ -964,6 +964,8 @@ double Peak::getValueByColName(const std::string &name_in) const {
return this->getIntensity();
else if (name == "sigint")
return this->getSigmaIntensity();
else if (name == "int/sigint")
return this->getIntensityOverSigma();
else if (name == "bincount")
return this->getBinCount();
else if (name == "row")
......
......@@ -53,6 +53,7 @@ const std::string typeFromName(const std::string &name) {
TYPE_INDEX.emplace("DSpacing", "double");
TYPE_INDEX.emplace("Intens", "double");
TYPE_INDEX.emplace("SigInt", "double");
TYPE_INDEX.emplace("Int/SigInt", "double");
TYPE_INDEX.emplace("BinCount", "double");
TYPE_INDEX.emplace("BankName", "str");
TYPE_INDEX.emplace("Row", "double");
......
......@@ -659,6 +659,7 @@ void PeaksWorkspace::initColumns() {
addPeakColumn("DSpacing");
addPeakColumn("Intens");
addPeakColumn("SigInt");
addPeakColumn("Int/SigInt");
addPeakColumn("BinCount");
addPeakColumn("BankName");
addPeakColumn("Row");
......@@ -722,6 +723,7 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
std::vector<double> L(np);
std::vector<double> intensity(np);
std::vector<double> sigmaIntensity(np);
std::vector<double> intensityOverSigma(np);
std::vector<double> binCount(np);
std::vector<double> initialEnergy(np);
std::vector<double> finalEnergy(np);
......@@ -744,6 +746,7 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const {
L[i] = p.getL();
intensity[i] = p.getIntensity();
sigmaIntensity[i] = p.getSigmaIntensity();
intensityOverSigma[i] = p.getIntensityOverSigma();
binCount[i] = p.getBinCount();
initialEnergy[i] = p.getInitialEnergy();
finalEnergy[i] = p.getFinalEnergy();
......
......@@ -3,7 +3,7 @@ from __future__ import (absolute_import, division, print_function)
from qtpy import QtGui
from qtpy.QtCore import QPoint
from qtpy.QtGui import QCursor, QFont, QFontMetrics
from qtpy.QtWidgets import (QTableView, QToolTip)
from qtpy.QtWidgets import (QMessageBox, QTableView, QToolTip)
NO_SELECTION_MESSAGE = "No selection"
COPY_SUCCESSFUL_MESSAGE = "Copy Successful"
......@@ -80,7 +80,6 @@ def copy_cells(table):
return
selection = selectionModel.selection()
# TODO show a warning if copying more cells than some number (100? 200? 300? 400??)
selectionRange = selection.first()
top = selectionRange.top()
......@@ -135,3 +134,12 @@ def copy_to_clipboard(data):
"""
cb = QtGui.QGuiApplication.clipboard()
cb.setText(data, mode=cb.Clipboard)
def ask_confirmation(self, message, title="Mantid Workbench"):
"""
:param message:
:return:
"""
reply = QMessageBox.question(self, title, message, QMessageBox.Yes, QMessageBox.No)
return True if reply == QMessageBox.Yes else False
......@@ -21,7 +21,8 @@ from mantidqt.widgets.tableworkspacedisplay.presenter import TableWorkspaceDispl
from workbench.plotting.functions import plot # noqa: F402
app = QApplication([])
# DEEE_WS_MON = Load("SavedTableWorkspace.nxs")
DEEE_WS_MON = Load("SmallPeakWS10.nxs")
DEEE_WS_MON = Load("SavedTableWorkspace.nxs")
# DEEE_WS_MON = Load("TOPAZ_3007.peaks.nxs")
# DEEE_WS_MON = Load("SmallPeakWS10.nxs")
window = TableWorkspaceDisplay(DEEE_WS_MON, plot)
app.exec_()
......@@ -17,26 +17,62 @@ class TableWorkspaceDisplayModel(object):
SPECTRUM_PLOT_LEGEND_STRING = '{}-{}'
BIN_PLOT_LEGEND_STRING = '{}-bin-{}'
# PEAKS_WORKSPACE_EDITABLE_COLUMNS = ["RunNumber", "h", "k", "l"]
def __init__(self, ws):
if not isinstance(ws, TableWorkspace) and not isinstance(ws, PeaksWorkspace):
raise ValueError("The workspace type is not supported: {0}".format(type(ws)))
self._ws = ws
self.ws = ws
self.ws_num_rows = self.ws.rowCount()
self.ws_num_cols = self.ws.columnCount()
@staticmethod
def is_peaks_workspace(ws):
return isinstance(ws, PeaksWorkspace)
def get_name(self):
return self._ws.name()
return self.ws.name()
def get_column_headers(self):
return self._ws.getColumnNames()
return self.ws.getColumnNames()
def get_column(self, index):
return self._ws.column(index)
return self.ws.column(index)
def get_number_of_rows(self):
return self._ws.rowCount()
return self.ws_num_rows
def get_number_of_columns(self):
return self._ws.columnCount()
return self.ws_num_cols
def is_peaks_workspace(self):
return isinstance(self._ws, PeaksWorkspace)
# class PeaksWorkspaceDisplayModel(TableWorkspaceDisplayModel):
# def __init__(self, ws):
# super(PeaksWorkspaceDisplayModel, self).__init__(ws)
# self.sigma_col_index = None
#
# def get_column_headers(self):
# column_names = self.ws.getColumnNames()
# self.sigma_col_index = column_names.index("SigInt") + 1
# # insert the intensity/sigma after the sigma column
# column_names.insert(self.sigma_col_index, "I/σ")
# # update the number of columns
# self.ws_num_cols = len(column_names)
# return column_names
#
# def get_column(self, index):
# """
# Get data for a column from the PeaksWorkspace.
#
# Handles the index for the additional column Intensity/Sigma column correctly,
# as the column itself is only added
# :param index:
# :return:
# """
# if index < self.sigma_col_index:
# return self.ws.column(index)
# elif index > self.sigma_col_index:
# return self.ws.column(index - 1)
# else:
# num_rows = self.get_number_of_rows()
# return [self.ws.getPeak(i).getIntensityOverSigma() for i in range(num_rows)]
......@@ -9,10 +9,10 @@
#
from __future__ import absolute_import, division, print_function
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QTableWidgetItem
from mantidqt.widgets.common.table_copying import copy_cells
from mantid.simpleapi import DeleteTableRows
from mantidqt.widgets.common.table_copying import copy_cells, show_no_selection_to_copy_toast
from .model import TableWorkspaceDisplayModel
from .view import TableWorkspaceDisplayView
......@@ -23,26 +23,35 @@ class TableWorkspaceDisplay(object):
def __init__(self, ws, plot=None, parent=None, model=None, view=None):
# Create model and view, or accept mocked versions
self.model = model if model else TableWorkspaceDisplayModel(ws)
if model:
self.model = model
self.model = TableWorkspaceDisplayModel(ws)
self.view = view if view else TableWorkspaceDisplayView(self, parent, self.model.get_name())
self.plot = plot
self.view.set_context_menu_actions(self.view)
column_headers = self.model.get_column_headers()
# self.editable_columns = self.model.get_editable_columns(column_headers)
self.view.setColumnCount(len(column_headers))
self.view.setHorizontalHeaderLabels(["{}[Y]".format(x) for x in column_headers])
self.load_data(self.view, self.model.is_peaks_workspace())
self.view.setHorizontalHeaderLabels(column_headers)
# self.view.setHorizontalHeaderLabels(["{}[Y]".format(x) for x in column_headers])
self.load_data(self.view)
def load_data(self, table, peaks_workspace=False):
def load_data(self, table):
num_rows = self.model.get_number_of_rows()
table.setRowCount(num_rows)
num_cols = self.model.get_number_of_columns()
for col in range(num_cols):
column_data = self.model.get_column(col)
# editable = False
# if peaks_workspace and col in self.editable_columns:
# editable = True
for row in range(num_rows):
item = QTableWidgetItem(str(column_data[row]))
if not peaks_workspace or (col != 0 and col != 2 and col != 3 and col != 4):
item.setFlags(item.flags() & ~Qt.ItemIsEditable)
# if not editable:
# item.setFlags(item.flags() & ~Qt.ItemIsEditable)
table.setItem(row, col, item)
def action_copy_cells(self, table):
......@@ -56,6 +65,26 @@ class TableWorkspaceDisplay(object):
def action_keypress_copy(self, table):
copy_cells(table)
def action_delete_row(self):
selection_model = self.view.selectionModel()
if not selection_model.hasSelection():
show_no_selection_to_copy_toast()
return
selected_rows = selection_model.selectedRows()
selected_rows_list = [index.row() for index in selected_rows]
selected_rows_str = ",".join([str(row) for row in selected_rows_list])
print("Selected rows:", selected_rows_str)
DeleteTableRows(self.model.ws, selected_rows_str)
# Reverse the list so that we delete in order from bottom -> top
# this prevents the row index from shifting up when deleting rows above
for row in reversed(selected_rows_list):
self.view.removeRow(row)
def action_statistics_on_rows(self):
raise NotImplementedError("Not implemented")
# def _do_action_plot(self, table, axis, get_index, plot_errors=False):
# if self.plot is None:
# raise ValueError("Trying to do a plot, but no plotting class dependency was injected in the constructor")
......
......@@ -12,9 +12,9 @@ from __future__ import (absolute_import, division, print_function)
from functools import partial
from qtpy import QtGui
from qtpy.QtCore import QPoint, Qt
from qtpy.QtGui import QCursor, QFont, QFontMetrics, QKeySequence
from qtpy.QtWidgets import (QAction, QHeaderView, QMessageBox, QTableView, QTableWidget, QToolTip)
from qtpy.QtCore import Qt
from qtpy.QtGui import QKeySequence
from qtpy.QtWidgets import (QAction, QHeaderView, QMessageBox, QTableView, QTableWidget)
import mantidqt.icons
......@@ -25,6 +25,8 @@ class TableWorkspaceDisplayView(QTableWidget):
self.presenter = presenter
self.COPY_ICON = mantidqt.icons.get_icon("fa.files-o")
self.DELETE_ROW = mantidqt.icons.get_icon("fa.minus-square-o")
self.STATISTICS_ON_ROW = mantidqt.icons.get_icon('fa.fighter-jet')
# change the default color of the rows - makes them light blue
# monitors and masked rows are colored in the table's custom model
......@@ -38,10 +40,12 @@ class TableWorkspaceDisplayView(QTableWidget):
self.resize(600, 400)
self.show()
def doubleClickedHeader(self):
print("Double clicked WOO")
def keyPressEvent(self, event):
if event.matches(QKeySequence.Copy):
self.presenter.action_keypress_copy(self)
super(TableWorkspaceDisplayView, self).keyPressEvent(event)
def set_context_menu_actions(self, table):
"""
......@@ -64,7 +68,7 @@ class TableWorkspaceDisplayView(QTableWidget):
horizontalHeader.setSectionResizeMode(QHeaderView.Fixed)
copy_bin_values = QAction(self.COPY_ICON, "Copy", horizontalHeader)
copy_bin_values.triggered.connect(partial(self.presenter.action_copy_bin_values, table))
copy_bin_values.triggered.connect(self.presenter.action_copy_bin_values)
horizontalHeader.addAction(copy_bin_values)
......@@ -73,13 +77,24 @@ class TableWorkspaceDisplayView(QTableWidget):
verticalHeader.setSectionResizeMode(QHeaderView.Fixed)
copy_spectrum_values = QAction(self.COPY_ICON, "Copy", verticalHeader)
copy_spectrum_values.triggered.connect(partial(self.presenter.action_copy_spectrum_values, table))
copy_spectrum_values.triggered.connect(self.presenter.action_copy_spectrum_values)
delete_row = QAction(self.DELETE_ROW, "Delete Row", verticalHeader)
delete_row.triggered.connect(self.presenter.action_delete_row)
statistics_on_rows = QAction(self.STATISTICS_ON_ROW, "Statistics on Rows", verticalHeader)
statistics_on_rows.triggered.connect(self.presenter.action_statistics_on_rows)
separator1 = QAction(verticalHeader)
separator1.setSeparator(True)
separator2 = QAction(verticalHeader)
separator2.setSeparator(True)
verticalHeader.addAction(copy_spectrum_values)
verticalHeader.addAction(separator1)
verticalHeader.addAction(delete_row)
verticalHeader.addAction(separator2)
verticalHeader.addAction(statistics_on_rows)
@staticmethod
def copy_to_clipboard(data):
......@@ -93,7 +108,6 @@ class TableWorkspaceDisplayView(QTableWidget):
cb = QtGui.QGuiApplication.clipboard()
cb.setText(data, mode=cb.Clipboard)
def ask_confirmation(self, message, title="Mantid Workbench"):
"""
:param message:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment