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>
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.
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.
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.
21
#ifndef KEXIFORMVIEW_H
22
#define KEXIFORMVIEW_H
25
#include <QDragMoveEvent>
26
#include <QResizeEvent>
29
#include <widget/kexidataawareview.h>
31
#include <core/KexiWindow.h>
32
#include <core/KexiWindowData.h>
33
#include <core/kexiblobbuffer.h>
34
#include <formeditor/form.h>
36
#include "kexiformpart.h"
40
class KexiFormScrollView;
45
namespace KFormDesigner
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.
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.
61
class KEXIFORMUTILS_EXPORT KexiFormView : public KexiDataAwareView
68
ResizeDefault = ResizeAuto,
70
NoResize = 2 /*! @todo */
73
KexiFormView(QWidget *parent, bool dbAware = true);
74
virtual ~KexiFormView();
76
// KexiDB::Connection* connection() { return m_conn; }
78
virtual QSize preferredSizeHint(const QSize& otherSize);
80
int resizeMode() const {
84
KFormDesigner::Form* form() const { return m_form; }
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.
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).
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.
98
void setUnsavedLocalBLOB(QWidget *widget, KexiBLOBBuffer::Id_t id);
101
/*! Reimplemented to update resize policy. */
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.
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.
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));
123
//2.0 changed void slotPropertySetSwitched(KoProperty::Set *b, bool forceReload = false,
124
//2.0 changed const QByteArray& propertyToSelect = QByteArray());
125
void slotPropertySetSwitched();
127
//2.0 changed void slotDirty(KFormDesigner::Form *f, bool isDirty);
130
void slotFocus(bool in);
132
void slotHandleDragMoveEvent(QDragMoveEvent* e);
134
//! Handles field(s) dropping from the data source pane onto the form
135
//! @see insertAutoFields()
136
void slotHandleDropEvent(QDropEvent* e);
138
void slotWidgetSelectionChanged(QWidget *w, KFormDesigner::Form::WidgetSelectionFlags flags);
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();
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);
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;
155
virtual KexiDB::SchemaData* storeNewData(const KexiDB::SchemaData& sdata, bool &cancel);
156
virtual tristate storeData(bool dontAsk = false);
158
KexiFormPart::TempData* tempData() const {
159
return dynamic_cast<KexiFormPart::TempData*>(window()->data());
161
KexiFormPart* formPart() const {
162
return dynamic_cast<KexiFormPart*>(part());
165
//moved to formmanager void disableWidgetActions();
166
//moved to formmanager void enableFormActions();
168
void setForm(KFormDesigner::Form *f);
174
//! Used in loadForm()
175
void updateAutoFieldsDataSource();
177
//! Used in loadForm()
178
void updateValuesForSubproperties();
180
virtual void resizeEvent(QResizeEvent *);
182
void initDataSource();
184
virtual void setFocusInternal();
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();*/
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();
203
void updateDataSourcePage();
205
/*! Reimplemented after KexiView.
206
Updates actions (e.g. availability). */
207
virtual void updateActions(bool activated);
209
//! Updates internal actions specific to forms.
210
//! @todo merge with other "update" routines?
211
void updateActionsInternal();
213
KexiDBForm *m_dbform;
214
KexiFormScrollView *m_scrollView;
215
//2.0 KoProperty::Set *m_propertySet;
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;
225
KexiDB::QuerySchema* m_query;
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. */
232
KexiDB::Cursor *m_cursor;
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;
239
//! Used in setFocusInternal()
240
QPointer<QWidget> m_setFocusInternalOnce;
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;
249
//! Cached form pointer
250
QPointer<KFormDesigner::Form> m_form;