ComboDelegate::ComboDelegate(TypeEditor type, QObject *parent)
: QItemDelegate(parent)
{
typeeditor = type;
}
QWidget *ComboDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &,
const QModelIndex &) const
{
QWidget *editor;
switch(typeeditor)
{
case TBool:
{
QComboBox *cmbox = new QComboBox(parent);
cmbox->addItem("true");
cmbox->addItem("false");
connect(cmbox,SIGNAL(activated(int)),SLOT(ComboDelegate::ch_index()));
return static_cast<QWidget *>(cmbox);
}
}
return editor;
}
void ComboDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QVariant data = index.model()->data(index, Qt::DisplayRole);
switch(typeeditor)
{
case TBool:
{
QComboBox *cmbox = static_cast<QComboBox *>(editor);
if (data.toString()=="true")
{
cmbox->setCurrentIndex(cmbox->findText("true"));
}
else
{
cmbox->setCurrentIndex(cmbox->findText("false"));
}
break;
}
}
}
void ComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QVariant data;
int ty;
switch(typeeditor)
{
case TBool:
QComboBox *cmbox = static_cast<QComboBox *>(editor);
data = cmbox->currentText();
int row = index.row();
int col = index.column();
col +=1;
ty = cmbox->currentIndex();
if (cmbox->currentText()=="true")
{
QModelIndex ind = model->index(row,col);
QMessageBox::information(0,"","emit");
}
else
{
cmbox->setCurrentIndex(cmbox->findText("false"));
}
break;
}
model->setData(index, data, Qt::EditRole);
}
void ComboDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
void ComboDelegate::ch_index(QWidget *editor)
{
emit closeEditor(editor,QAbstractItemDelegate::EditNextItem);
QMessageBox::critical(0,"Error","0");
}
//----------------------------------------------------------------------
LineDelegate::LineDelegate(TypeEditor type, QObject *parent)
: QItemDelegate(parent)
{
typeeditor = type;
}
QWidget *LineDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &,
const QModelIndex &) const
{
QWidget *editor;
switch(typeeditor)
{
case TLine:
{
QLineEdit *lin = new QLineEdit(parent);
lin->setReadOnly(true);
QMessageBox::critical(0,"","CreateLine");
return static_cast<QWidget *>(lin);
}
}
return editor;
}
void LineDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QVariant data = index.model()->data(index, Qt::DisplayRole);
switch(typeeditor)
{
case TLine:
{
QLineEdit *lin = static_cast<QLineEdit *>(editor);
QMessageBox::critical(0,"sdf","line");
lin->setText(data.toString());
break;
}
}
}
void LineDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QVariant data;
switch(typeeditor)
{
case TLine:
{
QLineEdit *lin = static_cast<QLineEdit *>(editor);
data = lin->text();
break;
}
}
model->setData(index, data, Qt::EditRole);
}
void LineDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
void LineDelegate::setEditorData_qs(QWidget *editor,
const QModelIndex &index,QString rt) const
{
QVariant data = index.model()->data(index, Qt::DisplayRole);
switch(typeeditor)
{
case TLine:
{
QLineEdit *lin = static_cast<QLineEdit *>(editor);
lin->setText(data.toString());
QMessageBox::information(0,"as",rt);
break;
}
}
}
void LineDelegate::ac ()
{
QMessageBox::critical(0,"LineDelegate","Line");
//emit closeEditor(this,QAbstractItemDelegate::EditNextItem);
}