kexi
kexidbautofield.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KEXIDBAUTOFIELD_H
00023 #define KEXIDBAUTOFIELD_H
00024
00025 #include <qwidget.h>
00026 #include <kexidb/field.h>
00027 #include <formeditor/container.h>
00028 #include "kexiformdataiteminterface.h"
00029
00030 class QBoxLayout;
00031 class QLabel;
00032
00034
00035 class KEXIFORMUTILS_EXPORT KexiDBAutoField :
00036 public QWidget,
00037 public KexiFormDataItemInterface,
00038 public KFormDesigner::DesignTimeDynamicChildWidgetHandler
00039 {
00040 Q_OBJECT
00041
00042 Q_OVERRIDE(QString caption READ caption WRITE setCaption DESIGNABLE true)
00043 Q_PROPERTY(bool autoCaption READ hasAutoCaption WRITE setAutoCaption DESIGNABLE true)
00044 Q_PROPERTY(QString dataSource READ dataSource WRITE setDataSource DESIGNABLE true)
00045 Q_PROPERTY(QCString dataSourceMimeType READ dataSourceMimeType WRITE setDataSourceMimeType DESIGNABLE true)
00046 Q_PROPERTY(LabelPosition labelPosition READ labelPosition WRITE setLabelPosition DESIGNABLE true)
00047 Q_PROPERTY(WidgetType widgetType READ widgetType WRITE setWidgetType DESIGNABLE true)
00048
00049 Q_PROPERTY(int fieldTypeInternal READ fieldTypeInternal WRITE setFieldTypeInternal DESIGNABLE true STORED false)
00050 Q_PROPERTY(QString fieldCaptionInternal READ fieldCaptionInternal WRITE setFieldCaptionInternal DESIGNABLE true STORED false)
00051 Q_ENUMS( WidgetType LabelPosition )
00052
00053 public:
00054 enum WidgetType { Auto = 100, Text, Integer, Double, Boolean, Date, Time, DateTime,
00055 MultiLineText, Enum, Image };
00056 enum LabelPosition { Left = 300, Top, NoLabel };
00057
00058 KexiDBAutoField(const QString &text, WidgetType type, LabelPosition pos, QWidget *parent = 0, const char *name = 0, bool designMode = true);
00059 KexiDBAutoField(QWidget *parent = 0, const char *name = 0, bool designMode = true);
00060
00061 virtual ~KexiDBAutoField();
00062
00063 inline QString dataSource() const { return KexiFormDataItemInterface::dataSource(); }
00064 inline QCString dataSourceMimeType() const { return KexiFormDataItemInterface::dataSourceMimeType(); }
00065 virtual void setDataSource( const QString &ds );
00066 virtual void setDataSourceMimeType(const QCString &ds) { KexiFormDataItemInterface::setDataSourceMimeType(ds); }
00067 virtual void setColumnInfo(KexiDB::QueryColumnInfo* cinfo);
00068
00069 virtual void setInvalidState(const QString& text);
00070 virtual bool isReadOnly() const;
00071
00072 virtual QVariant value();
00073 virtual bool valueIsNull();
00074 virtual bool valueIsEmpty();
00075 virtual bool valueChanged();
00076 virtual void clear();
00077
00079 virtual void installListener(KexiDataItemChangesListener* listener);
00080
00081 WidgetType widgetType() const { return m_widgetType_property; }
00082 void setWidgetType(WidgetType type);
00083
00084 LabelPosition labelPosition() const { return m_lblPosition; }
00085 void setLabelPosition(LabelPosition position);
00086
00087 QString caption() const { return m_caption; }
00088 void setCaption(const QString &caption);
00089
00090 bool hasAutoCaption() const { return m_autoCaption; }
00091 void setAutoCaption(bool autoCaption);
00092
00093 QWidget* editor() const { return m_editor; }
00094 QLabel* label() const { return m_label; }
00095
00096 virtual bool cursorAtStart();
00097 virtual bool cursorAtEnd();
00098
00099 static WidgetType widgetTypeForFieldType(KexiDB::Field::Type type);
00100
00104 void setFieldTypeInternal(int kexiDBFieldType);
00105
00109 void setFieldCaptionInternal(const QString& text);
00110
00112 int fieldTypeInternal() const { return m_fieldTypeInternal; }
00113
00115 QString fieldCaptionInternal() const { return m_fieldCaptionInternal; }
00116
00117 virtual QSize sizeHint() const;
00118 virtual void setFocusPolicy ( FocusPolicy policy );
00119
00120 protected:
00121 virtual void setValueInternal(const QVariant&add, bool removeOld);
00122 void init(const QString &text, WidgetType type, LabelPosition pos);
00123 void createEditor();
00124 void changeText(const QString &text, bool beautify = true);
00125
00126 void updateInformationAboutUnboundField();
00127
00128 protected slots:
00129 void slotValueChanged();
00130 virtual void paletteChange( const QPalette& oldPal );
00131
00132 private:
00133 WidgetType m_widgetType;
00134
00135 WidgetType m_widgetType_property;
00136 LabelPosition m_lblPosition;
00137 QBoxLayout *m_layout;
00138 QLabel *m_label;
00139 QWidget *m_editor;
00140 QString m_caption;
00141 KexiDB::Field::Type m_fieldTypeInternal;
00142 QString m_fieldCaptionInternal;
00143 bool m_autoCaption : 1;
00144 bool m_focusPolicyChanged : 1;
00145 bool m_designMode : 1;
00146 };
00147
00148 #endif
|