17#include <QApplication>
28#include <QTemporaryFile>
45int getNumberOfItemsInTree(QTreeWidgetItem *item) {
48 for (
int i = 0; i < item->childCount(); i++) {
49 if (item->child(i)->checkState(1) == Qt::Checked) {
51 count += getNumberOfItemsInTree(item->child(i));
61 : QGroupBox(w), m_execDurationlabel(nullptr), m_execDurationEdit(nullptr), m_Datelabel(nullptr),
62 m_execDateTimeEdit(nullptr), m_algexecDuration() {}
65 : QGroupBox(title, w), m_execDurationlabel(nullptr), m_execDurationEdit(nullptr), m_Datelabel(nullptr),
66 m_execDateTimeEdit(nullptr), m_algexecDuration() {
75 QDateTime datetime(QDate(0, 0, 0), QTime(0, 0, 0), Qt::LocalTime);
83 auto *formLayout =
new QFormLayout;
87 setLayout(formLayout);
89 setGeometry(5, 210, 205, 130);
111 dur.setNum(execDuration,
'g', 6);
114 if (execDurationEdit)
115 execDurationEdit->setText(dur);
118 std::tm t = execDate.to_localtime_tm();
119 QTime qt(t.tm_hour, t.tm_min, t.tm_sec);
120 QDate qd(t.tm_year + 1900, t.tm_mon + 1, t.tm_mday);
121 QDateTime datetime(qd, qt, Qt::LocalTime);
124 str = datetime.toString(
"dd/MM/yyyy hh:mm:ss");
128 datetimeEdit->setText(str);
132 : QGroupBox(w), m_osNameLabel(nullptr), m_osNameEdit(nullptr), m_osVersionLabel(nullptr), m_osVersionEdit(nullptr),
133 m_frmworkVersionLabel(nullptr), m_frmwkVersnEdit(nullptr) {}
136 : QGroupBox(title, w), m_osNameLabel(nullptr), m_osNameEdit(nullptr), m_osVersionLabel(nullptr),
137 m_osVersionEdit(nullptr), m_frmworkVersionLabel(nullptr), m_frmwkVersnEdit(nullptr) {
164 auto *formLayout =
new QFormLayout();
169 setLayout(formLayout);
171 setGeometry(214, 210, 347, 130);
201 : QDialog(parent), m_algHist(wsptr->getHistory()), m_histPropWindow(nullptr), m_execSumGrpBox(nullptr),
202 m_envHistGrpBox(nullptr), m_wsName(wsptr->
getName().c_str()), m_view(wsptr->getHistory().createView()) {
205 throw std::invalid_argument(
"No history found on the given workspace");
208 setWindowTitle(tr(
"Algorithm History"));
209 setMinimumHeight(500);
210 setMinimumWidth(750);
217 Qt::WindowFlags flags = windowFlags();
219 flags |= Qt::CustomizeWindowHint;
220 flags |= Qt::WindowMinimizeButtonHint;
221 flags |= Qt::WindowCloseButtonHint;
222 setWindowFlags(flags);
230 headers <<
"Algorithms"
249 connect(
m_Historytree, SIGNAL(unrollAlgorithmHistory(
const std::vector<int> &)),
this,
250 SLOT(
doUnroll(
const std::vector<int> &)));
254 auto *treeLayout =
new QHBoxLayout;
266 auto *environmentLayout =
new QHBoxLayout;
279 m_scriptComboMode->setToolTip(
"When to specify which version of an algorithm was used.");
285 auto *buttonLayout =
new QHBoxLayout;
286 buttonLayout->addStretch(1);
297 QVBoxLayout *mainLayout =
new QVBoxLayout(
this);
298 mainLayout->addLayout(treeLayout);
300 mainLayout->addLayout(environmentLayout);
301 mainLayout->addLayout(buttonLayout);
341 for (
size_t i = 0; i < noEntries; ++i) {
344 duration = entry->executionDuration();
345 Mantid::Types::Core::DateAndTime date = entry->executionDate();
346 pgrpBox->
setData(duration, date);
350 QMessageBox::critical(
this,
"Mantid",
"Invalid Pointer");
360 QMessageBox::critical(
this,
"Mantid",
"Invalid Pointer");
365 std::vector<PropertyHistory_sptr> histProp;
367 auto rIter = entries.rbegin();
368 histProp = (*rIter)->getProperties();
372 if (histProp.empty()) {
373 QMessageBox::critical(
this,
"Mantid",
"Properties not set");
377 if (phistPropWindow) {
379 return phistPropWindow;
381 QMessageBox::critical(
this,
"Mantid",
"Invalid Pointer");
391 if (curText ==
"Only Specify Old Versions") {
393 }
else if (curText ==
"Always Specify Versions") {
395 }
else if (curText ==
"Never Specify Versions") {
399 throw std::runtime_error(
"AlgorithmHistoryWindow::getScriptVersionMode "
400 "received unhandled version mode string");
405 QString scriptDir(
"");
407 if (prevDir.isEmpty()) {
412 QString filePath = QFileDialog::getSaveFileName(
this, tr(
"Save Script As "), scriptDir, tr(
"Script files (*.py)"));
414 if (filePath.isEmpty())
419 if (!filePath.endsWith(
".py"))
423 std::ofstream file(filePath.toStdString().c_str(), std::ofstream::trunc);
424 file << builder.
build();
432 std::string osname = envHistory.
osName();
433 std::string osversion = envHistory.
osVersion();
438 osNameEdit->setText(osname.c_str());
442 osVersionEdit->setText(osversion.c_str());
446 frmwkVersnEdit->setText(frwkversn.c_str());
465 double duration = algHistory->executionDuration();
466 Mantid::Types::Core::DateAndTime date = algHistory->executionDate();
474 const std::string contents = builder.
build();
475 script.append(contents.c_str());
478 QClipboard *clipboard = QApplication::clipboard();
479 if (
nullptr != clipboard) {
480 clipboard->setText(script);
485 for (
const auto &unrollIndex : unrollIndicies) {
486 m_view->unroll(unrollIndex);
494 QTreeWidgetItemIterator it(
m_Historytree, QTreeWidgetItemIterator::HasChildren);
497 if (state == Qt::Checked)
498 (*it)->setCheckState(1, Qt::Checked);
500 (*it)->setCheckState(1, Qt::Unchecked);
510 : m_Histprop(
std::move(propHist)) {
532 connect(
m_histpropTree, SIGNAL(customContextMenuRequested(
const QPoint &)),
this, SLOT(
popupMenu(
const QPoint &)));
539 while (ntopcount--) {
546 m_Histprop.assign(histProp.begin(), histProp.end());
561 QClipboard *clipboard = QApplication::clipboard();
577 QStringList propList;
578 std::string sProperty;
579 for (std::vector<PropertyHistory_sptr>::const_iterator pIter =
m_Histprop.begin(); pIter !=
m_Histprop.end();
581 sProperty = (*pIter)->name();
582 propList.append(sProperty.c_str());
584 sProperty = (*pIter)->value();
585 bool bisDefault = (*pIter)->isDefault();
586 if (bisDefault ==
true) {
587 if ((*pIter)->isEmptyDefault()) {
591 propList.append(sProperty.c_str());
593 bisDefault ? (sProperty =
"Yes") : (sProperty =
"No");
594 propList.append(sProperty.c_str());
595 int nDirection = (*pIter)->direction();
596 switch (nDirection) {
602 sProperty =
"Output";
614 propList.append(sProperty.c_str());
615 QTreeWidgetItem *item =
new QTreeWidgetItem(propList);
632 this->blockSignals(
true);
638 this->blockSignals(
false);
644 QModelIndex modelIndex;
645 if (item->parent()) {
648 modelIndex = indexFromItem(item, 1);
649 for (
auto i = 0; i < modelIndex.row(); i++) {
652 if (item->parent() && item->parent()->child(i)->checkState(1) == Qt::Checked) {
653 index += getNumberOfItemsInTree(item->parent()->child(i));
654 }
else if (item->parent() ==
nullptr && topLevelItem(i)->checkState(1) == Qt::Checked) {
655 index += getNumberOfItemsInTree(topLevelItem(i));
663 std::vector<QTreeWidgetItem *> checkedItems;
664 std::vector<int> unrollIndices;
667 for (
auto currentItem = item; currentItem; currentItem = currentItem->parent()) {
669 if (currentItem->checkState(
index) != Qt::Checked) {
670 currentItem->setCheckState(
index, Qt::Checked);
673 checkedItems.emplace_back(currentItem);
676 for (
auto it = checkedItems.rbegin(); it != checkedItems.rend(); ++it) {
677 auto currentItem = *it;
682 unrollIndices.emplace_back(unrollIndex);
684 this->blockSignals(
false);
686 this->blockSignals(
true);
696 for (
auto currentItem = item; currentItem; currentItem = currentItem->parent()) {
700 this->blockSignals(
false);
702 this->blockSignals(
true);
706 if (item->childCount() > 0) {
707 item->setCheckState(
index, Qt::Unchecked);
708 for (
int i = 0; i < item->childCount(); ++i) {
721 QTreeView::selectionChanged(selected, deselected);
726 this->blockSignals(
true);
728 auto algHistIter = entries.begin();
730 for (; algHistIter != entries.end(); ++algHistIter) {
731 int nAlgVersion = (*algHistIter)->version();
735 this->addTopLevelItem(item);
738 resizeColumnToContents(0);
739 resizeColumnToContents(1);
740 this->blockSignals(
false);
746 if (
history->childHistorySize() > 0) {
747 parentWidget->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
748 parentWidget->setCheckState(1, Qt::Unchecked);
751 for (
const auto &entry : entries) {
752 int nAlgVersion = entry->version();
756 parentWidget->addChild(item);
762 QString algName = name.c_str();
763 algName = algName +
" v.";
764 QString algVersion = QString::number(version, 10);
765 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.
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::vector< AlgorithmHistory_sptr > AlgorithmHistories
std::shared_ptr< const AlgorithmHistory > AlgorithmHistory_const_sptr
std::shared_ptr< AlgorithmHistory > AlgorithmHistory_sptr
std::vector< PropertyHistory_sptr > PropertyHistories