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

« back to all changes in this revision

Viewing changes to src/plugins/forms/widgets/kexidbautofield.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) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
 
3
   Copyright (C) 2005 Christian Nitschkowski <segfault_ii@web.de>
 
4
   Copyright (C) 2005-2006 Jarosław Staniek <staniek@kde.org>
 
5
 
 
6
   This program is free software; you can redistribute it and/or
 
7
   modify it under the terms of the GNU Library General Public
 
8
   License as published by the Free Software Foundation; either
 
9
   version 2 of the License, or (at your option) any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
   Library General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU Library General Public License
 
17
   along with this program; see the file COPYING.  If not, write to
 
18
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
*/
 
21
 
 
22
#ifndef KEXIDBAUTOFIELD_H
 
23
#define KEXIDBAUTOFIELD_H
 
24
 
 
25
#include "kexiformutils_export.h"
 
26
#include <formeditor/container.h>
 
27
#include <formeditor/widgetwithsubpropertiesinterface.h>
 
28
#include <formeditor/FormWidgetInterface.h>
 
29
#include <widget/dataviewcommon/kexiformdataiteminterface.h>
 
30
 
 
31
#include <KDbField>
 
32
 
 
33
#include <QWidget>
 
34
#include <QLabel>
 
35
 
 
36
class QLabel;
 
37
 
 
38
//! Universal "Auto Field" widget for Kexi forms
 
39
/*! It acts as a container for most data-aware widgets. */
 
40
class KEXIFORMUTILS_EXPORT KexiDBAutoField :
 
41
            public QWidget,
 
42
            public KexiFormDataItemInterface,
 
43
            public KFormDesigner::DesignTimeDynamicChildWidgetHandler,
 
44
            public KFormDesigner::WidgetWithSubpropertiesInterface,
 
45
            public KFormDesigner::FormWidgetInterface
 
46
{
 
47
    Q_OBJECT
 
48
//'caption' is uncovered now Q_PROPERTY(QString labelCaption READ caption WRITE setCaption)
 
49
    Q_PROPERTY(QString caption READ caption WRITE setCaption)
 
50
    Q_PROPERTY(QColor foregroundLabelColor READ foregroundLabelColor WRITE setForegroundLabelColor RESET unsetPalette)
 
51
    Q_PROPERTY(QColor backgroundLabelColor READ backgroundLabelColor WRITE setBackgroundLabelColor RESET unsetPalette)
 
52
    Q_PROPERTY(bool autoCaption READ hasAutoCaption WRITE setAutoCaption)
 
53
    Q_PROPERTY(QString dataSource READ dataSource WRITE setDataSource)
 
54
    Q_PROPERTY(QString dataSourcePartClass READ dataSourcePluginId WRITE setDataSourcePluginId)
 
55
    Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
 
56
    Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition)
 
57
    Q_PROPERTY(WidgetType widgetType READ widgetType WRITE setWidgetType)
 
58
    /*internal, for design time only*/
 
59
    Q_PROPERTY(int fieldTypeInternal READ fieldTypeInternal WRITE setFieldTypeInternal STORED false)
 
60
    Q_PROPERTY(QString fieldCaptionInternal READ fieldCaptionInternal WRITE setFieldCaptionInternal STORED false)
 
61
 
 
62
public:
 
63
    enum WidgetType { Auto = 100, Text, Integer, Double, Boolean, Date, Time, DateTime,
 
64
                      MultiLineText, ComboBox, Image
 
65
                    };
 
66
    Q_ENUM(WidgetType)
 
67
    enum LabelPosition { Left = 300, Top, NoLabel };
 
68
    Q_ENUM(LabelPosition)
 
69
 
 
70
    KexiDBAutoField(const QString &text, WidgetType type, LabelPosition pos,
 
71
                    QWidget *parent = 0);
 
72
    explicit KexiDBAutoField(QWidget *parent = 0, LabelPosition pos = Left);
 
73
 
 
74
    virtual ~KexiDBAutoField();
 
75
 
 
76
    inline QString dataSource() const {
 
77
        return KexiFormDataItemInterface::dataSource();
 
78
    }
 
79
    inline QString dataSourcePluginId() const {
 
80
        return KexiFormDataItemInterface::dataSourcePluginId();
 
81
    }
 
82
    virtual void setDataSource(const QString &ds);
 
83
    virtual void setDataSourcePluginId(const QString &pluginId) {
 
84
        KexiFormDataItemInterface::setDataSourcePluginId(pluginId);
 
85
    }
 
86
    virtual void setColumnInfo(KDbQueryColumnInfo* cinfo);
 
87
 
 
88
    virtual void setInvalidState(const QString& text);
 
89
    virtual bool isReadOnly() const;
 
90
    virtual void setReadOnly(bool readOnly);
 
91
 
 
92
    virtual QVariant value();
 
93
    virtual bool valueIsNull();
 
94
    virtual bool valueIsEmpty();
 
95
    virtual bool valueIsValid();
 
96
    virtual bool valueChanged();
 
97
    virtual void clear();
 
98
 
 
99
    //! Reimplemented to also install \a listenter for internal editor
 
100
    virtual void installListener(KexiDataItemChangesListener* listener);
 
101
 
 
102
    WidgetType widgetType() const;
 
103
    void setWidgetType(WidgetType type);
 
104
 
 
105
    LabelPosition labelPosition() const;
 
106
    virtual void setLabelPosition(LabelPosition position);
 
107
 
 
108
    QString caption() const;
 
109
    void setCaption(const QString &caption);
 
110
 
 
111
    bool hasAutoCaption() const;
 
112
    void setAutoCaption(bool autoCaption);
 
113
 
 
114
    /*! If \a displayDefaultValue is true, the value set by KexiDataItemInterface::setValue()
 
115
     is displayed in a special way. Used by KexiFormDataProvider::fillDataItems().
 
116
     \a widget is equal to 'this'.
 
117
     Reimplemented after KexiFormDataItemInterface. */
 
118
    virtual void setDisplayDefaultValue(QWidget* widget, bool displayDefaultValue);
 
119
 
 
120
    QWidget* editor() const;
 
121
    QLabel* label() const;
 
122
 
 
123
    virtual bool cursorAtStart();
 
124
    virtual bool cursorAtEnd();
 
125
 
 
126
    static WidgetType widgetTypeForFieldType(KDbField::Type type);
 
127
 
 
128
    /*! On design time it is not possible to pass a reference to KDbField object
 
129
     so we're just providing field type. Only used when widget type is Auto.
 
130
     @internal */
 
131
    void setFieldTypeInternal(int kexiDBFieldType);
 
132
 
 
133
    /*! On design time it is not possible to pass a reference to KDbField object
 
134
     so we're just providing field caption. Only used when widget type is Auto.
 
135
     @internal */
 
136
    void setFieldCaptionInternal(const QString& text);
 
137
 
 
138
    /*! @internal */
 
139
    int fieldTypeInternal() const;
 
140
 
 
141
    /*! @internal */
 
142
    QString fieldCaptionInternal() const;
 
143
 
 
144
    virtual QSize sizeHint() const;
 
145
    virtual void setFocusPolicy(Qt::FocusPolicy policy);
 
146
 
 
147
    //! Reimplemented to return internal editor's color.
 
148
    QColor paletteForegroundColor() const;
 
149
 
 
150
    //! Reimplemented to set internal editor's color.
 
151
    void setPaletteForegroundColor(const QColor & color);
 
152
 
 
153
    //! Reimplemented to return internal editor's color.
 
154
    QColor paletteBackgroundColor() const;
 
155
 
 
156
    //! Reimplemented to set internal editor's color.
 
157
    virtual void setPaletteBackgroundColor(const QColor & color);
 
158
 
 
159
    //! \return label's foreground color
 
160
    QColor foregroundLabelColor() const;
 
161
 
 
162
    //! Sets label's foreground color
 
163
    virtual void setForegroundLabelColor(const QColor & color);
 
164
 
 
165
    //! \return label's background color
 
166
    QColor backgroundLabelColor() const;
 
167
 
 
168
    //! Sets label's background color
 
169
    virtual void setBackgroundLabelColor(const QColor & color);
 
170
 
 
171
    //! Reimplemented to accept subproperties. @see KFormDesigner::WidgetWithSubpropertiesInterface
 
172
    virtual QVariant property(const char * name) const;
 
173
 
 
174
    //! Reimplemented to accept subproperties. @see KFormDesigner::WidgetWithSubpropertiesInterface
 
175
    virtual bool setProperty(const char * name, const QVariant & value);
 
176
 
 
177
    /*! Called by the top-level form on key press event to consume widget-specific shortcuts. */
 
178
    virtual bool keyPressed(QKeyEvent *ke);
 
179
 
 
180
public Q_SLOTS:
 
181
    virtual void unsetPalette();
 
182
 
 
183
protected Q_SLOTS:
 
184
    virtual void paletteChange(const QPalette& oldPal);
 
185
 
 
186
    //! Implemented for KexiDataItemInterface
 
187
    virtual void moveCursorToEnd();
 
188
 
 
189
    //! Implemented for KexiDataItemInterface
 
190
    virtual void moveCursorToStart();
 
191
 
 
192
    //! Implemented for KexiDataItemInterface
 
193
    virtual void selectAll();
 
194
 
 
195
protected:
 
196
    virtual void setValueInternal(const QVariant&add, bool removeOld);
 
197
    void init(const QString &text, WidgetType type, LabelPosition pos);
 
198
    virtual void createEditor();
 
199
    void changeText(const QString &text, bool beautify = true);
 
200
    void updateInformationAboutUnboundField();
 
201
 
 
202
    //! internal editor can be created too late, so certain properties should be copied
 
203
    void copyPropertiesToEditor();
 
204
 
 
205
    virtual bool eventFilter(QObject *o, QEvent *e);
 
206
 
 
207
    //! Used by @ref setLabelPositionInternal(LabelPosition)
 
208
    void setLabelPositionInternal(LabelPosition position, bool noLabel);
 
209
 
 
210
    //! Used by KexiDBAutoField::setColumnInfo() and KexiDBComboBox::setColumnInfo()
 
211
    void setColumnInfoInternal(KDbQueryColumnInfo* cinfo, KDbQueryColumnInfo* visibleColumnInfo);
 
212
 
 
213
private:
 
214
    class Private;
 
215
    Private * const d;
 
216
};
 
217
 
 
218
#endif