void FilterExpressionsPreferencesFrame::on_expressionTreeWidget_itemActivated(QTreeWidgetItem *item, int column) { if (!item || cur_line_edit_) return; QWidget *editor = NULL; cur_column_ = column; switch (column) { case label_col_: { cur_line_edit_ = new QLineEdit(); cur_column_ = column; saved_col_string_ = item->text(label_col_); connect(cur_line_edit_, SIGNAL(editingFinished()), this, SLOT(labelEditingFinished())); editor = cur_line_edit_; break; } case expression_col_: { SyntaxLineEdit *syntax_edit = new SyntaxLineEdit(); saved_col_string_ = item->text(expression_col_); connect(syntax_edit, SIGNAL(textChanged(QString)), this, SLOT(expressionTextChanged(QString))); connect(syntax_edit, SIGNAL(editingFinished()), this, SLOT(expressionEditingFinished())); editor = cur_line_edit_ = syntax_edit; break; } default: return; } if (cur_line_edit_) { cur_line_edit_->setText(saved_col_string_); cur_line_edit_->selectAll(); connect(cur_line_edit_, SIGNAL(destroyed()), this, SLOT(lineEditDestroyed())); } if (editor) { QFrame *edit_frame = new QFrame(); QHBoxLayout *hb = new QHBoxLayout(); QSpacerItem *spacer = new QSpacerItem(5, 10); hb->addWidget(editor, 0); hb->addSpacerItem(spacer); hb->setStretch(1, 1); hb->setContentsMargins(0, 0, 0, 0); edit_frame->setLineWidth(0); edit_frame->setFrameStyle(QFrame::NoFrame); // The documentation suggests setting autoFillbackground. That looks silly // so we clear the item text instead. item->setText(cur_column_, ""); edit_frame->setLayout(hb); ui->expressionTreeWidget->setItemWidget(item, cur_column_, edit_frame); editor->setFocus(); } }
void ColumnPreferencesFrame::on_columnTreeWidget_itemActivated(QTreeWidgetItem *item, int column) { if (!item || cur_line_edit_ || cur_combo_box_) return; QWidget *editor = NULL; cur_column_ = column; saved_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); switch (column) { case title_col_: { cur_line_edit_ = new QLineEdit(); cur_column_ = column; saved_col_string_ = item->text(title_col_); connect(cur_line_edit_, SIGNAL(editingFinished()), this, SLOT(columnTitleEditingFinished())); editor = cur_line_edit_; break; } case type_col_: { cur_combo_box_ = new QComboBox(); for (int i = 0; i < NUM_COL_FMTS; i++) { cur_combo_box_->addItem(col_format_desc(i), QVariant(i)); if (i == saved_combo_idx_) { cur_combo_box_->setCurrentIndex(i); } } connect(cur_combo_box_, SIGNAL(currentIndexChanged(int)), this, SLOT(columnTypeCurrentIndexChanged(int))); editor = cur_combo_box_; break; } case custom_field_col_: { SyntaxLineEdit *syntax_edit = new SyntaxLineEdit(); saved_col_string_ = item->text(custom_field_col_); connect(syntax_edit, SIGNAL(textChanged(QString)), syntax_edit, SLOT(checkFieldName(QString))); connect(syntax_edit, SIGNAL(editingFinished()), this, SLOT(customFieldEditingFinished())); editor = cur_line_edit_ = syntax_edit; saved_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); item->setText(type_col_, col_format_desc(COL_CUSTOM)); item->setData(type_col_, Qt::UserRole, QVariant(COL_CUSTOM)); break; } case custom_occurrence_col_: { SyntaxLineEdit *syntax_edit = new SyntaxLineEdit(); saved_col_string_ = item->text(custom_occurrence_col_); connect(syntax_edit, SIGNAL(textChanged(QString)), this, SLOT(customOccurrenceTextChanged(QString))); connect(syntax_edit, SIGNAL(editingFinished()), this, SLOT(customOccurrenceEditingFinished())); editor = cur_line_edit_ = syntax_edit; saved_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); item->setText(type_col_, col_format_desc(COL_CUSTOM)); item->setData(type_col_, Qt::UserRole, QVariant(COL_CUSTOM)); break; } default: return; } if (cur_line_edit_) { cur_line_edit_->setText(saved_col_string_); cur_line_edit_->selectAll(); connect(cur_line_edit_, SIGNAL(destroyed()), this, SLOT(lineEditDestroyed())); } if (cur_combo_box_) { connect(cur_combo_box_, SIGNAL(destroyed()), this, SLOT(comboDestroyed())); } if (editor) { QFrame *edit_frame = new QFrame(); QHBoxLayout *hb = new QHBoxLayout(); QSpacerItem *spacer = new QSpacerItem(5, 10); hb->addWidget(editor, 0); hb->addSpacerItem(spacer); hb->setStretch(1, 1); hb->setContentsMargins(0, 0, 0, 0); edit_frame->setLineWidth(0); edit_frame->setFrameStyle(QFrame::NoFrame); // The documentation suggests setting autoFillbackground. That looks silly // so we clear the item text instead. item->setText(cur_column_, ""); edit_frame->setLayout(hb); ui->columnTreeWidget->setItemWidget(item, cur_column_, edit_frame); editor->setFocus(); } }