-
Notifications
You must be signed in to change notification settings - Fork 0
/
control_dialog.cpp
104 lines (95 loc) · 3.34 KB
/
control_dialog.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
#include "control_dialog.h"
const QString max_number_sites = "20";
TableDelegate::TableDelegate(){}
QWidget *TableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == 0) // figure type
{
QComboBox *combo_editor;
combo_editor = new QComboBox(parent);
combo_editor->addItem(tr("Piramid"));
combo_editor->addItem(tr("Prisme"));
return combo_editor;
}
else if (index.column() == 1 || index.column() == 5) // base type
{
QLabel *l_base = new QLabel(parent);
return l_base;
}
else if (index.column() == 2) // hight
{
QSpinBox *editor = new QSpinBox(parent);
editor->setMinimum(0);
editor->setMaximum(1000);
return editor;
}
else if (index.column() == 3) // hight possicion
{
QRegExp rx;
rx.setPattern("(\\([0-9\\-][0-9]{0,6},[0-9\\-][0-9]{0,6},[0-9\\-][0-9]{0,6}\\)){1,1}");
QRegExpValidator *validator = new QRegExpValidator(rx);
QLineEdit *editor = new QLineEdit(parent);
editor->setValidator(validator);
QString currentText = index.model()->data(index, Qt::DisplayRole).toString();
editor->setText(currentText);
return editor;
}
else //if (index.column() == 4) // base points
{
QRegExp rx;
rx.setPattern("(\\([0-9\\-][0-9]{0,6},[0-9\\-][0-9]{0,6},[0-9\\-][0-9]{0,6}\\)){0," + max_number_sites + "}");
QRegExpValidator *validator = new QRegExpValidator(rx);
QLineEdit *editor = new QLineEdit(parent);
editor->setValidator(validator);
QString currentText = index.model()->data(index, Qt::DisplayRole).toString();
editor->setText(currentText);
return editor;
}
}
void TableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (!editor)
return;
if (index.column()==0)
{
QComboBox *combo_editor = qobject_cast<QComboBox *>(editor);
combo_editor->setEditText(index.model()->data(index, Qt::EditRole).toString());
return;
}
if (index.column()==2)
{
QSpinBox *spin_editor = qobject_cast<QSpinBox *>(editor);
spin_editor->setValue(index.model()->data(index, Qt::EditRole).toInt());
return;
}
if (index.column()==1 || index.column()==5)
{
QLabel *lable_editor = qobject_cast<QLabel *>(editor);
lable_editor->setText(index.model()->data(index, Qt::EditRole).toString());
return;
}
QLineEdit *textEditor = qobject_cast<QLineEdit *>(editor);
if (textEditor)
textEditor->setText(index.model()->data(index, Qt::EditRole).toString());
}
void TableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
if (!editor || index.column()==1 || index.column()==5)
return;
if (index.column()==0)
{
QComboBox *combo_editor = qobject_cast<QComboBox *>(editor);
model->setData(index, combo_editor->currentText());
return;
}
if (index.column()==2)
{
QSpinBox *combo_editor = qobject_cast<QSpinBox *>(editor);
model->setData(index, combo_editor->value());
return;
}
QLineEdit *textEditor = qobject_cast<QLineEdit *>(editor);
if (textEditor) {
model->setData(index, textEditor->text());
}
}