Salut

J'affiche des données dans une QTableView à laquelle j'ai associée un modèle.

je voudrais maintenant lui associer un QItemDelegate pour modifier les valeurs d'une colonne en particulier
j'ai donc défini ma classe FsComboDelegate héritant de QItemDelegate.
Je l'ai associée à ma QTableView ainsi:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
this->_tableViewSignals->setModel(new MessageTableModel(this->_tableViewSignals, /*...*/));	
this->_tableViewSignals->setItemDelegate(new FsComboDelegate(this->_tableViewSignals));
Je colle un point d'arret sur les fonctions de MyQItemDelegate. Seule la méthode paint est appelée. Les autres ne sont jamais invoquées.

A quoi ca peut être du?

Merci d'avance

les codes du model et du delegate:

delegate :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include "fscombodelegate.h"
#include <QComboBox>
#include <QItemDelegate>
 
FsComboDelegate::FsComboDelegate(QObject *parent)
	: QItemDelegate(parent)
{
 
}
 
FsComboDelegate::~FsComboDelegate()
{
 
}
void FsComboDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
							const QModelIndex &index) const{
								QItemDelegate::paint(painter, option,index);
}
 
 
 QWidget *FsComboDelegate::createEditor(QWidget *parent,
     const QStyleOptionViewItem &/* option */,
     const QModelIndex &/* index */) const
 {
     QComboBox *editor = new QComboBox(parent);
     editor->addItem("ND", (QVariant)0x00);
     editor->addItem("NO", (QVariant)0x03);
     editor->addItem("FT", (QVariant)0x0C);
     editor->addItem("NCD", (QVariant)0x30);
 
     return editor;
 }
 
 void FsComboDelegate::setEditorData(QWidget *editor,
                                     const QModelIndex &index) const
 {
	 //if(index.column() == 5) {
		 int value = index.model()->data(index, Qt::EditRole).toInt();
	// }
 
	 QComboBox *lComboBox = static_cast<QComboBox*>(editor);
 
     //TODO restore here
	 //lComboBox->setValue(value);
 }
 
 
  void FsComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
                                    const QModelIndex &index) const
 {
     QComboBox *lComboBox = static_cast<QComboBox*>(editor);
     //lComboBox->interpretText();
	 int value = lComboBox->currentText().toInt();
 
     model->setData(index, value, Qt::EditRole);
 }
 
 
  void FsComboDelegate::updateEditorGeometry(QWidget *editor,
     const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
 {
     editor->setGeometry(option.rect);
 }

model
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include "MessageTableModel.h"
#include <QtGui/QBrush>
 
#include "hmi_facade.h"
 
extern IcdGetBusListType IcdParserDllGetBusList;
extern IcdParseType IcdParserDllParse;				
extern IcdInitType IcdParserDllInit;		
extern IcdGetBusNumberType IcdParserDllGetBusNumber;
extern IcdGetSignalNumberOnBusType IcdParserDllGetSignalNumberOnbus;
extern IcdGetSignalListType IcdParserDllGetSignalList;		
 
 
MessageTableModel::MessageTableModel(QObject *parent, QString aVlName, int aPortId)
{
	_vlName = aVlName;
	_portId = aPortId;
 
	_nbSignals = IcdParserDllGetSignalNumberOnbus((char*)aVlName.toStdString().c_str(), aPortId);
	if(_nbSignals > 0) {
 
		_signals = new S_SignalDescription[_nbSignals];
 
		IcdParserDllGetSignalList((char*)aVlName.toStdString().c_str(), aPortId, _signals);
	} else {
		_signals = NULL;
		//TODO warn user in this case
	}
 
}
 
MessageTableModel::~MessageTableModel()
{
 
}
 
 
 
int	MessageTableModel::columnCount ( const QModelIndex & parent) const {
	return 6;
}
 
 
 
QVariant MessageTableModel::headerData (int section, Qt::Orientation orientation, int role) const {
	if (role == Qt::SizeHintRole) {
			//The size hint for the item that will be supplied to views. (QSize) 
		return QSize(10,20);
	} 
	else if(role == Qt::DisplayRole) {
		if (orientation == Qt::Horizontal) {
			switch (section) {
				case 0:
					return QString("Signal Name");
				case 1:
					return QString("Signal Type");
				case 2:
					return QString("Min value");
				case 3:
					return QString("Max value");
				case 4:
					return QString("Default Value");
				case 5:
					return QString("Default Validity");
				default:
					return QString("");
			}//switch
		}//horizontal
		else {
			return QVariant();
		}
	}
	else {
		return QVariant();
	}
}
 
 
 
QVariant MessageTableModel::data ( const QModelIndex & index, int role ) const  {
	if ((role == Qt::BackgroundRole)) {
		QBrush lBrush;
		lBrush.setColor(Qt::blue);
        return lBrush;
	}
	else if (role == Qt::DisplayRole) {
		switch(index.column()) {
			case 0 : //signal Name (icd input)
				return (QVariant) QString(_signals[index.row()].Signalname);
			case 1: //signal type (icd input)
				return (QVariant) QString(_signals[index.row()].Signaltype);
			case 2: //signal min value (icd input)
				if (QString(_signals[index.row()].Signaltype).compare(QString("float"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString::number(_signals[index.row()].FloatOperationalmin);
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("integer"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString::number(_signals[index.row()].IntegerOperationalmin);
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("boolean"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString("false");
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("opaque"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString("N/A");
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("string"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString("N/A");
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("enumerate"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString("N/A");
				}
				else {
					return QVariant();
				}
			case 3: //signal max value (icd input)
						if (QString(_signals[index.row()].Signaltype).compare(QString("float"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString::number(_signals[index.row()].FloatOperationalmax);
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("integer"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString::number(_signals[index.row()].IntegerOperationalmax);
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("boolean"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString("true");
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("opaque"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString("N/A");
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("string"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString("N/A");
				}
				else if (QString(_signals[index.row()].Signaltype).compare(QString("enumerate"), Qt::CaseInsensitive) == 0){
					return (QVariant) QString("N/A");
				}
				else {
					return QVariant();
				}
			case 4: //signal default value (user input)
				return (QVariant) "todod";
			case 5: //validity default value (user input)
				return QVariant();
			default:
				return (QVariant) "?";
		}
	}  
	else if (role == Qt::DecorationRole) {
		//The data to be rendered as a decoration in the form of an icon. (QColor, QIcon or QPixmap) 
		return QVariant();
	}
	else if (role == Qt::FontRole){
			//The font used for items rendered with the default delegate. (QFont)  
		return QVariant();
	}
else if (role == Qt::TextAlignmentRole){
			//The alignment of the text for items rendered with the default delegate. (Qt::AlignmentFlag)  
		return QVariant();
	}
else if (role == Qt::ForegroundRole){
			//The foreground brush (text color, typically) used for items rendered with the default delegate. (QBrush)  
		return QVariant();
	}
else if (role == Qt::CheckStateRole){
			//This role is used to obtain the checked state of an item. (Qt::CheckState)  
	return QVariant();
	}
 
return QVariant();
 
}
 
 
QModelIndex	MessageTableModel::index ( int row, int column, const QModelIndex & parent ) const  {
 
	return createIndex(row, column);
}
 
QModelIndex	MessageTableModel::parent ( const QModelIndex & index ) const  {
	QModelIndex lOut;
	return lOut;
}
 
int	MessageTableModel::rowCount ( const QModelIndex & parent) const  {
	return _nbSignals;
}