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