-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscorecheckerviewdelegate.cpp
More file actions
250 lines (236 loc) · 8.98 KB
/
scorecheckerviewdelegate.cpp
File metadata and controls
250 lines (236 loc) · 8.98 KB
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
#include "scorecheckerviewdelegate.h"
#include <QPushButton>
#include <QtGui>
#include <QDialog>
#include <QApplication>
#include <QComboBox>
#include <QSpinBox>
#include <QFileDialog>
#include <QLineEdit>
#include <iostream>
#include "scripteditdialog.h"
#include "templateeditwindow.h"
ScoreCheckerViewDelegate::ScoreCheckerViewDelegate(QObject *parent)
{
}
QWidget * ScoreCheckerViewDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QComboBox * combo= new QComboBox(parent);
QPushButton * button= new QPushButton(parent);
QSpinBox * spinbox= new QSpinBox(parent);
QString datavar;
int value;
switch(index.column())
{
case COLUMN_TYPE:
combo->addItem(tr("Path Exist"));
combo->addItem(tr("Command Output"));
combo->addItem(tr("Value"));
combo->addItem(tr("Script"));
combo->addItem(tr("QuestionAnswer"));
combo->addItem(tr("Template - beta"));
combo->setCurrentIndex(0);
return combo;
break;
case COLUMN_DESCRIPTION:
break;
case COLUMN_INSTRUCTIONS:
break;
case COLUMN_OPT1: //Opt1
if (index.model()->data(index.sibling(index.row(),0), Qt::DisplayRole).toString()=="")break;
value = index.model()->data(index.sibling(index.row(),0), Qt::EditRole).toInt();
switch(value)
{
case CHECKER_PATH: //PathCheck
break;
case CHECKER_RUN_COMMAND: //CommandCheck
break;
case CHECKER_VALUE: //ValueCheck
break;
case CHECKER_RUN_SCRIPT: //ScriptCheck
break;
case CHECKER_QA: //QuestionAnswer
break;
}
break;
case COLUMN_OPT2:
combo->addItem(tr("!Exist"));
combo->addItem(tr("Exist"));
combo->setCurrentIndex(index.data(Qt::EditRole).toBool());
return combo;
case COLUMN_SEARCH_STR: //SearchString
//return button;
case COLUMN_POINTS: //Points
break;
case COLUMN_FIXED:
button->setText(tr("HI"));
return button;
break;
}
return QStyledItemDelegate::createEditor(parent,option,index);
}
void ScoreCheckerViewDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
//QString value= index.model()->data(index, Qt::EditRole).toString();
//QComboBox * combo= static_cast<QComboBox *>(editor);
//combo->addItem(tr("Test Item"));
//editor->setProperty()
//QItemDelegate::setEditorData(editor,index);
int value = index.model()->data(index, Qt::EditRole).toInt();
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
QStyledItemDelegate::setEditorData(editor,index);
}
//
// Gets input from editors in the Qtable depending on which type of issue is edited.
// Changes settings through the model
//
void ScoreCheckerViewDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QLineEdit *lineedit;
QSpinBox * spinbox;
QComboBox * combo;
int value;
switch(index.column())
{
case COLUMN_TYPE: //ScoreChecker Type
combo = static_cast<QComboBox*>(editor);
model->setData(index,combo->currentIndex());
break;
case COLUMN_DESCRIPTION: //ScoreChecker Description
lineedit = static_cast<QLineEdit*>(editor);
model->setData(index,lineedit->text());
break;
case COLUMN_INSTRUCTIONS: //Instructions/Question
lineedit = static_cast<QLineEdit*>(editor);
model->setData(index,lineedit->text());
break;
case COLUMN_OPT1: //Opt1
if (index.model()->data(index.sibling(index.row(),0), Qt::DisplayRole).toString()=="")break;
value = index.model()->data(index.sibling(index.row(),0), Qt::EditRole).toInt();
switch(value)
{
case CHECKER_PATH: //PathCheck
lineedit = static_cast<QLineEdit*>(editor);
model->setData(index,lineedit->text());
break;
case CHECKER_RUN_COMMAND: //CommandCheck
case CHECKER_VALUE: //ValueCheck
lineedit = static_cast<QLineEdit*>(editor);
model->setData(index,lineedit->text());
break;
case CHECKER_RUN_SCRIPT: //ScriptCheck
break;
case CHECKER_QA: //CompoundCheck
break;
}
break;
case COLUMN_OPT2: //ScoreChecker Desired State
combo = static_cast<QComboBox*>(editor);
model->setData(index,combo->currentIndex());
break;
case COLUMN_SEARCH_STR:
lineedit = static_cast<QLineEdit*>(editor);
model->setData(index,lineedit->text());
break;
case COLUMN_POINTS: //ScoreChecker point value
spinbox = static_cast<QSpinBox*>(editor);
model->setData(index,spinbox->value());
//vecScoreCheckers->at(index.row()).setPoints(value.toInt());
break;
case COLUMN_FIXED: //ScoreChecker state
break;
default:
break;
}
}
// Handles special user interaction for editing the configuration
bool ScoreCheckerViewDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
if( event->type() == QEvent::MouseButtonPress)
{
switch(index.column())
{
case COLUMN_OPT1:
switch (model->data(index.sibling(index.row(),0),Qt::EditRole).toInt())
{
case CHECKER_PATH: ; //PathExist
{
QMouseEvent * e = (QMouseEvent *)event;
if (e->button()==Qt::RightButton)
{
QFileDialog opendialog(0, tr("Select Path"));
QString filename=opendialog.getOpenFileName(0,tr("Select Path"),model->data(index).toString());
if (filename.length()>0)model->setData(index, filename);
}
}
break;
case CHECKER_RUN_COMMAND:
break;
case CHECKER_VALUE:
{
QMouseEvent * e = (QMouseEvent *)event;
if (e->button()==Qt::RightButton)
{
QFileDialog opendialog(nullptr, tr("Select File"));
QString filename=opendialog.getOpenFileName(nullptr,tr("Select Path"),model->data(index).toString());
if (filename.length()>0)model->setData(index, filename);
}
}
break;
case CHECKER_RUN_SCRIPT:
{
QMouseEvent * e = (QMouseEvent *)event;
if (e->button()==Qt::RightButton)
{
ScriptEditDialog *scriptedit=new ScriptEditDialog(0,model->data(index, Qt::EditRole | Qt::DisplayRole).value<ScriptScoreChecker*>() );
scriptedit->exec();
//model->data(index, Qt::EditRole)
//if (scriptedit->getScript()!="")model->setData(index, scriptedit->getScript().c_str());
}
}
break;
case CHECKER_TEMPLATE: //TemplateChecker
QMouseEvent * e = (QMouseEvent *)event;
if (e->button()==Qt::RightButton)
{
TemplateEditWindow *templatewindow=new TemplateEditWindow(0,model->data(index, Qt::EditRole | Qt::DisplayRole).value<TemplateScoreChecker*>() );
templatewindow->exec();
//model->data(index, Qt::EditRole)
//if (scriptedit->getScript()!="")model->setData(index, scriptedit->getScript().c_str());
}
break;
}
break;
case COLUMN_FIXED:
QMouseEvent * e = (QMouseEvent *)event;
//std::cout << "Button Clicked in col #7\n";
model->setData(index,1); //trigger a check
return true;
break;
}
}
return QStyledItemDelegate::editorEvent(event, model, option, index);
}
// Properly sizes the widgets inside the cells
void ScoreCheckerViewDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
editor->setGeometry(option.rect);
}
void ScoreCheckerViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
/*QStyleOptionButton button;
QRect r = option.rect;//getting the rect of the cell
int x,y,w,h;
x = r.left() + r.width() - 60;//the X coordinate
y = r.top();//the Y coordinate
w = 60;//button width
h = 30;//button height
button.rect = QRect(x,y,w,h);
button.text = "=^.^=";
button.state = QStyle::State_Enabled;
QApplication::style()->drawControl( QStyle::CE_PushButton, &button, painter);*/
//QItemDelegate::paint(painter, option, index);
QStyledItemDelegate::paint(painter, option, index);
}