// //////////////////////////////////////////
// //////////////////////////////////////////
{
//Q_OBJECT
// //////////////////////////////
public:
// //////////////////////////////
FilterRecordItemDelegate
(QObject *parent
=NULL);
};
// //////////////////////////////////
// //////////////////////////////////
{
}
// //////////////////////////////////
// //////////////////////////////////
{
if (!index.isValid())
return NULL;
int col = index.column();
switch(col)
{
case 1:
{
editor
->addItem
( tr
("Regular expression"),
QRegExp::RegExp );
editor
->addItem
( tr
("Wildcard") ,
QRegExp::Wildcard );
editor
->addItem
( tr
("Fixed string") ,
QRegExp::FixedString );
report = editor;
break;
}
case 2:
{
report = editor;
break;
}
}
return report;
}
// //////////////////////////////////
void FilterRecordItemDelegate
::setEditorData(QWidget *editor,
// //////////////////////////////////
{
if (!index.isValid())
return;
int col = index.column();
switch(col)
{
case 1:
{
int value = index.model()->data(index, Qt::EditRole).toInt();
QComboBox *cmbBox
= static_cast<QComboBox
*>
(editor
);
cmbBox->setCurrentIndex(value);
break;
}
case 2:
{
int value = index.model()->data(index, Qt::EditRole).toBool();
QCheckBox *chckBox
= static_cast<QCheckBox
*>
(editor
);
chckBox->setChecked(value);
break;
}
}
}
// //////////////////////////////////
void FilterRecordItemDelegate
::setModelData(QWidget *editor,
// //////////////////////////////////
{
if (!index.isValid())
return;
int col = index.column();
switch(col)
{
case 1:
{
QComboBox *cmbBox
= static_cast<QComboBox
*>
(editor
);
int value = cmbBox->currentIndex();
model->setData(index, value, Qt::EditRole);
break;
}
case 2:
{
QCheckBox *chckBox
= static_cast<QCheckBox
*>
(editor
);
bool value = chckBox->isChecked();
model->setData(index, value, Qt::EditRole);
break;
}
}
}
// //////////////////////////////////////////
class FilterRecordItemDelegate : public QItemDelegate
// //////////////////////////////////////////
{
//Q_OBJECT
// //////////////////////////////
public:
// //////////////////////////////
FilterRecordItemDelegate(QObject *parent=NULL);
QWidget *createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData (QWidget *editor, const QModelIndex &index) const;
void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
};
// //////////////////////////////////
FilterRecordItemDelegate::FilterRecordItemDelegate(QObject *parent) : QItemDelegate(parent)
// //////////////////////////////////
{
}
// //////////////////////////////////
QWidget *FilterRecordItemDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
// //////////////////////////////////
{
if (!index.isValid())
return NULL;
QWidget *report = NULL;
int col = index.column();
switch(col)
{
case 1:
{
QComboBox *editor = new QComboBox(parent);
editor->addItem( tr("Regular expression"), QRegExp::RegExp );
editor->addItem( tr("Wildcard") , QRegExp::Wildcard );
editor->addItem( tr("Fixed string") , QRegExp::FixedString );
report = editor;
break;
}
case 2:
{
QCheckBox *editor = new QCheckBox(parent);
report = editor;
break;
}
}
return report;
}
// //////////////////////////////////
void FilterRecordItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
// //////////////////////////////////
{
if (!index.isValid())
return;
int col = index.column();
switch(col)
{
case 1:
{
int value = index.model()->data(index, Qt::EditRole).toInt();
QComboBox *cmbBox = static_cast<QComboBox*>(editor);
cmbBox->setCurrentIndex(value);
break;
}
case 2:
{
int value = index.model()->data(index, Qt::EditRole).toBool();
QCheckBox *chckBox = static_cast<QCheckBox*>(editor);
chckBox->setChecked(value);
break;
}
}
}
// //////////////////////////////////
void FilterRecordItemDelegate::setModelData(QWidget *editor,
QAbstractItemModel *model,
const QModelIndex &index) const
// //////////////////////////////////
{
if (!index.isValid())
return;
int col = index.column();
switch(col)
{
case 1:
{
QComboBox *cmbBox = static_cast<QComboBox*>(editor);
int value = cmbBox->currentIndex();
model->setData(index, value, Qt::EditRole);
break;
}
case 2:
{
QCheckBox *chckBox = static_cast<QCheckBox*>(editor);
bool value = chckBox->isChecked();
model->setData(index, value, Qt::EditRole);
break;
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks