1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/* This file is part of the KDE project
Copyright (C) 2002 Peter Simonsson <[email protected]>
Copyright (C) 2003-2007 Jaroslaw Staniek <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _KEXICOMBOBOXBASE_H_
#define _KEXICOMBOBOXBASE_H_
#include "kexidb/field.h"
#include "kexiinputtableedit.h"
#include <kexidb/lookupfieldschema.h>
class KPushButton;
class KLineEdit;
class KexiComboBoxPopup;
class KexiTableItem;
class KexiTableViewColumn;
/*! @short A base class for handling data-aware combo boxes.
This class is used by KexiComboBoxTableEdit and KexiDBComboBox.
*/
class KEXIDATATABLE_EXPORT KexiComboBoxBase
{
public:
KexiComboBoxBase();
virtual ~KexiComboBoxBase();
//! \return column related to this combo; for KexiComboBoxTableEdit 0 is returned here
virtual KexiTableViewColumn *column() const = 0;
//! \return database field related to this combo
virtual KexiDB::Field *field() const = 0;
//! \return the original value
virtual TQVariant origValue() const = 0;
//! Note: Generally in current implementation this is integer > 0; may be null if no value is set
virtual TQVariant value();
virtual TQVariant visibleValue();
//! Reimplement this and call this impl.: used to clear internal editor
virtual void clear();
virtual tristate valueChangedInternal();
virtual bool valueIsNull();
virtual bool valueIsEmpty();
public:
virtual void hide();
void createPopup(bool show);
void showPopup();
//! Call this from slot
virtual void slotRowAccepted(KexiTableItem *item, int row);
//! Call this from slot
virtual void slotItemSelected(KexiTableItem*);
//! Call this from slot
void slotInternalEditorValueChanged(const TQVariant &v);
//! Implement this to return the internal editor
virtual TQWidget *internalEditor() const = 0;
protected:
virtual void setValueInternal(const TQVariant& add, bool removeOld);
//! Used to select row item for an user-entered value \a v.
//! Only for "lookup table" mode.
KexiTableItem* selectItemForEnteredValueInLookupTable(const TQVariant& v);
/*! \return value from \a returnFromColumn related to \a str value from column \a lookInColumn.
If \a allowNulls is true, NULL is returend if no matched column found, else:
\a str is returned.
Example: lookInColumn=0, returnFromColumn=1 --returns user-visible string
for column #1 for id-column #0 */
TQString valueForString(const TQString& str, int* row, uint lookInColumn,
uint returnFromColumn, bool allowNulls = false);
//! sets \a value for the line edit without setting a flag (m_userEnteredValue) that indicates that
//! the text has been entered by hand (by a user)
void setValueOrTextInInternalEditor(const TQVariant& value); //TQString& text);
//! \return lookup field schema for this combo box, if present and if is valid (i.e. has defined row source)
KexiDB::LookupFieldSchema* lookupFieldSchema() const;
int rowToHighlightForLookupTable() const;
//! Implement this to perform "move cursor to end" in the internal editor
virtual void moveCursorToEndInInternalEditor() = 0;
//! Implement this to perform "select all" in the internal editor
virtual void selectAllInInternalEditor() = 0;
//! Implement this to perform "set value" in the internal editor
virtual void setValueInInternalEditor(const TQVariant& value) = 0;
//! Implement this to return value from the internal editor
virtual TQVariant valueFromInternalEditor() = 0;
//! Implement this as signal
virtual void editRequested() = 0;
//! Implement this as signal
virtual void acceptRequested() = 0;
//! Implement this to return a position \a pos mapped from parent (e.g. viewport)
//! to global coordinates. TQPoint(-1, -1) should be returned if this cannot be computed.
virtual TQPoint mapFromParentToGlobal(const TQPoint& pos) const = 0;
//! Implement this to return a hint for popup width.
virtual int popupWidthHint() const = 0;
//! Implement this to update button state. Table view just updates on/off state
//! for the button depending on visibility of the popup
virtual void updateButton() {}
virtual KexiComboBoxPopup *popup() const = 0;
virtual void setPopup(KexiComboBoxPopup *popup) = 0;
virtual TQVariant visibleValueForLookupField();
void updateTextForHighlightedRow();
bool handleKeyPressForPopup( TQKeyEvent *ke );
void acceptPopupSelection();
//! Used by KexiDBComboBox.
void undoChanges();
TQVariant m_visibleValue;
TQVariant m_userEnteredValue; //!< value (usually a text) entered by hand (by the user)
bool m_internalEditorValueChanged : 1; //!< true if user has text or other value inside editor
bool m_slotInternalEditorValueChanged_enabled : 1; //!< Used in slotInternalEditorValueChanged()
bool m_setValueOrTextInInternalEditor_enabled : 1; //!< Used in setValueOrTextInInternalEditor() and slotItemSelected()
bool m_mouseBtnPressedWhenPopupVisible : 1; //!< Used only by KexiComboBoxTableEdit
bool m_insideCreatePopup : 1; //!< true if we're inside createPopup(); used in slotItemSelected()
bool m_updatePopupSelectionOnShow : 1; //!< Set to false as soon as the item corresponding with the current
//!< value is selected in the popup table. This avoids selecting item
//!< for origValue() and thus loosing the recent choice.
bool m_moveCursorToEndInInternalEditor_enabled : 1;
bool m_selectAllInInternalEditor_enabled : 1;
bool m_setValueInInternalEditor_enabled : 1;
bool m_setVisibleValueOnSetValueInternal : 1; //!< Used in setValueInternal() to control whether
//!< we want to set visible value on setValueInternal()
//!< - true for table view's combo box
};
#endif
|