forked from avartak/TkCommissioner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmreferencechooser.h
104 lines (81 loc) · 4.05 KB
/
frmreferencechooser.h
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
#ifndef REFERENCECHOOSER_H
#define REFERENCECHOOSER_H
// Qt includes
#include <QAbstractButton>
#include <QString>
#include <QtSql/QSqlQuery>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QStandardItemModel>
#include <QStandardItem>
// UI file
#include "ui_frmreferencechooser.h"
class ReferenceChooser : public QDialog, private Ui::ReferenceChooser {
Q_OBJECT
public:
ReferenceChooser(QWidget *parent = 0) {
Q_UNUSED(parent);
setupUi(this);
sameRunType = false;
refRunModel = new QStandardItemModel(0, 2,this);
refRunView->setModel(refRunModel);
refRunView->setSelectionMode(QAbstractItemView::SingleSelection);
refRunView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
connect(refRunView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, SLOT(runChanged(QModelIndex,QModelIndex)));
}
~ReferenceChooser() {
}
signals:
void refSignal(QString, QString, bool);
public Q_SLOTS:
void runChanged(QModelIndex current, QModelIndex) {
referenceRunNumber = refRunModel->item(current.row(),0)->text();
}
void on_buttonBox_clicked(QAbstractButton* button) {
if (buttonBox->buttonRole(button) == QDialogButtonBox::RejectRole) return;
QString newRunType;
QString refRunType;
QString myQuery = QString("select distinct runnumber, modedescription from viewallrun left outer join analysis using(runnumber) where partitionname='%1' and local = 1").arg(referencePartition);
QSqlQuery query(myQuery);
while (query.next()) {
QString runNumber = query.value(0).toString();
QString modeDescription = query.value(1).toString();
if (runNumber == newRunNumber) newRunType = modeDescription;
if (runNumber == referenceRunNumber) refRunType = modeDescription;
}
if (!newRunType.isEmpty() && !refRunType.isEmpty() && newRunType == refRunType) sameRunType = true;
emit refSignal(referencePartition, referenceRunNumber, sameRunType);
}
public:
void addReferenceRuns(QString partitionName, QString currentRunNumber) {
newRunNumber = currentRunNumber;
referenceRunNumber = currentRunNumber;
referencePartition = partitionName;
QString myQuery = QString("select distinct runnumber, modedescription, case when analysisid is not null then 1 else 0 end as analyzed from viewallrun left outer join analysis using(runnumber) where partitionname='%1' and local = 1 order by RUNNUMBER desc").arg(partitionName);
QSqlQuery query(myQuery);
while (query.next()) {
QString runNumber = query.value(0).toString();
QString modeDescription = query.value(1).toString();
bool analyzed = query.value(2).toBool();
if (runNumber != currentRunNumber && analyzed) {
QList<QStandardItem*> *list = new QList<QStandardItem*>;
QStandardItem* runItem = new QStandardItem(runNumber);
runItem->setEditable(false);
QStandardItem* modItem = new QStandardItem(modeDescription);
modItem->setEditable(false);
list->append(runItem);
list->append(modItem);
refRunModel->appendRow(*list);
}
}
refRunModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Run Number"));
refRunModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Mode"));
}
private:
QString newRunNumber;
QString referenceRunNumber;
QString referencePartition;
bool sameRunType;
QStandardItemModel* refRunModel;
};
#endif