QWidget *ColoringRulesTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    Q_UNUSED(option);
    QWidget *w = NULL;

    QTreeWidgetItem *ti = tree_->topLevelItem(index.row());
    if (!ti) return NULL;

    switch (index.column()) {
    case name_col_:
    {
        SyntaxLineEdit *sle = new SyntaxLineEdit(parent);
        connect(sle, SIGNAL(textChanged(QString)), this, SLOT(ruleNameChanged(QString)));
        sle->setText(ti->text(name_col_));
        w = (QWidget*) sle;
    }
        break;

    case filter_col_:
    {
        SyntaxLineEdit *dfe = new SyntaxLineEdit(parent);
        connect(dfe, SIGNAL(textChanged(QString)), dfe, SLOT(checkDisplayFilter(QString)));
        connect(dfe, SIGNAL(textChanged(QString)), this, SLOT(ruleFilterChanged(QString)));
        dfe->setText(ti->text(filter_col_));
        w = (QWidget*) dfe;
    }
        break;
    default:
        break;
    }

    return w;
}
QWidget *ColoringRulesTreeDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
{
    QWidget *w = NULL;

    QTreeWidgetItem *ti = tree_->topLevelItem(index.row());
    if (!ti) return NULL;

    switch (index.column()) {
    case name_col_:
    {
        SyntaxLineEdit *sle = new SyntaxLineEdit(parent);
        connect(sle, SIGNAL(textChanged(QString)), this, SLOT(ruleNameChanged(QString)));
        sle->setText(ti->text(name_col_));
        w = (QWidget*) sle;
    }
        break;

    case filter_col_:
    {
        DisplayFilterEdit *dfe = new DisplayFilterEdit(parent);
        // It's possible to have an invalid filter and an enabled OK button at this point.
        // We might want to add a local slot for checking the filter status.
        connect(dfe, SIGNAL(textChanged(QString)), dfe, SLOT(checkDisplayFilter(QString)));
        dfe->setText(ti->text(filter_col_));
        w = (QWidget*) dfe;
    }
        break;
    default:
        break;
    }

    return w;
}