/
AlgorithmHistoryWindow.cpp
650 lines (566 loc) · 20.8 KB
/
AlgorithmHistoryWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#include "AlgorithmHistoryWindow.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidQtAPI/AlgorithmInputHistory.h"
#include "MantidQtAPI/FileDialogHandler.h"
#include <QLineEdit>
#include <QLabel>
#include <QFileDialog>
#include <QDateTime>
#include <QFormLayout>
#include <QMenu>
#include <QAction>
#include <QMessageBox>
#include <QApplication>
#include <QClipboard>
#include <QTextStream>
#include <QTemporaryFile>
#include <QDir>
#include <numeric>
#include <iostream>
#include <fstream>
#include <stdio.h>
using namespace Mantid::Kernel;
using namespace Mantid::API;
namespace
{
/// static history window logger
Mantid::Kernel::Logger window_log("AlgorithmHistoryWindow");
/// static tree widget logger
Mantid::Kernel::Logger widget_log("AlgHistoryTreeWidget");
}
AlgExecSummaryGrpBox::AlgExecSummaryGrpBox(QWidget *w) : QGroupBox(w),
m_execDurationlabel(NULL),m_execDurationEdit(NULL),
m_Datelabel(NULL),m_execDateTimeEdit(NULL), m_algexecDuration()
{
}
AlgExecSummaryGrpBox::AlgExecSummaryGrpBox(QString title,QWidget*w)
: QGroupBox(title,w), m_execDurationlabel(NULL),m_execDurationEdit(NULL),
m_Datelabel(NULL),m_execDateTimeEdit(NULL), m_algexecDuration()
{
m_execDurationEdit=new QLineEdit("",this);
if(m_execDurationEdit)
m_execDurationEdit->setReadOnly(1);
m_execDurationlabel=new QLabel("Duration:",this,0);
if(m_execDurationlabel)m_execDurationlabel->setBuddy(m_execDurationEdit);
QDateTime datetime(QDate(0,0,0), QTime(0,0,0),Qt::LocalTime );
m_execDateTimeEdit=new QLineEdit("",this);
if(m_execDateTimeEdit)
m_execDateTimeEdit->setReadOnly(1);
m_Datelabel=new QLabel("Date:",this,0);
if(m_Datelabel)m_Datelabel->setBuddy(m_execDateTimeEdit);
QFormLayout *formLayout = new QFormLayout;
if(formLayout){
formLayout->addRow(m_execDurationlabel,m_execDurationEdit);
formLayout->addRow(m_Datelabel,m_execDateTimeEdit);
setLayout(formLayout);
}
setGeometry (5,210,205,130);
}
AlgExecSummaryGrpBox::~AlgExecSummaryGrpBox()
{
if(m_execDurationlabel){
delete m_execDurationlabel;
m_execDurationlabel=NULL;
}
if(m_execDurationEdit){
delete m_execDurationEdit;
m_execDurationEdit=NULL;
}
if(m_Datelabel){
delete m_Datelabel;
m_Datelabel=NULL;
}
if(m_Datelabel){
delete m_Datelabel;
m_Datelabel=NULL;
}
if(m_execDateTimeEdit){
delete m_execDateTimeEdit;
m_execDateTimeEdit=NULL;
}
}
void AlgExecSummaryGrpBox::setData(const double execDuration,const Mantid::Kernel::DateAndTime execDate)
{
QString dur("");
dur.setNum(execDuration,'g',6);
dur+=" seconds";
QLineEdit* execDurationEdit=getAlgExecDurationCtrl();
if(execDurationEdit)execDurationEdit->setText(dur);
//Get the timeinfo structure, but converting from UTC to local time
std::tm t = execDate.to_localtime_tm() ;
QTime qt(t.tm_hour,t.tm_min,t.tm_sec);
QDate qd(t.tm_year+1900,t.tm_mon+1,t.tm_mday);
QDateTime datetime(qd,qt,Qt::LocalTime );
QString str("");
str=datetime.toString("dd/MM/yyyy hh:mm:ss");
QLineEdit* datetimeEdit=getAlgExecDateCtrl();
if(datetimeEdit)datetimeEdit->setText(str);
}
AlgEnvHistoryGrpBox::AlgEnvHistoryGrpBox(QWidget *w) : QGroupBox(w),
m_osNameLabel(NULL),m_osNameEdit(NULL),m_osVersionLabel(NULL),m_osVersionEdit(NULL),
m_frmworkVersionLabel(NULL),m_frmwkVersnEdit(NULL)
{
}
AlgEnvHistoryGrpBox::AlgEnvHistoryGrpBox(QString title,QWidget*w):QGroupBox(title,w),
m_osNameLabel(NULL),m_osNameEdit(NULL),m_osVersionLabel(NULL),m_osVersionEdit(NULL),
m_frmworkVersionLabel(NULL),m_frmwkVersnEdit(NULL)
{
//OS Name Label & Edit Box
m_osNameEdit=new QLineEdit("",this);
if(m_osNameEdit)
{
m_osNameEdit->setReadOnly(1);
}
m_osNameLabel=new QLabel("OS Name:",this,0);
if(m_osNameLabel)m_osNameLabel->setBuddy(m_osNameEdit);
//OS Version Label & Edit Box
m_osVersionEdit=new QLineEdit("",this);
if(m_osVersionEdit)
{
m_osVersionEdit->setReadOnly(1);
m_osVersionLabel=new QLabel("OS Version:",this,0);
}
if(m_osVersionLabel)
m_osVersionLabel->setBuddy(m_osVersionEdit);
//Mantid Framework Version Label & Edit Box
m_frmwkVersnEdit=new QLineEdit("",this);
if(m_frmwkVersnEdit)
m_frmwkVersnEdit->setReadOnly(1);
m_frmworkVersionLabel=new QLabel("Framework Version:",this,0);
if(m_frmworkVersionLabel)
m_frmworkVersionLabel->setBuddy(m_frmwkVersnEdit);
QFormLayout * formLayout=new QFormLayout();
if(formLayout)
{
formLayout->addRow(m_osNameLabel,m_osNameEdit);
formLayout->addRow(m_osVersionLabel,m_osVersionEdit);
formLayout->addRow(m_frmworkVersionLabel,m_frmwkVersnEdit);
setLayout(formLayout);
}
setGeometry (214,210,347,130);
}
AlgEnvHistoryGrpBox::~AlgEnvHistoryGrpBox()
{
if(m_osNameLabel){delete m_osNameLabel;m_osNameLabel=NULL;}
if(m_osNameEdit){delete m_osNameEdit;m_osNameEdit=NULL;}
if(m_osNameEdit){delete m_osNameEdit;m_osNameEdit=NULL;}
if(m_osVersionLabel){delete m_osVersionLabel;m_osVersionLabel=NULL;}
if(m_osVersionEdit){delete m_osVersionEdit;m_osVersionEdit=NULL;}
if(m_frmworkVersionLabel){delete m_frmworkVersionLabel;m_frmworkVersionLabel=NULL;}
if(m_frmwkVersnEdit){ delete m_frmwkVersnEdit;m_frmwkVersnEdit=NULL;}
}
AlgorithmHistoryWindow::AlgorithmHistoryWindow(QWidget *parent,const boost::shared_ptr<const Workspace> wsptr):
MantidDialog(parent),m_algHist(wsptr->getHistory()),m_histPropWindow(NULL),m_execSumGrpBox(NULL),m_envHistGrpBox(NULL),
m_wsName(wsptr->getName().c_str()), m_view(wsptr->getHistory().createView())
{
setWindowTitle(tr("Algorithm History"));
setMinimumHeight(500);
setMinimumWidth(750);
setGeometry(50,150,540,380);
//Create a tree widget to display the algorithm names in the workspace history
m_Historytree = new AlgHistoryTreeWidget(this);
if(m_Historytree)
{
QStringList headers;
headers << "Algorithms" << "Unroll";
m_Historytree->setColumnCount(2);
m_Historytree->setColumnWidth(0, 180);
m_Historytree->setColumnWidth(1, 55);
m_Historytree->setHeaderLabels(headers);
m_Historytree->setGeometry (5,5,205,200);
//Populate the History Tree widget
m_Historytree->populateAlgHistoryTreeWidget(m_algHist);
}
//create a tree widget to display history properties
if(!m_histPropWindow)
m_histPropWindow=createAlgHistoryPropWindow();
//connect history tree with window
connect(m_Historytree, SIGNAL(updateAlgorithmHistoryWindow(Mantid::API::AlgorithmHistory_const_sptr)),this,
SLOT(updateAll(Mantid::API::AlgorithmHistory_const_sptr)));
connect(m_Historytree, SIGNAL(unrollAlgorithmHistory(const std::vector<int>&)), this, SLOT(doUnroll(const std::vector<int>&)));
connect(m_Historytree, SIGNAL(rollAlgorithmHistory(int)), this, SLOT(doRoll(int)));
// The tree and the history details layout
QHBoxLayout *treeLayout = new QHBoxLayout;
treeLayout->addWidget(m_Historytree,3); // History stretches 1
treeLayout->addWidget(m_histPropWindow->m_histpropTree,5); // Properties gets more space
//Create a GroupBox to display exec date,duration
if(!m_execSumGrpBox)m_execSumGrpBox=createExecSummaryGrpBox();
//Create a Groupbox to display environment details
if(!m_envHistGrpBox)m_envHistGrpBox=createEnvHistGrpBox(wsptr->getHistory().getEnvironmentHistory());
QHBoxLayout *environmentLayout = new QHBoxLayout;
environmentLayout->addWidget(m_execSumGrpBox, 1);
environmentLayout->addWidget(m_envHistGrpBox, 2);
// The buttons at the bottom
m_scriptVersionLabel = new QLabel("Algorithm Versions:", this);
m_scriptComboMode = new QComboBox(this);
// N.B. The combobox item strings below are used in AlgorithmHistoryWindow::getScriptVersionMode()
// If you change them here, you MUST change them there too.
m_scriptComboMode->addItem("Only Specify Old Versions");
m_scriptComboMode->addItem("Never Specify Versions");
m_scriptComboMode->addItem("Always Specify Versions");
m_scriptComboMode->setToolTip("When to specify which version of an algorithm was used.");
m_scriptButtonFile = new QPushButton("Script to File",this);
m_scriptButtonClipboard = new QPushButton("Script to Clipboard",this);
connect(m_scriptButtonFile,SIGNAL(clicked()), this, SLOT(writeToScriptFile()));
connect(m_scriptButtonClipboard,SIGNAL(clicked()), this, SLOT(copytoClipboard()));
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(1); // Align the button to the right
buttonLayout->addWidget(m_scriptVersionLabel);
buttonLayout->addWidget(m_scriptComboMode);
buttonLayout->addWidget(m_scriptButtonFile);
buttonLayout->addWidget(m_scriptButtonClipboard);
//Main layout
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addLayout(treeLayout);
mainLayout->addLayout(environmentLayout);
mainLayout->addLayout(buttonLayout);
}
AlgorithmHistoryWindow::~AlgorithmHistoryWindow()
{
if(m_Historytree){delete m_Historytree;m_Historytree=NULL;}
if(m_histPropWindow){ delete m_histPropWindow;m_histPropWindow=NULL;}
if(m_execSumGrpBox){delete m_execSumGrpBox;m_execSumGrpBox=NULL;}
if(m_envHistGrpBox){delete m_envHistGrpBox;m_envHistGrpBox=NULL;}
}
AlgExecSummaryGrpBox* AlgorithmHistoryWindow::createExecSummaryGrpBox()
{
AlgExecSummaryGrpBox *pgrpBox=new AlgExecSummaryGrpBox("Execution Summary",this);
if(pgrpBox)
{
//iterating through algorithm history to display exec duration,date
//last executed algorithm exec duration,date will be displayed in gruopbox
const size_t noEntries = m_algHist.size();
for( size_t i = 0; i < noEntries; ++i)
{
const auto entry = m_algHist.getAlgorithmHistory(i);
double duration=0;
duration = entry->executionDuration();
Mantid::Kernel::DateAndTime date = entry->executionDate();
pgrpBox->setData(duration,date);
}
return pgrpBox;
}
else{
QMessageBox::critical(this,"Mantid","Invalid Pointer");
return 0;
}
}
AlgEnvHistoryGrpBox* AlgorithmHistoryWindow::createEnvHistGrpBox(const EnvironmentHistory& envHist)
{
AlgEnvHistoryGrpBox * pEnvGrpBox=new AlgEnvHistoryGrpBox("Environment History",this);
if(pEnvGrpBox){
pEnvGrpBox->fillEnvHistoryGroupBox(envHist);
return pEnvGrpBox;
}
else{
QMessageBox::critical(this,"Mantid","Invalid Pointer");
return 0;
}
}
AlgHistoryProperties* AlgorithmHistoryWindow::createAlgHistoryPropWindow()
{
std::vector<PropertyHistory_sptr> histProp;
const Mantid::API::AlgorithmHistories & entries = m_algHist.getAlgorithmHistories();
auto rIter = entries.rbegin();
histProp=(*rIter)->getProperties();
//AlgHistoryProperties * phistPropWindow=new AlgHistoryProperties(this,m_algHist);
if(histProp.empty()){
QMessageBox::critical(this,"Mantid","Properties not set");
return 0;
}
AlgHistoryProperties * phistPropWindow=new AlgHistoryProperties(this,histProp);
if(phistPropWindow){
phistPropWindow->displayAlgHistoryProperties();
return phistPropWindow;
}
else{QMessageBox::critical(this,"Mantid","Invalid Pointer");
return 0;
}
}
//! Used by the save script to clipboard/file buttons to select which versioning mode to use.
std::string AlgorithmHistoryWindow::getScriptVersionMode()
{
std::string curText = m_scriptComboMode->currentText().toStdString();
if(curText == "Only Specify Old Versions")
{
return "old";
}
else if(curText == "Always Specify Versions")
{
return "all";
}
else if(curText == "Never Specify Versions")
{
return "none";
}
throw std::runtime_error("AlgorithmHistoryWindow::getScriptVersionMode received unhandled version mode string");
}
void AlgorithmHistoryWindow::writeToScriptFile()
{
QString prevDir = MantidQt::API::AlgorithmInputHistory::Instance().getPreviousDirectory();
QString scriptDir("");
// Default script directory
if(prevDir.isEmpty())
{
scriptDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("pythonscripts.directory"));
}
else
{
scriptDir = prevDir;
}
QString filePath = MantidQt::API::FileDialogHandler::getSaveFileName(this,tr("Save Script As "),scriptDir,tr("Script files (*.py)"));
// An empty string indicates they clicked cancel
if( filePath.isEmpty() ) return;
ScriptBuilder builder(m_view, getScriptVersionMode());
std::ofstream file(filePath.toStdString().c_str(), std::ofstream::trunc);
file << builder.build();
file.flush();
file.close();
MantidQt::API::AlgorithmInputHistory::Instance().setPreviousDirectory(QFileInfo(filePath).absoluteDir().path());
}
void AlgEnvHistoryGrpBox::fillEnvHistoryGroupBox(const EnvironmentHistory& envHistory)
{
std::string osname=envHistory.osName();
std::string osversion=envHistory.osVersion();
std::string frwkversn=envHistory.frameworkVersion();
QLineEdit* osNameEdit=getosNameEdit();
if(osNameEdit)osNameEdit->setText(osname.c_str());
QLineEdit* osVersionEdit=getosVersionEdit();
if(osVersionEdit)osVersionEdit->setText(osversion.c_str());
QLineEdit* frmwkVersnEdit=getfrmworkVersionEdit();
if(frmwkVersnEdit)frmwkVersnEdit->setText(frwkversn.c_str());
}
void AlgorithmHistoryWindow::updateAll(Mantid::API::AlgorithmHistory_const_sptr algHistory)
{
updateAlgHistoryProperties(algHistory);
updateExecSummaryGrpBox(algHistory);
}
void AlgorithmHistoryWindow::updateAlgHistoryProperties(AlgorithmHistory_const_sptr algHistory)
{
PropertyHistories histProp = algHistory->getProperties();
if(m_histPropWindow)
{ m_histPropWindow->setAlgProperties(histProp);
m_histPropWindow->clearData();
m_histPropWindow->displayAlgHistoryProperties();
}
}
void AlgorithmHistoryWindow::updateExecSummaryGrpBox(AlgorithmHistory_const_sptr algHistory)
{
//getting the selcted algorithm at pos from History vector
double duration=algHistory->executionDuration();
Mantid::Kernel::DateAndTime date=algHistory->executionDate();
if(m_execSumGrpBox)m_execSumGrpBox->setData(duration,date);
}
void AlgorithmHistoryWindow::copytoClipboard()
{
ScriptBuilder builder(m_view, getScriptVersionMode());
QString script;
const std::string contents = builder.build();
script.append(contents.c_str());
// Send to clipboard.
QClipboard *clipboard = QApplication::clipboard();
if(NULL != clipboard)
{
clipboard->setText(script);
}
}
void AlgorithmHistoryWindow::doUnroll(const std::vector<int>& unrollIndicies )
{
for(auto it=unrollIndicies.begin(); it!=unrollIndicies.end(); ++it)
{
m_view->unroll(*it);
}
}
void AlgorithmHistoryWindow::doRoll( int index )
{
m_view->roll(index);
}
//--------------------------------------------------------------------------------------------------
// AlgHistoryProperties Definitions
//--------------------------------------------------------------------------------------------------
AlgHistoryProperties::AlgHistoryProperties(QWidget*w,const std::vector<PropertyHistory_sptr>& propHist):
m_Histprop(propHist)
{
QStringList hList;
hList<<"Name"<<"Value"<<"Default?:"<<"Direction"<<"";
m_histpropTree = new QTreeWidget(w);
if(m_histpropTree)
{
m_histpropTree->setColumnCount(5);
m_histpropTree->setSelectionMode(QAbstractItemView::NoSelection);
m_histpropTree->setHeaderLabels(hList);
m_histpropTree->setGeometry (213,5,350,200);
}
}
void AlgHistoryProperties::clearData()
{
if(m_histpropTree)
{ m_histpropTree->clear();
int ntopcount=m_histpropTree->topLevelItemCount() ;
while(ntopcount--)
{m_histpropTree->topLevelItem(ntopcount);
}
}
}
void AlgHistoryProperties::setAlgProperties( const std::vector<PropertyHistory_sptr>& histProp)
{
m_Histprop.assign(histProp.begin(),histProp.end());
}
const PropertyHistories& AlgHistoryProperties:: getAlgProperties()
{
return m_Histprop;
}
void AlgHistoryProperties::displayAlgHistoryProperties()
{
QStringList propList;
std::string sProperty;
for ( std::vector<PropertyHistory_sptr>::const_iterator pIter = m_Histprop.begin();
pIter != m_Histprop.end(); ++pIter )
{
sProperty=(*pIter)->name();
propList.append(sProperty.c_str());
sProperty=(*pIter)->value();
propList.append(sProperty.c_str());
bool bisDefault=(*pIter)->isDefault();
bisDefault? (sProperty="Yes"):(sProperty="No");
propList.append(sProperty.c_str());
int nDirection=(*pIter)->direction();
switch(nDirection)
{
case 0:{sProperty="Input";break;}
case 1:{sProperty="Output";break;}
case 2:{sProperty="InOut";break;}
default:{sProperty="N/A";break;}
}
propList.append(sProperty.c_str());
QTreeWidgetItem * item= new QTreeWidgetItem(propList);
if(m_histpropTree)m_histpropTree->addTopLevelItem(item);
propList.clear();
}// end of properties for loop
// Fit some column widths to data
m_histpropTree->resizeColumnToContents(0); // Property name
m_histpropTree->resizeColumnToContents(2); // Default
m_histpropTree->resizeColumnToContents(3); // Direction
}
//--------------------------------------------------------------------------------------------------
// AlgHistoryTreeWidget Definitions
//--------------------------------------------------------------------------------------------------
void AlgHistoryTreeWidget::onItemChanged(QTreeWidgetItem* item, int index)
{
this->blockSignals(true);
if (index == UNROLL_COLUMN_INDEX && item->checkState(index) == Qt::Checked)
{
itemChecked(item, index);
}
else if(index == UNROLL_COLUMN_INDEX && item->checkState(index) == Qt::Unchecked)
{
itemUnchecked(item, index);
}
this->blockSignals(false);
}
void AlgHistoryTreeWidget::itemChecked(QTreeWidgetItem* item, int index)
{
std::vector<int> indicies;
QModelIndex modelIndex;
do
{
modelIndex = indexFromItem(item, index);
indicies.push_back(modelIndex.row()+1);
if(item->flags().testFlag(Qt::ItemIsUserCheckable))
{
item->setCheckState(index, Qt::Checked);
}
item = item->parent();
} while(item);
indicies[indicies.size()-1] -= 1;
//sum the indices to obtain the positions we must unroll
std::vector<int> unrollIndicies;
unrollIndicies.reserve(indicies.size());
std::partial_sum(indicies.rbegin(), indicies.rend(), std::back_inserter(unrollIndicies) );
this->blockSignals(false);
emit unrollAlgorithmHistory(unrollIndicies);
this->blockSignals(true);
}
void AlgHistoryTreeWidget::itemUnchecked(QTreeWidgetItem* item, int index)
{
int rollIndex = 0;
QModelIndex modelIndex;
//disable any children
uncheckAllChildren(item, index);
//find where we are in the tree
do
{
modelIndex = indexFromItem(item, index);
rollIndex += modelIndex.row()+1;
item = item->parent();
} while(item);
--rollIndex;
this->blockSignals(false);
emit rollAlgorithmHistory(rollIndex);
this->blockSignals(true);
}
void AlgHistoryTreeWidget::uncheckAllChildren(QTreeWidgetItem* item, int index)
{
if(item->childCount() > 0)
{
item->setCheckState(index, Qt::Unchecked);
for(int i=0; i<item->childCount(); ++i)
{
uncheckAllChildren(item->child(i), index);
}
}
}
void AlgHistoryTreeWidget::treeSelectionChanged()
{
AlgHistoryItem* item = dynamic_cast<AlgHistoryItem*>(this->selectedItems()[0]);
emit updateAlgorithmHistoryWindow(item->getAlgorithmHistory());
}
void AlgHistoryTreeWidget::selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
{
QTreeView::selectionChanged(selected, deselected);
treeSelectionChanged();
}
void AlgHistoryTreeWidget::populateAlgHistoryTreeWidget(const WorkspaceHistory& wsHist)
{
this->blockSignals(true);
const Mantid::API::AlgorithmHistories & entries = wsHist.getAlgorithmHistories();
auto algHistIter = entries.begin();
QString algName = "";
for (; algHistIter != entries.end(); ++algHistIter)
{
int nAlgVersion = (*algHistIter)->version();
algName = concatVersionwithName((*algHistIter)->name(),nAlgVersion);
AlgHistoryItem * item = new AlgHistoryItem(QStringList(algName), *algHistIter);
this->addTopLevelItem(item);
populateNestedHistory(item, *algHistIter);
}
resizeColumnToContents(0); // Algorithm name
resizeColumnToContents(1); // Unroll
this->blockSignals(false);
}
void AlgHistoryTreeWidget::populateNestedHistory(AlgHistoryItem* parentWidget, Mantid::API::AlgorithmHistory_sptr history)
{
QString algName = "";
const Mantid::API::AlgorithmHistories & entries = history->getChildHistories();
if(history->childHistorySize() > 0)
{
parentWidget->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled );
parentWidget->setCheckState(1, Qt::Unchecked);
}
for (auto algHistIter = entries.begin(); algHistIter != entries.end(); ++algHistIter)
{
int nAlgVersion = (*algHistIter)->version();
algName = concatVersionwithName((*algHistIter)->name(),nAlgVersion);
AlgHistoryItem * item = new AlgHistoryItem(QStringList(algName), *algHistIter, parentWidget);
parentWidget->addChild(item);
populateNestedHistory(item, *algHistIter);
}
}
QString AlgHistoryTreeWidget::concatVersionwithName(const std::string& name,const int version)
{
QString algName = name.c_str();
algName = algName + " v.";
QString algVersion=QString::number(version,10);
algName += algVersion;
return algName;
}