17#include <Poco/ActiveResult.h>
20#include <QDesktopWidget>
29namespace MantidWidgets {
36 m_currentPageNumber(1) {
54 m_icatUiForm.facilityName->setText(QString::fromStdString(
78 m_calendar =
new QCalendarWidget(qobject_cast<QWidget *>(this->parent()));
100 connect(
m_icatUiForm.searchResultsTbl, SIGNAL(itemDoubleClicked(QTableWidgetItem *)),
this,
106 connect(
m_icatUiForm.dataFileFilterCombo, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
doFilter(
int)));
115 connect(
m_icatUiForm.dataFileResultsTbl, SIGNAL(itemClicked(QTableWidgetItem *)),
this,
148 QRegExp re(
"[0-9]*(-|:){1}[0-9]*");
149 m_icatUiForm.RunRange->setValidator(
new QRegExpValidator(re,
this));
151 m_icatUiForm.pageStartNum->setValidator(
new QIntValidator(0, 999,
this));
154 this->resize(minimumSizeHint());
156 this->setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, this->window()->size(),
157 QDesktopWidget().availableGeometry()));
213 for (
int i = 0; i < table->columnCount(); ++i) {
214 table->horizontalHeaderItem(i)->setFont(font);
225 table->setRowCount(
static_cast<int>(numOfRows));
226 table->setColumnCount(
static_cast<int>(numOfColumns));
229 table->setAlternatingRowColors(
true);
230 table->setStyleSheet(
"alternate-background-color: rgb(216, 225, 255)");
231 table->setSortingEnabled(
false);
232 table->verticalHeader()->setVisible(
false);
235 for (
size_t i = 0; i < numOfRows; ++i) {
236 table->setRowHeight(
static_cast<int>(i), 20);
250 QStringList columnHeaders;
251 columnHeaders.reserve(
static_cast<int>(
workspace->columnCount()));
254 for (
size_t col = 0; col <
workspace->columnCount(); col++) {
257 columnHeaders.push_back(QString::fromStdString(column->name()));
259 for (
size_t row = 0; row <
workspace->rowCount(); ++row) {
261 std::ostringstream ostr;
262 column->print(row, ostr);
265 QTableWidgetItem *newItem =
new QTableWidgetItem(QString::fromStdString(ostr.str()));
266 table->setItem(
static_cast<int>(row),
static_cast<int>(col), newItem);
269 newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
270 newItem->setToolTip(QString::fromStdString(ostr.str()));
274 table->setHorizontalHeaderLabels(columnHeaders);
306 m_icatUiForm.searchResultsLbl->setText(
"0 investigations found.");
330 QAbstractItemModel *model = table->model();
333 for (
int col = 0; col < table->columnCount(); col++) {
335 if (searchFor.compare(model->headerData(col, Qt::Horizontal, Qt::DisplayRole).toString().toStdString()) == 0) {
349 settings.beginGroup(
"/ICatSettings");
359 settings.beginGroup(
"/ICatSettings");
361 QString lastdir = settings.value(
"lastDownloadPath").toString();
364 if (lastdir.isEmpty()) {
382 std::vector<std::string> instrumentList =
392 for (
unsigned i = 0; i < instrumentList.size(); i++) {
393 QString instrument = QString::fromStdString(instrumentList.at(i));
396 if (userInstrument.compare(instrument) == 0) {
407 std::vector<std::string> invesTypeList =
410 std::vector<std::string>::const_iterator citr;
411 for (citr = invesTypeList.begin(); citr != invesTypeList.end(); ++citr) {
413 m_icatUiForm.InvestigationType->addItem(QString::fromStdString(*citr));
429 std::map<std::string, std::string> searchFieldInput;
432 searchFieldInput.emplace(
"InvestigationName",
m_icatUiForm.InvestigationName->text().toStdString());
433 searchFieldInput.emplace(
"Instrument",
m_icatUiForm.Instrument->currentText().toStdString());
435 searchFieldInput.emplace(
"RunRange",
m_icatUiForm.RunRange->text().toStdString());
437 searchFieldInput.emplace(
"InvestigatorSurname",
m_icatUiForm.InvestigatorSurname->text().toStdString());
438 searchFieldInput.emplace(
"DataFileName",
m_icatUiForm.DataFileName->text().toStdString());
439 searchFieldInput.emplace(
"InvestigationId",
m_icatUiForm.InvestigationId->text().toStdString());
443 searchFieldInput.emplace(
"StartDate",
m_icatUiForm.StartDate->text().toStdString());
446 searchFieldInput.emplace(
"EndDate",
m_icatUiForm.EndDate->text().toStdString());
448 searchFieldInput.emplace(
"Keywords",
m_icatUiForm.Keywords->text().toStdString());
449 searchFieldInput.emplace(
"SampleName",
m_icatUiForm.SampleName->text().toStdString());
450 searchFieldInput.emplace(
"InvestigationType",
m_icatUiForm.InvestigationType->currentText().toStdString());
456 searchFieldInput.emplace(
"MyData", boost::lexical_cast<std::string>(
m_icatUiForm.myDataCbox->isChecked()));
458 return (searchFieldInput);
470 m_calendar->setMinimumDate(QDate(1950, 1, 1));
471 m_calendar->setMaximumDate(QDate(2050, 1, 1));
475 QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, QSize(445, 205), QDesktopWidget().availableGeometry()));
479 m_calendar->setWindowTitle(
"Calendar picker");
495 m_icatUiForm.StartDate->setText(date.toString(
"dd/MM/yyyy"));
497 m_icatUiForm.EndDate->setText(date.toString(
"dd/MM/yyyy"));
507 std::string startDateInput =
m_icatUiForm.StartDate->text().toStdString();
508 std::string endDateInput =
m_icatUiForm.EndDate->text().toStdString();
512 if (startDateInput.size() <= 2 || endDateInput.size() <= 2)
530 label->setToolTip(QString::fromStdString(
"<span style=\"color: black;\">" + text +
"</span>"));
532 label->setToolTip(QString::fromStdString(
"<span style=\"color: white;\">" + text +
"</span>"));
566 auto name = sender()->objectName();
570 if (name.compare(
"searchBtn") == 0)
584 m_icatUiForm.searchResultsLbl->setText(
"An error has occurred in the search form.");
603 m_icatUiForm.searchResultsLbl->setText(
"searching investigations...");
606 QTableWidget *resultsTable =
m_icatUiForm.searchResultsTbl;
607 int sort_section = resultsTable->horizontalHeader()->sortIndicatorSection();
608 Qt::SortOrder sort_order = resultsTable->horizontalHeader()->sortIndicatorOrder();
611 std::string searchResults =
"searchResults";
622 double totalNumPages = ceil(
static_cast<double>(numrows) / limit);
627 m_icatUiForm.resPageEndNumTxt->setText(QString::number(totalNumPages));
634 m_icatUiForm.searchResultsLbl->setText(QString::number(numrows) +
" investigations found.");
646 for (
auto &
error : errors) {
647 QLabel *label =
m_icatUiForm.searchFrame->findChild<QLabel *>(QString::fromStdString(
error.first));
666 m_icatUiForm.InvestigatorSurname_err->setVisible(
false);
667 m_icatUiForm.InvestigationAbstract_err->setVisible(
false);
681 foreach (QLineEdit *widget, this->findChildren<QLineEdit *>()) { widget->clear(); }
716 workspace = std::dynamic_pointer_cast<Mantid::API::ITableWorkspace>(
721 m_icatUiForm.searchResultsLbl->setText(
"You have not input any terms to search for.");
733 QTableWidget *resultsTable =
m_icatUiForm.searchResultsTbl;
752 resultsTable->setColumnHidden(
headerIndexByName(resultsTable,
"DatabaseID"),
true);
753 resultsTable->setColumnHidden(
headerIndexByName(resultsTable,
"SessionID"),
true);
756 resultsTable->resizeColumnToContents(
headerIndexByName(resultsTable,
"InvestigationID"));
759 resultsTable->setSortingEnabled(
true);
760 if (sort_section == 0) {
761 resultsTable->sortByColumn(
headerIndexByName(resultsTable,
"Start date"), Qt::DescendingOrder);
763 resultsTable->sortByColumn(sort_section, sort_order);
774 auto searchResultsTable =
m_icatUiForm.searchResultsTbl;
775 return searchResultsTable
776 ->item(searchResultsTable->selectionModel()->selectedRows().at(0).row(),
790 int totalNumPages =
m_icatUiForm.resPageEndNumTxt->text().toInt();
820 int pageNum =
m_icatUiForm.pageStartNum->text().toInt();
823 if (pageNum >
m_icatUiForm.resPageEndNumTxt->text().toInt() || pageNum <= 0) {
847 m_icatUiForm.dataFileLbl->setText(
"searching for related datafiles...");
849 QTableWidget *searchResultsTable =
m_icatUiForm.searchResultsTbl;
852 QTableWidgetItem *investigationId =
853 searchResultsTable->item(item->row(),
headerIndexByName(searchResultsTable,
"InvestigationID"));
856 std::string dataFileResults =
"dataFileResults";
866 investigationId->text().toStdString(),
867 searchResultsTable->item(item->row(),
headerIndexByName(searchResultsTable,
"SessionID"))->text().toStdString());
888 workspace = std::dynamic_pointer_cast<Mantid::API::ITableWorkspace>(
902 QTableWidget *dataFileTable =
m_icatUiForm.dataFileResultsTbl;
931 dataFileTable->resizeColumnsToContents();
936 dataFileTable->setColumnHidden(
headerIndexByName(dataFileTable,
"Location"),
true);
937 dataFileTable->setColumnHidden(
headerIndexByName(dataFileTable,
"File size(bytes)"),
true);
948 dataFileTable->setSortingEnabled(
true);
949 dataFileTable->sortByColumn(
headerIndexByName(dataFileTable,
"Name"), Qt::DescendingOrder);
958 table->insertColumn(0);
961 table->setHorizontalHeaderItem(0,
new QTableWidgetItem());
967 for (
int row = 0; row < table->rowCount(); row++) {
968 auto *newItem =
new QTableWidgetItem();
970 newItem->setCheckState(Qt::Unchecked);
972 newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
974 table->setItem(row, 0, newItem);
988 std::vector<std::pair<int64_t, std::string>> fileInfo;
990 for (
int row = 0; row < table->rowCount(); row++) {
991 if (table->item(row, 0)->checkState()) {
992 fileInfo.emplace_back(table->item(row,
headerIndexByName(table,
"Id"))->text().toLongLong(),
1004 QTableWidget *searchResultsTable =
m_icatUiForm.searchResultsTbl;
1009 searchResultsTable->item(item->row(),
headerIndexByName(searchResultsTable,
"Title"))->text());
1014 searchResultsTable->item(item->row(),
headerIndexByName(searchResultsTable,
"Instrument"))->text());
1018 searchResultsTable->item(item->row(),
headerIndexByName(searchResultsTable,
"Run range"))->text());
1027 std::unordered_set<std::string> extensions;
1030 for (
unsigned row = 0; row < column->size(); row++) {
1032 QString extension = QString::fromStdString(Poco::Path(column->cell<std::string>(row)).getExtension());
1033 extensions.insert(extension.toLower().toStdString());
1036 return (extensions);
1043 for (
const auto &extension : extensions) {
1044 m_icatUiForm.dataFileFilterCombo->addItem(QString::fromStdString(
"." + extension));
1058 std::string location = table->item(row,
headerIndexByName(table,
"Location"))->text().toStdString();
1066 std::ifstream hasAccessToArchives(fileLocation.c_str());
1067 if (hasAccessToArchives) {
1085 if (
m_icatUiForm.dataFileResultsTbl->selectionModel()->selection().indexes().empty()) {
1097 for (
int row = 0; row < table->rowCount(); ++row) {
1099 table->setRowHidden(row,
true);
1105 table->item(row, 0)->setCheckState(Qt::Unchecked);
1112 if (
index == 0 || (item->text().toLower().contains(
m_icatUiForm.dataFileFilterCombo->itemText(
index).toLower()))) {
1113 table->setRowHidden(row,
false);
1122 QString downloadSavePath = QFileDialog::getExistingDirectory(
this, tr(
"Select a directory to save data files."),
1126 if (!downloadSavePath.isEmpty()) {
1149 loadAlgorithm->initialize();
1152 for (
auto &filePath : filePaths) {
1153 if (filePath.empty())
1156 loadAlgorithm->setPropertyValue(
"Filename", filePath);
1158 loadAlgorithm->setPropertyValue(
"OutputWorkspace", Poco::Path(Poco::Path(filePath).getFileName()).getBaseName());
1161 while (!result.available()) {
1162 QCoreApplication::processEvents();
1177 QItemSelectionModel *selectionModel = table->selectionModel();
1183 selectionModel->select(selectionModel->selection(), QItemSelectionModel::Deselect);
1186 for (
int row = 0; row < table->rowCount(); ++row) {
1188 table->item(row, 0)->setCheckState(Qt::Checked);
1190 table->item(row, 0)->setCheckState(Qt::Unchecked);
1201 QTableWidgetItem *checkbox = table->item(item->row(), 0);
1203 for (
int col = 0; col < table->columnCount(); col++) {
1204 for (
int row = 0; row < table->rowCount(); ++row) {
1205 if (checkbox->checkState()) {
1206 table->item(item->row(), 0)->setCheckState(Qt::Checked);
1207 table->item(item->row(), col)->setSelected(
true);
1209 table->item(item->row(), 0)->setCheckState(Qt::Unchecked);
1211 table->item(item->row(), col)->setSelected(
false);
1223 for (
int row = 0; row < table->rowCount(); ++row) {
1226 if (!table->item(row, 0)->isSelected()) {
1227 table->item(row, 0)->setCheckState(Qt::Unchecked);
1231 QModelIndexList indexes = table->selectionModel()->selectedRows();
1233 for (
int i = 0; i < indexes.count(); ++i) {
1234 int row = indexes.at(i).row();
1235 table->item(row, 0)->setCheckState(Qt::Checked);
1254 for (
int row = 0; row < table->rowCount(); row++) {
1255 auto *item =
new QTableWidgetItem;
1256 item->setData(Qt::EditRole, table->item(row, byteColumn)->text().toInt());
1257 table->setItem(row, byteColumn, item);
1259 table->sortByColumn(byteColumn);
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
This class provides a wrapper around QDesktopServices to fix a bug in opening URLs in firefox when tc...
static bool openUrl(const QUrl &url)
Opens a url in the appropriate web browser.
virtual std::string transformArchivePath(const std::string &path) const
Transform's the archive path based on operating system used.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
UserCatalogInfo : Takes catalog info from the facility (via CatalogInfo), but provides the ability to...
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< Column > Column_sptr
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
CatalogConfigService * makeCatalogConfigServiceAdapter(const T &adaptee, const std::string &key="icatDownload.mountPoint")