23#include <tqwindowsstyle.h>
26#include "kexicomboboxbase.h"
27#include <widget/utils/kexicomboboxdropdownbutton.h>
28#include "kexicomboboxpopup.h"
29#include "kexitableview.h"
30#include "kexitableitem.h"
35KexiComboBoxBase::KexiComboBoxBase()
43 m_moveCursorToEndInInternalEditor_enabled =
true;
44 m_selectAllInInternalEditor_enabled =
true;
45 m_setValueInInternalEditor_enabled =
true;
49KexiComboBoxBase::~KexiComboBoxBase()
68 if (!lookupFieldSchema)
75 KexiTableViewData *tvData = popup()->tableView()->KexiDataAwareObjectInterface::data();
77 KexiTableViewData::Iterator it(tvData->iterator());
79 for (;it.current();++it, row++)
81 if (it.current()->at(boundColumn).toInt(&ok) == rowUid && ok || !ok)
84 if (!ok || !it.current())
94 TQString add(add_.toString());
98 bool hasValueToSet =
true;
99 int rowToHighlight = -1;
101 if (lookupFieldSchema) {
114 popup()->tableView()->setHighlightedRow(rowToHighlight);
119 KexiTableItem *it = popup()->tableView()->highlightedItem();
121 valueToSet = it->at( visibleColumn );
124 hasValueToSet =
false;
135 valueToSet =
field()->enumHint(row).stripWhiteSpace();
144 popup()->tableView()->clearSelection();
145 popup()->tableView()->setHighlightedRow(0);
148 if (rowToHighlight!=-1)
149 popup()->tableView()->setHighlightedRow(rowToHighlight);
153 popup()->tableView()->setHighlightedRow(
origValue().toInt());
161 popup()->tableView()->clearSelection();
176 const bool valueIsText = v.type()==TQVariant::String || v.type()==TQVariant::CString;
177 const TQString txt( valueIsText ? v.toString().stripWhiteSpace().lower() : TQString() );
178 KexiTableViewData *lookupData = popup()->tableView()->KexiDataAwareObjectInterface::data();
179 const int visibleColumn =
lookupFieldSchema->visibleColumn( lookupData->columnsCount() );
180 if (-1 == visibleColumn)
182 KexiTableViewData::Iterator it(lookupData->iterator());
184 for (row = 0;it.current();++it, row++) {
186 if (it.current()->at(visibleColumn).toString().stripWhiteSpace().lower() == txt)
190 if (it.current()->at(visibleColumn) == v)
198 popup()->tableView()->selectRow(row);
200 popup()->tableView()->clearSelection();
208 uint lookInColumn, uint returnFromColumn,
bool allowNulls)
217 const TQString txt = str.stripWhiteSpace().lower();
218 KexiTableViewData::Iterator it( relData->iterator() );
219 for (*row = 0;it.current();++it, (*row)++) {
220 if (it.current()->at(lookInColumn).toString().stripWhiteSpace().lower()==txt)
224 return it.current()->at(returnFromColumn).toString();
231 kexiwarn <<
"KexiComboBoxBase::valueForString(): no related row found, ID will be painted!" << endl;
250 KexiTableItem *it = popup() ? popup()->tableView()->selectedItem() : 0;
258 KexiTableItem *it = popup() ? popup()->tableView()->selectedItem() : 0;
272 const int row = popup()->tableView()->currentRow();
274 return TQVariant( row );
284TQVariant KexiComboBoxBase::visibleValueForLookupField()
290 if (-1 == visibleColumn)
292 KexiTableItem *it = popup()->tableView()->
selectedItem();
293 return it ? it->at( TQMIN( (uint)visibleColumn, it->count()-1) ) : TQVariant();
296TQVariant KexiComboBoxBase::visibleValue()
298 return m_visibleValue;
308tristate KexiComboBoxBase::valueChangedInternal()
318 KexiTableItem *it = popup() ? popup()->tableView()->
selectedItem() : 0;
324 const int row = popup() ? popup()->tableView()->currentRow() : -1;
332bool KexiComboBoxBase::valueIsNull()
335 TQVariant v(
value() );
340bool KexiComboBoxBase::valueIsEmpty()
342 return valueIsNull();
345void KexiComboBoxBase::showPopup()
355 TQWidget* thisWidget =
dynamic_cast<TQWidget*
>(
this);
360 TQObject::connect(popup(), TQ_SIGNAL(rowAccepted(KexiTableItem*,
int)),
362 TQObject::connect(popup()->tableView(), TQ_SIGNAL(itemSelected(KexiTableItem*)),
365 popup()->setFocusProxy( widgetToFocus );
366 popup()->tableView()->setFocusProxy( widgetToFocus );
367 popup()->installEventFilter(thisWidget);
370 popup()->tableView()->clearSelection();
372 popup()->tableView()->selectRow( 0 );
373 popup()->tableView()->setHighlightedRow( 0 );
380 if (posMappedToGlobal != TQPoint(-1,-1)) {
382 popup()->move( posMappedToGlobal + TQPoint(0, thisWidget->height()) );
385 popup()->resize(w, 0);
388 popup()->updateSize(w);
390 int rowToHighlight = -1;
402 m_moveCursorToEndInInternalEditor_enabled = show;
403 m_selectAllInInternalEditor_enabled = show;
404 m_setValueInInternalEditor_enabled = show;
405 if (rowToHighlight==-1) {
406 rowToHighlight = TQMAX( popup()->tableView()->highlightedRow(), 0);
409 popup()->tableView()->selectRow( rowToHighlight );
410 popup()->tableView()->setHighlightedRow( rowToHighlight );
411 if (rowToHighlight < popup()->tableView()->rowsPerPage())
412 popup()->tableView()->ensureCellVisible( 0, -1 );
414 m_moveCursorToEndInInternalEditor_enabled =
true;
415 m_selectAllInInternalEditor_enabled =
true;
416 m_setValueInInternalEditor_enabled =
true;
423 widgetToFocus->setFocus();
428void KexiComboBoxBase::hide()
444void KexiComboBoxBase::acceptPopupSelection()
448 KexiTableItem *item = popup()->tableView()->highlightedItem();
450 popup()->tableView()->selectRow( popup()->tableView()->highlightedRow() );
458 kexidbg <<
"KexiComboBoxBase::slotItemSelected(): m_visibleValue = " << m_visibleValue << endl;
460 TQVariant valueToSet;
468 KexiTableItem *item = popup()->tableView()->selectedItem();
470 valueToSet = item->at(1);
473 KexiTableItem *item = popup()->tableView()->selectedItem();
475 if (item && visibleColumn!=-1 ) {
476 valueToSet = item->at( TQMIN( (uint)visibleColumn, item->count()-1) );
481 valueToSet =
field()->enumHint( popup()->tableView()->currentRow() );
484 TQWidget* thisWidget =
dynamic_cast<TQWidget*
>(
this);
485 thisWidget->parentWidget()->setFocus();
504 if (v.toString().isEmpty()) {
506 popup()->tableView()->clearSelection();
522bool KexiComboBoxBase::handleKeyPressForPopup( TQKeyEvent *ke )
524 const int k = ke->key();
525 int highlightedOrSelectedRow = popup() ? popup()->tableView()->
highlightedRow() : -1;
526 if (popup() && highlightedOrSelectedRow < 0)
527 highlightedOrSelectedRow = popup()->tableView()->
currentRow();
529 const bool enterPressed = k==TQt::Key_Enter || k==TQt::Key_Return;
534 if (!popup() || (!enterPressed && !popup()->isVisible())) {
540 popup()->tableView()->setHighlightedRow(
541 TQMAX(highlightedOrSelectedRow-1, 0) );
542 updateTextForHighlightedRow();
545 popup()->tableView()->setHighlightedRow(
546 TQMIN(highlightedOrSelectedRow+1, popup()->tableView()->rows()-1) );
547 updateTextForHighlightedRow();
549 case TQt::Key_PageUp:
550 popup()->tableView()->setHighlightedRow(
551 TQMAX(highlightedOrSelectedRow-popup()->tableView()->rowsPerPage(), 0) );
552 updateTextForHighlightedRow();
554 case TQt::Key_PageDown:
555 popup()->tableView()->setHighlightedRow(
556 TQMIN(highlightedOrSelectedRow+popup()->tableView()->rowsPerPage(),
557 popup()->tableView()->rows()-1) );
558 updateTextForHighlightedRow();
561 popup()->tableView()->setHighlightedRow( 0 );
562 updateTextForHighlightedRow();
565 popup()->tableView()->setHighlightedRow( popup()->tableView()->rows()-1 );
566 updateTextForHighlightedRow();
569 case TQt::Key_Return:
571 if (popup()->tableView()->highlightedRow()>=0)
572 popup()->tableView()->selectRow( popup()->tableView()->highlightedRow() );
579void KexiComboBoxBase::updateTextForHighlightedRow()
581 KexiTableItem *item = popup() ? popup()->tableView()->highlightedItem() : 0;
589 if (lookupFieldSchema) {
592 popup()->tableView()->selectRow( popup()->tableView()->highlightedRow() );
593 m_visibleValue = visibleValueForLookupField();
bool m_mouseBtnPressedWhenPopupVisible
Used only by KexiComboBoxTableEdit.
TQVariant m_userEnteredValue
value (usually a text) entered by hand (by the user)
virtual TQVariant valueFromInternalEditor()=0
Implement this to return value from the internal editor.
virtual void moveCursorToEndInInternalEditor()=0
Implement this to perform "move cursor to end" in the internal editor.
virtual void editRequested()=0
Implement this as signal.
virtual void slotItemSelected(KexiTableItem *)
Call this from slot.
virtual KexiTableViewColumn * column() const =0
virtual TQWidget * internalEditor() const =0
Implement this to return the internal editor.
virtual TQVariant value()
Note: Generally in current implementation this is integer > 0; may be null if no value is set.
bool m_setVisibleValueOnSetValueInternal
KexiTableItem * selectItemForEnteredValueInLookupTable(const TQVariant &v)
virtual void setValueInInternalEditor(const TQVariant &value)=0
Implement this to perform "set value" in the internal editor.
void setValueOrTextInInternalEditor(const TQVariant &value)
void createPopup(bool show)
virtual TQPoint mapFromParentToGlobal(const TQPoint &pos) const =0
virtual TQVariant origValue() const =0
virtual void slotRowAccepted(KexiTableItem *item, int row)
Call this from slot.
virtual void clear()
Reimplement this and call this impl.: used to clear internal editor.
virtual int popupWidthHint() const =0
Implement this to return a hint for popup width.
bool m_setValueOrTextInInternalEditor_enabled
Used in setValueOrTextInInternalEditor() and slotItemSelected().
KexiDB::LookupFieldSchema * lookupFieldSchema() const
virtual void acceptRequested()=0
Implement this as signal.
bool m_updatePopupSelectionOnShow
TQString valueForString(const TQString &str, int *row, uint lookInColumn, uint returnFromColumn, bool allowNulls=false)
bool m_internalEditorValueChanged
true if user has text or other value inside editor
virtual void setValueInternal(const TQVariant &add, bool removeOld)
virtual void updateButton()
virtual KexiDB::Field * field() const =0
void slotInternalEditorValueChanged(const TQVariant &v)
Call this from slot.
bool m_slotInternalEditorValueChanged_enabled
Used in slotInternalEditorValueChanged().
void undoChanges()
Used by KexiDBComboBox.
bool m_insideCreatePopup
true if we're inside createPopup(); used in slotItemSelected()
virtual void selectAllInInternalEditor()=0
Implement this to perform "select all" in the internal editor.
int rowToHighlightForLookupTable() const
virtual TableSchema * table() const
Provides information about lookup field's setup.
int visibleColumn(uint fieldsCount) const
LookupFieldSchema * lookupFieldSchema(const Field &field) const
KexiTableViewData * data() const
KexiTableItem * selectedItem() const
KexiTableViewData * relatedData() const
int highlightedRow() const
3-state logical type with three values: true, false and cancelled and convenient operators.