14#include <Poco/AutoPtr.h>
15#include <Poco/Notification.h>
16#include <Poco/NotificationCenter.h>
26#include <QStyledItemDelegate>
34QStringList headerLabels = {
"Workspace Name",
"Ws Index"};
44namespace MantidWidgets {
67 this->setColumnCount(headerLabels.size());
68 this->verticalHeader()->setVisible(
false);
69 this->horizontalHeader()->setVisible(
true);
70 this->setHorizontalHeaderLabels(headerLabels);
72 this->setSelectionMode(QAbstractItemView::ExtendedSelection);
73 this->setSortingEnabled(
true);
74 this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
80 Mantid::API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_addObserver);
81 Mantid::API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_remObserver);
82 Mantid::API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_clearObserver);
83 Mantid::API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_renameObserver);
84 Mantid::API::AnalysisDataService::Instance().notificationCenter.removeObserver(
m_replaceObserver);
100 const QTableWidgetItem *item = currentItem();
101 return (item !=
nullptr);
112 insertRow(rowCount());
113 auto nameItem = std::make_unique<QTableWidgetItem>(QString::fromStdString(
name));
114 auto indexItem = std::make_unique<QTableWidgetItem>(QString::fromStdString(
getIndexString(
name)));
116 nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
118 setItem(rowCount() - 1,
namesCol, nameItem.release());
119 setItem(rowCount() - 1,
indexCol, indexItem.release());
124 this->item(row,
namesCol)->setText(QString::fromStdString(newName));
129 for (
auto const &
name : names) {
137 auto selRows = selectionModel()->selectedRows();
139 nameIndexPairVec.reserve(
static_cast<std::size_t
>(selRows.size()));
140 for (
auto const &
index : selRows) {
141 std::string txt = item(
index.row(),
namesCol)->text().toStdString();
143 std::string idx = item(
index.row(),
indexCol)->text().toStdString();
144 nameIndexPairVec.push_back(std::make_pair(txt, idx));
147 nameIndexPairVec.shrink_to_fit();
148 return nameIndexPairVec;
152 auto selIndex = this->selectedIndexes();
153 if (!selIndex.isEmpty()) {
154 for (
auto &
index : selIndex) {
155 std::string selName = this->item(
index.row(),
namesCol)->text().toStdString();
162 auto selIndex = this->selectedIndexes();
163 if (!selIndex.isEmpty()) {
164 auto rangeFirst = this->item(selIndex.takeFirst().row(),
indexCol)->text();
165 for (
auto &
index : selIndex) {
172 const std::lock_guard<std::mutex> lock(
m_adsMutex);
179 const std::lock_guard<std::mutex> lock(
m_adsMutex);
180 QString
name = QString::fromStdString(pNf->objectName());
181 auto items = findItems(
name, Qt::MatchExactly);
182 if (!items.isEmpty()) {
183 for (
auto &item : items)
184 removeRow(item->row());
186 if (rowCount() == 0) {
192 const std::lock_guard<std::mutex> lock(
m_adsMutex);
193 this->clearContents();
194 while (rowCount() > 0) {
201 const std::lock_guard<std::mutex> lock(
m_adsMutex);
203 QString newName = QString::fromStdString(pNf->newObjectName());
204 QString currName = QString::fromStdString(pNf->objectName());
207 auto currItems = findItems(currName, Qt::MatchExactly);
208 auto newItems = findItems(newName, Qt::MatchExactly);
211 if (!currItems.isEmpty() && newItems.isEmpty())
212 renameItem(pNf->newObjectName(), currItems.first()->row());
213 else if (currItems.isEmpty() && newItems.isEmpty())
215 else if (!currItems.isEmpty() && !newItems.isEmpty()) {
217 removeRow(currItems.first()->row());
218 renameItem(pNf->newObjectName(), newItems.first()->row());
221 if (!currItems.isEmpty())
222 removeRow(currItems.first()->row());
227 const std::lock_guard<std::mutex> lock(
m_adsMutex);
228 QString
name = QString::fromStdString(pNf->objectName());
230 auto items = findItems(
name, Qt::MatchExactly);
232 if ((eligible && !items.isEmpty()) || (!eligible && items.isEmpty()))
234 else if (items.isEmpty() && eligible) {
237 removeRow(items.first()->row());
242 auto const workspace = Mantid::API::AnalysisDataService::Instance().retrieve(
name);
251 if (
name.find_last_of(
"_") <
name.size())
252 return m_suffix.contains(QString::fromStdString(
name.substr(
name.find_last_of(
"_"))));
257 const std::lock_guard<std::mutex> lock(
m_adsMutex);
258 this->clearContents();
259 auto const items = Mantid::API::AnalysisDataService::Instance().getObjectNames();
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
std::vector< std::pair< std::string, std::string > > StringPairVec
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
Poco::NotificationCenter notificationCenter
Sends notifications to observers.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::AfterReplaceNotification > & WorkspaceAfterReplaceNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::ClearNotification > & ClearADSNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::RenameNotification > & WorkspaceRenameNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::AddNotification > & WorkspaceAddNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::PostDeleteNotification > & WorkspacePostDeleteNotification_ptr