~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/widget/tableview/kexicomboboxbase.h

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
Import upstream version 3.0.1.1

Show diffs side-by-side

added added

removed removed

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