~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kexi/plugins/forms/kexiformview.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
 
3
   Copyright (C) 2004-2010 Jarosław Staniek <staniek@kde.org>
 
4
 
 
5
   This library 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 library 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 library; see the file COPYING.LIB.  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 KEXIFORMVIEW_H
 
22
#define KEXIFORMVIEW_H
 
23
 
 
24
#include <qtimer.h>
 
25
#include <QDragMoveEvent>
 
26
#include <QResizeEvent>
 
27
#include <QDropEvent>
 
28
 
 
29
#include <widget/kexidataawareview.h>
 
30
 
 
31
#include <core/KexiWindow.h>
 
32
#include <core/KexiWindowData.h>
 
33
#include <core/kexiblobbuffer.h>
 
34
#include <formeditor/form.h>
 
35
 
 
36
#include "kexiformpart.h"
 
37
 
 
38
class KexiFormPart;
 
39
class KexiDBForm;
 
40
class KexiFormScrollView;
 
41
namespace KexiDB
 
42
{
 
43
class Cursor;
 
44
}
 
45
namespace KFormDesigner
 
46
{
 
47
class Container;
 
48
}
 
49
 
 
50
//! The KexiFormView lass provides a data-driven (record-based) form view .
 
51
/*! The KexiFormView can display data provided "by hand"
 
52
 or from KexiDB-compatible database source.
 
53
 
 
54
 This class provides a single view used inside KexiWindow.
 
55
 It takes care of saving/loading form, of enabling actions when needed.
 
56
 One KexiFormView object is instantiated for data view mode
 
57
 and a second KexiFormView object is instantiated for design view mode.
 
58
 
 
59
 @see KexiDataTable
 
60
*/
 
61
class KEXIFORMUTILS_EXPORT KexiFormView : public KexiDataAwareView
 
62
{
 
63
    Q_OBJECT
 
64
 
 
65
public:
 
66
    enum ResizeMode {
 
67
        ResizeAuto = 0,
 
68
        ResizeDefault = ResizeAuto,
 
69
        ResizeFixed = 1,
 
70
        NoResize = 2 /*! @todo */
 
71
    };
 
72
 
 
73
    KexiFormView(QWidget *parent, bool dbAware = true);
 
74
    virtual ~KexiFormView();
 
75
 
 
76
//  KexiDB::Connection* connection() { return m_conn; }
 
77
 
 
78
    virtual QSize preferredSizeHint(const QSize& otherSize);
 
79
 
 
80
    int resizeMode() const {
 
81
        return m_resizeMode;
 
82
    }
 
83
 
 
84
    KFormDesigner::Form* form() const { return m_form; }
 
85
 
 
86
    /*! Assigns \a id local (static) BLOB's identifier for \a widget widget.
 
87
     Previously assigned BLOB will be usassigned.
 
88
     If \a id is 0, BLOB is unassigned and no new is assigned.
 
89
 
 
90
     This method is called when a widget supporting BLOB data
 
91
     (currently, images from KexiDBImageBox, within KexiDBFactory) has BLOB assigned by identifier \a id.
 
92
     BLOB identifiers are defined by KexiBLOBBuffer (KexiBLOBBuffer::self() instance).
 
93
 
 
94
     The data collected by this method is used on form's design saving (in design mode).
 
95
     Local BLOBs are retrieved KexiBLOBBuffer::self() and stored in "kexi__blobs" 'system' table.
 
96
     Note that db-aware BLOBs (non local) are not handled this way.
 
97
    */
 
98
    void setUnsavedLocalBLOB(QWidget *widget, KexiBLOBBuffer::Id_t id);
 
99
 
 
100
public slots:
 
101
    /*! Reimplemented to update resize policy. */
 
102
    virtual void show();
 
103
 
 
104
    /*! Inserts autofields onto the form at \a pos position.
 
105
     \a sourcePartClass can be "org.kexi-project.table" or "org.kexi-project.query",
 
106
     \a sourceName is a name of a table or query, \a fields is a list of fields to insert (one or more)
 
107
     Fields are inserted using standard KFormDesigner::InsertWidgetCommand framework,
 
108
     so undo/redo is available for this operation.
 
109
 
 
110
     If multiple fields are provided, they will be aligned vertically.
 
111
     If \a pos is QPoint(-1,-1) (the default), position is computed automatically
 
112
     based on a position last inserted field using this method.
 
113
     If this method has not been called yet, position of QPoint(40, 40) will be set.
 
114
 
 
115
     Called by:
 
116
     - slotHandleDropEvent() when field(s) are dropped from the data source pane onto the form
 
117
     - KexiFormManager is a used clicked "Insert fields" button on the data source pane. */
 
118
    void insertAutoFields(const QString& sourcePartClass, const QString& sourceName,
 
119
                          const QStringList& fields, KFormDesigner::Container* targetContainerWidget,
 
120
                          const QPoint& pos = QPoint(-1, -1));
 
121
 
 
122
protected slots:
 
123
//2.0 changed    void slotPropertySetSwitched(KoProperty::Set *b, bool forceReload = false,
 
124
//2.0 changed                                 const QByteArray& propertyToSelect = QByteArray());
 
125
    void slotPropertySetSwitched();
 
126
 
 
127
//2.0 changed    void slotDirty(KFormDesigner::Form *f, bool isDirty);
 
128
    void slotModified();
 
129
 
 
130
    void slotFocus(bool in);
 
131
 
 
132
    void slotHandleDragMoveEvent(QDragMoveEvent* e);
 
133
 
 
134
    //! Handles field(s) dropping from the data source pane onto the form
 
135
    //! @see insertAutoFields()
 
136
    void slotHandleDropEvent(QDropEvent* e);
 
137
 
 
138
    void slotWidgetSelectionChanged(QWidget *w, KFormDesigner::Form::WidgetSelectionFlags flags);
 
139
 
 
140
//moved to formmanager  void slotWidgetSelected(KFormDesigner::Form *form, bool multiple);
 
141
//moved to formmanager  void slotFormWidgetSelected(KFormDesigner::Form *form);
 
142
//moved to formmanager  void slotNoFormSelected();
 
143
 
 
144
//moved to formmanager  void setUndoEnabled(bool enabled);
 
145
//moved to formmanager  void setRedoEnabled(bool enabled);
 
146
    void slotWidgetNameChanged(const QByteArray& oldname, const QByteArray& newname);
 
147
 
 
148
protected:
 
149
    virtual tristate beforeSwitchTo(Kexi::ViewMode mode, bool &dontStore);
 
150
    virtual tristate afterSwitchFrom(Kexi::ViewMode mode);
 
151
    virtual KoProperty::Set* propertySet() {
 
152
        return &m_form->propertySet(); // 2.0 m_propertySet;
 
153
    }
 
154
 
 
155
    virtual KexiDB::SchemaData* storeNewData(const KexiDB::SchemaData& sdata, bool &cancel);
 
156
    virtual tristate storeData(bool dontAsk = false);
 
157
 
 
158
    KexiFormPart::TempData* tempData() const {
 
159
        return dynamic_cast<KexiFormPart::TempData*>(window()->data());
 
160
    }
 
161
    KexiFormPart* formPart() const {
 
162
        return dynamic_cast<KexiFormPart*>(part());
 
163
    }
 
164
 
 
165
//moved to formmanager  void disableWidgetActions();
 
166
//moved to formmanager  void enableFormActions();
 
167
 
 
168
    void setForm(KFormDesigner::Form *f);
 
169
 
 
170
    void initForm();
 
171
 
 
172
    void loadForm();
 
173
 
 
174
    //! Used in loadForm()
 
175
    void updateAutoFieldsDataSource();
 
176
 
 
177
    //! Used in loadForm()
 
178
    void updateValuesForSubproperties();
 
179
 
 
180
    virtual void resizeEvent(QResizeEvent *);
 
181
 
 
182
    void initDataSource();
 
183
 
 
184
    virtual void setFocusInternal();
 
185
 
 
186
    /*  // for navigator
 
187
        virtual void moveToRecordRequested(uint r);
 
188
        virtual void moveToLastRecordRequested();
 
189
        virtual void moveToPreviousRecordRequested();
 
190
        virtual void moveToNextRecordRequested();
 
191
        virtual void moveToFirstRecordRequested();
 
192
        virtual void addNewRecordRequested();*/
 
193
 
 
194
    /*! Called after loading the form contents (before showing it).
 
195
     Also called when the form window (KexiWindow) is detached
 
196
     (in KMDI's Child Frame mode), because otherwise tabstop ordering can get broken. */
 
197
    void updateTabStopsOrder();
 
198
 
 
199
    /*! @internal */
 
200
    void deleteQuery();
 
201
 
 
202
    /*! @internal */
 
203
    void updateDataSourcePage();
 
204
 
 
205
    /*! Reimplemented after KexiView.
 
206
     Updates actions (e.g. availability). */
 
207
    virtual void updateActions(bool activated);
 
208
 
 
209
    //! Updates internal actions specific to forms.
 
210
    //! @todo merge with other "update" routines?
 
211
    void updateActionsInternal();
 
212
 
 
213
    KexiDBForm *m_dbform;
 
214
    KexiFormScrollView *m_scrollView;
 
215
//2.0     KoProperty::Set *m_propertySet;
 
216
 
 
217
    /*! Database cursor used for data retrieving.
 
218
     It is shared between subsequent Data view sessions (just reopened on switch),
 
219
     but deleted and recreated from scratch when form's "dataSource" property changed
 
220
     since last form viewing (m_previousDataSourceString is used for that). */
 
221
    QString m_previousDataSourceString;
 
222
 
 
223
    int m_resizeMode;
 
224
 
 
225
    KexiDB::QuerySchema* m_query;
 
226
 
 
227
    /*! True, if m_query is created as temporary object within this form.
 
228
     If user selected an existing, predefined (stored) query, m_queryIsOwned will be false,
 
229
     so the query object will not be destroyed. */
 
230
    bool m_queryIsOwned;
 
231
 
 
232
    KexiDB::Cursor *m_cursor;
 
233
 
 
234
    /*! For new (empty) forms only:
 
235
     Our form's area will be resized more than once.
 
236
     We will resize form widget itself later (in resizeEvent()). */
 
237
    int m_delayedFormContentsResizeOnShow;
 
238
 
 
239
    //! Used in setFocusInternal()
 
240
    QPointer<QWidget> m_setFocusInternalOnce;
 
241
 
 
242
    /*! Stores geometry of widget recently inserted using insertAutoFields() method.
 
243
     having this information, we'r eable to compute position for a newly
 
244
     inserted widget in insertAutoFields() is such position has not been specified.
 
245
     (the position is specified when a widget is inserted with mouse drag & dropping
 
246
     but not with clicking of 'Insert fields' button from Data Source pane) */
 
247
    QRect m_widgetGeometryForRecentInsertAutoFields;
 
248
 
 
249
    //! Cached form pointer
 
250
    QPointer<KFormDesigner::Form> m_form;
 
251
};
 
252
 
 
253
#endif