crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )

> Сигналы в QItem Delegate
Друль
  опции профиля:
сообщение 30.5.2010, 14:17
Сообщение #1


Новичок


Группа: Новичок
Сообщений: 2
Регистрация: 30.5.2010
Пользователь №: 1766

Спасибо сказали: 0 раз(а)




Репутация:   0  


Раскрывающийся текст
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);

}

Нужо при изменении индекса комбо бокса, если на комбо тру значит прейти к редактированию сл ячейки QLineEdit, протсо сигнал послать нельзя так как методы константные подскажите как это реализовать...
Заранее спс...
Перейти в начало страницы
 
Быстрая цитата+Цитировать сообщение

Сообщений в этой теме


Быстрый ответОтветить в данную темуНачать новую тему
Теги
Нет тегов для показа


1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0




RSS Текстовая версия Сейчас: 22.1.2025, 21:03