void KexiComboBoxBase::setValueOrTextInInternalEditor(const QVariant& value) { if (!m_setValueOrTextInInternalEditor_enabled) return; setValueInInternalEditor(value); //this text is not entered by hand: m_userEnteredValue = QVariant(); m_internalEditorValueChanged = false; }
void KexiDateTableEdit::setValueInternal(const QVariant& add_, bool removeOld) { if (removeOld) { //new date entering... just fill the line edit //! @todo cut string if too long.. QString add(add_.toString()); m_lineedit->setText(add); m_lineedit->setCursorPosition(add.length()); return; } setValueInInternalEditor(KexiDataItemInterface::originalValue()); m_lineedit->setCursorPosition(0); //ok? }
void KexiDateTableEdit::handleAction(const QString& actionName) { const bool alreadyVisible = m_lineedit->isVisible(); if (actionName == "edit_paste") { const QVariant newValue(m_formatter.fromString(qApp->clipboard()->text())); if (!alreadyVisible) { //paste as the entire text if the cell was not in edit mode emit editRequested(); m_lineedit->clear(); } setValueInInternalEditor(newValue); } else KexiInputTableEdit::handleAction(actionName); }
void KexiComboBoxTableEdit::handleAction(const QString& actionName) { const bool alreadyVisible = m_lineedit->isVisible(); if (actionName == "edit_paste") { if (!alreadyVisible) { //paste as the entire text if the cell was not in edit mode emit editRequested(); m_lineedit->clear(); } //! @todo does not work with BLOBs! setValueInInternalEditor(qApp->clipboard()->text()); } else KexiInputTableEdit::handleAction(actionName); }
void KexiComboBoxBase::setValueInternal(const QVariant& add_, bool removeOld) { Q_UNUSED(removeOld); m_mouseBtnPressedWhenPopupVisible = false; m_updatePopupSelectionOnShow = true; QString add(add_.toString()); if (add.isEmpty()) { KexiTableViewData *relData = column() ? column()->relatedData() : 0; QVariant valueToSet; bool hasValueToSet = true; int rowToHighlight = -1; KexiDB::LookupFieldSchema *lookupFieldSchema = this->lookupFieldSchema(); if (lookupFieldSchema) { //use 'lookup field' model //! @todo support more RowSourceType's, not only table if (lookupFieldSchema->boundColumn() == -1) //! @todo errmsg return; if (m_setVisibleValueOnSetValueInternal) { //only for table views if (!popup()) createPopup(false/*!show*/); } if (popup()) { const int rowToHighlight = rowToHighlightForLookupTable(); popup()->tableView()->setHighlightedRecord(rowToHighlight); const int visibleColumn = lookupFieldSchema->visibleColumn(popup()->tableView()->data()->columnsCount()); if (m_setVisibleValueOnSetValueInternal && -1 != visibleColumn) { //only for table views KexiDB::RecordData *record = popup()->tableView()->highlightedItem(); if (record) valueToSet = record->at(visibleColumn); } else { hasValueToSet = false; } } } else if (relData) { //use 'related table data' model valueToSet = valueForString(origValue().toString(), &rowToHighlight, 0, 1); } else { //use 'enum hints' model const int row = origValue().toInt(); valueToSet = field()->enumHint(row).trimmed(); } if (hasValueToSet) setValueOrTextInInternalEditor(valueToSet); /*impl.*/moveCursorToEndInInternalEditor(); /*impl.*/selectAllInInternalEditor(); if (popup()) { if (origValue().isNull()) { popup()->tableView()->clearSelection(); popup()->tableView()->setHighlightedRecord(0); } else { if (relData) { if (rowToHighlight != -1) popup()->tableView()->setHighlightedRecord(rowToHighlight); } else if (!lookupFieldSchema) { //popup()->tableView()->selectRow(origValue().toInt()); popup()->tableView()->setHighlightedRecord(origValue().toInt()); } } } } else { //todo: autocompl.? if (popup()) popup()->tableView()->clearSelection(); /*impl.*/setValueInInternalEditor(add); //not setLineEditText(), because 'add' is entered by user! //setLineEditText( add ); /*impl.*/moveCursorToEndInInternalEditor(); } }
void KexiComboBoxBase::createPopup(bool show) { //kDebug() << show << field() << popup() << m_updatePopupSelectionOnShow; if (!field()) return; m_insideCreatePopup = true; QWidget* thisWidget = dynamic_cast<QWidget*>(this); QWidget *widgetToFocus = internalEditor() ? internalEditor() : thisWidget; if (m_reinstantiatePopupOnShow) { QWidget *oldPopup = popup(); setPopup(0); delete oldPopup; } if (!popup()) { setPopup(column() ? new KexiComboBoxPopup(thisWidget, *column()) : new KexiComboBoxPopup(thisWidget, *field())); QObject::connect(popup(), SIGNAL(rowAccepted(KexiDB::RecordData*,int)), thisWidget, SLOT(slotRowAccepted(KexiDB::RecordData*,int))); QObject::connect(popup()->tableView(), SIGNAL(itemSelected(KexiDB::RecordData*)), thisWidget, SLOT(slotItemSelected(KexiDB::RecordData*))); popup()->setFocusProxy(widgetToFocus); popup()->tableView()->setFocusProxy(widgetToFocus); popup()->installEventFilter(thisWidget); if (origValue().isNull()) popup()->tableView()->clearSelection(); else { popup()->tableView()->selectRow(0); popup()->tableView()->setHighlightedRecord(0); } } if (show && internalEditor() && !internalEditor()->isVisible()) /*emit*/editRequested(); QPoint posMappedToGlobal = mapFromParentToGlobal(thisWidget->pos()); if (posMappedToGlobal != QPoint(-1, -1)) { //! todo alter the position to fit the popup within screen boundaries popup()->hide(); popup()->move(posMappedToGlobal + QPoint(0, thisWidget->height())); //kDebug() << "pos:" << posMappedToGlobal + QPoint(0, thisWidget->height()); //to avoid flickering: first resize to 0-height, then show and resize back to prev. height const int w = popupWidthHint(); popup()->resize(w, 0); if (show) { popup()->show(); //kDebug(44010) << "SHOW!!!"; } popup()->updateSize(w); if (m_updatePopupSelectionOnShow) { int rowToHighlight = -1; KexiDB::LookupFieldSchema *lookupFieldSchema = this->lookupFieldSchema(); KexiTableViewData *relData = column() ? column()->relatedData() : 0; if (lookupFieldSchema) { rowToHighlight = rowToHighlightForLookupTable(); } else if (relData) { (void)valueForString(origValue().toString(), &rowToHighlight, 0, 1); } else //enum hint rowToHighlight = origValue().toInt(); /*-->*/ m_moveCursorToEndInInternalEditor_enabled = show; m_selectAllInInternalEditor_enabled = show; m_setValueInInternalEditor_enabled = show; if (rowToHighlight == -1) { rowToHighlight = qMax(popup()->tableView()->highlightedRecord(), 0); setValueInInternalEditor(QVariant()); } popup()->tableView()->selectRow(rowToHighlight); popup()->tableView()->setHighlightedRecord(rowToHighlight); if (rowToHighlight < popup()->tableView()->rowsPerPage()) popup()->tableView()->ensureCellVisible(0, -1); /*-->*/ m_moveCursorToEndInInternalEditor_enabled = true; m_selectAllInInternalEditor_enabled = true; m_setValueInInternalEditor_enabled = true; } } if (show) { moveCursorToEndInInternalEditor(); selectAllInInternalEditor(); widgetToFocus->setFocus(); popup()->show(); popup()->raise(); popup()->repaint(); } m_insideCreatePopup = false; }