17#include <QApplication>
28#include <QTemporaryFile>
46int getNumberOfItemsInTree(QTreeWidgetItem *item) {
49 for (
int i = 0; i < item->childCount(); i++) {
50 if (item->child(i)->checkState(1) == Qt::Checked) {
52 count += getNumberOfItemsInTree(item->child(i));
62 : QGroupBox(w), m_execDurationlabel(nullptr), m_execDurationEdit(nullptr), m_Datelabel(nullptr),
63 m_execDateTimeEdit(nullptr), m_algexecDuration() {}
66 : QGroupBox(title, w), m_execDurationlabel(nullptr), m_execDurationEdit(nullptr), m_Datelabel(nullptr),
67 m_execDateTimeEdit(nullptr), m_algexecDuration() {
76 QDateTime datetime(QDate(0, 0, 0), QTime(0, 0, 0), QTimeZone(QTimeZone::LocalTime));
84 auto *formLayout =
new QFormLayout;
88 setLayout(formLayout);
90 setGeometry(5, 210, 205, 130);
112 dur.setNum(execDuration,
'g', 6);
115 if (execDurationEdit)
116 execDurationEdit->setText(dur);
119 std::tm t = execDate.to_localtime_tm();
120 QTime qt(t.tm_hour, t.tm_min, t.tm_sec);
121 QDate qd(t.tm_year + 1900, t.tm_mon + 1, t.tm_mday);
122 QDateTime datetime(qd, qt, QTimeZone(QTimeZone::LocalTime));
125 str = datetime.toString(
"dd/MM/yyyy hh:mm:ss");
129 datetimeEdit->setText(str);
133 : QGroupBox(w), m_osNameLabel(nullptr), m_osNameEdit(nullptr), m_osVersionLabel(nullptr), m_osVersionEdit(nullptr),
134 m_frmworkVersionLabel(nullptr), m_frmwkVersnEdit(nullptr) {}
137 : QGroupBox(title, w), m_osNameLabel(nullptr), m_osNameEdit(nullptr), m_osVersionLabel(nullptr),
138 m_osVersionEdit(nullptr), m_frmworkVersionLabel(nullptr), m_frmwkVersnEdit(nullptr) {
165 auto *formLayout =
new QFormLayout();
170 setLayout(formLayout);
172 setGeometry(214, 210, 347, 130);
202 : QDialog(parent), m_algHist(wsptr->getHistory()), m_histPropWindow(nullptr), m_execSumGrpBox(nullptr),
203 m_envHistGrpBox(nullptr), m_wsName(wsptr->
getName().c_str()), m_view(wsptr->getHistory().createView()) {
206 throw std::invalid_argument(
"No history found on the given workspace");
209 setWindowTitle(tr(
"Algorithm History"));
210 setMinimumHeight(500);
211 setMinimumWidth(750);
218 Qt::WindowFlags flags = windowFlags();
220 flags |= Qt::CustomizeWindowHint;
221 flags |= Qt::WindowMinimizeButtonHint;
222 flags |= Qt::WindowCloseButtonHint;
223 setWindowFlags(flags);
231 headers <<
"Algorithms"
250 connect(
m_Historytree, SIGNAL(unrollAlgorithmHistory(
const std::vector<int> &)),
this,
251 SLOT(
doUnroll(
const std::vector<int> &)));
255 auto *treeLayout =
new QHBoxLayout;
267 auto *environmentLayout =
new QHBoxLayout;
280 m_scriptComboMode->setToolTip(
"When to specify which version of an algorithm was used.");
286 auto *buttonLayout =
new QHBoxLayout;
287 buttonLayout->addStretch(1);
298 QVBoxLayout *mainLayout =
new QVBoxLayout(
this);
299 mainLayout->addLayout(treeLayout);
301 mainLayout->addLayout(environmentLayout);
302 mainLayout->addLayout(buttonLayout);
342 for (
size_t i = 0; i < noEntries; ++i) {
345 duration = entry->executionDuration();
346 Mantid::Types::Core::DateAndTime date = entry->executionDate();
347 pgrpBox->
setData(duration, date);
351 QMessageBox::critical(
this,
"Mantid",
"Invalid Pointer");
361 QMessageBox::critical(
this,
"Mantid",
"Invalid Pointer");
366 std::vector<PropertyHistory_sptr> histProp;
368 auto rIter = entries.rbegin();
369 histProp = (*rIter)->getProperties();
373 if (histProp.empty()) {
374 QMessageBox::critical(
this,
"Mantid",
"Properties not set");
378 if (phistPropWindow) {
380 return phistPropWindow;
382 QMessageBox::critical(
this,
"Mantid",
"Invalid Pointer");
392 if (curText ==
"Only Specify Old Versions") {
394 }
else if (curText ==
"Always Specify Versions") {
396 }
else if (curText ==
"Never Specify Versions") {
400 throw std::runtime_error(
"AlgorithmHistoryWindow::getScriptVersionMode "
401 "received unhandled version mode string");
405 QString prevDir = MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
406 QString scriptDir(
"");
408 if (prevDir.isEmpty()) {
409 scriptDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString(
"pythonscripts.directory"));
413 QString filePath = QFileDialog::getSaveFileName(
this, tr(
"Save Script As "), scriptDir, tr(
"Script files (*.py)"));
415 if (filePath.isEmpty())
420 if (!filePath.endsWith(
".py"))
424 std::ofstream file(filePath.toStdString().c_str(), std::ofstream::trunc);
425 file << builder.
build();
429 MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(QFileInfo(filePath).absoluteDir().path());
435 std::string osname = envHistory.
osName();
436 osNameEdit->setText(osname.c_str());
441 std::string osversion = envHistory.
osVersion();
442 osVersionEdit->setText(osversion.c_str());
446 if (frmwkVersnEdit) {
448 frmwkVersnEdit->setText(frwkversn.c_str());
468 double duration = algHistory->executionDuration();
469 Mantid::Types::Core::DateAndTime date = algHistory->executionDate();
477 const std::string contents = builder.
build();
478 script.append(contents.c_str());
481 QClipboard *clipboard = QApplication::clipboard();
482 if (
nullptr != clipboard) {
483 clipboard->setText(script);
488 for (
const auto &unrollIndex : unrollIndicies) {
489 m_view->unroll(unrollIndex);
497 QTreeWidgetItemIterator it(
m_Historytree, QTreeWidgetItemIterator::HasChildren);
500 if (state == Qt::Checked)
501 (*it)->setCheckState(1, Qt::Checked);
503 (*it)->setCheckState(1, Qt::Unchecked);
513 : m_Histprop(
std::move(propHist)) {
534 connect(
m_histpropTree, SIGNAL(customContextMenuRequested(
const QPoint &)),
this, SLOT(
popupMenu(
const QPoint &)));
541 while (ntopcount--) {
548 m_Histprop.assign(histProp.begin(), histProp.end());
563 QClipboard *clipboard = QApplication::clipboard();
579 QStringList propList;
580 for (std::vector<PropertyHistory_sptr>::const_iterator pIter =
m_Histprop.begin(); pIter !=
m_Histprop.end();
582 std::string sProperty = (*pIter)->name();
583 propList.append(sProperty.c_str());
585 sProperty = (*pIter)->value();
586 bool bisDefault = (*pIter)->isDefault();
587 if (bisDefault ==
true) {
588 if ((*pIter)->isEmptyDefault()) {
592 propList.append(sProperty.c_str());
594 bisDefault ? (sProperty =
"Yes") : (sProperty =
"No");
595 propList.append(sProperty.c_str());
596 int nDirection = (*pIter)->direction();
597 switch (nDirection) {
603 sProperty =
"Output";
615 propList.append(sProperty.c_str());
616 QTreeWidgetItem *item =
new QTreeWidgetItem(propList);
633 this->blockSignals(
true);
639 this->blockSignals(
false);
645 QModelIndex modelIndex;
646 if (item->parent()) {
649 modelIndex = indexFromItem(item, 1);
650 for (
auto i = 0; i < modelIndex.row(); i++) {
653 if (item->parent() && item->parent()->child(i)->checkState(1) == Qt::Checked) {
654 index += getNumberOfItemsInTree(item->parent()->child(i));
655 }
else if (item->parent() ==
nullptr && topLevelItem(i)->checkState(1) == Qt::Checked) {
656 index += getNumberOfItemsInTree(topLevelItem(i));
664 std::vector<QTreeWidgetItem *> checkedItems;
665 std::vector<int> unrollIndices;
668 for (
auto currentItem = item; currentItem; currentItem = currentItem->parent()) {
670 if (currentItem->checkState(
index) != Qt::Checked) {
671 currentItem->setCheckState(
index, Qt::Checked);
674 checkedItems.emplace_back(currentItem);
677 for (
auto it = checkedItems.rbegin(); it != checkedItems.rend(); ++it) {
678 auto currentItem = *it;
683 unrollIndices.emplace_back(unrollIndex);
685 this->blockSignals(
false);
687 this->blockSignals(
true);
697 for (
auto currentItem = item; currentItem; currentItem = currentItem->parent()) {
701 this->blockSignals(
false);
703 this->blockSignals(
true);
707 if (item->childCount() > 0) {
708 item->setCheckState(
index, Qt::Unchecked);
709 for (
int i = 0; i < item->childCount(); ++i) {
722 QTreeView::selectionChanged(selected, deselected);
727 this->blockSignals(
true);
729 auto algHistIter = entries.begin();
731 for (; algHistIter != entries.end(); ++algHistIter) {
732 int nAlgVersion = (*algHistIter)->version();
736 this->addTopLevelItem(item);
739 resizeColumnToContents(0);
740 resizeColumnToContents(1);
741 this->blockSignals(
false);
747 if (
history->childHistorySize() > 0) {
748 parentWidget->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
749 parentWidget->setCheckState(1, Qt::Unchecked);
752 for (
const auto &entry : entries) {
753 int nAlgVersion = entry->version();
757 parentWidget->addChild(item);
763 QString algName =
name.c_str();
764 algName = algName +
" v.";
765 QString algVersion = QString::number(version, 10);
766 algName += algVersion;
std::map< DeltaEMode::Type, std::string > index
std::string getName(const IMDDimension &self)
std::vector< history_type > history
history information
QLineEdit * getosNameEdit() const
QLineEdit * getosVersionEdit() const
void fillEnvHistoryGroupBox(const Mantid::Kernel::EnvironmentHistory &envHist)
QLineEdit * getfrmworkVersionEdit() const
QLineEdit * m_osVersionEdit
QLineEdit * m_frmwkVersnEdit
QLabel * m_frmworkVersionLabel
AlgEnvHistoryGrpBox(QWidget *w)
~AlgEnvHistoryGrpBox() override
QLabel * m_osVersionLabel
QLineEdit * m_execDurationEdit
QLineEdit * m_execDateTimeEdit
QLabel * m_execDurationlabel
QLineEdit * getAlgExecDateCtrl() const
AlgExecSummaryGrpBox(QWidget *w)
void setData(const double execDuration, const Mantid::Types::Core::DateAndTime execDate)
~AlgExecSummaryGrpBox() override
QLineEdit * getAlgExecDurationCtrl() const
QTreeWidget * m_histpropTree
void popupMenu(const QPoint &pos)
void setAlgProperties(const std::vector< Mantid::Kernel::PropertyHistory_sptr > &histProp)
AlgHistoryProperties(QWidget *w, std::vector< Mantid::Kernel::PropertyHistory_sptr > propHist)
const Mantid::Kernel::PropertyHistories & getAlgProperties()
void copySelectedItemText()
void displayAlgHistoryProperties()
Populates the Algorithm History display with property names, values, directions and whether their val...
QString m_selectedItemText
std::vector< Mantid::Kernel::PropertyHistory_sptr > m_Histprop
void treeSelectionChanged()
void itemChecked(QTreeWidgetItem *item, int index)
QString concatVersionwithName(const std::string &name, const int version)
void uncheckAllChildren(QTreeWidgetItem *item, int index)
static const int UNROLL_COLUMN_INDEX
void updateAlgorithmHistoryWindow(Mantid::API::AlgorithmHistory_const_sptr algHistory)
void populateNestedHistory(AlgHistoryItem *parentWidget, const Mantid::API::AlgorithmHistory_sptr &history)
void itemUnchecked(QTreeWidgetItem *item, int index)
void rollAlgorithmHistory(int index)
void onItemChanged(QTreeWidgetItem *item, int index)
void populateAlgHistoryTreeWidget(const Mantid::API::WorkspaceHistory &wsHist)
void unrollAlgorithmHistory(const std::vector< int > &indicies)
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
void getItemIndex(QTreeWidgetItem *item, int &index)
void updateAlgHistoryProperties(const Mantid::API::AlgorithmHistory_const_sptr &algHistory)
QCheckBox * m_unrollAllHistoryCheckbox
AlgExecSummaryGrpBox * createExecSummaryGrpBox()
AlgEnvHistoryGrpBox * m_envHistGrpBox
void closeEvent(QCloseEvent *ce) override
~AlgorithmHistoryWindow() override
AlgExecSummaryGrpBox * m_execSumGrpBox
QPushButton * m_scriptButtonFile
AlgEnvHistoryGrpBox * createEnvHistGrpBox(const Mantid::Kernel::EnvironmentHistory &envHistory)
const Mantid::API::WorkspaceHistory & m_algHist
QLabel * m_scriptVersionLabel
AlgorithmHistoryWindow(QWidget *parent, const std::shared_ptr< const Mantid::API::Workspace > &)
void updateAll(const Mantid::API::AlgorithmHistory_const_sptr &algHistmakeory)
void updateExecSummaryGrpBox(const Mantid::API::AlgorithmHistory_const_sptr &algHistory)
std::shared_ptr< Mantid::API::HistoryView > m_view
void updateAlgorithmHistoryWindow(QString algName)
AlgHistoryProperties * m_histPropWindow
QComboBox * m_scriptComboMode
std::string getScriptVersionMode()
Used by the save script to clipboard/file buttons to select which versioning.
AlgHistoryTreeWidget * m_Historytree
AlgHistoryProperties * createAlgHistoryPropWindow()
void doUnroll(const std::vector< int > &unrollIndicies)
void unrollAll(int state)
QPushButton * m_scriptButtonClipboard
This class build a sttring which cana be executed as a python script.
const std::string build()
build a python script from the history view
This class stores information about the Workspace History used by algorithms on a workspace and the e...
AlgorithmHistory_const_sptr getAlgorithmHistory(const size_t index) const
Retrieve an algorithm history by index.
bool empty() const
Is the history empty.
const AlgorithmHistories & getAlgorithmHistories() const
Retrieve the algorithm history list.
size_t size() const
How many entries are there.
Base Workspace Abstract Class.
This class stores information about the Environment of the computer used by the framework.
std::string osName() const
returns the os name
std::string frameworkVersion() const
returns the framework version
std::string osVersion() const
returns the os version
The Logger class is in charge of the publishing messages from the framework through various channels.
std::vector< AlgorithmHistory_sptr > AlgorithmHistories
std::shared_ptr< const AlgorithmHistory > AlgorithmHistory_const_sptr
Mantid::Kernel::SingletonHolder< AnalysisDataServiceImpl > AnalysisDataService
std::shared_ptr< AlgorithmHistory > AlgorithmHistory_sptr
std::vector< PropertyHistory_sptr > PropertyHistories