Хранилища Subversion OpenInventory

Редакция

Редакция 77 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 77 Редакция 137
1
#include "delegateforclassestable.h"
1
#include "delegateforclassestable.h"
2
#include <QtGui>
2
#include <QtGui>
3
3
4
DelegateForClassesTable::DelegateForClassesTable(QObject *parent) :
4
DelegateForClassesTable::DelegateForClassesTable(QObject *parent) :
5
    QItemDelegate(parent)
5
    QItemDelegate(parent)
6
{
6
{
7
    items.append(tr("CHAR(10)"));
7
    items.append(tr("CHAR(10)"));
8
    items.append(tr("CHAR(30)"));
8
    items.append(tr("CHAR(30)"));
9
    items.append(tr("INT(10)"));
9
    items.append(tr("INT(10)"));
10
    items.append(tr("DATE"));
10
    items.append(tr("DATE"));
11
     items.append(tr("TYFTA"));
11
    items.append(tr("BLOB"));
12
}
12
}
13
QWidget *DelegateForClassesTable::createEditor(QWidget *parent,
13
QWidget *DelegateForClassesTable::createEditor(QWidget *parent,
14
    const QStyleOptionViewItem &/* option */,
14
    const QStyleOptionViewItem &/* option */,
15
    const QModelIndex &/* index */) const
15
    const QModelIndex &/* index */) const
16
{
16
{
17
    //QSpinBox *editor = new QSpinBox(parent);
17
    //QSpinBox *editor = new QSpinBox(parent);
18
    //editor->setMinimum(0);
18
    //editor->setMinimum(0);
19
    //editor->setMaximum(100);
19
    //editor->setMaximum(100);
20
    QComboBox *editor = new QComboBox(parent);
20
    QComboBox *editor = new QComboBox(parent);
21
    editor->addItems(items);
21
    editor->addItems(items);
22
22
23
    /*
23
    /*
24
    editor->addItem("0");
24
    editor->addItem("0");
25
    editor->addItem("1");
25
    editor->addItem("1");
26
    editor->addItem("2");
26
    editor->addItem("2");
27
    editor->addItem("3");
27
    editor->addItem("3");
28
    editor->addItem("4");
28
    editor->addItem("4");
29
    editor->addItem("5");
29
    editor->addItem("5");
30
    editor->addItem("6");
30
    editor->addItem("6");
31
    editor->addItem("7");
31
    editor->addItem("7");
32
    editor->addItem("8");
32
    editor->addItem("8");
33
    editor->addItem("9");
33
    editor->addItem("9");
34
  //  editor->addItem("0");
34
  //  editor->addItem("0");
35
    */
35
    */
36
36
37
    return editor;
37
    return editor;
38
}
38
}
39
//! [1]
39
//! [1]
40
40
41
//! [2]
41
//! [2]
42
void DelegateForClassesTable::setEditorData(QWidget *editor,
42
void DelegateForClassesTable::setEditorData(QWidget *editor,
43
                                    const QModelIndex &index) const
43
                                    const QModelIndex &index) const
44
{
44
{
45
   // int value = index.model()->data(index, Qt::EditRole).toInt();
45
   // int value = index.model()->data(index, Qt::EditRole).toInt();
46
46
47
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
47
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
48
 //   spinBox->setValue(value);
48
 //   spinBox->setValue(value);
49
QString value = index.model()->data(index, Qt::EditRole).toString();
49
QString value = index.model()->data(index, Qt::EditRole).toString();
50
QComboBox *comboBox = static_cast<QComboBox*>(editor);
50
QComboBox *comboBox = static_cast<QComboBox*>(editor);
51
int curr_index = items.indexOf(value);
51
int curr_index = items.indexOf(value);
52
if (curr_index!= -1) comboBox->setCurrentIndex(curr_index);
52
if (curr_index!= -1) comboBox->setCurrentIndex(curr_index);
53
else {
53
else {
54
54
55
}
55
}
56
/*
56
/*
57
if (value == "0") comboBox->setCurrentIndex(0);
57
if (value == "0") comboBox->setCurrentIndex(0);
58
if (value == "1") comboBox->setCurrentIndex(1);
58
if (value == "1") comboBox->setCurrentIndex(1);
59
if (value == "2") comboBox->setCurrentIndex(2);
59
if (value == "2") comboBox->setCurrentIndex(2);
60
if (value == "3") comboBox->setCurrentIndex(3);
60
if (value == "3") comboBox->setCurrentIndex(3);
61
if (value == "4") comboBox->setCurrentIndex(4);
61
if (value == "4") comboBox->setCurrentIndex(4);
62
if (value == "5") comboBox->setCurrentIndex(5);
62
if (value == "5") comboBox->setCurrentIndex(5);
63
if (value == "6") comboBox->setCurrentIndex(6);
63
if (value == "6") comboBox->setCurrentIndex(6);
64
if (value == "7") comboBox->setCurrentIndex(7);
64
if (value == "7") comboBox->setCurrentIndex(7);
65
if (value == "8") comboBox->setCurrentIndex(8);
65
if (value == "8") comboBox->setCurrentIndex(8);
66
if (value == "9") comboBox->setCurrentIndex(9);
66
if (value == "9") comboBox->setCurrentIndex(9);
67
*/
67
*/
68
comboBox->setEditable(false);
68
comboBox->setEditable(false);
69
69
70
70
71
//comboBox->setItemText(0, value);
71
//comboBox->setItemText(0, value);
72
72
73
}
73
}
74
//! [2]
74
//! [2]
75
75
76
//! [3]
76
//! [3]
77
void DelegateForClassesTable::setModelData(QWidget *editor, QAbstractItemModel *model,
77
void DelegateForClassesTable::setModelData(QWidget *editor, QAbstractItemModel *model,
78
                                   const QModelIndex &index) const
78
                                   const QModelIndex &index) const
79
{
79
{
80
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
80
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
81
  //  spinBox->interpretText();
81
  //  spinBox->interpretText();
82
  //  int value = spinBox->value();
82
  //  int value = spinBox->value();
83
83
84
  //  model->setData(index, value, Qt::EditRole);
84
  //  model->setData(index, value, Qt::EditRole);
85
85
86
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
86
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
87
    int currIndex;
87
    int currIndex;
88
    currIndex = comboBox->currentIndex();
88
    currIndex = comboBox->currentIndex();
89
    QString value = comboBox->itemText(currIndex);
89
    QString value = comboBox->itemText(currIndex);
90
    model->setData(index, value, Qt::EditRole);
90
    model->setData(index, value, Qt::EditRole);
91
}
91
}
92
//! [3]
92
//! [3]
93
93
94
//! [4]
94
//! [4]
95
void DelegateForClassesTable::updateEditorGeometry(QWidget *editor,
95
void DelegateForClassesTable::updateEditorGeometry(QWidget *editor,
96
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
96
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
97
{
97
{
98
    editor->setGeometry(option.rect);
98
    editor->setGeometry(option.rect);
99
}
99
}
100
//! [4]
100
//! [4]
101
101
102
102
103
void DelegateForClassesTable::setItems(QStringList new_items){
103
void DelegateForClassesTable::setItems(QStringList new_items){
104
104
105
    DelegateForClassesTable::items =  new_items;
105
    DelegateForClassesTable::items =  new_items;
106
106
107
}
107
}
108
 
108