Хранилища Subversion OpenInventory

Редакция

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

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