Mantid
Loading...
Searching...
No Matches
AlgorithmHistoryWindow.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
12
15
16#include <QAction>
17#include <QApplication>
18#include <QClipboard>
19#include <QCloseEvent>
20#include <QDateTime>
21#include <QDir>
22#include <QFileDialog>
23#include <QFormLayout>
24#include <QLabel>
25#include <QLineEdit>
26#include <QMenu>
27#include <QMessageBox>
28#include <QTemporaryFile>
29#include <QTextStream>
30#include <QTimeZone>
31
32#include <cstdio>
33#include <fstream>
34#include <numeric>
35#include <utility>
36
37using namespace Mantid::Kernel;
38using namespace Mantid::API;
39
40namespace {
42Mantid::Kernel::Logger window_log("AlgorithmHistoryWindow");
44Mantid::Kernel::Logger widget_log("AlgHistoryTreeWidget");
45
46int getNumberOfItemsInTree(QTreeWidgetItem *item) {
47 // item is the root of the tree
48 int count{1};
49 for (int i = 0; i < item->childCount(); i++) {
50 if (item->child(i)->checkState(1) == Qt::Checked) {
51 // recurse into unrolled algorithms
52 count += getNumberOfItemsInTree(item->child(i));
53 } else {
54 count++;
55 }
56 }
57 return count;
58}
59} // namespace
60
62 : QGroupBox(w), m_execDurationlabel(nullptr), m_execDurationEdit(nullptr), m_Datelabel(nullptr),
63 m_execDateTimeEdit(nullptr), m_algexecDuration() {}
64
65AlgExecSummaryGrpBox::AlgExecSummaryGrpBox(const QString &title, QWidget *w)
66 : QGroupBox(title, w), m_execDurationlabel(nullptr), m_execDurationEdit(nullptr), m_Datelabel(nullptr),
67 m_execDateTimeEdit(nullptr), m_algexecDuration() {
68
69 m_execDurationEdit = new QLineEdit("", this);
71 m_execDurationEdit->setReadOnly(true);
72 m_execDurationlabel = new QLabel("Duration:", this);
75
76 QDateTime datetime(QDate(0, 0, 0), QTime(0, 0, 0), QTimeZone(QTimeZone::LocalTime));
77 m_execDateTimeEdit = new QLineEdit("", this);
79 m_execDateTimeEdit->setReadOnly(true);
80 m_Datelabel = new QLabel("Date:", this);
81 if (m_Datelabel)
83
84 auto *formLayout = new QFormLayout;
85 if (formLayout) {
86 formLayout->addRow(m_execDurationlabel, m_execDurationEdit);
87 formLayout->addRow(m_Datelabel, m_execDateTimeEdit);
88 setLayout(formLayout);
89 }
90 setGeometry(5, 210, 205, 130);
91}
95 m_execDurationlabel = nullptr;
96 }
98 delete m_execDurationEdit;
99 m_execDurationEdit = nullptr;
100 }
101 if (m_Datelabel) {
102 delete m_Datelabel;
103 m_Datelabel = nullptr;
104 }
105 if (m_execDateTimeEdit) {
106 delete m_execDateTimeEdit;
107 m_execDateTimeEdit = nullptr;
108 }
109}
110void AlgExecSummaryGrpBox::setData(const double execDuration, const Mantid::Types::Core::DateAndTime execDate) {
111 QString dur("");
112 dur.setNum(execDuration, 'g', 6);
113 dur += " seconds";
114 QLineEdit *execDurationEdit = getAlgExecDurationCtrl();
115 if (execDurationEdit)
116 execDurationEdit->setText(dur);
117
118 // Get the timeinfo structure, but converting from UTC to local time
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));
123
124 QString str("");
125 str = datetime.toString("dd/MM/yyyy hh:mm:ss");
126
127 QLineEdit *datetimeEdit = getAlgExecDateCtrl();
128 if (datetimeEdit)
129 datetimeEdit->setText(str);
130}
131
133 : QGroupBox(w), m_osNameLabel(nullptr), m_osNameEdit(nullptr), m_osVersionLabel(nullptr), m_osVersionEdit(nullptr),
134 m_frmworkVersionLabel(nullptr), m_frmwkVersnEdit(nullptr) {}
135
136AlgEnvHistoryGrpBox::AlgEnvHistoryGrpBox(const QString &title, QWidget *w)
137 : QGroupBox(title, w), m_osNameLabel(nullptr), m_osNameEdit(nullptr), m_osVersionLabel(nullptr),
138 m_osVersionEdit(nullptr), m_frmworkVersionLabel(nullptr), m_frmwkVersnEdit(nullptr) {
139 // OS Name Label & Edit Box
140 m_osNameEdit = new QLineEdit("", this);
141 if (m_osNameEdit) {
142 m_osNameEdit->setReadOnly(true);
143 }
144 m_osNameLabel = new QLabel("OS Name:", this);
145 if (m_osNameLabel)
146 m_osNameLabel->setBuddy(m_osNameEdit);
147
148 // OS Version Label & Edit Box
149 m_osVersionEdit = new QLineEdit("", this);
150 if (m_osVersionEdit) {
151 m_osVersionEdit->setReadOnly(true);
152 m_osVersionLabel = new QLabel("OS Version:", this);
153 }
156
157 // Mantid Framework Version Label & Edit Box
158 m_frmwkVersnEdit = new QLineEdit("", this);
160 m_frmwkVersnEdit->setReadOnly(true);
161 m_frmworkVersionLabel = new QLabel("Framework Version:", this);
164
165 auto *formLayout = new QFormLayout();
166 if (formLayout) {
167 formLayout->addRow(m_osNameLabel, m_osNameEdit);
168 formLayout->addRow(m_osVersionLabel, m_osVersionEdit);
169 formLayout->addRow(m_frmworkVersionLabel, m_frmwkVersnEdit);
170 setLayout(formLayout);
171 }
172 setGeometry(214, 210, 347, 130);
173}
175 if (m_osNameLabel) {
176 delete m_osNameLabel;
177 m_osNameLabel = nullptr;
178 }
179 if (m_osNameEdit) {
180 delete m_osNameEdit;
181 m_osNameEdit = nullptr;
182 }
183 if (m_osVersionLabel) {
184 delete m_osVersionLabel;
185 m_osVersionLabel = nullptr;
186 }
187 if (m_osVersionEdit) {
188 delete m_osVersionEdit;
189 m_osVersionEdit = nullptr;
190 }
193 m_frmworkVersionLabel = nullptr;
194 }
195 if (m_frmwkVersnEdit) {
196 delete m_frmwkVersnEdit;
197 m_frmwkVersnEdit = nullptr;
198 }
199}
200
201AlgorithmHistoryWindow::AlgorithmHistoryWindow(QWidget *parent, const std::shared_ptr<const Workspace> &wsptr)
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()) {
204
205 if (m_algHist.empty()) {
206 throw std::invalid_argument("No history found on the given workspace");
207 }
208
209 setWindowTitle(tr("Algorithm History"));
210 setMinimumHeight(500);
211 setMinimumWidth(750);
212 resize(540, 380);
213
214#ifdef Q_OS_MAC
215 // Work around to ensure that floating windows remain on top of the main
216 // application window, but below other applications on Mac
217 // Note: Qt::Tool cannot have both a max and min button on OSX
218 Qt::WindowFlags flags = windowFlags();
219 flags |= Qt::Tool;
220 flags |= Qt::CustomizeWindowHint;
221 flags |= Qt::WindowMinimizeButtonHint;
222 flags |= Qt::WindowCloseButtonHint;
223 setWindowFlags(flags);
224#endif
225
226 // Create a tree widget to display the algorithm names in the workspace
227 // history
229 if (m_Historytree) {
230 QStringList headers;
231 headers << "Algorithms"
232 << "Unroll";
233
234 m_Historytree->setColumnCount(2);
235 m_Historytree->setColumnWidth(0, 180);
236 m_Historytree->setColumnWidth(1, 55);
237 m_Historytree->setHeaderLabels(headers);
238 m_Historytree->setGeometry(5, 5, 205, 200);
239 // Populate the History Tree widget
241 }
242
243 // create a tree widget to display history properties
244 if (!m_histPropWindow)
246
247 // connect history tree with window
250 connect(m_Historytree, SIGNAL(unrollAlgorithmHistory(const std::vector<int> &)), this,
251 SLOT(doUnroll(const std::vector<int> &)));
252 connect(m_Historytree, SIGNAL(rollAlgorithmHistory(int)), this, SLOT(doRoll(int)));
253
254 // The tree and the history details layout
255 auto *treeLayout = new QHBoxLayout;
256 treeLayout->addWidget(m_Historytree, 3); // History stretches 1
257 treeLayout->addWidget(m_histPropWindow->m_histpropTree,
258 5); // Properties gets more space
259
260 // Create a GroupBox to display exec date,duration
261 if (!m_execSumGrpBox)
263 // Create a Groupbox to display environment details
264 if (!m_envHistGrpBox)
265 m_envHistGrpBox = createEnvHistGrpBox(wsptr->getHistory().getEnvironmentHistory());
266
267 auto *environmentLayout = new QHBoxLayout;
268 environmentLayout->addWidget(m_execSumGrpBox, 1);
269 environmentLayout->addWidget(m_envHistGrpBox, 2);
270
271 // The buttons at the bottom
272 m_scriptVersionLabel = new QLabel("Algorithm Versions:", this);
273 m_scriptComboMode = new QComboBox(this);
274 // N.B. The combobox item strings below are used in
275 // AlgorithmHistoryWindow::getScriptVersionMode()
276 // If you change them here, you MUST change them there too.
277 m_scriptComboMode->addItem("Only Specify Old Versions");
278 m_scriptComboMode->addItem("Never Specify Versions");
279 m_scriptComboMode->addItem("Always Specify Versions");
280 m_scriptComboMode->setToolTip("When to specify which version of an algorithm was used.");
281 m_scriptButtonFile = new QPushButton("Script to File", this);
282 m_scriptButtonClipboard = new QPushButton("Script to Clipboard", this);
283 connect(m_scriptButtonFile, SIGNAL(clicked()), this, SLOT(writeToScriptFile()));
284 connect(m_scriptButtonClipboard, SIGNAL(clicked()), this, SLOT(copytoClipboard()));
285
286 auto *buttonLayout = new QHBoxLayout;
287 buttonLayout->addStretch(1); // Align the button to the right
288 buttonLayout->addWidget(m_scriptVersionLabel);
289 buttonLayout->addWidget(m_scriptComboMode);
290 buttonLayout->addWidget(m_scriptButtonFile);
291 buttonLayout->addWidget(m_scriptButtonClipboard);
292
293 // Unroll all checkbox below tree layout
294 m_unrollAllHistoryCheckbox = new QCheckBox("Unroll All Algorithms", this);
295 connect(m_unrollAllHistoryCheckbox, SIGNAL(stateChanged(int)), this, SLOT(unrollAll(int)));
296
297 // Main layout
298 QVBoxLayout *mainLayout = new QVBoxLayout(this);
299 mainLayout->addLayout(treeLayout);
300 mainLayout->addWidget(m_unrollAllHistoryCheckbox);
301 mainLayout->addLayout(environmentLayout);
302 mainLayout->addLayout(buttonLayout);
303}
304
305AlgorithmHistoryWindow::AlgorithmHistoryWindow(QWidget *parent, const QString &workspaceName)
306 : AlgorithmHistoryWindow(parent,
307 AnalysisDataService::Instance().retrieveWS<const Workspace>(workspaceName.toStdString())) {
308}
309
311 if (m_Historytree) {
312 delete m_Historytree;
313 m_Historytree = nullptr;
314 }
315 if (m_histPropWindow) {
316 delete m_histPropWindow;
317 m_histPropWindow = nullptr;
318 }
319 if (m_execSumGrpBox) {
320 delete m_execSumGrpBox;
321 m_execSumGrpBox = nullptr;
322 }
323 if (m_envHistGrpBox) {
324 delete m_envHistGrpBox;
325 m_envHistGrpBox = nullptr;
326 }
327}
328
329// Delete window object on close
330// Without this the windows stay in memory when closed in workbench
332 this->deleteLater();
333 ce->accept();
334}
335
337 AlgExecSummaryGrpBox *pgrpBox = new AlgExecSummaryGrpBox("Execution Summary", this);
338 if (pgrpBox) {
339 // iterating through algorithm history to display exec duration,date
340 // last executed algorithm exec duration,date will be displayed in gruopbox
341 const size_t noEntries = m_algHist.size();
342 for (size_t i = 0; i < noEntries; ++i) {
343 const auto entry = m_algHist.getAlgorithmHistory(i);
344 double duration = 0;
345 duration = entry->executionDuration();
346 Mantid::Types::Core::DateAndTime date = entry->executionDate();
347 pgrpBox->setData(duration, date);
348 }
349 return pgrpBox;
350 } else {
351 QMessageBox::critical(this, "Mantid", "Invalid Pointer");
352 return nullptr;
353 }
354}
356 AlgEnvHistoryGrpBox *pEnvGrpBox = new AlgEnvHistoryGrpBox("Environment History", this);
357 if (pEnvGrpBox) {
358 pEnvGrpBox->fillEnvHistoryGroupBox(envHist);
359 return pEnvGrpBox;
360 } else {
361 QMessageBox::critical(this, "Mantid", "Invalid Pointer");
362 return nullptr;
363 }
364}
366 std::vector<PropertyHistory_sptr> histProp;
368 auto rIter = entries.rbegin();
369 histProp = (*rIter)->getProperties();
370
371 // AlgHistoryProperties * phistPropWindow=new
372 // AlgHistoryProperties(this,m_algHist);
373 if (histProp.empty()) {
374 QMessageBox::critical(this, "Mantid", "Properties not set");
375 return nullptr;
376 }
377 AlgHistoryProperties *phistPropWindow = new AlgHistoryProperties(this, histProp);
378 if (phistPropWindow) {
379 phistPropWindow->displayAlgHistoryProperties();
380 return phistPropWindow;
381 } else {
382 QMessageBox::critical(this, "Mantid", "Invalid Pointer");
383 return nullptr;
384 }
385}
386
388// mode to use.
390 std::string curText = m_scriptComboMode->currentText().toStdString();
391
392 if (curText == "Only Specify Old Versions") {
393 return "old";
394 } else if (curText == "Always Specify Versions") {
395 return "all";
396 } else if (curText == "Never Specify Versions") {
397 return "none";
398 }
399
400 throw std::runtime_error("AlgorithmHistoryWindow::getScriptVersionMode "
401 "received unhandled version mode string");
402}
403
405 QString prevDir = MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
406 QString scriptDir("");
407 // Default script directory
408 if (prevDir.isEmpty()) {
409 scriptDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("pythonscripts.directory"));
410 } else {
411 scriptDir = prevDir;
412 }
413 QString filePath = QFileDialog::getSaveFileName(this, tr("Save Script As "), scriptDir, tr("Script files (*.py)"));
414 // An empty string indicates they clicked cancel
415 if (filePath.isEmpty())
416 return;
417
418 // fix for 34451 in Linux, unlike native filedialog, QFileDialog will not add file extension by type
419 // This only occur in Linux as in Win and Mac QFileDialog calls the native filedialog
420 if (!filePath.endsWith(".py"))
421 filePath += ".py";
422
424 std::ofstream file(filePath.toStdString().c_str(), std::ofstream::trunc);
425 file << builder.build();
426 file.flush();
427 file.close();
428
429 MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(QFileInfo(filePath).absoluteDir().path());
430}
431
433 QLineEdit *osNameEdit = getosNameEdit();
434 if (osNameEdit) {
435 std::string osname = envHistory.osName();
436 osNameEdit->setText(osname.c_str());
437 }
438
439 QLineEdit *osVersionEdit = getosVersionEdit();
440 if (osVersionEdit) {
441 std::string osversion = envHistory.osVersion();
442 osVersionEdit->setText(osversion.c_str());
443 }
444
445 QLineEdit *frmwkVersnEdit = getfrmworkVersionEdit();
446 if (frmwkVersnEdit) {
447 std::string frwkversn = envHistory.frameworkVersion();
448 frmwkVersnEdit->setText(frwkversn.c_str());
449 }
450}
451
456
465
467 // getting the selected algorithm at pos from History vector
468 double duration = algHistory->executionDuration();
469 Mantid::Types::Core::DateAndTime date = algHistory->executionDate();
470 if (m_execSumGrpBox)
471 m_execSumGrpBox->setData(duration, date);
472}
473
476 QString script;
477 const std::string contents = builder.build();
478 script.append(contents.c_str());
479
480 // Send to clipboard.
481 QClipboard *clipboard = QApplication::clipboard();
482 if (nullptr != clipboard) {
483 clipboard->setText(script);
484 }
485}
486
487void AlgorithmHistoryWindow::doUnroll(const std::vector<int> &unrollIndicies) {
488 for (const auto &unrollIndex : unrollIndicies) {
489 m_view->unroll(unrollIndex);
490 }
491}
492
494
496 // Iterate all items in tree which have child algorithms to be unrolled
497 QTreeWidgetItemIterator it(m_Historytree, QTreeWidgetItemIterator::HasChildren);
498 while (*it) {
499 // set state of unroll based on checkbox sate
500 if (state == Qt::Checked)
501 (*it)->setCheckState(1, Qt::Checked);
502 else
503 (*it)->setCheckState(1, Qt::Unchecked);
504 ++it;
505 }
506}
507
508//--------------------------------------------------------------------------------------------------
509// AlgHistoryProperties Definitions
510//--------------------------------------------------------------------------------------------------
511
512AlgHistoryProperties::AlgHistoryProperties(QWidget *w, std::vector<PropertyHistory_sptr> propHist)
513 : m_Histprop(std::move(propHist)) {
514 QStringList hList;
515 hList << "Name"
516 << "Value"
517 << "Default?:"
518 << "Direction";
519
520 m_histpropTree = new QTreeWidget(w);
521 m_histpropTree->setTextElideMode(Qt::ElideMiddle);
522 m_histpropTree->setColumnCount(4);
523 m_histpropTree->setSelectionMode(QAbstractItemView::NoSelection);
524 m_histpropTree->setHeaderLabels(hList);
525 m_histpropTree->setGeometry(213, 5, 350, 200);
526
527 m_contextMenu = new QMenu(w);
528
529 m_copyAction = new QAction("Copy to Clipboard", m_contextMenu);
530 connect(m_copyAction, SIGNAL(triggered()), this, SLOT(copySelectedItemText()));
531 m_contextMenu->addAction(m_copyAction);
532
533 m_histpropTree->setContextMenuPolicy(Qt::CustomContextMenu);
534 connect(m_histpropTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(popupMenu(const QPoint &)));
535}
536
538 if (m_histpropTree) {
539 m_histpropTree->clear();
540 int ntopcount = m_histpropTree->topLevelItemCount();
541 while (ntopcount--) {
542 m_histpropTree->topLevelItem(ntopcount);
543 }
544 }
545}
546
547void AlgHistoryProperties::setAlgProperties(const std::vector<PropertyHistory_sptr> &histProp) {
548 m_Histprop.assign(histProp.begin(), histProp.end());
549}
550
552
553void AlgHistoryProperties::popupMenu(const QPoint &pos) {
554 QTreeWidgetItem *treeItem = m_histpropTree->itemAt(pos);
555 if (!treeItem)
556 return;
557
558 m_selectedItemText = treeItem->text(m_histpropTree->currentColumn());
559 m_contextMenu->popup(QCursor::pos());
560}
561
563 QClipboard *clipboard = QApplication::clipboard();
564 if (clipboard)
565 clipboard->setText(m_selectedItemText);
566}
567
579 QStringList propList;
580 for (std::vector<PropertyHistory_sptr>::const_iterator pIter = m_Histprop.begin(); pIter != m_Histprop.end();
581 ++pIter) {
582 std::string sProperty = (*pIter)->name();
583 propList.append(sProperty.c_str());
584
585 sProperty = (*pIter)->value();
586 bool bisDefault = (*pIter)->isDefault();
587 if (bisDefault == true) {
588 if ((*pIter)->isEmptyDefault()) {
589 sProperty = ""; // replace EMPTY_XXX with empty string
590 }
591 }
592 propList.append(sProperty.c_str());
593
594 bisDefault ? (sProperty = "Yes") : (sProperty = "No");
595 propList.append(sProperty.c_str());
596 int nDirection = (*pIter)->direction();
597 switch (nDirection) {
598 case 0: {
599 sProperty = "Input";
600 break;
601 }
602 case 1: {
603 sProperty = "Output";
604 break;
605 }
606 case 2: {
607 sProperty = "InOut";
608 break;
609 }
610 default: {
611 sProperty = "N/A";
612 break;
613 }
614 }
615 propList.append(sProperty.c_str());
616 QTreeWidgetItem *item = new QTreeWidgetItem(propList);
617 if (m_histpropTree)
618 m_histpropTree->addTopLevelItem(item);
619 propList.clear();
620
621 } // end of properties for loop
622
623 // Fit some column widths to data
624 m_histpropTree->resizeColumnToContents(0); // Property name
625 m_histpropTree->resizeColumnToContents(2); // Default
626 m_histpropTree->resizeColumnToContents(3); // Direction
627}
628
629//--------------------------------------------------------------------------------------------------
630// AlgHistoryTreeWidget Definitions
631//--------------------------------------------------------------------------------------------------
632void AlgHistoryTreeWidget::onItemChanged(QTreeWidgetItem *item, int index) {
633 this->blockSignals(true);
634 if (index == UNROLL_COLUMN_INDEX && item->checkState(index) == Qt::Checked) {
635 itemChecked(item, index);
636 } else if (index == UNROLL_COLUMN_INDEX && item->checkState(index) == Qt::Unchecked) {
637 itemUnchecked(item, index);
638 }
639 this->blockSignals(false);
640}
641
642void AlgHistoryTreeWidget::getItemIndex(QTreeWidgetItem *item, int &index) {
643 // Counts all of the algorithms which precede the given one, including child
644 // algorithms if an algorithm is unrolled.
645 QModelIndex modelIndex;
646 if (item->parent()) {
647 index++;
648 }
649 modelIndex = indexFromItem(item, 1);
650 for (auto i = 0; i < modelIndex.row(); i++) {
651 // If an algorithm is unrolled, add all of its children to the index,
652 // otherwise just add one.
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));
657 } else {
658 index += 1;
659 }
660 }
661}
662
663void AlgHistoryTreeWidget::itemChecked(QTreeWidgetItem *item, int index) {
664 std::vector<QTreeWidgetItem *> checkedItems;
665 std::vector<int> unrollIndices;
666 int unrollIndex{0};
667
668 for (auto currentItem = item; currentItem; currentItem = currentItem->parent()) {
669 // Check the item if it isn't already checked.
670 if (currentItem->checkState(index) != Qt::Checked) {
671 currentItem->setCheckState(index, Qt::Checked);
672 }
673
674 checkedItems.emplace_back(currentItem);
675 }
676
677 for (auto it = checkedItems.rbegin(); it != checkedItems.rend(); ++it) {
678 auto currentItem = *it;
679
680 // Find where we are in the tree.
681 getItemIndex(currentItem, unrollIndex);
682
683 unrollIndices.emplace_back(unrollIndex);
684 }
685 this->blockSignals(false);
686 emit unrollAlgorithmHistory(unrollIndices);
687 this->blockSignals(true);
688}
689
690void AlgHistoryTreeWidget::itemUnchecked(QTreeWidgetItem *item, int index) {
691 int rollIndex{0};
692
693 // disable any children
695
696 // find where we are in the tree
697 for (auto currentItem = item; currentItem; currentItem = currentItem->parent()) {
698 getItemIndex(currentItem, rollIndex);
699 }
700
701 this->blockSignals(false);
702 emit rollAlgorithmHistory(rollIndex);
703 this->blockSignals(true);
704}
705
706void AlgHistoryTreeWidget::uncheckAllChildren(QTreeWidgetItem *item, int index) {
707 if (item->childCount() > 0) {
708 item->setCheckState(index, Qt::Unchecked);
709 for (int i = 0; i < item->childCount(); ++i) {
710 uncheckAllChildren(item->child(i), index);
711 }
712 }
713}
714
716 if (const AlgHistoryItem *item = dynamic_cast<AlgHistoryItem *>(this->selectedItems()[0])) {
717 emit updateAlgorithmHistoryWindow(item->getAlgorithmHistory());
718 }
719}
720
721void AlgHistoryTreeWidget::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) {
722 QTreeView::selectionChanged(selected, deselected);
724}
725
727 this->blockSignals(true);
729 auto algHistIter = entries.begin();
730
731 for (; algHistIter != entries.end(); ++algHistIter) {
732 int nAlgVersion = (*algHistIter)->version();
733 const QString algName = concatVersionwithName((*algHistIter)->name(), nAlgVersion);
734
735 AlgHistoryItem *item = new AlgHistoryItem(QStringList(algName), *algHistIter);
736 this->addTopLevelItem(item);
737 populateNestedHistory(item, *algHistIter);
738 }
739 resizeColumnToContents(0); // Algorithm name
740 resizeColumnToContents(1); // Unroll
741 this->blockSignals(false);
742}
743
746 const Mantid::API::AlgorithmHistories &entries = history->getChildHistories();
747 if (history->childHistorySize() > 0) {
748 parentWidget->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
749 parentWidget->setCheckState(1, Qt::Unchecked);
750 }
751
752 for (const auto &entry : entries) {
753 int nAlgVersion = entry->version();
754 const QString algName = concatVersionwithName(entry->name(), nAlgVersion);
755
756 AlgHistoryItem *item = new AlgHistoryItem(QStringList(algName), entry, parentWidget);
757 parentWidget->addChild(item);
758 populateNestedHistory(item, entry);
759 }
760}
761
762QString AlgHistoryTreeWidget::concatVersionwithName(const std::string &name, const int version) {
763 QString algName = name.c_str();
764 algName = algName + " v.";
765 QString algVersion = QString::number(version, 10);
766 algName += algVersion;
767 return algName;
768}
std::string name
Definition Run.cpp:60
std::map< DeltaEMode::Type, std::string > index
int count
counter
Definition Matrix.cpp:37
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 * getAlgExecDateCtrl() const
void setData(const double execDuration, const Mantid::Types::Core::DateAndTime execDate)
QLineEdit * getAlgExecDurationCtrl() const
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 displayAlgHistoryProperties()
Populates the Algorithm History display with property names, values, directions and whether their val...
std::vector< Mantid::Kernel::PropertyHistory_sptr > m_Histprop
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)
AlgExecSummaryGrpBox * createExecSummaryGrpBox()
AlgEnvHistoryGrpBox * m_envHistGrpBox
void closeEvent(QCloseEvent *ce) override
AlgExecSummaryGrpBox * m_execSumGrpBox
AlgEnvHistoryGrpBox * createEnvHistGrpBox(const Mantid::Kernel::EnvironmentHistory &envHistory)
const Mantid::API::WorkspaceHistory & m_algHist
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
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)
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.
Definition Workspace.h:29
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.
Definition Logger.h:51
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
STL namespace.